WriteSource WIC API simplifies WIC writer a bit
This commit is contained in:
Родитель
eb48e991f9
Коммит
5472168735
|
@ -63,8 +63,6 @@ namespace DirectX
|
|||
DXGI_FORMAT _WICToDXGI( _In_ const GUID& guid );
|
||||
bool _DXGIToWIC( _In_ DXGI_FORMAT format, _Out_ GUID& guid );
|
||||
|
||||
size_t _WICBitsPerPixel( _In_ REFGUID targetGuid );
|
||||
|
||||
IWICImagingFactory* _GetWIC();
|
||||
|
||||
inline WICBitmapDitherType _GetWICDither( _In_ DWORD flags )
|
||||
|
|
|
@ -113,34 +113,6 @@ bool _DXGIToWIC( DXGI_FORMAT format, GUID& guid )
|
|||
return false;
|
||||
}
|
||||
|
||||
size_t _WICBitsPerPixel( REFGUID targetGuid )
|
||||
{
|
||||
IWICImagingFactory* pWIC = _GetWIC();
|
||||
if ( !pWIC )
|
||||
return 0;
|
||||
|
||||
ScopedObject<IWICComponentInfo> cinfo;
|
||||
if ( FAILED( pWIC->CreateComponentInfo( targetGuid, &cinfo ) ) )
|
||||
return 0;
|
||||
|
||||
WICComponentType type;
|
||||
if ( FAILED( cinfo->GetComponentType( &type ) ) )
|
||||
return 0;
|
||||
|
||||
if ( type != WICPixelFormat )
|
||||
return 0;
|
||||
|
||||
ScopedObject<IWICPixelFormatInfo> pfinfo;
|
||||
if ( FAILED( cinfo->QueryInterface( __uuidof(IWICPixelFormatInfo), reinterpret_cast<void**>( &pfinfo ) ) ) )
|
||||
return 0;
|
||||
|
||||
UINT bpp;
|
||||
if ( FAILED( pfinfo->GetBitsPerPixel( &bpp ) ) )
|
||||
return 0;
|
||||
|
||||
return bpp;
|
||||
}
|
||||
|
||||
IWICImagingFactory* _GetWIC()
|
||||
{
|
||||
static IWICImagingFactory* s_Factory = nullptr;
|
||||
|
|
|
@ -426,22 +426,8 @@ static HRESULT _EncodeImage( _In_ const Image& image, _In_ DWORD flags, _In_ IWI
|
|||
if ( FAILED(hr) )
|
||||
return hr;
|
||||
|
||||
size_t bpp = _WICBitsPerPixel( targetGuid );
|
||||
if ( bpp == 0 )
|
||||
return E_FAIL;
|
||||
|
||||
size_t rowPitch = ( image.width * bpp + 7 ) / 8;
|
||||
size_t slicePitch = rowPitch * image.height;
|
||||
|
||||
std::unique_ptr<uint8_t[]> temp( new uint8_t[ slicePitch ] );
|
||||
if ( !temp )
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
hr = FC->CopyPixels( 0, static_cast<UINT>( rowPitch ), static_cast<UINT>( slicePitch ), temp.get() );
|
||||
if ( FAILED(hr) )
|
||||
return hr;
|
||||
|
||||
hr = frame->WritePixels( static_cast<UINT>( image.height ), static_cast<UINT>( rowPitch ), static_cast<UINT>( slicePitch ), temp.get() );
|
||||
WICRect rect = { 0, 0, static_cast<UINT>( image.width ), static_cast<UINT>( image.height ) };
|
||||
hr = frame->WriteSource( FC.Get(), &rect );
|
||||
if ( FAILED(hr) )
|
||||
return hr;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче