当前位置: 首页>>代码示例>>C++>>正文


C++ IWICFormatConverter::CopyPixels方法代码示例

本文整理汇总了C++中IWICFormatConverter::CopyPixels方法的典型用法代码示例。如果您正苦于以下问题:C++ IWICFormatConverter::CopyPixels方法的具体用法?C++ IWICFormatConverter::CopyPixels怎么用?C++ IWICFormatConverter::CopyPixels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IWICFormatConverter的用法示例。


在下文中一共展示了IWICFormatConverter::CopyPixels方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: convert_file_icon

    static bool convert_file_icon(const HICON icon, Bmp& bmp) {
        static IWICImagingFactory* img_factory = 0;
        if (!img_factory) {
            // In VS 2011 beta, clsid has to be changed to CLSID_WICImagingFactory1 (from CLSID_WICImagingFactory)
            if (!SUCCEEDED(::CoInitialize(0)) || !SUCCEEDED(::CoCreateInstance(CLSID_WICImagingFactory1, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&img_factory)))) {
                return false;
            }
        }
        IWICBitmap* pBitmap = 0;
        IWICFormatConverter* pConverter = 0;
        UINT cx = 0, cy = 0;
	    if (SUCCEEDED(img_factory->CreateBitmapFromHICON(icon, &pBitmap))) {
		    if (SUCCEEDED(img_factory->CreateFormatConverter(&pConverter))) {
			    if (SUCCEEDED(pConverter->Initialize(pBitmap, GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, 0, 0.0f, WICBitmapPaletteTypeCustom))) {
				    if (SUCCEEDED(pConverter->GetSize(&cx, &cy))) {
						const UINT stride = cx * sizeof(DWORD);
						const UINT buf_size = cy * stride;
                        Byte* buf = new Byte[buf_size];
						pConverter->CopyPixels(0, stride, buf_size, buf);
                        bmp.load_bits_only(buf, buf_size, cx, -(int)cy);
                        delete [] buf;
				    }
			    }
			    pConverter->Release();
		    }
		    pBitmap->Release();
	    }
        return true;
    }
开发者ID:pawelt,项目名称:stacky,代码行数:29,代码来源:stacky.cpp

示例2: processImage

bool WICImageLoader::processImage(IWICBitmapDecoder* pDecoder)
{
    HRESULT hr = E_FAIL;
	IWICBitmapFrameDecode* pFrame = NULL;

	if(NULL != pDecoder)
	{
		hr = pDecoder->GetFrame(0, &pFrame);
	}

	if(SUCCEEDED(hr))
	{
		hr = pFrame->GetPixelFormat(&_format);
	}

	IWICFormatConverter* pConv = NULL;

	if(SUCCEEDED(hr))
	{
		hr = convertFormatIfRequired(pFrame, &pConv);
	}

	if(SUCCEEDED(hr))
	{
		_bpp = getBitsPerPixel(_format); 

		if(NULL != pConv) 
		{
			hr = pConv->GetSize((UINT*)&_width, (UINT*)&_height);
		}
		else
		{
			hr = pFrame->GetSize((UINT*)&_width, (UINT*)&_height);
		}
	}

	assert(_bpp > 0);
	assert(_width > 0 && _height > 0);

	if(SUCCEEDED(hr))
	{
		size_t rowPitch = (_width * _bpp + 7) / 8;
		_dataLen = rowPitch * _height;
		_data = new (std::nothrow) BYTE[_dataLen];

		if(NULL != pConv)
		{
			hr = pConv->CopyPixels(NULL, static_cast<UINT>(rowPitch), static_cast<UINT>(_dataLen), _data);
		}
		else
		{
			hr = pFrame->CopyPixels(NULL, static_cast<UINT>(rowPitch), static_cast<UINT>(_dataLen), _data);
		}
	}

	SafeRelease(&pFrame);
	SafeRelease(&pConv);
	return SUCCEEDED(hr);
}
开发者ID:602147629,项目名称:PlanetWar,代码行数:59,代码来源:WICImageLoader-winrt.cpp

示例3: SHCreateMemStream

void GL::Image::load(const unsigned char *buf, size_t bufSize)
{
    if (CoInitializeEx(NULL, COINIT_MULTITHREADED) != S_OK) {
        // bad!
        return;
    }
    IStream *stream = SHCreateMemStream((const BYTE*)buf, (UINT)bufSize);
    if (stream != NULL) {
        IWICImagingFactory *pFactory;
        if (CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (LPVOID*)&pFactory) == S_OK) {
            IWICBitmapDecoder *pDecoder;
            if (pFactory->CreateDecoderFromStream(stream, &CLSID_WICPngDecoder, WICDecodeMetadataCacheOnDemand, &pDecoder) == S_OK) {
                IWICBitmapFrameDecode *frame;
                if (pDecoder->GetFrame(0, &frame) == S_OK) {
                    UINT w, h;
                    if (frame->GetSize(&w, &h) == S_OK) {
                        width_ = w;
                        height_ = h;
                    }
                    IWICFormatConverter *formatConverter;
                    if (pFactory->CreateFormatConverter(&formatConverter) == S_OK) {
                        if (formatConverter->Initialize(frame, GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, nullptr, 0.0, WICBitmapPaletteTypeCustom) == S_OK) {
                            unsigned char *pixels = new unsigned char[w * h * 4];
                            if (formatConverter->CopyPixels(0, w * 4, w * h * 4, pixels) == S_OK) {
                                loadTextureData_(pixels);
                            }
                            delete[] pixels;
                        }
                        formatConverter->Release();
                    }
                }
                pDecoder->Release();
            }
            pFactory->Release();
        }
        stream->Release();
    }
    CoUninitialize();
}
开发者ID:MaddTheSane,项目名称:Glypha,代码行数:39,代码来源:GLImage_Win32.cpp

示例4: LoadResourceImage


//.........这里部分代码省略.........
    }

    if (SUCCEEDED(hr))
    {
        // Create a WIC stream to map onto the memory.
        hr = pIWICFactory->CreateStream(&pStream);
    }

    if (SUCCEEDED(hr))
    {
        // Initialize the stream with the memory pointer and size.
        hr = pStream->InitializeFromMemory(
            reinterpret_cast<BYTE*>(pImageFile),
            imageFileSize);
    }

    if (SUCCEEDED(hr))
    {
        // Create a decoder for the stream.
        hr = pIWICFactory->CreateDecoderFromStream(
            pStream,
            NULL,
            WICDecodeMetadataCacheOnLoad,
            &pDecoder);
    }

    if (SUCCEEDED(hr))
    {
        // Create the initial frame.
        hr = pDecoder->GetFrame(0, &pSource);
    }

    if (SUCCEEDED(hr))
    {
        // Convert the image format to 32bppPBGRA
        // (DXGI_FORMAT_B8G8R8A8_UNORM + D2D1_ALPHA_MODE_PREMULTIPLIED).
        hr = pIWICFactory->CreateFormatConverter(&pConverter);
    }

    if (SUCCEEDED(hr))
    {
        hr = pIWICFactory->CreateBitmapScaler(&pScaler);
    }

    if (SUCCEEDED(hr))
    {
        hr = pScaler->Initialize(
            pSource,
            nOutputWidth,
            nOutputHeight,
            WICBitmapInterpolationModeCubic
            );
    }

    if (SUCCEEDED(hr))
    {
        hr = pConverter->Initialize(
            pScaler,
            GUID_WICPixelFormat32bppPBGRA,
            WICBitmapDitherTypeNone,
            NULL,
            0.f,
            WICBitmapPaletteTypeMedianCut);
    }

    UINT width = 0;
    UINT height = 0;
    if (SUCCEEDED(hr))
    {
        hr = pConverter->GetSize(&width, &height);
    }

    // make sure the image scaled correctly so the output buffer is big enough
    if (SUCCEEDED(hr))
    {
        if ((width != nOutputWidth) || (height != nOutputHeight))
        {
            hr = E_FAIL;
        }
    }

    if (SUCCEEDED(hr))
    {
        hr = pConverter->CopyPixels(NULL, width * sizeof(RGBQUAD), nOutputWidth * nOutputHeight * sizeof(RGBQUAD), reinterpret_cast<BYTE*>(pOutputBuffer));
    }

    SafeRelease(pScaler);
    SafeRelease(pConverter);
    SafeRelease(pSource);
    SafeRelease(pDecoder);
    SafeRelease(pStream);
    SafeRelease(pIWICFactory);

    if (SUCCEEDED(hrCoInit))
    {
        CoUninitialize();
    }

    return hr;
}
开发者ID:starwada,项目名称:K4W_Sample,代码行数:101,代码来源:CoordinateMappingBasics.cpp

示例5: ConvertRgbToYCbCr

    HRESULT YCbCrPixelFormatConverter::ConvertRgbToYCbCr( 
        /* [in] */ const WICRect *prc,
        /* [in] */ UINT cbStride,
        /* [in] */ UINT cbPixelsSize,
        /* [out] */ BYTE *pbPixels)
    {
        HRESULT result = S_OK;
        
        //Sanity check
        WICPixelFormatGUID srcPixelFormat;
        bitmapSource->GetPixelFormat(&srcPixelFormat);
        if (srcPixelFormat != GUID_WICPixelFormat32bppBGRA)
        {
             result = E_UNEXPECTED;
             return result;
        }

        IWICImagingFactory *codecFactory = NULL;
        IWICFormatConverter *formatConverter = NULL;    

        if (SUCCEEDED(result))
        {
            result = CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (LPVOID*) &codecFactory);
        }

        if (SUCCEEDED(result))
        {             
            result = codecFactory->CreateFormatConverter(&formatConverter);        
        }
        
        if (SUCCEEDED(result))
        {
            //We will convert to 24RGB first, since it is easier to convert to YCbCr from there
            result = formatConverter->Initialize(bitmapSource,
                GUID_WICPixelFormat24bppBGR, WICBitmapDitherTypeSolid, NULL, 1.0, WICBitmapPaletteTypeFixedWebPalette);
        }

        if (SUCCEEDED(result))
        {
            result = formatConverter->CopyPixels(prc, cbStride, cbPixelsSize, pbPixels);
        }
        //Since the two formats have same number of bytes, we will do an inplace conversion
        UINT width, height;
        if (prc == NULL)
        {
            if (SUCCEEDED(result))
            {
                result = bitmapSource->GetSize(&width, &height);
            }
        }
        else
        {
            width = prc->Width;
            height = prc->Height;
        }

        if (SUCCEEDED(result))
        {
            //Loop on the data and do the conversion
            BYTE *curPos = NULL;            
            curPos = pbPixels;
            for (int i = 0 ; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                BYTE R, G ,B;
                BYTE Y, Cb, Cr;

                B = *curPos;
                G = *(curPos+1);
                R = *(curPos+2);      

                //Do the maths
                Y = Clamp(0, 255, (0.257*R) + (0.504*G) + (0.098*B) + 16);
                Cb = Clamp(0, 255, (-0.148*R) - (0.291*G) + (0.439*B) + 128);
                Cr = Clamp(0, 255, (0.439*R) - (0.368*G) - (0.071*B) + 128);

                *curPos = Cr;
                *(curPos+1) = Cb;
                *(curPos+2) = Y;      
                   
                //Advance to next pixel
                curPos += 3;
                }
                curPos += (cbStride - (width * 3)); //Fast forward remaining part of the stride
            }
        }
        if (formatConverter)
        {
            formatConverter->Release();
        }

        if (codecFactory)
        {
            codecFactory->Release();
        }
        return result;
       }  
开发者ID:AhFu,项目名称:WPF-Samples,代码行数:98,代码来源:YCbCrPixelFormatConverter.cpp

示例6: LoadResourceImage


//.........这里部分代码省略.........
        imageFileSize = SizeofResource(HINST_THISCOMPONENT, imageResHandle);
        hr = imageFileSize ? S_OK : E_FAIL;
    }

    if (SUCCEEDED(hr))
    {
        // Create a WIC stream to map onto the memory.
        hr = pIWICFactory->CreateStream(&pStream);
    }

    if (SUCCEEDED(hr))
    {
        // Initialize the stream with the memory pointer and size.
        hr = pStream->InitializeFromMemory(
            reinterpret_cast<BYTE*>(pImageFile),
            imageFileSize
            );
    }

    if (SUCCEEDED(hr))
    {
        // Create a decoder for the stream.
        hr = pIWICFactory->CreateDecoderFromStream(
            pStream,
            NULL,
            WICDecodeMetadataCacheOnLoad,
            &pDecoder
            );
    }

    if (SUCCEEDED(hr))
    {
        // Create the initial frame.
        hr = pDecoder->GetFrame(0, &pSource);
    }

    if (SUCCEEDED(hr))
    {
        // Convert the image format to 32bppPBGRA
        // (DXGI_FORMAT_B8G8R8A8_UNORM + D2D1_ALPHA_MODE_PREMULTIPLIED).
        hr = pIWICFactory->CreateFormatConverter(&pConverter);
    }

    if (SUCCEEDED(hr))
    {
        hr = pIWICFactory->CreateBitmapScaler(&pScaler);
    }

    if (SUCCEEDED(hr))
    {
        hr = pScaler->Initialize(
            pSource,
            m_colorWidth,
            m_colorHeight,
            WICBitmapInterpolationModeCubic
            );
    }

    if (SUCCEEDED(hr))
    {
        hr = pConverter->Initialize(
            pScaler,
            GUID_WICPixelFormat32bppPBGRA,
            WICBitmapDitherTypeNone,
            NULL,
            0.f,
            WICBitmapPaletteTypeMedianCut
            );
    }

    UINT width = 0;
    UINT height = 0;
    if (SUCCEEDED(hr))
    {
        hr = pConverter->GetSize(&width, &height);
    }

    // make sure the output buffer is large enough
    if (SUCCEEDED(hr))
    {
        if ( width*height*cBytesPerPixel > cOutputBuffer )
        {
            hr = E_FAIL;
        }
    }

    if (SUCCEEDED(hr))
    {
        hr = pConverter->CopyPixels(NULL, width*cBytesPerPixel, cOutputBuffer, outputBuffer);
    }

    SafeRelease(pScaler);
    SafeRelease(pConverter);
    SafeRelease(pSource);
    SafeRelease(pDecoder);
    SafeRelease(pStream);
    SafeRelease(pIWICFactory);

    return hr;
}
开发者ID:cmorato,项目名称:kinect-easy-grabber,代码行数:101,代码来源:KinectEasyGrabber.cpp

示例7: LoadJPG

void LoadJPG(wchar_t *pwszJpg, HWND hwnd)
{
    IWICImagingFactory *pFactory = NULL;
    HRESULT hr = CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFactory));
    if (SUCCEEDED(hr)) {
        IWICBitmapDecoder *pDecoder = NULL;
        hr = pFactory->CreateDecoderFromFilename(pwszJpg, NULL, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &pDecoder);
        if (SUCCEEDED(hr)) {
            IWICBitmapFrameDecode *pIDecoderFrame = NULL;
            hr = pDecoder->GetFrame(0, &pIDecoderFrame);
            if (SUCCEEDED(hr)) {
                IWICFormatConverter *pFC = NULL;
                hr = pFactory->CreateFormatConverter(&pFC);
                hr = pFC->Initialize(pIDecoderFrame, GUID_WICPixelFormat24bppBGR, WICBitmapDitherTypeNone, NULL, 0.0, WICBitmapPaletteTypeCustom);

                const int nBytesPixel = 3; // GUID_WICPixelFormat24bppBGR 每像素3字节(24bits)

                BITMAPINFO bmpInfo;
                ZeroMemory(&bmpInfo, sizeof(BITMAPINFO));
                bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
                hr = pIDecoderFrame->GetSize((UINT*)&bmpInfo.bmiHeader.biWidth, (UINT*)&bmpInfo.bmiHeader.biHeight);
                bmpInfo.bmiHeader.biPlanes = 1;
                bmpInfo.bmiHeader.biBitCount = 8 * nBytesPixel;
                bmpInfo.bmiHeader.biCompression = BI_RGB;

                BYTE *pBuf = NULL;
                HDC hdc = GetDC(hwnd);
                bmpInfo.bmiHeader.biHeight *= -1; // BMP 方向调整
                HBITMAP hBmp = CreateDIBSection(hdc, &bmpInfo, DIB_RGB_COLORS, (void**)&pBuf, NULL, 0);
                bmpInfo.bmiHeader.biHeight *= -1;

                // 计算扫描线
                unsigned int cbStride = nBytesPixel * bmpInfo.bmiHeader.biWidth;
                unsigned int total = cbStride*bmpInfo.bmiHeader.biHeight;
                hr = pFC->CopyPixels(NULL, cbStride, total, pBuf);

                // HSL色彩空间变换
                DirectX::XMVECTORF32 colorTransofrom = { 1.0f, 1.0f, 1.0f, 1.0f };

                if (SUCCEEDED(hr)) {
                    for (int i = 0; i < bmpInfo.bmiHeader.biHeight; i++) {
                        for (int j = 0; j < bmpInfo.bmiHeader.biWidth; j++) {
                            BYTE *pColor = pBuf + cbStride*i + j * nBytesPixel;

                            DirectX::XMVECTOR colorM = DirectX::PackedVector::XMLoadUByteN4((DirectX::PackedVector::XMUBYTEN4*)pColor);
                            colorM = DirectX::XMColorRGBToHSL(colorM);
                            colorM = DirectX::XMColorModulate(colorM, colorTransofrom);
                            colorM = DirectX::XMColorHSLToRGB(colorM);
                            DirectX::PackedVector::XMStoreUByteN4((DirectX::PackedVector::XMUBYTEN4*)pColor, colorM);

                            SetPixel(hdc, j, i, RGB(pColor[2], pColor[1], pColor[0]));
                        }
                    }
                }

                ReleaseDC(hwnd, hdc);

                if (SUCCEEDED(hr)) {
                    MakeMemDC(hBmp, hwnd);
                    InvalidateRect(hwnd, NULL, TRUE);
                }

                hr = pFC->Release();
                pIDecoderFrame->Release();
            }
            pDecoder->Release();
        }

        pFactory->Release();
    }
}
开发者ID:HP-Enterprise,项目名称:Training,代码行数:71,代码来源:main.cpp

示例8: CreateTextureFromWIC


//.........这里部分代码省略.........

                if ( sRGB )
                    format = MakeSRGB( format );
            }
        }
    }

    // Verify our target format is supported by the current device
    // (handles WDDM 1.0 or WDDM 1.1 device driver cases as well as DirectX 11.0 Runtime without 16bpp format support)
    UINT support = 0;
    hr = d3dDevice->CheckFormatSupport( format, &support );
    if ( FAILED(hr) || !(support & D3D11_FORMAT_SUPPORT_TEXTURE2D) )
    {
        // Fallback to RGBA 32-bit format which is supported by all devices
        memcpy( &convertGUID, &GUID_WICPixelFormat32bppRGBA, sizeof(WICPixelFormatGUID) );
        format = DXGI_FORMAT_R8G8B8A8_UNORM;
        bpp = 32;
    }

    // Allocate temporary memory for image
    size_t rowPitch = ( twidth * bpp + 7 ) / 8;
    size_t imageSize = rowPitch * theight;

    std::unique_ptr<uint8_t[]> temp( new (std::nothrow) uint8_t[ imageSize ] );
    if (!temp)
        return E_OUTOFMEMORY;

    // Load image data
    if ( memcmp( &convertGUID, &pixelFormat, sizeof(GUID) ) == 0
         && twidth == width
         && theight == height )
    {
        // No format conversion or resize needed
        hr = frame->CopyPixels( 0, static_cast<UINT>( rowPitch ), static_cast<UINT>( imageSize ), temp.get() );  
        if ( FAILED(hr) )
            return hr;
    }
    else if ( twidth != width || theight != height )
    {
        // Resize
        IWICImagingFactory* pWIC = _GetWIC();
        if ( !pWIC )
            return E_NOINTERFACE;

        IWICBitmapScaler* scaler;
        hr = pWIC->CreateBitmapScaler( &scaler );
        if ( FAILED(hr) )
            return hr;

        hr = scaler->Initialize( frame, twidth, theight, WICBitmapInterpolationModeFant );
        if ( FAILED(hr) )
            return hr;

        WICPixelFormatGUID pfScaler;
        hr = scaler->GetPixelFormat( &pfScaler );
        if ( FAILED(hr) )
            return hr;

        if ( memcmp( &convertGUID, &pfScaler, sizeof(GUID) ) == 0 )
        {
            // No format conversion needed
            hr = scaler->CopyPixels( 0, static_cast<UINT>( rowPitch ), static_cast<UINT>( imageSize ), temp.get() );  
            if ( FAILED(hr) )
                return hr;
        }
        else
开发者ID:Noplace,项目名称:Solar,代码行数:67,代码来源:WICTextureLoader.cpp


注:本文中的IWICFormatConverter::CopyPixels方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。