mirror of
https://github.com/microsoft/DirectXTex
synced 2024-11-22 04:20:07 +00:00
Fixed bugs in WIC loader for multframe images when resizing was required
- texconv & texassemble now load multi-frames if present from WIC files (tiff, gif)
This commit is contained in:
parent
5541a2cbcf
commit
f618e9f19d
@ -439,71 +439,82 @@ static HRESULT _DecodeMultiframe( _In_ DWORD flags, _In_ const TexMetadata& meta
|
|||||||
if ( FAILED(hr) )
|
if ( FAILED(hr) )
|
||||||
return hr;
|
return hr;
|
||||||
|
|
||||||
if ( memcmp( &pfGuid, &sourceGUID, sizeof(WICPixelFormatGUID) ) == 0 )
|
if ( w == metadata.width && h == metadata.height )
|
||||||
{
|
{
|
||||||
if ( w == metadata.width && h == metadata.height )
|
// This frame does not need resized
|
||||||
|
if ( memcmp( &pfGuid, &sourceGUID, sizeof(WICPixelFormatGUID) ) == 0 )
|
||||||
{
|
{
|
||||||
// This frame does not need resized or format converted, just copy...
|
|
||||||
hr = frame->CopyPixels( 0, static_cast<UINT>( img->rowPitch ), static_cast<UINT>( img->slicePitch ), img->pixels );
|
hr = frame->CopyPixels( 0, static_cast<UINT>( img->rowPitch ), static_cast<UINT>( img->slicePitch ), img->pixels );
|
||||||
if ( FAILED(hr) )
|
if ( FAILED(hr) )
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// This frame needs resizing, but not format converted
|
ComPtr<IWICFormatConverter> FC;
|
||||||
ComPtr<IWICBitmapScaler> scaler;
|
hr = pWIC->CreateFormatConverter( FC.GetAddressOf() );
|
||||||
hr = pWIC->CreateBitmapScaler( scaler.GetAddressOf() );
|
|
||||||
if ( FAILED(hr) )
|
if ( FAILED(hr) )
|
||||||
return hr;
|
return hr;
|
||||||
|
|
||||||
hr = scaler->Initialize( frame.Get(), static_cast<UINT>( metadata.width ), static_cast<UINT>( metadata.height ), _GetWICInterp( flags ) );
|
BOOL canConvert = FALSE;
|
||||||
|
hr = FC->CanConvert( pfGuid, sourceGUID, &canConvert );
|
||||||
|
if ( FAILED(hr) || !canConvert )
|
||||||
|
{
|
||||||
|
return E_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = FC->Initialize( frame.Get(), sourceGUID, _GetWICDither( flags ), 0, 0, WICBitmapPaletteTypeCustom );
|
||||||
if ( FAILED(hr) )
|
if ( FAILED(hr) )
|
||||||
return hr;
|
return hr;
|
||||||
|
|
||||||
hr = scaler->CopyPixels( 0, static_cast<UINT>( img->rowPitch ), static_cast<UINT>( img->slicePitch ), img->pixels );
|
hr = FC->CopyPixels( 0, static_cast<UINT>( img->rowPitch ), static_cast<UINT>( img->slicePitch ), img->pixels );
|
||||||
if ( FAILED(hr) )
|
if ( FAILED(hr) )
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// This frame required format conversion
|
// This frame needs resizing
|
||||||
ComPtr<IWICFormatConverter> FC;
|
ComPtr<IWICBitmapScaler> scaler;
|
||||||
hr = pWIC->CreateFormatConverter( FC.GetAddressOf() );
|
hr = pWIC->CreateBitmapScaler( scaler.GetAddressOf() );
|
||||||
if ( FAILED(hr) )
|
if ( FAILED(hr) )
|
||||||
return hr;
|
return hr;
|
||||||
|
|
||||||
BOOL canConvert = FALSE;
|
hr = scaler->Initialize( frame.Get(), static_cast<UINT>( metadata.width ), static_cast<UINT>( metadata.height ), _GetWICInterp( flags ) );
|
||||||
hr = FC->CanConvert( sourceGUID, pfGuid, &canConvert );
|
|
||||||
if ( FAILED(hr) || !canConvert )
|
|
||||||
{
|
|
||||||
return E_UNEXPECTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
hr = FC->Initialize( frame.Get(), pfGuid, _GetWICDither( flags ), 0, 0, WICBitmapPaletteTypeCustom );
|
|
||||||
if ( FAILED(hr) )
|
if ( FAILED(hr) )
|
||||||
return hr;
|
return hr;
|
||||||
|
|
||||||
if ( w == metadata.width && h == metadata.height )
|
WICPixelFormatGUID pfScaler;
|
||||||
|
hr = scaler->GetPixelFormat( &pfScaler );
|
||||||
|
if ( FAILED(hr) )
|
||||||
|
return hr;
|
||||||
|
|
||||||
|
if ( memcmp( &pfScaler, &sourceGUID, sizeof(WICPixelFormatGUID) ) == 0 )
|
||||||
{
|
{
|
||||||
// This frame is the same size, no need to scale
|
hr = scaler->CopyPixels( 0, static_cast<UINT>( img->rowPitch ), static_cast<UINT>( img->slicePitch ), img->pixels );
|
||||||
hr = FC->CopyPixels( 0, static_cast<UINT>( img->rowPitch ), static_cast<UINT>( img->slicePitch ), img->pixels );
|
|
||||||
if ( FAILED(hr) )
|
if ( FAILED(hr) )
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// This frame needs resizing and format converted
|
// The WIC bitmap scaler is free to return a different pixel format than the source image, so here we
|
||||||
ComPtr<IWICBitmapScaler> scaler;
|
// convert it to our desired format
|
||||||
hr = pWIC->CreateBitmapScaler( scaler.GetAddressOf() );
|
ComPtr<IWICFormatConverter> FC;
|
||||||
|
hr = pWIC->CreateFormatConverter( FC.GetAddressOf() );
|
||||||
if ( FAILED(hr) )
|
if ( FAILED(hr) )
|
||||||
return hr;
|
return hr;
|
||||||
|
|
||||||
hr = scaler->Initialize( FC.Get(), static_cast<UINT>( metadata.width ), static_cast<UINT>( metadata.height ), _GetWICInterp( flags ) );
|
BOOL canConvert = FALSE;
|
||||||
|
hr = FC->CanConvert( pfScaler, sourceGUID, &canConvert );
|
||||||
|
if ( FAILED(hr) || !canConvert )
|
||||||
|
{
|
||||||
|
return E_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr = FC->Initialize( scaler.Get(), sourceGUID, _GetWICDither( flags ), 0, 0, WICBitmapPaletteTypeCustom );
|
||||||
if ( FAILED(hr) )
|
if ( FAILED(hr) )
|
||||||
return hr;
|
return hr;
|
||||||
|
|
||||||
hr = scaler->CopyPixels( 0, static_cast<UINT>( img->rowPitch ), static_cast<UINT>( img->slicePitch ), img->pixels );
|
hr = FC->CopyPixels( 0, static_cast<UINT>( img->rowPitch ), static_cast<UINT>( img->slicePitch ), img->pixels );
|
||||||
if ( FAILED(hr) )
|
if ( FAILED(hr) )
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
@ -217,6 +217,9 @@ void PrintInfo( const TexMetadata& info )
|
|||||||
if ( info.mipLevels > 1 )
|
if ( info.mipLevels > 1 )
|
||||||
wprintf( L",%Iu", info.mipLevels);
|
wprintf( L",%Iu", info.mipLevels);
|
||||||
|
|
||||||
|
if ( info.arraySize > 1 )
|
||||||
|
wprintf( L",%Iu", info.arraySize);
|
||||||
|
|
||||||
wprintf( L" ");
|
wprintf( L" ");
|
||||||
PrintFormat( info.format );
|
PrintFormat( info.format );
|
||||||
|
|
||||||
@ -541,7 +544,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
static_assert( WIC_FLAGS_FILTER_CUBIC == TEX_FILTER_CUBIC, "WIC_FLAGS_* & TEX_FILTER_* should match" );
|
static_assert( WIC_FLAGS_FILTER_CUBIC == TEX_FILTER_CUBIC, "WIC_FLAGS_* & TEX_FILTER_* should match" );
|
||||||
static_assert( WIC_FLAGS_FILTER_FANT == TEX_FILTER_FANT, "WIC_FLAGS_* & TEX_FILTER_* should match" );
|
static_assert( WIC_FLAGS_FILTER_FANT == TEX_FILTER_FANT, "WIC_FLAGS_* & TEX_FILTER_* should match" );
|
||||||
|
|
||||||
hr = LoadFromWICFile( pConv->szSrc, dwFilter, &info, *image.get() );
|
hr = LoadFromWICFile( pConv->szSrc, dwFilter | WIC_FLAGS_ALL_FRAMES, &info, *image.get() );
|
||||||
if ( FAILED(hr) )
|
if ( FAILED(hr) )
|
||||||
{
|
{
|
||||||
wprintf( L" FAILED (%x)\n", hr);
|
wprintf( L" FAILED (%x)\n", hr);
|
||||||
|
@ -370,6 +370,9 @@ void PrintInfo( const TexMetadata& info )
|
|||||||
if ( info.mipLevels > 1 )
|
if ( info.mipLevels > 1 )
|
||||||
wprintf( L",%Iu", info.mipLevels);
|
wprintf( L",%Iu", info.mipLevels);
|
||||||
|
|
||||||
|
if ( info.arraySize > 1 )
|
||||||
|
wprintf( L",%Iu", info.arraySize);
|
||||||
|
|
||||||
wprintf( L" ");
|
wprintf( L" ");
|
||||||
PrintFormat( info.format );
|
PrintFormat( info.format );
|
||||||
|
|
||||||
@ -1045,7 +1048,11 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|
|||||||
static_assert( WIC_FLAGS_FILTER_CUBIC == TEX_FILTER_CUBIC, "WIC_FLAGS_* & TEX_FILTER_* should match" );
|
static_assert( WIC_FLAGS_FILTER_CUBIC == TEX_FILTER_CUBIC, "WIC_FLAGS_* & TEX_FILTER_* should match" );
|
||||||
static_assert( WIC_FLAGS_FILTER_FANT == TEX_FILTER_FANT, "WIC_FLAGS_* & TEX_FILTER_* should match" );
|
static_assert( WIC_FLAGS_FILTER_FANT == TEX_FILTER_FANT, "WIC_FLAGS_* & TEX_FILTER_* should match" );
|
||||||
|
|
||||||
hr = LoadFromWICFile( pConv->szSrc, dwFilter, &info, *image );
|
DWORD wicFlags = dwFilter;
|
||||||
|
if (FileType == CODEC_DDS)
|
||||||
|
wicFlags |= WIC_FLAGS_ALL_FRAMES;
|
||||||
|
|
||||||
|
hr = LoadFromWICFile( pConv->szSrc, wicFlags, &info, *image );
|
||||||
if ( FAILED(hr) )
|
if ( FAILED(hr) )
|
||||||
{
|
{
|
||||||
wprintf( L" FAILED (%x)\n", hr);
|
wprintf( L" FAILED (%x)\n", hr);
|
||||||
|
Loading…
Reference in New Issue
Block a user