2009-05-23 12:56:19 +02:00
|
|
|
/*
|
2010-07-28 21:33:14 +02:00
|
|
|
* Copyright (C) 2009-2010 Tony Wasserka
|
2009-05-23 12:56:19 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
2009-06-01 18:30:15 +02:00
|
|
|
#include "wine/unicode.h"
|
2009-05-23 12:56:19 +02:00
|
|
|
#include "d3dx9_36_private.h"
|
|
|
|
|
2010-04-09 08:43:17 +02:00
|
|
|
#include "initguid.h"
|
|
|
|
#include "wincodec.h"
|
|
|
|
|
2009-05-23 12:56:19 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
|
|
|
|
|
|
|
|
|
2010-08-24 21:29:38 +02:00
|
|
|
/* Wine-specific WIC GUIDs */
|
|
|
|
|
|
|
|
DEFINE_GUID(GUID_WineContainerFormatTga, 0x0c44fda1,0xa5c5,0x4298,0x96,0x85,0x47,0x3f,0xc1,0x7c,0xd3,0x22);
|
|
|
|
|
2009-05-23 12:56:19 +02:00
|
|
|
/************************************************************
|
|
|
|
* D3DXGetImageInfoFromFileInMemory
|
|
|
|
*
|
|
|
|
* Fills a D3DXIMAGE_INFO structure with info about an image
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* data [I] pointer to the image file data
|
|
|
|
* datasize [I] size of the passed data
|
|
|
|
* info [O] pointer to the destination structure
|
|
|
|
*
|
|
|
|
* RETURNS
|
2009-06-01 18:30:15 +02:00
|
|
|
* Success: D3D_OK, if info is not NULL and data and datasize make up a valid image file or
|
|
|
|
* if info is NULL and data and datasize are not NULL
|
|
|
|
* Failure: D3DXERR_INVALIDDATA, if data is no valid image file and datasize and info are not NULL
|
|
|
|
* D3DERR_INVALIDCALL, if data is NULL or
|
|
|
|
* if datasize is 0
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* datasize may be bigger than the actual file size
|
2009-05-23 12:56:19 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI D3DXGetImageInfoFromFileInMemory(LPCVOID data, UINT datasize, D3DXIMAGE_INFO *info)
|
|
|
|
{
|
2010-04-09 08:43:17 +02:00
|
|
|
IWICImagingFactory *factory;
|
|
|
|
IWICBitmapDecoder *decoder = NULL;
|
|
|
|
IWICStream *stream;
|
|
|
|
HRESULT hr;
|
|
|
|
HRESULT initresult;
|
2010-11-12 10:44:09 +01:00
|
|
|
static int warn_once;
|
2010-04-09 08:43:17 +02:00
|
|
|
|
2010-11-12 10:44:09 +01:00
|
|
|
if (!warn_once++)
|
|
|
|
FIXME("(%p, %d, %p): partially implemented\n", data, datasize, info);
|
2010-04-09 08:43:17 +02:00
|
|
|
|
|
|
|
/* TODO: Add support for (or at least detect) TGA, DDS, PPM and DIB */
|
|
|
|
|
|
|
|
if (!data || !datasize)
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
if (!info)
|
|
|
|
return D3D_OK;
|
|
|
|
|
|
|
|
initresult = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, &IID_IWICImagingFactory, (void**)&factory);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
IWICImagingFactory_CreateStream(factory, &stream);
|
|
|
|
IWICStream_InitializeFromMemory(stream, (BYTE*)data, datasize);
|
|
|
|
hr = IWICImagingFactory_CreateDecoderFromStream(factory, (IStream*)stream, NULL, 0, &decoder);
|
|
|
|
IStream_Release(stream);
|
|
|
|
IWICImagingFactory_Release(factory);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
GUID container_format;
|
|
|
|
UINT frame_count;
|
|
|
|
|
|
|
|
hr = IWICBitmapDecoder_GetContainerFormat(decoder, &container_format);
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
if (IsEqualGUID(&container_format, &GUID_ContainerFormatBmp)) {
|
|
|
|
TRACE("File type is BMP\n");
|
|
|
|
info->ImageFileFormat = D3DXIFF_BMP;
|
|
|
|
} else if (IsEqualGUID(&container_format, &GUID_ContainerFormatPng)) {
|
|
|
|
TRACE("File type is PNG\n");
|
|
|
|
info->ImageFileFormat = D3DXIFF_PNG;
|
|
|
|
} else if(IsEqualGUID(&container_format, &GUID_ContainerFormatJpeg)) {
|
|
|
|
TRACE("File type is JPG\n");
|
|
|
|
info->ImageFileFormat = D3DXIFF_JPG;
|
2010-08-24 21:29:38 +02:00
|
|
|
} else if(IsEqualGUID(&container_format, &GUID_WineContainerFormatTga)) {
|
|
|
|
TRACE("File type is TGA\n");
|
|
|
|
info->ImageFileFormat = D3DXIFF_TGA;
|
2010-04-09 08:43:17 +02:00
|
|
|
} else {
|
|
|
|
WARN("Unsupported image file format %s\n", debugstr_guid(&container_format));
|
|
|
|
hr = D3DXERR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IWICBitmapDecoder_GetFrameCount(decoder, &frame_count);
|
|
|
|
if (SUCCEEDED(hr) && !frame_count)
|
|
|
|
hr = D3DXERR_INVALIDDATA;
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
IWICBitmapFrameDecode *frame = NULL;
|
|
|
|
|
|
|
|
hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IWICBitmapFrameDecode_GetSize(frame, &info->Width, &info->Height);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
WICPixelFormatGUID pixel_format;
|
|
|
|
|
|
|
|
hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &pixel_format);
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
if (IsEqualGUID(&pixel_format, &GUID_WICPixelFormat1bppIndexed))
|
|
|
|
info->Format = D3DFMT_L8;
|
|
|
|
else if (IsEqualGUID(&pixel_format, &GUID_WICPixelFormat4bppIndexed))
|
|
|
|
info->Format = D3DFMT_L8;
|
|
|
|
else if (IsEqualGUID(&pixel_format, &GUID_WICPixelFormat8bppIndexed))
|
|
|
|
info->Format = D3DFMT_L8;
|
|
|
|
else if (IsEqualGUID(&pixel_format, &GUID_WICPixelFormat16bppBGR555))
|
|
|
|
info->Format = D3DFMT_X1R5G5B5;
|
|
|
|
else if (IsEqualGUID(&pixel_format, &GUID_WICPixelFormat24bppBGR))
|
|
|
|
info->Format = D3DFMT_R8G8B8;
|
|
|
|
else if (IsEqualGUID(&pixel_format, &GUID_WICPixelFormat32bppBGR))
|
|
|
|
info->Format = D3DFMT_X8R8G8B8;
|
2010-04-12 11:21:14 +02:00
|
|
|
else if (IsEqualGUID(&pixel_format, &GUID_WICPixelFormat32bppBGRA))
|
|
|
|
info->Format = D3DFMT_A8R8G8B8;
|
2010-04-09 08:43:17 +02:00
|
|
|
else {
|
|
|
|
WARN("Unsupported pixel format %s\n", debugstr_guid(&pixel_format));
|
|
|
|
hr = D3DXERR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frame)
|
|
|
|
IWICBitmapFrameDecode_Release(frame);
|
|
|
|
|
|
|
|
info->Depth = 1;
|
|
|
|
info->MipLevels = 1;
|
|
|
|
info->ResourceType = D3DRTYPE_TEXTURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (decoder)
|
|
|
|
IWICBitmapDecoder_Release(decoder);
|
|
|
|
|
|
|
|
if (SUCCEEDED(initresult))
|
|
|
|
CoUninitialize();
|
2009-06-01 18:30:15 +02:00
|
|
|
|
2010-04-09 08:43:17 +02:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
/* Missing formats are not detected yet and will fail silently without the FIXME */
|
|
|
|
FIXME("Invalid or unsupported image file\n");
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
}
|
2009-06-01 18:30:15 +02:00
|
|
|
|
2010-04-09 08:43:17 +02:00
|
|
|
return D3D_OK;
|
2009-05-23 12:56:19 +02:00
|
|
|
}
|
|
|
|
|
2009-06-01 18:30:15 +02:00
|
|
|
/************************************************************
|
|
|
|
* D3DXGetImageInfoFromFile
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: D3D_OK, if we successfully load a valid image file or
|
|
|
|
* if we successfully load a file which is no valid image and info is NULL
|
|
|
|
* Failure: D3DXERR_INVALIDDATA, if we fail to load file or
|
|
|
|
* if file is not a valid image file and info is not NULL
|
|
|
|
* D3DERR_INVALIDCALL, if file is NULL
|
|
|
|
*
|
|
|
|
*/
|
2009-05-23 12:56:19 +02:00
|
|
|
HRESULT WINAPI D3DXGetImageInfoFromFileA(LPCSTR file, D3DXIMAGE_INFO *info)
|
|
|
|
{
|
2009-06-01 18:30:15 +02:00
|
|
|
LPWSTR widename;
|
|
|
|
HRESULT hr;
|
|
|
|
int strlength;
|
2010-04-05 20:28:07 +02:00
|
|
|
|
|
|
|
TRACE("(%s, %p): relay\n", debugstr_a(file), info);
|
2009-06-01 18:30:15 +02:00
|
|
|
|
|
|
|
if( !file ) return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
strlength = MultiByteToWideChar(CP_ACP, 0, file, -1, NULL, 0);
|
|
|
|
widename = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, strlength * sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, file, -1, widename, strlength);
|
|
|
|
|
|
|
|
hr = D3DXGetImageInfoFromFileW(widename, info);
|
|
|
|
HeapFree(GetProcessHeap(), 0, widename);
|
|
|
|
|
|
|
|
return hr;
|
2009-05-23 12:56:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI D3DXGetImageInfoFromFileW(LPCWSTR file, D3DXIMAGE_INFO *info)
|
|
|
|
{
|
2009-06-01 18:30:15 +02:00
|
|
|
HRESULT hr;
|
|
|
|
DWORD size;
|
|
|
|
LPVOID buffer;
|
2010-04-05 20:28:07 +02:00
|
|
|
|
|
|
|
TRACE("(%s, %p): relay\n", debugstr_w(file), info);
|
2009-06-01 18:30:15 +02:00
|
|
|
|
|
|
|
if( !file ) return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
hr = map_view_of_file(file, &buffer, &size);
|
|
|
|
if(FAILED(hr)) return D3DXERR_INVALIDDATA;
|
|
|
|
|
|
|
|
hr = D3DXGetImageInfoFromFileInMemory(buffer, size, info);
|
|
|
|
UnmapViewOfFile(buffer);
|
|
|
|
|
|
|
|
return hr;
|
2009-05-23 12:56:19 +02:00
|
|
|
}
|
|
|
|
|
2009-06-01 18:30:15 +02:00
|
|
|
/************************************************************
|
|
|
|
* D3DXGetImageInfoFromResource
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: D3D_OK, if resource is a valid image file
|
|
|
|
* Failure: D3DXERR_INVALIDDATA, if resource is no valid image file or NULL or
|
|
|
|
* if we fail to load resource
|
|
|
|
*
|
|
|
|
*/
|
2009-05-23 12:56:19 +02:00
|
|
|
HRESULT WINAPI D3DXGetImageInfoFromResourceA(HMODULE module, LPCSTR resource, D3DXIMAGE_INFO *info)
|
|
|
|
{
|
2009-06-01 18:30:15 +02:00
|
|
|
HRSRC resinfo;
|
2010-04-05 20:28:07 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %s, %p)\n", module, debugstr_a(resource), info);
|
2009-06-01 18:30:15 +02:00
|
|
|
|
|
|
|
resinfo = FindResourceA(module, resource, (LPCSTR)RT_RCDATA);
|
|
|
|
if(resinfo) {
|
|
|
|
LPVOID buffer;
|
|
|
|
HRESULT hr;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
hr = load_resource_into_memory(module, resinfo, &buffer, &size);
|
|
|
|
if(FAILED(hr)) return D3DXERR_INVALIDDATA;
|
|
|
|
return D3DXGetImageInfoFromFileInMemory(buffer, size, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
resinfo = FindResourceA(module, resource, (LPCSTR)RT_BITMAP);
|
|
|
|
if(resinfo) {
|
|
|
|
FIXME("Implement loading bitmaps from resource type RT_BITMAP\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
return D3DXERR_INVALIDDATA;
|
2009-05-23 12:56:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI D3DXGetImageInfoFromResourceW(HMODULE module, LPCWSTR resource, D3DXIMAGE_INFO *info)
|
|
|
|
{
|
2009-06-01 18:30:15 +02:00
|
|
|
HRSRC resinfo;
|
2010-04-05 20:28:07 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %s, %p)\n", module, debugstr_w(resource), info);
|
2009-06-01 18:30:15 +02:00
|
|
|
|
|
|
|
resinfo = FindResourceW(module, resource, (LPCWSTR)RT_RCDATA);
|
|
|
|
if(resinfo) {
|
|
|
|
LPVOID buffer;
|
|
|
|
HRESULT hr;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
hr = load_resource_into_memory(module, resinfo, &buffer, &size);
|
|
|
|
if(FAILED(hr)) return D3DXERR_INVALIDDATA;
|
|
|
|
return D3DXGetImageInfoFromFileInMemory(buffer, size, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
resinfo = FindResourceW(module, resource, (LPCWSTR)RT_BITMAP);
|
|
|
|
if(resinfo) {
|
|
|
|
FIXME("Implement loading bitmaps from resource type RT_BITMAP\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
return D3DXERR_INVALIDDATA;
|
2009-05-23 12:56:19 +02:00
|
|
|
}
|
2009-06-22 17:21:30 +02:00
|
|
|
|
|
|
|
/************************************************************
|
|
|
|
* D3DXLoadSurfaceFromFileInMemory
|
|
|
|
*
|
|
|
|
* Loads data from a given buffer into a surface and fills a given
|
|
|
|
* D3DXIMAGE_INFO structure with info about the source data.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pDestSurface [I] pointer to the surface
|
|
|
|
* pDestPalette [I] palette to use
|
|
|
|
* pDestRect [I] to be filled area of the surface
|
|
|
|
* pSrcData [I] pointer to the source data
|
|
|
|
* SrcDataSize [I] size of the source data in bytes
|
|
|
|
* pSrcRect [I] area of the source data to load
|
|
|
|
* dwFilter [I] filter to apply on stretching
|
|
|
|
* Colorkey [I] colorkey
|
|
|
|
* pSrcInfo [O] pointer to a D3DXIMAGE_INFO structure
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: D3D_OK
|
|
|
|
* Failure: D3DERR_INVALIDCALL, if pDestSurface or pSrcData or SrcDataSize are NULL
|
|
|
|
* D3DXERR_INVALIDDATA, if pSrcData is no valid image file
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI D3DXLoadSurfaceFromFileInMemory(LPDIRECT3DSURFACE9 pDestSurface,
|
|
|
|
CONST PALETTEENTRY *pDestPalette,
|
|
|
|
CONST RECT *pDestRect,
|
|
|
|
LPCVOID pSrcData,
|
|
|
|
UINT SrcDataSize,
|
|
|
|
CONST RECT *pSrcRect,
|
|
|
|
DWORD dwFilter,
|
|
|
|
D3DCOLOR Colorkey,
|
|
|
|
D3DXIMAGE_INFO *pSrcInfo)
|
|
|
|
{
|
2010-08-31 17:43:35 +02:00
|
|
|
D3DXIMAGE_INFO imginfo;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2010-11-08 19:57:45 +01:00
|
|
|
IWICImagingFactory *factory;
|
|
|
|
IWICBitmapDecoder *decoder;
|
|
|
|
IWICBitmapFrameDecode *bitmapframe;
|
|
|
|
IWICStream *stream;
|
|
|
|
|
|
|
|
const PixelFormatDesc *formatdesc;
|
|
|
|
WICRect wicrect;
|
|
|
|
RECT rect;
|
|
|
|
|
2010-08-31 17:43:35 +02:00
|
|
|
TRACE("(%p, %p, %p, %p, %d, %p, %d, %x, %p)\n", pDestSurface, pDestPalette, pDestRect, pSrcData,
|
|
|
|
SrcDataSize, pSrcRect, dwFilter, Colorkey, pSrcInfo);
|
|
|
|
|
|
|
|
if (!pDestSurface || !pSrcData | !SrcDataSize)
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
hr = D3DXGetImageInfoFromFileInMemory(pSrcData, SrcDataSize, &imginfo);
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2010-11-08 19:57:45 +01:00
|
|
|
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
2010-08-31 17:43:35 +02:00
|
|
|
|
2010-11-08 19:57:45 +01:00
|
|
|
if (FAILED(CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, &IID_IWICImagingFactory, (void**)&factory)))
|
|
|
|
goto cleanup_err;
|
2010-08-31 17:43:35 +02:00
|
|
|
|
2010-11-08 19:57:45 +01:00
|
|
|
if (FAILED(IWICImagingFactory_CreateStream(factory, &stream)))
|
|
|
|
{
|
|
|
|
IWICImagingFactory_Release(factory);
|
|
|
|
goto cleanup_err;
|
|
|
|
}
|
2010-08-31 17:43:35 +02:00
|
|
|
|
2010-11-08 19:57:45 +01:00
|
|
|
IWICStream_InitializeFromMemory(stream, (BYTE*)pSrcData, SrcDataSize);
|
2010-08-31 17:43:35 +02:00
|
|
|
|
2010-11-08 19:57:45 +01:00
|
|
|
hr = IWICImagingFactory_CreateDecoderFromStream(factory, (IStream*)stream, NULL, 0, &decoder);
|
2010-08-31 17:43:35 +02:00
|
|
|
|
2010-11-08 19:57:45 +01:00
|
|
|
IStream_Release(stream);
|
|
|
|
IWICImagingFactory_Release(factory);
|
2010-08-31 17:43:35 +02:00
|
|
|
|
2010-11-08 19:57:45 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
goto cleanup_err;
|
2010-08-31 17:43:35 +02:00
|
|
|
|
2010-11-08 19:57:45 +01:00
|
|
|
hr = IWICBitmapDecoder_GetFrame(decoder, 0, &bitmapframe);
|
2010-08-31 17:43:35 +02:00
|
|
|
|
2010-11-08 19:57:45 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
goto cleanup_bmp;
|
2010-08-31 17:43:35 +02:00
|
|
|
|
2010-11-08 19:57:45 +01:00
|
|
|
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;
|
|
|
|
}
|
2010-08-31 17:43:35 +02:00
|
|
|
|
2010-11-08 19:57:45 +01:00
|
|
|
SetRect(&rect, 0, 0, wicrect.Width, wicrect.Height);
|
2010-08-31 17:43:35 +02:00
|
|
|
|
2010-11-08 19:57:45 +01:00
|
|
|
formatdesc = get_format_info(imginfo.Format);
|
2010-08-31 17:43:35 +02:00
|
|
|
|
2010-11-08 19:57:45 +01:00
|
|
|
if (formatdesc->format == D3DFMT_UNKNOWN)
|
|
|
|
{
|
|
|
|
FIXME("Unsupported pixel format\n");
|
|
|
|
hr = D3DXERR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BYTE *buffer;
|
|
|
|
DWORD pitch;
|
2010-08-31 17:43:35 +02:00
|
|
|
|
2010-11-08 19:57:45 +01:00
|
|
|
pitch = formatdesc->bytes_per_pixel * wicrect.Width;
|
|
|
|
buffer = HeapAlloc(GetProcessHeap(), 0, pitch * wicrect.Height);
|
2010-08-31 17:43:35 +02:00
|
|
|
|
2010-11-08 19:57:45 +01:00
|
|
|
hr = IWICBitmapFrameDecode_CopyPixels(bitmapframe, &wicrect, pitch,
|
|
|
|
pitch * wicrect.Height, buffer);
|
2010-08-31 17:43:35 +02:00
|
|
|
|
2010-11-08 19:57:45 +01:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = D3DXLoadSurfaceFromMemory(pDestSurface, pDestPalette, pDestRect,
|
|
|
|
buffer, imginfo.Format, pitch,
|
|
|
|
NULL, &rect, dwFilter, Colorkey);
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, buffer);
|
|
|
|
}
|
2010-02-15 09:48:03 +01:00
|
|
|
|
2010-11-08 19:57:45 +01:00
|
|
|
IWICBitmapFrameDecode_Release(bitmapframe);
|
2010-11-08 20:01:11 +01:00
|
|
|
|
|
|
|
cleanup_bmp:
|
2010-11-08 19:57:45 +01:00
|
|
|
IWICBitmapDecoder_Release(decoder);
|
2010-08-31 17:43:35 +02:00
|
|
|
|
|
|
|
cleanup_err:
|
2010-11-08 19:57:45 +01:00
|
|
|
CoUninitialize();
|
2010-08-31 17:43:35 +02:00
|
|
|
|
2010-11-08 19:57:45 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
2010-08-31 17:43:35 +02:00
|
|
|
|
|
|
|
if (pSrcInfo)
|
|
|
|
*pSrcInfo = imginfo;
|
|
|
|
|
|
|
|
return D3D_OK;
|
2009-06-22 17:21:30 +02:00
|
|
|
}
|
2009-06-22 17:33:48 +02:00
|
|
|
|
|
|
|
/************************************************************
|
|
|
|
* D3DXLoadSurfaceFromFile
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI D3DXLoadSurfaceFromFileA(LPDIRECT3DSURFACE9 pDestSurface,
|
|
|
|
CONST PALETTEENTRY *pDestPalette,
|
|
|
|
CONST RECT *pDestRect,
|
|
|
|
LPCSTR pSrcFile,
|
|
|
|
CONST RECT *pSrcRect,
|
|
|
|
DWORD dwFilter,
|
|
|
|
D3DCOLOR Colorkey,
|
|
|
|
D3DXIMAGE_INFO *pSrcInfo)
|
|
|
|
{
|
|
|
|
LPWSTR pWidename;
|
|
|
|
HRESULT hr;
|
|
|
|
int strlength;
|
2010-04-05 20:28:07 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %p, %p, %s, %p, %u, %#x, %p): relay\n", pDestSurface, pDestPalette, pDestRect, debugstr_a(pSrcFile),
|
|
|
|
pSrcRect, dwFilter, Colorkey, pSrcInfo);
|
2009-06-22 17:33:48 +02:00
|
|
|
|
|
|
|
if( !pSrcFile || !pDestSurface ) return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
strlength = MultiByteToWideChar(CP_ACP, 0, pSrcFile, -1, NULL, 0);
|
|
|
|
pWidename = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, strlength * sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pSrcFile, -1, pWidename, strlength);
|
|
|
|
|
|
|
|
hr = D3DXLoadSurfaceFromFileW(pDestSurface, pDestPalette, pDestRect, pWidename, pSrcRect, dwFilter, Colorkey, pSrcInfo);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pWidename);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI D3DXLoadSurfaceFromFileW(LPDIRECT3DSURFACE9 pDestSurface,
|
|
|
|
CONST PALETTEENTRY *pDestPalette,
|
|
|
|
CONST RECT *pDestRect,
|
|
|
|
LPCWSTR pSrcFile,
|
|
|
|
CONST RECT *pSrcRect,
|
|
|
|
DWORD Filter,
|
|
|
|
D3DCOLOR Colorkey,
|
|
|
|
D3DXIMAGE_INFO *pSrcInfo)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
DWORD dwSize;
|
|
|
|
LPVOID pBuffer;
|
2010-04-05 20:28:07 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %p, %p, %s, %p, %u, %#x, %p): relay\n", pDestSurface, pDestPalette, pDestRect, debugstr_w(pSrcFile),
|
|
|
|
pSrcRect, Filter, Colorkey, pSrcInfo);
|
2009-06-22 17:33:48 +02:00
|
|
|
|
|
|
|
if( !pSrcFile || !pDestSurface ) return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
hr = map_view_of_file(pSrcFile, &pBuffer, &dwSize);
|
|
|
|
if(FAILED(hr)) return D3DXERR_INVALIDDATA;
|
|
|
|
|
|
|
|
hr = D3DXLoadSurfaceFromFileInMemory(pDestSurface, pDestPalette, pDestRect, pBuffer, dwSize, pSrcRect, Filter, Colorkey, pSrcInfo);
|
|
|
|
UnmapViewOfFile(pBuffer);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
2009-06-22 17:38:15 +02:00
|
|
|
|
|
|
|
/************************************************************
|
|
|
|
* D3DXLoadSurfaceFromResource
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI D3DXLoadSurfaceFromResourceA(LPDIRECT3DSURFACE9 pDestSurface,
|
|
|
|
CONST PALETTEENTRY *pDestPalette,
|
|
|
|
CONST RECT *pDestRect,
|
|
|
|
HMODULE hSrcModule,
|
|
|
|
LPCSTR pResource,
|
|
|
|
CONST RECT *pSrcRect,
|
|
|
|
DWORD dwFilter,
|
|
|
|
D3DCOLOR Colorkey,
|
|
|
|
D3DXIMAGE_INFO *pSrcInfo)
|
|
|
|
{
|
|
|
|
HRSRC hResInfo;
|
2010-04-05 20:28:07 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %p, %p, %p, %s, %p, %u, %#x, %p): relay\n", pDestSurface, pDestPalette, pDestRect, hSrcModule,
|
|
|
|
debugstr_a(pResource), pSrcRect, dwFilter, Colorkey, pSrcInfo);
|
2009-06-22 17:38:15 +02:00
|
|
|
|
|
|
|
if( !pDestSurface ) return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
hResInfo = FindResourceA(hSrcModule, pResource, (LPCSTR)RT_RCDATA);
|
|
|
|
if(hResInfo) {
|
|
|
|
LPVOID pBuffer;
|
|
|
|
HRESULT hr;
|
|
|
|
DWORD dwSize;
|
|
|
|
|
|
|
|
hr = load_resource_into_memory(hSrcModule, hResInfo, &pBuffer, &dwSize);
|
|
|
|
if(FAILED(hr)) return D3DXERR_INVALIDDATA;
|
|
|
|
return D3DXLoadSurfaceFromFileInMemory(pDestSurface, pDestPalette, pDestRect, pBuffer, dwSize, pSrcRect, dwFilter, Colorkey, pSrcInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
hResInfo = FindResourceA(hSrcModule, pResource, (LPCSTR)RT_BITMAP);
|
|
|
|
if(hResInfo) {
|
|
|
|
FIXME("Implement loading bitmaps from resource type RT_BITMAP\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI D3DXLoadSurfaceFromResourceW(LPDIRECT3DSURFACE9 pDestSurface,
|
|
|
|
CONST PALETTEENTRY *pDestPalette,
|
|
|
|
CONST RECT *pDestRect,
|
|
|
|
HMODULE hSrcModule,
|
|
|
|
LPCWSTR pResource,
|
|
|
|
CONST RECT *pSrcRect,
|
|
|
|
DWORD dwFilter,
|
|
|
|
D3DCOLOR Colorkey,
|
|
|
|
D3DXIMAGE_INFO *pSrcInfo)
|
|
|
|
{
|
|
|
|
HRSRC hResInfo;
|
2010-04-05 20:28:07 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %p, %p, %p, %s, %p, %u, %#x, %p): relay\n", pDestSurface, pDestPalette, pDestRect, hSrcModule,
|
|
|
|
debugstr_w(pResource), pSrcRect, dwFilter, Colorkey, pSrcInfo);
|
2009-06-22 17:38:15 +02:00
|
|
|
|
|
|
|
if( !pDestSurface ) return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
hResInfo = FindResourceW(hSrcModule, pResource, (LPCWSTR)RT_RCDATA);
|
|
|
|
if(hResInfo) {
|
|
|
|
LPVOID pBuffer;
|
|
|
|
HRESULT hr;
|
|
|
|
DWORD dwSize;
|
|
|
|
|
|
|
|
hr = load_resource_into_memory(hSrcModule, hResInfo, &pBuffer, &dwSize);
|
|
|
|
if(FAILED(hr)) return D3DXERR_INVALIDDATA;
|
|
|
|
return D3DXLoadSurfaceFromFileInMemory(pDestSurface, pDestPalette, pDestRect, pBuffer, dwSize, pSrcRect, dwFilter, Colorkey, pSrcInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
hResInfo = FindResourceW(hSrcModule, pResource, (LPCWSTR)RT_BITMAP);
|
|
|
|
if(hResInfo) {
|
|
|
|
FIXME("Implement loading bitmaps from resource type RT_BITMAP\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
}
|
2009-06-22 17:45:27 +02:00
|
|
|
|
2009-10-13 13:58:29 +02:00
|
|
|
|
|
|
|
/************************************************************
|
2010-07-28 21:33:14 +02:00
|
|
|
* helper functions for D3DXLoadSurfaceFromMemory
|
2009-10-13 13:58:29 +02:00
|
|
|
*/
|
2010-07-28 21:33:14 +02:00
|
|
|
struct argb_conversion_info
|
2009-10-13 13:58:29 +02:00
|
|
|
{
|
2010-07-28 21:33:14 +02:00
|
|
|
CONST PixelFormatDesc *srcformat;
|
|
|
|
CONST PixelFormatDesc *destformat;
|
2009-10-13 13:58:29 +02:00
|
|
|
DWORD srcshift[4], destshift[4];
|
|
|
|
DWORD srcmask[4], destmask[4];
|
|
|
|
BOOL process_channel[4];
|
2010-07-28 21:33:14 +02:00
|
|
|
DWORD channelmask;
|
|
|
|
};
|
2009-10-13 13:58:29 +02:00
|
|
|
|
2010-07-28 21:33:14 +02:00
|
|
|
static void init_argb_conversion_info(CONST PixelFormatDesc *srcformat, CONST PixelFormatDesc *destformat, struct argb_conversion_info *info)
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
ZeroMemory(info->process_channel, 4 * sizeof(BOOL));
|
|
|
|
info->channelmask = 0;
|
2009-10-13 13:58:29 +02:00
|
|
|
|
2010-07-28 21:33:14 +02:00
|
|
|
info->srcformat = srcformat;
|
|
|
|
info->destformat = destformat;
|
2009-10-13 13:58:29 +02:00
|
|
|
|
|
|
|
for(i = 0;i < 4;i++) {
|
|
|
|
/* srcshift is used to extract the _relevant_ components */
|
2010-07-28 21:33:14 +02:00
|
|
|
info->srcshift[i] = srcformat->shift[i] + max( srcformat->bits[i] - destformat->bits[i], 0);
|
2009-10-13 13:58:29 +02:00
|
|
|
|
|
|
|
/* destshift is used to move the components to the correct position */
|
2010-07-28 21:33:14 +02:00
|
|
|
info->destshift[i] = destformat->shift[i] + max(destformat->bits[i] - srcformat->bits[i], 0);
|
2009-10-13 13:58:29 +02:00
|
|
|
|
2010-07-28 21:33:14 +02:00
|
|
|
info->srcmask[i] = ((1 << srcformat->bits[i]) - 1) << srcformat->shift[i];
|
|
|
|
info->destmask[i] = ((1 << destformat->bits[i]) - 1) << destformat->shift[i];
|
2009-10-13 13:58:29 +02:00
|
|
|
|
|
|
|
/* channelmask specifies bits which aren't used in the source format but in the destination one */
|
|
|
|
if(destformat->bits[i]) {
|
2010-07-28 21:33:14 +02:00
|
|
|
if(srcformat->bits[i]) info->process_channel[i] = TRUE;
|
|
|
|
else info->channelmask |= info->destmask[i];
|
2009-10-13 13:58:29 +02:00
|
|
|
}
|
|
|
|
}
|
2010-07-28 21:33:14 +02:00
|
|
|
}
|
|
|
|
|
2011-02-16 02:39:21 +01:00
|
|
|
static DWORD dword_from_bytes(CONST BYTE *src, UINT bytes_per_pixel)
|
|
|
|
{
|
|
|
|
DWORD ret = 0;
|
|
|
|
static BOOL fixme_once;
|
|
|
|
|
|
|
|
if(bytes_per_pixel > sizeof(DWORD)) {
|
2011-02-23 21:49:13 +01:00
|
|
|
if(!fixme_once++) FIXME("Unsupported image: %u bytes per pixel\n", bytes_per_pixel);
|
2011-02-16 02:39:21 +01:00
|
|
|
bytes_per_pixel = sizeof(DWORD);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&ret, src, bytes_per_pixel);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dword_to_bytes(BYTE *dst, DWORD dword, UINT bytes_per_pixel)
|
|
|
|
{
|
|
|
|
static BOOL fixme_once;
|
|
|
|
|
|
|
|
if(bytes_per_pixel > sizeof(DWORD)) {
|
2011-02-23 21:49:13 +01:00
|
|
|
if(!fixme_once++) FIXME("Unsupported image: %u bytes per pixel\n", bytes_per_pixel);
|
2011-02-16 02:39:21 +01:00
|
|
|
ZeroMemory(dst, bytes_per_pixel);
|
|
|
|
bytes_per_pixel = sizeof(DWORD);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(dst, &dword, bytes_per_pixel);
|
|
|
|
}
|
|
|
|
|
2010-07-28 21:33:14 +02:00
|
|
|
/************************************************************
|
|
|
|
* get_relevant_argb_components
|
|
|
|
*
|
|
|
|
* Extracts the relevant components from the source color and
|
|
|
|
* drops the less significant bits if they aren't used by the destination format.
|
|
|
|
*/
|
|
|
|
static void get_relevant_argb_components(CONST struct argb_conversion_info *info, CONST DWORD col, DWORD *out)
|
|
|
|
{
|
|
|
|
UINT i = 0;
|
|
|
|
for(;i < 4;i++)
|
|
|
|
if(info->process_channel[i])
|
|
|
|
out[i] = (col & info->srcmask[i]) >> info->srcshift[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************
|
|
|
|
* make_argb_color
|
|
|
|
*
|
|
|
|
* Recombines the output of get_relevant_argb_components and converts
|
|
|
|
* it to the destination format.
|
|
|
|
*/
|
2011-02-16 02:39:21 +01:00
|
|
|
static DWORD make_argb_color(CONST struct argb_conversion_info *info, CONST DWORD *in)
|
2010-07-28 21:33:14 +02:00
|
|
|
{
|
|
|
|
UINT i;
|
2011-02-16 02:39:21 +01:00
|
|
|
DWORD val = 0;
|
2010-07-28 21:33:14 +02:00
|
|
|
|
|
|
|
for(i = 0;i < 4;i++) {
|
|
|
|
if(info->process_channel[i]) {
|
|
|
|
/* necessary to make sure that e.g. an X4R4G4B4 white maps to an R8G8B8 white instead of 0xf0f0f0 */
|
|
|
|
signed int shift;
|
2011-02-16 02:39:21 +01:00
|
|
|
for(shift = info->destshift[i]; shift > info->destformat->shift[i]; shift -= info->srcformat->bits[i]) val |= in[i] << shift;
|
|
|
|
val |= (in[i] >> (info->destformat->shift[i] - shift)) << info->destformat->shift[i];
|
2010-07-28 21:33:14 +02:00
|
|
|
}
|
|
|
|
}
|
2011-02-16 02:39:21 +01:00
|
|
|
val |= info->channelmask; /* new channels are set to their maximal value */
|
|
|
|
return val;
|
2010-07-28 21:33:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************
|
|
|
|
* copy_simple_data
|
|
|
|
*
|
|
|
|
* Copies the source buffer to the destination buffer, performing
|
|
|
|
* any necessary format conversion and color keying.
|
2010-08-21 12:54:38 +02:00
|
|
|
* Pixels outsize the source rect are blacked out.
|
2010-07-28 21:33:14 +02:00
|
|
|
* Works only for ARGB formats with 1 - 4 bytes per pixel.
|
|
|
|
*/
|
2010-11-11 22:13:06 +01:00
|
|
|
static void copy_simple_data(CONST BYTE *src, UINT srcpitch, POINT srcsize,
|
|
|
|
CONST PixelFormatDesc *srcformat,
|
|
|
|
BYTE *dest, UINT destpitch, POINT destsize,
|
|
|
|
CONST PixelFormatDesc *destformat,
|
|
|
|
D3DCOLOR colorkey)
|
2010-07-28 21:33:14 +02:00
|
|
|
{
|
2010-11-11 22:13:06 +01:00
|
|
|
struct argb_conversion_info conv_info, ck_conv_info;
|
|
|
|
DWORD channels[4], pixel;
|
2010-07-28 21:33:14 +02:00
|
|
|
UINT minwidth, minheight;
|
|
|
|
UINT x, y;
|
|
|
|
|
|
|
|
ZeroMemory(channels, sizeof(channels));
|
|
|
|
init_argb_conversion_info(srcformat, destformat, &conv_info);
|
2009-10-13 13:58:29 +02:00
|
|
|
|
|
|
|
minwidth = (srcsize.x < destsize.x) ? srcsize.x : destsize.x;
|
|
|
|
minheight = (srcsize.y < destsize.y) ? srcsize.y : destsize.y;
|
|
|
|
|
2010-11-11 22:13:06 +01:00
|
|
|
if(colorkey) {
|
|
|
|
/* color keys are always represented in D3DFMT_A8R8G8B8 format */
|
|
|
|
const PixelFormatDesc *ckformatdesc;
|
|
|
|
|
|
|
|
ckformatdesc = get_format_info(D3DFMT_A8R8G8B8);
|
|
|
|
init_argb_conversion_info(srcformat, ckformatdesc, &ck_conv_info);
|
|
|
|
}
|
|
|
|
|
2009-10-13 13:58:29 +02:00
|
|
|
for(y = 0;y < minheight;y++) {
|
2011-02-16 02:39:21 +01:00
|
|
|
const BYTE *srcptr = src + y * srcpitch;
|
2010-08-04 17:53:14 +02:00
|
|
|
BYTE *destptr = dest + y * destpitch;
|
2011-02-16 02:39:21 +01:00
|
|
|
DWORD val = 0;
|
|
|
|
|
2009-10-13 13:58:29 +02:00
|
|
|
for(x = 0;x < minwidth;x++) {
|
|
|
|
/* extract source color components */
|
2011-04-05 17:26:57 +02:00
|
|
|
pixel = dword_from_bytes(srcptr, srcformat->bytes_per_pixel);
|
|
|
|
get_relevant_argb_components(&conv_info, pixel, channels);
|
2009-10-13 13:58:29 +02:00
|
|
|
|
|
|
|
/* recombine the components */
|
2011-04-05 17:26:57 +02:00
|
|
|
val = make_argb_color(&conv_info, channels);
|
2010-07-28 21:33:14 +02:00
|
|
|
|
2010-11-11 22:13:06 +01:00
|
|
|
if(colorkey) {
|
2011-02-16 02:39:21 +01:00
|
|
|
get_relevant_argb_components(&ck_conv_info, pixel, channels);
|
|
|
|
pixel = make_argb_color(&ck_conv_info, channels);
|
2010-11-11 22:13:06 +01:00
|
|
|
if(pixel == colorkey)
|
|
|
|
/* make this pixel transparent */
|
2011-02-16 02:39:21 +01:00
|
|
|
val &= ~conv_info.destmask[0];
|
2010-11-11 22:13:06 +01:00
|
|
|
}
|
|
|
|
|
2011-02-16 02:39:21 +01:00
|
|
|
dword_to_bytes(destptr, val, destformat->bytes_per_pixel);
|
2009-10-13 13:58:29 +02:00
|
|
|
srcptr += srcformat->bytes_per_pixel;
|
|
|
|
destptr += destformat->bytes_per_pixel;
|
|
|
|
}
|
2010-08-21 12:54:38 +02:00
|
|
|
|
|
|
|
if(srcsize.x < destsize.x) /* black out remaining pixels */
|
|
|
|
ZeroMemory(destptr, destformat->bytes_per_pixel * (destsize.x - srcsize.x));
|
2009-10-13 13:58:29 +02:00
|
|
|
}
|
2010-08-21 12:54:38 +02:00
|
|
|
if(srcsize.y < destsize.y) /* black out remaining pixels */
|
|
|
|
ZeroMemory(dest + srcsize.y * destpitch, destpitch * (destsize.y - srcsize.y));
|
2009-10-13 13:58:29 +02:00
|
|
|
}
|
|
|
|
|
2010-07-28 21:56:00 +02:00
|
|
|
/************************************************************
|
|
|
|
* point_filter_simple_data
|
|
|
|
*
|
|
|
|
* Copies the source buffer to the destination buffer, performing
|
|
|
|
* any necessary format conversion, color keying and stretching
|
|
|
|
* using a point filter.
|
|
|
|
* Works only for ARGB formats with 1 - 4 bytes per pixel.
|
|
|
|
*/
|
2010-11-11 22:13:06 +01:00
|
|
|
static void point_filter_simple_data(CONST BYTE *src, UINT srcpitch, POINT srcsize,
|
|
|
|
CONST PixelFormatDesc *srcformat,
|
|
|
|
BYTE *dest, UINT destpitch, POINT destsize,
|
|
|
|
CONST PixelFormatDesc *destformat,
|
|
|
|
D3DCOLOR colorkey)
|
2010-07-28 21:56:00 +02:00
|
|
|
{
|
2010-11-11 22:13:06 +01:00
|
|
|
struct argb_conversion_info conv_info, ck_conv_info;
|
|
|
|
DWORD channels[4], pixel;
|
2010-07-28 21:56:00 +02:00
|
|
|
|
|
|
|
UINT x, y;
|
|
|
|
|
|
|
|
ZeroMemory(channels, sizeof(channels));
|
|
|
|
init_argb_conversion_info(srcformat, destformat, &conv_info);
|
|
|
|
|
2010-11-11 22:13:06 +01:00
|
|
|
if(colorkey) {
|
|
|
|
/* color keys are always represented in D3DFMT_A8R8G8B8 format */
|
|
|
|
const PixelFormatDesc *ckformatdesc;
|
|
|
|
|
|
|
|
ckformatdesc = get_format_info(D3DFMT_A8R8G8B8);
|
|
|
|
init_argb_conversion_info(srcformat, ckformatdesc, &ck_conv_info);
|
|
|
|
}
|
|
|
|
|
2010-07-28 21:56:00 +02:00
|
|
|
for(y = 0;y < destsize.y;y++) {
|
2010-08-04 17:53:14 +02:00
|
|
|
BYTE *destptr = dest + y * destpitch;
|
|
|
|
const BYTE *bufptr = src + srcpitch * (y * srcsize.y / destsize.y);
|
2010-07-28 21:56:00 +02:00
|
|
|
|
|
|
|
for(x = 0;x < destsize.x;x++) {
|
2010-08-21 13:07:09 +02:00
|
|
|
const BYTE *srcptr = bufptr + (x * srcsize.x / destsize.x) * srcformat->bytes_per_pixel;
|
2011-02-16 02:39:21 +01:00
|
|
|
DWORD val = 0;
|
2010-08-21 13:07:09 +02:00
|
|
|
|
2010-07-28 21:56:00 +02:00
|
|
|
/* extract source color components */
|
2011-04-05 17:26:57 +02:00
|
|
|
pixel = dword_from_bytes(srcptr, srcformat->bytes_per_pixel);
|
|
|
|
get_relevant_argb_components(&conv_info, pixel, channels);
|
2010-07-28 21:56:00 +02:00
|
|
|
|
|
|
|
/* recombine the components */
|
2011-04-05 17:26:57 +02:00
|
|
|
val = make_argb_color(&conv_info, channels);
|
2010-07-28 21:56:00 +02:00
|
|
|
|
2010-11-11 22:13:06 +01:00
|
|
|
if(colorkey) {
|
2011-02-16 02:39:21 +01:00
|
|
|
get_relevant_argb_components(&ck_conv_info, pixel, channels);
|
|
|
|
pixel = make_argb_color(&ck_conv_info, channels);
|
2010-11-11 22:13:06 +01:00
|
|
|
if(pixel == colorkey)
|
|
|
|
/* make this pixel transparent */
|
2011-02-16 02:39:21 +01:00
|
|
|
val &= ~conv_info.destmask[0];
|
2010-11-11 22:13:06 +01:00
|
|
|
}
|
|
|
|
|
2011-02-16 02:39:21 +01:00
|
|
|
dword_to_bytes(destptr, val, destformat->bytes_per_pixel);
|
2010-07-28 21:56:00 +02:00
|
|
|
destptr += destformat->bytes_per_pixel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-22 17:45:27 +02:00
|
|
|
/************************************************************
|
|
|
|
* D3DXLoadSurfaceFromMemory
|
|
|
|
*
|
|
|
|
* Loads data from a given memory chunk into a surface,
|
|
|
|
* applying any of the specified filters.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pDestSurface [I] pointer to the surface
|
|
|
|
* pDestPalette [I] palette to use
|
|
|
|
* pDestRect [I] to be filled area of the surface
|
|
|
|
* pSrcMemory [I] pointer to the source data
|
|
|
|
* SrcFormat [I] format of the source pixel data
|
|
|
|
* SrcPitch [I] number of bytes in a row
|
|
|
|
* pSrcPalette [I] palette used in the source image
|
|
|
|
* pSrcRect [I] area of the source data to load
|
|
|
|
* dwFilter [I] filter to apply on stretching
|
|
|
|
* Colorkey [I] colorkey
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: D3D_OK, if we successfully load the pixel data into our surface or
|
|
|
|
* if pSrcMemory is NULL but the other parameters are valid
|
|
|
|
* Failure: D3DERR_INVALIDCALL, if pDestSurface, SrcPitch or pSrcRect are NULL or
|
2010-07-28 21:51:42 +02:00
|
|
|
* if SrcFormat is an invalid format (other than D3DFMT_UNKNOWN) or
|
|
|
|
* if DestRect is invalid
|
2009-06-22 17:45:27 +02:00
|
|
|
* D3DXERR_INVALIDDATA, if we fail to lock pDestSurface
|
|
|
|
* E_FAIL, if SrcFormat is D3DFMT_UNKNOWN or the dimensions of pSrcRect are invalid
|
|
|
|
*
|
|
|
|
* NOTES
|
2009-10-13 13:58:29 +02:00
|
|
|
* pSrcRect specifies the dimensions of the source data;
|
|
|
|
* negative values for pSrcRect are allowed as we're only looking at the width and height anyway.
|
2009-06-22 17:45:27 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI D3DXLoadSurfaceFromMemory(LPDIRECT3DSURFACE9 pDestSurface,
|
|
|
|
CONST PALETTEENTRY *pDestPalette,
|
|
|
|
CONST RECT *pDestRect,
|
|
|
|
LPCVOID pSrcMemory,
|
|
|
|
D3DFORMAT SrcFormat,
|
|
|
|
UINT SrcPitch,
|
|
|
|
CONST PALETTEENTRY *pSrcPalette,
|
|
|
|
CONST RECT *pSrcRect,
|
|
|
|
DWORD dwFilter,
|
|
|
|
D3DCOLOR Colorkey)
|
|
|
|
{
|
2009-10-13 13:58:29 +02:00
|
|
|
CONST PixelFormatDesc *srcformatdesc, *destformatdesc;
|
|
|
|
D3DSURFACE_DESC surfdesc;
|
|
|
|
D3DLOCKED_RECT lockrect;
|
|
|
|
POINT srcsize, destsize;
|
|
|
|
HRESULT hr;
|
2010-04-05 20:28:07 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %p, %p, %p, %x, %u, %p, %p %u, %#x)\n", pDestSurface, pDestPalette, pDestRect, pSrcMemory,
|
|
|
|
SrcFormat, SrcPitch, pSrcPalette, pSrcRect, dwFilter, Colorkey);
|
2009-06-22 17:45:27 +02:00
|
|
|
|
|
|
|
if( !pDestSurface || !pSrcMemory || !pSrcRect ) return D3DERR_INVALIDCALL;
|
|
|
|
if(SrcFormat == D3DFMT_UNKNOWN || pSrcRect->left >= pSrcRect->right || pSrcRect->top >= pSrcRect->bottom) return E_FAIL;
|
2009-10-13 13:58:29 +02:00
|
|
|
|
2010-07-28 21:33:14 +02:00
|
|
|
if(dwFilter == D3DX_DEFAULT) dwFilter = D3DX_FILTER_TRIANGLE | D3DX_FILTER_DITHER;
|
2009-10-13 13:58:29 +02:00
|
|
|
|
|
|
|
IDirect3DSurface9_GetDesc(pDestSurface, &surfdesc);
|
|
|
|
|
|
|
|
srcformatdesc = get_format_info(SrcFormat);
|
|
|
|
destformatdesc = get_format_info(surfdesc.Format);
|
|
|
|
if( srcformatdesc->type == FORMAT_UNKNOWN || srcformatdesc->bytes_per_pixel > 4) return E_NOTIMPL;
|
|
|
|
if(destformatdesc->type == FORMAT_UNKNOWN || destformatdesc->bytes_per_pixel > 4) return E_NOTIMPL;
|
|
|
|
|
|
|
|
srcsize.x = pSrcRect->right - pSrcRect->left;
|
|
|
|
srcsize.y = pSrcRect->bottom - pSrcRect->top;
|
|
|
|
if( !pDestRect ) {
|
|
|
|
destsize.x = surfdesc.Width;
|
|
|
|
destsize.y = surfdesc.Height;
|
|
|
|
} else {
|
2010-07-28 21:51:42 +02:00
|
|
|
if(pDestRect->left > pDestRect->right || pDestRect->right > surfdesc.Width) return D3DERR_INVALIDCALL;
|
|
|
|
if(pDestRect->top > pDestRect->bottom || pDestRect->bottom > surfdesc.Height) return D3DERR_INVALIDCALL;
|
|
|
|
if(pDestRect->left < 0 || pDestRect->top < 0) return D3DERR_INVALIDCALL;
|
2009-10-13 13:58:29 +02:00
|
|
|
destsize.x = pDestRect->right - pDestRect->left;
|
|
|
|
destsize.y = pDestRect->bottom - pDestRect->top;
|
2010-07-28 21:51:42 +02:00
|
|
|
if(destsize.x == 0 || destsize.y == 0) return D3D_OK;
|
2009-10-13 13:58:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hr = IDirect3DSurface9_LockRect(pDestSurface, &lockrect, pDestRect, 0);
|
|
|
|
if(FAILED(hr)) return D3DXERR_INVALIDDATA;
|
|
|
|
|
2010-07-28 21:56:00 +02:00
|
|
|
if((dwFilter & 0xF) == D3DX_FILTER_NONE) {
|
2010-08-04 17:53:14 +02:00
|
|
|
copy_simple_data(pSrcMemory, SrcPitch, srcsize, srcformatdesc,
|
2010-11-11 22:13:06 +01:00
|
|
|
lockrect.pBits, lockrect.Pitch, destsize, destformatdesc,
|
|
|
|
Colorkey);
|
2010-07-28 21:56:00 +02:00
|
|
|
} else /*if((dwFilter & 0xF) == D3DX_FILTER_POINT) */ {
|
|
|
|
/* always apply a point filter until D3DX_FILTER_LINEAR, D3DX_FILTER_TRIANGLE and D3DX_FILTER_BOX are implemented */
|
2010-08-04 17:53:14 +02:00
|
|
|
point_filter_simple_data(pSrcMemory, SrcPitch, srcsize, srcformatdesc,
|
2010-11-11 22:13:06 +01:00
|
|
|
lockrect.pBits, lockrect.Pitch, destsize, destformatdesc,
|
|
|
|
Colorkey);
|
2010-07-28 21:56:00 +02:00
|
|
|
}
|
2009-10-13 13:58:29 +02:00
|
|
|
|
|
|
|
IDirect3DSurface9_UnlockRect(pDestSurface);
|
|
|
|
return D3D_OK;
|
2009-06-22 17:45:27 +02:00
|
|
|
}
|
2009-06-22 17:57:20 +02:00
|
|
|
|
|
|
|
/************************************************************
|
|
|
|
* D3DXLoadSurfaceFromSurface
|
|
|
|
*
|
|
|
|
* Copies the contents from one surface to another, performing any required
|
|
|
|
* format conversion, resizing or filtering.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pDestSurface [I] pointer to the destination surface
|
|
|
|
* pDestPalette [I] palette to use
|
|
|
|
* pDestRect [I] to be filled area of the surface
|
|
|
|
* pSrcSurface [I] pointer to the source surface
|
|
|
|
* pSrcPalette [I] palette used for the source surface
|
|
|
|
* pSrcRect [I] area of the source data to load
|
|
|
|
* dwFilter [I] filter to apply on resizing
|
|
|
|
* Colorkey [I] any ARGB value or 0 to disable color-keying
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: D3D_OK
|
|
|
|
* Failure: D3DERR_INVALIDCALL, if pDestSurface or pSrcSurface are NULL
|
|
|
|
* D3DXERR_INVALIDDATA, if one of the surfaces is not lockable
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI D3DXLoadSurfaceFromSurface(LPDIRECT3DSURFACE9 pDestSurface,
|
|
|
|
CONST PALETTEENTRY *pDestPalette,
|
|
|
|
CONST RECT *pDestRect,
|
|
|
|
LPDIRECT3DSURFACE9 pSrcSurface,
|
|
|
|
CONST PALETTEENTRY *pSrcPalette,
|
|
|
|
CONST RECT *pSrcRect,
|
|
|
|
DWORD dwFilter,
|
|
|
|
D3DCOLOR Colorkey)
|
|
|
|
{
|
|
|
|
RECT rect;
|
|
|
|
D3DLOCKED_RECT lock;
|
|
|
|
D3DSURFACE_DESC SrcDesc;
|
|
|
|
HRESULT hr;
|
2010-04-05 20:28:07 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %p, %p, %p, %p, %p, %u, %#x): relay\n", pDestSurface, pDestPalette, pDestRect,
|
|
|
|
pSrcSurface, pSrcPalette, pSrcRect, dwFilter, Colorkey);
|
2009-06-22 17:57:20 +02:00
|
|
|
|
|
|
|
if( !pDestSurface || !pSrcSurface ) return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
IDirect3DSurface9_GetDesc(pSrcSurface, &SrcDesc);
|
|
|
|
|
|
|
|
if( !pSrcRect ) SetRect(&rect, 0, 0, SrcDesc.Width, SrcDesc.Height);
|
|
|
|
else rect = *pSrcRect;
|
|
|
|
|
|
|
|
hr = IDirect3DSurface9_LockRect(pSrcSurface, &lock, NULL, D3DLOCK_READONLY);
|
|
|
|
if(FAILED(hr)) return D3DXERR_INVALIDDATA;
|
|
|
|
|
|
|
|
hr = D3DXLoadSurfaceFromMemory(pDestSurface, pDestPalette, pDestRect,
|
|
|
|
lock.pBits, SrcDesc.Format, lock.Pitch,
|
|
|
|
pSrcPalette, &rect, dwFilter, Colorkey);
|
|
|
|
|
|
|
|
IDirect3DSurface9_UnlockRect(pSrcSurface);
|
|
|
|
return hr;
|
|
|
|
}
|