diff --git a/DirectXTex/DirectXTexWIC.cpp b/DirectXTex/DirectXTexWIC.cpp index 6a255f0..f599a11 100644 --- a/DirectXTex/DirectXTexWIC.cpp +++ b/DirectXTex/DirectXTexWIC.cpp @@ -439,71 +439,82 @@ static HRESULT _DecodeMultiframe( _In_ DWORD flags, _In_ const TexMetadata& meta if ( FAILED(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( img->rowPitch ), static_cast( img->slicePitch ), img->pixels ); if ( FAILED(hr) ) return hr; } else { - // This frame needs resizing, but not format converted - ComPtr scaler; - hr = pWIC->CreateBitmapScaler( scaler.GetAddressOf() ); + ComPtr FC; + hr = pWIC->CreateFormatConverter( FC.GetAddressOf() ); if ( FAILED(hr) ) return hr; - hr = scaler->Initialize( frame.Get(), static_cast( metadata.width ), static_cast( 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) ) return hr; - - hr = scaler->CopyPixels( 0, static_cast( img->rowPitch ), static_cast( img->slicePitch ), img->pixels ); + + hr = FC->CopyPixels( 0, static_cast( img->rowPitch ), static_cast( img->slicePitch ), img->pixels ); if ( FAILED(hr) ) return hr; } } else { - // This frame required format conversion - ComPtr FC; - hr = pWIC->CreateFormatConverter( FC.GetAddressOf() ); + // This frame needs resizing + ComPtr scaler; + hr = pWIC->CreateBitmapScaler( scaler.GetAddressOf() ); if ( FAILED(hr) ) return hr; - BOOL canConvert = FALSE; - hr = FC->CanConvert( sourceGUID, pfGuid, &canConvert ); - if ( FAILED(hr) || !canConvert ) - { - return E_UNEXPECTED; - } - - hr = FC->Initialize( frame.Get(), pfGuid, _GetWICDither( flags ), 0, 0, WICBitmapPaletteTypeCustom ); + hr = scaler->Initialize( frame.Get(), static_cast( metadata.width ), static_cast( metadata.height ), _GetWICInterp( flags ) ); if ( FAILED(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 = FC->CopyPixels( 0, static_cast( img->rowPitch ), static_cast( img->slicePitch ), img->pixels ); + hr = scaler->CopyPixels( 0, static_cast( img->rowPitch ), static_cast( img->slicePitch ), img->pixels ); if ( FAILED(hr) ) return hr; } else { - // This frame needs resizing and format converted - ComPtr scaler; - hr = pWIC->CreateBitmapScaler( scaler.GetAddressOf() ); + // The WIC bitmap scaler is free to return a different pixel format than the source image, so here we + // convert it to our desired format + ComPtr FC; + hr = pWIC->CreateFormatConverter( FC.GetAddressOf() ); if ( FAILED(hr) ) return hr; - hr = scaler->Initialize( FC.Get(), static_cast( metadata.width ), static_cast( 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) ) return hr; - hr = scaler->CopyPixels( 0, static_cast( img->rowPitch ), static_cast( img->slicePitch ), img->pixels ); + hr = FC->CopyPixels( 0, static_cast( img->rowPitch ), static_cast( img->slicePitch ), img->pixels ); if ( FAILED(hr) ) return hr; } diff --git a/Texassemble/texassemble.cpp b/Texassemble/texassemble.cpp index c349d2f..c7e7697 100644 --- a/Texassemble/texassemble.cpp +++ b/Texassemble/texassemble.cpp @@ -217,6 +217,9 @@ void PrintInfo( const TexMetadata& info ) if ( info.mipLevels > 1 ) wprintf( L",%Iu", info.mipLevels); + if ( info.arraySize > 1 ) + wprintf( L",%Iu", info.arraySize); + wprintf( L" "); 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_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) ) { wprintf( L" FAILED (%x)\n", hr); diff --git a/Texconv/texconv.cpp b/Texconv/texconv.cpp index 13281e6..edb8618 100644 --- a/Texconv/texconv.cpp +++ b/Texconv/texconv.cpp @@ -370,6 +370,9 @@ void PrintInfo( const TexMetadata& info ) if ( info.mipLevels > 1 ) wprintf( L",%Iu", info.mipLevels); + if ( info.arraySize > 1 ) + wprintf( L",%Iu", info.arraySize); + wprintf( L" "); 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_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) ) { wprintf( L" FAILED (%x)\n", hr);