本文整理汇总了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;
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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