本文整理汇总了C++中IWICBitmapFrameDecode::GetPixelFormat方法的典型用法代码示例。如果您正苦于以下问题:C++ IWICBitmapFrameDecode::GetPixelFormat方法的具体用法?C++ IWICBitmapFrameDecode::GetPixelFormat怎么用?C++ IWICBitmapFrameDecode::GetPixelFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWICBitmapFrameDecode
的用法示例。
在下文中一共展示了IWICBitmapFrameDecode::GetPixelFormat方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: CoCreateInstance
unsigned char *BBWin8Game::LoadImageData( String path,int *pwidth,int *pheight,int *pformat ){
if( !_wicFactory ){
DXASS( CoCreateInstance( CLSID_WICImagingFactory,0,CLSCTX_INPROC_SERVER,__uuidof(IWICImagingFactory),(LPVOID*)&_wicFactory ) );
}
path=PathToFilePath( path );
IWICBitmapDecoder *decoder;
if( !SUCCEEDED( _wicFactory->CreateDecoderFromFilename( path.ToCString<wchar_t>(),NULL,GENERIC_READ,WICDecodeMetadataCacheOnDemand,&decoder ) ) ){
return 0;
}
unsigned char *data=0;
IWICBitmapFrameDecode *bitmapFrame;
DXASS( decoder->GetFrame( 0,&bitmapFrame ) );
UINT width,height;
WICPixelFormatGUID pixelFormat;
DXASS( bitmapFrame->GetSize( &width,&height ) );
DXASS( bitmapFrame->GetPixelFormat( &pixelFormat ) );
if( pixelFormat==GUID_WICPixelFormat24bppBGR ){
unsigned char *t=(unsigned char*)malloc( width*3*height );
DXASS( bitmapFrame->CopyPixels( 0,width*3,width*3*height,t ) );
data=(unsigned char*)malloc( width*4*height );
unsigned char *s=t,*d=data;
int n=width*height;
while( n-- ){
*d++=s[2];
*d++=s[1];
*d++=s[0];
*d++=0xff;
s+=3;
}
free( t );
}else if( pixelFormat==GUID_WICPixelFormat32bppBGRA ){
unsigned char *t=(unsigned char*)malloc( width*4*height );
DXASS( bitmapFrame->CopyPixels( 0,width*4,width*4*height,t ) );
data=t;
int n=width*height;
while( n-- ){ //premultiply alpha
unsigned char r=t[0];
t[0]=t[2]*t[3]/255;
t[1]=t[1]*t[3]/255;
t[2]=r*t[3]/255;
t+=4;
}
}
if( data ){
*pwidth=width;
*pheight=height;
*pformat=4;
}
bitmapFrame->Release();
decoder->Release();
gc_force_sweep=true;
return data;
}
示例3: Initialize
bool Image::Initialize(wchar_t *filename, Graphics *graphics)
{
std::ifstream file;
IWICImagingFactory *pWIC;
IWICStream *stream;
IWICBitmapDecoder *decoder;
IWICBitmapFrameDecode *frame;
unsigned int width, height, twidth, theight, maxsize, bpp, i, support, rowPitch, imageSize;
float ratio;
WICPixelFormatGUID pixelFormat;
DXGI_FORMAT format;
IWICComponentInfo *cinfo;
IWICPixelFormatInfo *pfinfo;
IWICBitmapScaler *scaler;
bool autogen = false;
D3D11_TEXTURE2D_DESC desc;
D3D11_SUBRESOURCE_DATA initData;
D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc;
file.open(filename, std::ios::in | std::ios::binary | std::ios::ate);
if(!file.is_open()) return false;
m_size = file.tellg();
file.seekg(0, std::ios::beg);
m_bytes = new unsigned char [m_size];
file.read((char *)m_bytes, m_size);
file.close();
RETURN_FAIL( CoCreateInstance( CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, __uuidof(IWICImagingFactory), (LPVOID*)&pWIC ) );
RETURN_FAIL( pWIC->CreateStream( &stream ) );
RETURN_FAIL( stream->InitializeFromMemory( m_bytes, m_size ) );
RETURN_FAIL( pWIC->CreateDecoderFromStream( stream, 0, WICDecodeMetadataCacheOnDemand, &decoder ) );
RETURN_FAIL( decoder->GetFrame( 0, &frame ) );
RETURN_FAIL( frame->GetSize( &width, &height ) );
SAFE_RELEASE( stream );
SAFE_RELEASE( decoder );
if( width <= 0 || height <= 0 ) return false;
maxsize = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION;
if( width > maxsize || height > maxsize )
{
ratio = static_cast<float>(height) / static_cast<float>(width);
if(width > height)
{
twidth = maxsize;
theight = static_cast<unsigned int>( static_cast<float>(maxsize) * ratio );
}
else
{
theight = maxsize;
twidth = static_cast<unsigned int>( static_cast<float>(maxsize) / ratio );
}
}
else
{
twidth = width;
theight = height;
}
RETURN_FAIL( frame->GetPixelFormat( &pixelFormat ) );
format = DXGI_FORMAT_UNKNOWN;
for( i = 0; i < _countof(g_WICFormats); ++i )
{
if( memcmp( &g_WICFormats[i].wic, &pixelFormat, sizeof(GUID) ) == 0 )
{
format = g_WICFormats[i].dxgi;
break;
}
}
RETURN_FAIL( pWIC->CreateComponentInfo( pixelFormat, &cinfo ) );
RETURN_FAIL( cinfo->QueryInterface( __uuidof(IWICPixelFormatInfo), (LPVOID*)&pfinfo ) );
RETURN_FAIL( pfinfo->GetBitsPerPixel( &bpp ) );
SAFE_RELEASE( cinfo );
SAFE_RELEASE( pfinfo );
RETURN_FAIL( graphics->GetDevice()->CheckFormatSupport( format, &support ) );
if( !(support & D3D11_FORMAT_SUPPORT_TEXTURE2D) ) return false;
rowPitch = ( twidth * bpp + 7 ) / 8;
imageSize = rowPitch * theight;
std::unique_ptr<uint8_t[]> temp( new (std::nothrow) uint8_t[ imageSize ] );
if( !temp ) return false;
if( twidth == width && theight == height )
{
RETURN_FAIL( frame->CopyPixels( 0, rowPitch, imageSize, temp.get() ) );
}
else
{
RETURN_FAIL( pWIC->CreateBitmapScaler( &scaler ) );
RETURN_FAIL( scaler->Initialize( frame, twidth, theight, WICBitmapInterpolationModeFant ) );
//.........这里部分代码省略.........