2 * Copyright (C) 2009 Tony Wasserka
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "wine/debug.h"
21 #include "wine/unicode.h"
22 #include "d3dx9_36_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(d3dx
);
30 /************************************************************
31 * D3DXGetImageInfoFromFileInMemory
33 * Fills a D3DXIMAGE_INFO structure with info about an image
36 * data [I] pointer to the image file data
37 * datasize [I] size of the passed data
38 * info [O] pointer to the destination structure
41 * Success: D3D_OK, if info is not NULL and data and datasize make up a valid image file or
42 * if info is NULL and data and datasize are not NULL
43 * Failure: D3DXERR_INVALIDDATA, if data is no valid image file and datasize and info are not NULL
44 * D3DERR_INVALIDCALL, if data is NULL or
48 * datasize may be bigger than the actual file size
51 HRESULT WINAPI
D3DXGetImageInfoFromFileInMemory(LPCVOID data
, UINT datasize
, D3DXIMAGE_INFO
*info
)
53 IWICImagingFactory
*factory
;
54 IWICBitmapDecoder
*decoder
= NULL
;
59 FIXME("(%p, %d, %p): partially implemented\n", data
, datasize
, info
);
61 /* TODO: Add support for (or at least detect) TGA, DDS, PPM and DIB */
63 if (!data
|| !datasize
)
64 return D3DERR_INVALIDCALL
;
69 initresult
= CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
71 hr
= CoCreateInstance(&CLSID_WICImagingFactory
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IWICImagingFactory
, (void**)&factory
);
74 IWICImagingFactory_CreateStream(factory
, &stream
);
75 IWICStream_InitializeFromMemory(stream
, (BYTE
*)data
, datasize
);
76 hr
= IWICImagingFactory_CreateDecoderFromStream(factory
, (IStream
*)stream
, NULL
, 0, &decoder
);
77 IStream_Release(stream
);
78 IWICImagingFactory_Release(factory
);
82 GUID container_format
;
85 hr
= IWICBitmapDecoder_GetContainerFormat(decoder
, &container_format
);
87 if (IsEqualGUID(&container_format
, &GUID_ContainerFormatBmp
)) {
88 TRACE("File type is BMP\n");
89 info
->ImageFileFormat
= D3DXIFF_BMP
;
90 } else if (IsEqualGUID(&container_format
, &GUID_ContainerFormatPng
)) {
91 TRACE("File type is PNG\n");
92 info
->ImageFileFormat
= D3DXIFF_PNG
;
93 } else if(IsEqualGUID(&container_format
, &GUID_ContainerFormatJpeg
)) {
94 TRACE("File type is JPG\n");
95 info
->ImageFileFormat
= D3DXIFF_JPG
;
97 WARN("Unsupported image file format %s\n", debugstr_guid(&container_format
));
98 hr
= D3DXERR_INVALIDDATA
;
103 hr
= IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
104 if (SUCCEEDED(hr
) && !frame_count
)
105 hr
= D3DXERR_INVALIDDATA
;
108 IWICBitmapFrameDecode
*frame
= NULL
;
110 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
113 hr
= IWICBitmapFrameDecode_GetSize(frame
, &info
->Width
, &info
->Height
);
116 WICPixelFormatGUID pixel_format
;
118 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &pixel_format
);
120 if (IsEqualGUID(&pixel_format
, &GUID_WICPixelFormat1bppIndexed
))
121 info
->Format
= D3DFMT_L8
;
122 else if (IsEqualGUID(&pixel_format
, &GUID_WICPixelFormat4bppIndexed
))
123 info
->Format
= D3DFMT_L8
;
124 else if (IsEqualGUID(&pixel_format
, &GUID_WICPixelFormat8bppIndexed
))
125 info
->Format
= D3DFMT_L8
;
126 else if (IsEqualGUID(&pixel_format
, &GUID_WICPixelFormat16bppBGR555
))
127 info
->Format
= D3DFMT_X1R5G5B5
;
128 else if (IsEqualGUID(&pixel_format
, &GUID_WICPixelFormat24bppBGR
))
129 info
->Format
= D3DFMT_R8G8B8
;
130 else if (IsEqualGUID(&pixel_format
, &GUID_WICPixelFormat32bppBGR
))
131 info
->Format
= D3DFMT_X8R8G8B8
;
133 WARN("Unsupported pixel format %s\n", debugstr_guid(&pixel_format
));
134 hr
= D3DXERR_INVALIDDATA
;
140 IWICBitmapFrameDecode_Release(frame
);
144 info
->ResourceType
= D3DRTYPE_TEXTURE
;
149 IWICBitmapDecoder_Release(decoder
);
151 if (SUCCEEDED(initresult
))
155 /* Missing formats are not detected yet and will fail silently without the FIXME */
156 FIXME("Invalid or unsupported image file\n");
157 return D3DXERR_INVALIDDATA
;
163 /************************************************************
164 * D3DXGetImageInfoFromFile
167 * Success: D3D_OK, if we successfully load a valid image file or
168 * if we successfully load a file which is no valid image and info is NULL
169 * Failure: D3DXERR_INVALIDDATA, if we fail to load file or
170 * if file is not a valid image file and info is not NULL
171 * D3DERR_INVALIDCALL, if file is NULL
174 HRESULT WINAPI
D3DXGetImageInfoFromFileA(LPCSTR file
, D3DXIMAGE_INFO
*info
)
180 TRACE("(%s, %p): relay\n", debugstr_a(file
), info
);
182 if( !file
) return D3DERR_INVALIDCALL
;
184 strlength
= MultiByteToWideChar(CP_ACP
, 0, file
, -1, NULL
, 0);
185 widename
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, strlength
* sizeof(WCHAR
));
186 MultiByteToWideChar(CP_ACP
, 0, file
, -1, widename
, strlength
);
188 hr
= D3DXGetImageInfoFromFileW(widename
, info
);
189 HeapFree(GetProcessHeap(), 0, widename
);
194 HRESULT WINAPI
D3DXGetImageInfoFromFileW(LPCWSTR file
, D3DXIMAGE_INFO
*info
)
200 TRACE("(%s, %p): relay\n", debugstr_w(file
), info
);
202 if( !file
) return D3DERR_INVALIDCALL
;
204 hr
= map_view_of_file(file
, &buffer
, &size
);
205 if(FAILED(hr
)) return D3DXERR_INVALIDDATA
;
207 hr
= D3DXGetImageInfoFromFileInMemory(buffer
, size
, info
);
208 UnmapViewOfFile(buffer
);
213 /************************************************************
214 * D3DXGetImageInfoFromResource
217 * Success: D3D_OK, if resource is a valid image file
218 * Failure: D3DXERR_INVALIDDATA, if resource is no valid image file or NULL or
219 * if we fail to load resource
222 HRESULT WINAPI
D3DXGetImageInfoFromResourceA(HMODULE module
, LPCSTR resource
, D3DXIMAGE_INFO
*info
)
226 TRACE("(%p, %s, %p)\n", module
, debugstr_a(resource
), info
);
228 resinfo
= FindResourceA(module
, resource
, (LPCSTR
)RT_RCDATA
);
234 hr
= load_resource_into_memory(module
, resinfo
, &buffer
, &size
);
235 if(FAILED(hr
)) return D3DXERR_INVALIDDATA
;
236 return D3DXGetImageInfoFromFileInMemory(buffer
, size
, info
);
239 resinfo
= FindResourceA(module
, resource
, (LPCSTR
)RT_BITMAP
);
241 FIXME("Implement loading bitmaps from resource type RT_BITMAP\n");
244 return D3DXERR_INVALIDDATA
;
247 HRESULT WINAPI
D3DXGetImageInfoFromResourceW(HMODULE module
, LPCWSTR resource
, D3DXIMAGE_INFO
*info
)
251 TRACE("(%p, %s, %p)\n", module
, debugstr_w(resource
), info
);
253 resinfo
= FindResourceW(module
, resource
, (LPCWSTR
)RT_RCDATA
);
259 hr
= load_resource_into_memory(module
, resinfo
, &buffer
, &size
);
260 if(FAILED(hr
)) return D3DXERR_INVALIDDATA
;
261 return D3DXGetImageInfoFromFileInMemory(buffer
, size
, info
);
264 resinfo
= FindResourceW(module
, resource
, (LPCWSTR
)RT_BITMAP
);
266 FIXME("Implement loading bitmaps from resource type RT_BITMAP\n");
269 return D3DXERR_INVALIDDATA
;
272 /************************************************************
273 * D3DXLoadSurfaceFromFileInMemory
275 * Loads data from a given buffer into a surface and fills a given
276 * D3DXIMAGE_INFO structure with info about the source data.
279 * pDestSurface [I] pointer to the surface
280 * pDestPalette [I] palette to use
281 * pDestRect [I] to be filled area of the surface
282 * pSrcData [I] pointer to the source data
283 * SrcDataSize [I] size of the source data in bytes
284 * pSrcRect [I] area of the source data to load
285 * dwFilter [I] filter to apply on stretching
286 * Colorkey [I] colorkey
287 * pSrcInfo [O] pointer to a D3DXIMAGE_INFO structure
291 * Failure: D3DERR_INVALIDCALL, if pDestSurface or pSrcData or SrcDataSize are NULL
292 * D3DXERR_INVALIDDATA, if pSrcData is no valid image file
295 HRESULT WINAPI
D3DXLoadSurfaceFromFileInMemory(LPDIRECT3DSURFACE9 pDestSurface
,
296 CONST PALETTEENTRY
*pDestPalette
,
297 CONST RECT
*pDestRect
,
300 CONST RECT
*pSrcRect
,
303 D3DXIMAGE_INFO
*pSrcInfo
)
305 FIXME("(%p, %p, %p, %p, %d, %p, %d, %x, %p): stub\n", pDestSurface
, pDestPalette
,
306 pDestRect
, pSrcData
, SrcDataSize
, pSrcRect
, dwFilter
, Colorkey
, pSrcInfo
);
308 if( !pDestSurface
|| !pSrcData
| !SrcDataSize
) return D3DERR_INVALIDCALL
;
312 /************************************************************
313 * D3DXLoadSurfaceFromFile
315 HRESULT WINAPI
D3DXLoadSurfaceFromFileA(LPDIRECT3DSURFACE9 pDestSurface
,
316 CONST PALETTEENTRY
*pDestPalette
,
317 CONST RECT
*pDestRect
,
319 CONST RECT
*pSrcRect
,
322 D3DXIMAGE_INFO
*pSrcInfo
)
328 TRACE("(%p, %p, %p, %s, %p, %u, %#x, %p): relay\n", pDestSurface
, pDestPalette
, pDestRect
, debugstr_a(pSrcFile
),
329 pSrcRect
, dwFilter
, Colorkey
, pSrcInfo
);
331 if( !pSrcFile
|| !pDestSurface
) return D3DERR_INVALIDCALL
;
333 strlength
= MultiByteToWideChar(CP_ACP
, 0, pSrcFile
, -1, NULL
, 0);
334 pWidename
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, strlength
* sizeof(WCHAR
));
335 MultiByteToWideChar(CP_ACP
, 0, pSrcFile
, -1, pWidename
, strlength
);
337 hr
= D3DXLoadSurfaceFromFileW(pDestSurface
, pDestPalette
, pDestRect
, pWidename
, pSrcRect
, dwFilter
, Colorkey
, pSrcInfo
);
338 HeapFree(GetProcessHeap(), 0, pWidename
);
343 HRESULT WINAPI
D3DXLoadSurfaceFromFileW(LPDIRECT3DSURFACE9 pDestSurface
,
344 CONST PALETTEENTRY
*pDestPalette
,
345 CONST RECT
*pDestRect
,
347 CONST RECT
*pSrcRect
,
350 D3DXIMAGE_INFO
*pSrcInfo
)
356 TRACE("(%p, %p, %p, %s, %p, %u, %#x, %p): relay\n", pDestSurface
, pDestPalette
, pDestRect
, debugstr_w(pSrcFile
),
357 pSrcRect
, Filter
, Colorkey
, pSrcInfo
);
359 if( !pSrcFile
|| !pDestSurface
) return D3DERR_INVALIDCALL
;
361 hr
= map_view_of_file(pSrcFile
, &pBuffer
, &dwSize
);
362 if(FAILED(hr
)) return D3DXERR_INVALIDDATA
;
364 hr
= D3DXLoadSurfaceFromFileInMemory(pDestSurface
, pDestPalette
, pDestRect
, pBuffer
, dwSize
, pSrcRect
, Filter
, Colorkey
, pSrcInfo
);
365 UnmapViewOfFile(pBuffer
);
370 /************************************************************
371 * D3DXLoadSurfaceFromResource
373 HRESULT WINAPI
D3DXLoadSurfaceFromResourceA(LPDIRECT3DSURFACE9 pDestSurface
,
374 CONST PALETTEENTRY
*pDestPalette
,
375 CONST RECT
*pDestRect
,
378 CONST RECT
*pSrcRect
,
381 D3DXIMAGE_INFO
*pSrcInfo
)
385 TRACE("(%p, %p, %p, %p, %s, %p, %u, %#x, %p): relay\n", pDestSurface
, pDestPalette
, pDestRect
, hSrcModule
,
386 debugstr_a(pResource
), pSrcRect
, dwFilter
, Colorkey
, pSrcInfo
);
388 if( !pDestSurface
) return D3DERR_INVALIDCALL
;
390 hResInfo
= FindResourceA(hSrcModule
, pResource
, (LPCSTR
)RT_RCDATA
);
396 hr
= load_resource_into_memory(hSrcModule
, hResInfo
, &pBuffer
, &dwSize
);
397 if(FAILED(hr
)) return D3DXERR_INVALIDDATA
;
398 return D3DXLoadSurfaceFromFileInMemory(pDestSurface
, pDestPalette
, pDestRect
, pBuffer
, dwSize
, pSrcRect
, dwFilter
, Colorkey
, pSrcInfo
);
401 hResInfo
= FindResourceA(hSrcModule
, pResource
, (LPCSTR
)RT_BITMAP
);
403 FIXME("Implement loading bitmaps from resource type RT_BITMAP\n");
406 return D3DXERR_INVALIDDATA
;
409 HRESULT WINAPI
D3DXLoadSurfaceFromResourceW(LPDIRECT3DSURFACE9 pDestSurface
,
410 CONST PALETTEENTRY
*pDestPalette
,
411 CONST RECT
*pDestRect
,
414 CONST RECT
*pSrcRect
,
417 D3DXIMAGE_INFO
*pSrcInfo
)
421 TRACE("(%p, %p, %p, %p, %s, %p, %u, %#x, %p): relay\n", pDestSurface
, pDestPalette
, pDestRect
, hSrcModule
,
422 debugstr_w(pResource
), pSrcRect
, dwFilter
, Colorkey
, pSrcInfo
);
424 if( !pDestSurface
) return D3DERR_INVALIDCALL
;
426 hResInfo
= FindResourceW(hSrcModule
, pResource
, (LPCWSTR
)RT_RCDATA
);
432 hr
= load_resource_into_memory(hSrcModule
, hResInfo
, &pBuffer
, &dwSize
);
433 if(FAILED(hr
)) return D3DXERR_INVALIDDATA
;
434 return D3DXLoadSurfaceFromFileInMemory(pDestSurface
, pDestPalette
, pDestRect
, pBuffer
, dwSize
, pSrcRect
, dwFilter
, Colorkey
, pSrcInfo
);
437 hResInfo
= FindResourceW(hSrcModule
, pResource
, (LPCWSTR
)RT_BITMAP
);
439 FIXME("Implement loading bitmaps from resource type RT_BITMAP\n");
442 return D3DXERR_INVALIDDATA
;
446 /************************************************************
449 * Copies the source buffer to the destination buffer, performing
450 * any necessary format conversion and color keying.
451 * Works only for ARGB formats with 1 - 4 bytes per pixel.
453 static void copy_simple_data(CONST BYTE
*src
, UINT srcpitch
, POINT srcsize
, CONST PixelFormatDesc
*srcformat
,
454 CONST BYTE
*dest
, UINT destpitch
, POINT destsize
, CONST PixelFormatDesc
*destformat
,
457 DWORD srcshift
[4], destshift
[4];
458 DWORD srcmask
[4], destmask
[4];
459 BOOL process_channel
[4];
461 DWORD channelmask
= 0;
463 UINT minwidth
, minheight
;
464 BYTE
*srcptr
, *destptr
;
467 ZeroMemory(channels
, sizeof(channels
));
468 ZeroMemory(process_channel
, sizeof(process_channel
));
470 for(i
= 0;i
< 4;i
++) {
471 /* srcshift is used to extract the _relevant_ components */
472 srcshift
[i
] = srcformat
->shift
[i
] + max( srcformat
->bits
[i
] - destformat
->bits
[i
], 0);
474 /* destshift is used to move the components to the correct position */
475 destshift
[i
] = destformat
->shift
[i
] + max(destformat
->bits
[i
] - srcformat
->bits
[i
], 0);
477 srcmask
[i
] = ((1 << srcformat
->bits
[i
]) - 1) << srcformat
->shift
[i
];
478 destmask
[i
] = ((1 << destformat
->bits
[i
]) - 1) << destformat
->shift
[i
];
480 /* channelmask specifies bits which aren't used in the source format but in the destination one */
481 if(destformat
->bits
[i
]) {
482 if(srcformat
->bits
[i
]) process_channel
[i
] = TRUE
;
483 else channelmask
|= destmask
[i
];
487 minwidth
= (srcsize
.x
< destsize
.x
) ? srcsize
.x
: destsize
.x
;
488 minheight
= (srcsize
.y
< destsize
.y
) ? srcsize
.y
: destsize
.y
;
490 for(y
= 0;y
< minheight
;y
++) {
491 srcptr
= (BYTE
*)( src
+ y
* srcpitch
);
492 destptr
= (BYTE
*)(dest
+ y
* destpitch
);
493 for(x
= 0;x
< minwidth
;x
++) {
494 /* extract source color components */
495 if(srcformat
->type
== FORMAT_ARGB
) {
496 const DWORD col
= *(DWORD
*)srcptr
;
498 if(process_channel
[i
])
499 channels
[i
] = (col
& srcmask
[i
]) >> srcshift
[i
];
502 /* recombine the components */
503 if(destformat
->type
== FORMAT_ARGB
) {
504 DWORD
* const pixel
= (DWORD
*)destptr
;
507 for(i
= 0;i
< 4;i
++) {
508 if(process_channel
[i
]) {
509 /* necessary to make sure that e.g. an X4R4G4B4 white maps to an R8G8B8 white instead of 0xf0f0f0 */
511 for(shift
= destshift
[i
]; shift
> destformat
->shift
[i
]; shift
-= srcformat
->bits
[i
]) *pixel
|= channels
[i
] << shift
;
512 *pixel
|= (channels
[i
] >> (destformat
->shift
[i
] - shift
)) << destformat
->shift
[i
];
515 *pixel
|= channelmask
; /* new channels are set to their maximal value */
517 srcptr
+= srcformat
->bytes_per_pixel
;
518 destptr
+= destformat
->bytes_per_pixel
;
523 /************************************************************
524 * D3DXLoadSurfaceFromMemory
526 * Loads data from a given memory chunk into a surface,
527 * applying any of the specified filters.
530 * pDestSurface [I] pointer to the surface
531 * pDestPalette [I] palette to use
532 * pDestRect [I] to be filled area of the surface
533 * pSrcMemory [I] pointer to the source data
534 * SrcFormat [I] format of the source pixel data
535 * SrcPitch [I] number of bytes in a row
536 * pSrcPalette [I] palette used in the source image
537 * pSrcRect [I] area of the source data to load
538 * dwFilter [I] filter to apply on stretching
539 * Colorkey [I] colorkey
542 * Success: D3D_OK, if we successfully load the pixel data into our surface or
543 * if pSrcMemory is NULL but the other parameters are valid
544 * Failure: D3DERR_INVALIDCALL, if pDestSurface, SrcPitch or pSrcRect are NULL or
545 * if SrcFormat is an invalid format (other than D3DFMT_UNKNOWN)
546 * D3DXERR_INVALIDDATA, if we fail to lock pDestSurface
547 * E_FAIL, if SrcFormat is D3DFMT_UNKNOWN or the dimensions of pSrcRect are invalid
550 * pSrcRect specifies the dimensions of the source data;
551 * negative values for pSrcRect are allowed as we're only looking at the width and height anyway.
554 HRESULT WINAPI
D3DXLoadSurfaceFromMemory(LPDIRECT3DSURFACE9 pDestSurface
,
555 CONST PALETTEENTRY
*pDestPalette
,
556 CONST RECT
*pDestRect
,
560 CONST PALETTEENTRY
*pSrcPalette
,
561 CONST RECT
*pSrcRect
,
565 CONST PixelFormatDesc
*srcformatdesc
, *destformatdesc
;
566 D3DSURFACE_DESC surfdesc
;
567 D3DLOCKED_RECT lockrect
;
568 POINT srcsize
, destsize
;
571 TRACE("(%p, %p, %p, %p, %x, %u, %p, %p %u, %#x)\n", pDestSurface
, pDestPalette
, pDestRect
, pSrcMemory
,
572 SrcFormat
, SrcPitch
, pSrcPalette
, pSrcRect
, dwFilter
, Colorkey
);
574 if( !pDestSurface
|| !pSrcMemory
|| !pSrcRect
) return D3DERR_INVALIDCALL
;
575 if(SrcFormat
== D3DFMT_UNKNOWN
|| pSrcRect
->left
>= pSrcRect
->right
|| pSrcRect
->top
>= pSrcRect
->bottom
) return E_FAIL
;
577 if(dwFilter
!= D3DX_FILTER_NONE
) return E_NOTIMPL
;
579 IDirect3DSurface9_GetDesc(pDestSurface
, &surfdesc
);
581 srcformatdesc
= get_format_info(SrcFormat
);
582 destformatdesc
= get_format_info(surfdesc
.Format
);
583 if( srcformatdesc
->type
== FORMAT_UNKNOWN
|| srcformatdesc
->bytes_per_pixel
> 4) return E_NOTIMPL
;
584 if(destformatdesc
->type
== FORMAT_UNKNOWN
|| destformatdesc
->bytes_per_pixel
> 4) return E_NOTIMPL
;
586 srcsize
.x
= pSrcRect
->right
- pSrcRect
->left
;
587 srcsize
.y
= pSrcRect
->bottom
- pSrcRect
->top
;
589 destsize
.x
= surfdesc
.Width
;
590 destsize
.y
= surfdesc
.Height
;
592 destsize
.x
= pDestRect
->right
- pDestRect
->left
;
593 destsize
.y
= pDestRect
->bottom
- pDestRect
->top
;
596 hr
= IDirect3DSurface9_LockRect(pDestSurface
, &lockrect
, pDestRect
, 0);
597 if(FAILED(hr
)) return D3DXERR_INVALIDDATA
;
599 copy_simple_data((CONST BYTE
*)pSrcMemory
, SrcPitch
, srcsize
, srcformatdesc
,
600 (CONST BYTE
*)lockrect
.pBits
, lockrect
.Pitch
, destsize
, destformatdesc
,
603 IDirect3DSurface9_UnlockRect(pDestSurface
);
607 /************************************************************
608 * D3DXLoadSurfaceFromSurface
610 * Copies the contents from one surface to another, performing any required
611 * format conversion, resizing or filtering.
614 * pDestSurface [I] pointer to the destination surface
615 * pDestPalette [I] palette to use
616 * pDestRect [I] to be filled area of the surface
617 * pSrcSurface [I] pointer to the source surface
618 * pSrcPalette [I] palette used for the source surface
619 * pSrcRect [I] area of the source data to load
620 * dwFilter [I] filter to apply on resizing
621 * Colorkey [I] any ARGB value or 0 to disable color-keying
625 * Failure: D3DERR_INVALIDCALL, if pDestSurface or pSrcSurface are NULL
626 * D3DXERR_INVALIDDATA, if one of the surfaces is not lockable
629 HRESULT WINAPI
D3DXLoadSurfaceFromSurface(LPDIRECT3DSURFACE9 pDestSurface
,
630 CONST PALETTEENTRY
*pDestPalette
,
631 CONST RECT
*pDestRect
,
632 LPDIRECT3DSURFACE9 pSrcSurface
,
633 CONST PALETTEENTRY
*pSrcPalette
,
634 CONST RECT
*pSrcRect
,
640 D3DSURFACE_DESC SrcDesc
;
643 TRACE("(%p, %p, %p, %p, %p, %p, %u, %#x): relay\n", pDestSurface
, pDestPalette
, pDestRect
,
644 pSrcSurface
, pSrcPalette
, pSrcRect
, dwFilter
, Colorkey
);
646 if( !pDestSurface
|| !pSrcSurface
) return D3DERR_INVALIDCALL
;
648 IDirect3DSurface9_GetDesc(pSrcSurface
, &SrcDesc
);
650 if( !pSrcRect
) SetRect(&rect
, 0, 0, SrcDesc
.Width
, SrcDesc
.Height
);
651 else rect
= *pSrcRect
;
653 hr
= IDirect3DSurface9_LockRect(pSrcSurface
, &lock
, NULL
, D3DLOCK_READONLY
);
654 if(FAILED(hr
)) return D3DXERR_INVALIDDATA
;
656 hr
= D3DXLoadSurfaceFromMemory(pDestSurface
, pDestPalette
, pDestRect
,
657 lock
.pBits
, SrcDesc
.Format
, lock
.Pitch
,
658 pSrcPalette
, &rect
, dwFilter
, Colorkey
);
660 IDirect3DSurface9_UnlockRect(pSrcSurface
);