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, ...@@ -314,6 +314,15 @@ HRESULT WINAPI D3DXLoadSurfaceFromFileInMemory(LPDIRECT3DSURFACE9 pDestSurface,
D3DXIMAGE_INFO imginfo; D3DXIMAGE_INFO imginfo;
HRESULT hr; 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, TRACE("(%p, %p, %p, %p, %d, %p, %d, %x, %p)\n", pDestSurface, pDestPalette, pDestRect, pSrcData,
SrcDataSize, pSrcRect, dwFilter, Colorkey, pSrcInfo); SrcDataSize, pSrcRect, dwFilter, Colorkey, pSrcInfo);
...@@ -325,109 +334,86 @@ HRESULT WINAPI D3DXLoadSurfaceFromFileInMemory(LPDIRECT3DSURFACE9 pDestSurface, ...@@ -325,109 +334,86 @@ HRESULT WINAPI D3DXLoadSurfaceFromFileInMemory(LPDIRECT3DSURFACE9 pDestSurface,
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
switch (imginfo.ImageFileFormat) CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
{
case D3DXIFF_BMP:
case D3DXIFF_PNG:
case D3DXIFF_JPG:
{
IWICImagingFactory *factory;
IWICBitmapDecoder *decoder;
IWICBitmapFrameDecode *bitmapframe;
IWICStream *stream;
const PixelFormatDesc *formatdesc; if (FAILED(CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, &IID_IWICImagingFactory, (void**)&factory)))
WICRect wicrect; goto cleanup_err;
RECT rect;
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))) IWICStream_InitializeFromMemory(stream, (BYTE*)pSrcData, SrcDataSize);
goto cleanup_err;
if (FAILED(IWICImagingFactory_CreateStream(factory, &stream))) hr = IWICImagingFactory_CreateDecoderFromStream(factory, (IStream*)stream, NULL, 0, &decoder);
{
IWICImagingFactory_Release(factory);
goto cleanup_err;
}
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); hr = IWICBitmapDecoder_GetFrame(decoder, 0, &bitmapframe);
IWICImagingFactory_Release(factory);
if (FAILED(hr)) if (FAILED(hr))
goto cleanup_err; 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)) SetRect(&rect, 0, 0, wicrect.Width, wicrect.Height);
goto cleanup_bmp;
if (pSrcRect) formatdesc = get_format_info(imginfo.Format);
{
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;
}
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) hr = IWICBitmapFrameDecode_CopyPixels(bitmapframe, &wicrect, pitch,
{ pitch * wicrect.Height, buffer);
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);
}
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: cleanup_bmp:
IWICBitmapFrameDecode_Release(bitmapframe); IWICBitmapFrameDecode_Release(bitmapframe);
IWICBitmapDecoder_Release(decoder); IWICBitmapDecoder_Release(decoder);
cleanup_err: cleanup_err:
CoUninitialize(); CoUninitialize();
if (FAILED(hr)) if (FAILED(hr))
return D3DXERR_INVALIDDATA; return D3DXERR_INVALIDDATA;
break;
}
default:
FIXME("Unsupported image file format\n");
return E_NOTIMPL;
}
if (pSrcInfo) if (pSrcInfo)
*pSrcInfo = imginfo; *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