Commit 31682b3d authored by Vincent Povirk's avatar Vincent Povirk Committed by Alexandre Julliard

d3dx9_36: Don't check the image format in D3DXLoadSurfaceFromFileInMemory.

If the format is not supported, D3DXGetImageInfoFromFileInMemory will fail.
parent 384b9553
......@@ -314,6 +314,15 @@ HRESULT WINAPI D3DXLoadSurfaceFromFileInMemory(LPDIRECT3DSURFACE9 pDestSurface,
D3DXIMAGE_INFO imginfo;
HRESULT hr;
IWICImagingFactory *factory;
IWICBitmapDecoder *decoder;
IWICBitmapFrameDecode *bitmapframe;
IWICStream *stream;
const PixelFormatDesc *formatdesc;
WICRect wicrect;
RECT rect;
TRACE("(%p, %p, %p, %p, %d, %p, %d, %x, %p)\n", pDestSurface, pDestPalette, pDestRect, pSrcData,
SrcDataSize, pSrcRect, dwFilter, Colorkey, pSrcInfo);
......@@ -325,109 +334,86 @@ HRESULT WINAPI D3DXLoadSurfaceFromFileInMemory(LPDIRECT3DSURFACE9 pDestSurface,
if (FAILED(hr))
return hr;
switch (imginfo.ImageFileFormat)
{
case D3DXIFF_BMP:
case D3DXIFF_PNG:
case D3DXIFF_JPG:
{
IWICImagingFactory *factory;
IWICBitmapDecoder *decoder;
IWICBitmapFrameDecode *bitmapframe;
IWICStream *stream;
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
const PixelFormatDesc *formatdesc;
WICRect wicrect;
RECT rect;
if (FAILED(CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, &IID_IWICImagingFactory, (void**)&factory)))
goto cleanup_err;
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if (FAILED(IWICImagingFactory_CreateStream(factory, &stream)))
{
IWICImagingFactory_Release(factory);
goto cleanup_err;
}
if (FAILED(CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, &IID_IWICImagingFactory, (void**)&factory)))
goto cleanup_err;
IWICStream_InitializeFromMemory(stream, (BYTE*)pSrcData, SrcDataSize);
if (FAILED(IWICImagingFactory_CreateStream(factory, &stream)))
{
IWICImagingFactory_Release(factory);
goto cleanup_err;
}
hr = IWICImagingFactory_CreateDecoderFromStream(factory, (IStream*)stream, NULL, 0, &decoder);
IWICStream_InitializeFromMemory(stream, (BYTE*)pSrcData, SrcDataSize);
IStream_Release(stream);
IWICImagingFactory_Release(factory);
hr = IWICImagingFactory_CreateDecoderFromStream(factory, (IStream*)stream, NULL, 0, &decoder);
if (FAILED(hr))
goto cleanup_err;
IStream_Release(stream);
IWICImagingFactory_Release(factory);
hr = IWICBitmapDecoder_GetFrame(decoder, 0, &bitmapframe);
if (FAILED(hr))
goto cleanup_err;
if (FAILED(hr))
goto cleanup_bmp;
hr = IWICBitmapDecoder_GetFrame(decoder, 0, &bitmapframe);
if (pSrcRect)
{
wicrect.X = pSrcRect->left;
wicrect.Y = pSrcRect->top;
wicrect.Width = pSrcRect->right - pSrcRect->left;
wicrect.Height = pSrcRect->bottom - pSrcRect->top;
}
else
{
wicrect.X = 0;
wicrect.Y = 0;
wicrect.Width = imginfo.Width;
wicrect.Height = imginfo.Height;
}
if (FAILED(hr))
goto cleanup_bmp;
SetRect(&rect, 0, 0, wicrect.Width, wicrect.Height);
if (pSrcRect)
{
wicrect.X = pSrcRect->left;
wicrect.Y = pSrcRect->top;
wicrect.Width = pSrcRect->right - pSrcRect->left;
wicrect.Height = pSrcRect->bottom - pSrcRect->top;
}
else
{
wicrect.X = 0;
wicrect.Y = 0;
wicrect.Width = imginfo.Width;
wicrect.Height = imginfo.Height;
}
formatdesc = get_format_info(imginfo.Format);
SetRect(&rect, 0, 0, wicrect.Width, wicrect.Height);
if (formatdesc->format == D3DFMT_UNKNOWN)
{
FIXME("Unsupported pixel format\n");
hr = D3DXERR_INVALIDDATA;
}
else
{
BYTE *buffer;
DWORD pitch;
formatdesc = get_format_info(imginfo.Format);
pitch = formatdesc->bytes_per_pixel * wicrect.Width;
buffer = HeapAlloc(GetProcessHeap(), 0, pitch * wicrect.Height);
if (formatdesc->format == D3DFMT_UNKNOWN)
{
FIXME("Unsupported pixel format\n");
hr = D3DXERR_INVALIDDATA;
}
else
{
BYTE *buffer;
DWORD pitch;
pitch = formatdesc->bytes_per_pixel * wicrect.Width;
buffer = HeapAlloc(GetProcessHeap(), 0, pitch * wicrect.Height);
hr = IWICBitmapFrameDecode_CopyPixels(bitmapframe, &wicrect, pitch,
pitch * wicrect.Height, buffer);
if (SUCCEEDED(hr))
{
hr = D3DXLoadSurfaceFromMemory(pDestSurface, pDestPalette, pDestRect,
buffer, imginfo.Format, pitch,
NULL, &rect, dwFilter, Colorkey);
}
hr = IWICBitmapFrameDecode_CopyPixels(bitmapframe, &wicrect, pitch,
pitch * wicrect.Height, buffer);
HeapFree(GetProcessHeap(), 0, buffer);
}
if (SUCCEEDED(hr))
{
hr = D3DXLoadSurfaceFromMemory(pDestSurface, pDestPalette, pDestRect,
buffer, imginfo.Format, pitch,
NULL, &rect, dwFilter, Colorkey);
}
HeapFree(GetProcessHeap(), 0, buffer);
}
cleanup_bmp:
IWICBitmapFrameDecode_Release(bitmapframe);
IWICBitmapDecoder_Release(decoder);
IWICBitmapFrameDecode_Release(bitmapframe);
IWICBitmapDecoder_Release(decoder);
cleanup_err:
CoUninitialize();
CoUninitialize();
if (FAILED(hr))
return D3DXERR_INVALIDDATA;
break;
}
default:
FIXME("Unsupported image file format\n");
return E_NOTIMPL;
}
if (FAILED(hr))
return D3DXERR_INVALIDDATA;
if (pSrcInfo)
*pSrcInfo = imginfo;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment