2009-05-23 12:56:19 +02:00
|
|
|
/*
|
2010-07-28 21:33:14 +02:00
|
|
|
* Copyright (C) 2009-2010 Tony Wasserka
|
2012-04-29 21:43:08 +02:00
|
|
|
* Copyright (C) 2012 Józef Kucia
|
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"
|
2012-05-29 11:29:22 +02:00
|
|
|
#include "ole2.h"
|
2010-04-09 08:43:17 +02:00
|
|
|
#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);
|
|
|
|
|
2012-05-04 13:01:19 +02:00
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const GUID *wic_guid;
|
|
|
|
D3DFORMAT d3dformat;
|
|
|
|
} wic_pixel_formats[] = {
|
2013-05-12 23:57:50 +02:00
|
|
|
{ &GUID_WICPixelFormat8bppIndexed, D3DFMT_P8 },
|
|
|
|
{ &GUID_WICPixelFormat1bppIndexed, D3DFMT_P8 },
|
|
|
|
{ &GUID_WICPixelFormat4bppIndexed, D3DFMT_P8 },
|
2012-05-04 13:01:19 +02:00
|
|
|
{ &GUID_WICPixelFormat16bppBGR555, D3DFMT_X1R5G5B5 },
|
|
|
|
{ &GUID_WICPixelFormat16bppBGR565, D3DFMT_R5G6B5 },
|
|
|
|
{ &GUID_WICPixelFormat24bppBGR, D3DFMT_R8G8B8 },
|
|
|
|
{ &GUID_WICPixelFormat32bppBGR, D3DFMT_X8R8G8B8 },
|
|
|
|
{ &GUID_WICPixelFormat32bppBGRA, D3DFMT_A8R8G8B8 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static D3DFORMAT wic_guid_to_d3dformat(const GUID *guid)
|
|
|
|
{
|
2013-01-03 23:46:48 +01:00
|
|
|
unsigned int i;
|
2012-05-04 13:01:19 +02:00
|
|
|
|
|
|
|
for (i = 0; i < sizeof(wic_pixel_formats) / sizeof(wic_pixel_formats[0]); i++)
|
|
|
|
{
|
|
|
|
if (IsEqualGUID(wic_pixel_formats[i].wic_guid, guid))
|
|
|
|
return wic_pixel_formats[i].d3dformat;
|
|
|
|
}
|
|
|
|
|
|
|
|
return D3DFMT_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2012-05-04 13:01:21 +02:00
|
|
|
static const GUID *d3dformat_to_wic_guid(D3DFORMAT format)
|
|
|
|
{
|
2013-01-03 23:46:48 +01:00
|
|
|
unsigned int i;
|
2012-05-04 13:01:21 +02:00
|
|
|
|
|
|
|
for (i = 0; i < sizeof(wic_pixel_formats) / sizeof(wic_pixel_formats[0]); i++)
|
|
|
|
{
|
|
|
|
if (wic_pixel_formats[i].d3dformat == format)
|
|
|
|
return wic_pixel_formats[i].wic_guid;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-04-29 21:43:08 +02:00
|
|
|
/* dds_header.flags */
|
|
|
|
#define DDS_CAPS 0x1
|
|
|
|
#define DDS_HEIGHT 0x2
|
|
|
|
#define DDS_WIDTH 0x2
|
|
|
|
#define DDS_PITCH 0x8
|
|
|
|
#define DDS_PIXELFORMAT 0x1000
|
|
|
|
#define DDS_MIPMAPCOUNT 0x20000
|
|
|
|
#define DDS_LINEARSIZE 0x80000
|
|
|
|
#define DDS_DEPTH 0x800000
|
|
|
|
|
|
|
|
/* dds_header.caps */
|
|
|
|
#define DDS_CAPS_COMPLEX 0x8
|
|
|
|
#define DDS_CAPS_TEXTURE 0x1000
|
|
|
|
#define DDS_CAPS_MIPMAP 0x400000
|
|
|
|
|
|
|
|
/* dds_header.caps2 */
|
|
|
|
#define DDS_CAPS2_CUBEMAP 0x200
|
|
|
|
#define DDS_CAPS2_CUBEMAP_POSITIVEX 0x400
|
|
|
|
#define DDS_CAPS2_CUBEMAP_NEGATIVEX 0x800
|
|
|
|
#define DDS_CAPS2_CUBEMAP_POSITIVEY 0x1000
|
|
|
|
#define DDS_CAPS2_CUBEMAP_NEGATIVEY 0x2000
|
|
|
|
#define DDS_CAPS2_CUBEMAP_POSITIVEZ 0x4000
|
|
|
|
#define DDS_CAPS2_CUBEMAP_NEGATIVEZ 0x8000
|
2012-05-13 23:00:06 +02:00
|
|
|
#define DDS_CAPS2_CUBEMAP_ALL_FACES ( DDS_CAPS2_CUBEMAP_POSITIVEX | DDS_CAPS2_CUBEMAP_NEGATIVEX \
|
|
|
|
| DDS_CAPS2_CUBEMAP_POSITIVEY | DDS_CAPS2_CUBEMAP_NEGATIVEY \
|
|
|
|
| DDS_CAPS2_CUBEMAP_POSITIVEZ | DDS_CAPS2_CUBEMAP_NEGATIVEZ )
|
2012-04-29 21:43:08 +02:00
|
|
|
#define DDS_CAPS2_VOLUME 0x200000
|
|
|
|
|
|
|
|
/* dds_pixel_format.flags */
|
|
|
|
#define DDS_PF_ALPHA 0x1
|
|
|
|
#define DDS_PF_ALPHA_ONLY 0x2
|
|
|
|
#define DDS_PF_FOURCC 0x4
|
|
|
|
#define DDS_PF_RGB 0x40
|
|
|
|
#define DDS_PF_YUV 0x200
|
|
|
|
#define DDS_PF_LUMINANCE 0x20000
|
2012-05-13 23:00:03 +02:00
|
|
|
#define DDS_PF_BUMPDUDV 0x80000
|
2012-04-29 21:43:08 +02:00
|
|
|
|
|
|
|
struct dds_pixel_format
|
|
|
|
{
|
|
|
|
DWORD size;
|
|
|
|
DWORD flags;
|
|
|
|
DWORD fourcc;
|
|
|
|
DWORD bpp;
|
|
|
|
DWORD rmask;
|
|
|
|
DWORD gmask;
|
|
|
|
DWORD bmask;
|
|
|
|
DWORD amask;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct dds_header
|
|
|
|
{
|
|
|
|
DWORD signature;
|
|
|
|
DWORD size;
|
|
|
|
DWORD flags;
|
|
|
|
DWORD height;
|
|
|
|
DWORD width;
|
|
|
|
DWORD pitch_or_linear_size;
|
|
|
|
DWORD depth;
|
|
|
|
DWORD miplevels;
|
|
|
|
DWORD reserved[11];
|
|
|
|
struct dds_pixel_format pixel_format;
|
|
|
|
DWORD caps;
|
|
|
|
DWORD caps2;
|
|
|
|
DWORD caps3;
|
|
|
|
DWORD caps4;
|
|
|
|
DWORD reserved2;
|
|
|
|
};
|
|
|
|
|
2012-04-29 21:43:10 +02:00
|
|
|
static D3DFORMAT dds_fourcc_to_d3dformat(DWORD fourcc)
|
|
|
|
{
|
2013-01-03 23:46:48 +01:00
|
|
|
unsigned int i;
|
2012-04-29 21:43:10 +02:00
|
|
|
static const DWORD known_fourcc[] = {
|
|
|
|
MAKEFOURCC('U','Y','V','Y'),
|
|
|
|
MAKEFOURCC('Y','U','Y','2'),
|
|
|
|
MAKEFOURCC('R','G','B','G'),
|
|
|
|
MAKEFOURCC('G','R','G','B'),
|
|
|
|
MAKEFOURCC('D','X','T','1'),
|
|
|
|
MAKEFOURCC('D','X','T','2'),
|
|
|
|
MAKEFOURCC('D','X','T','3'),
|
|
|
|
MAKEFOURCC('D','X','T','4'),
|
2014-02-18 22:17:01 +01:00
|
|
|
MAKEFOURCC('D','X','T','5'),
|
|
|
|
D3DFMT_R16F,
|
|
|
|
D3DFMT_G16R16F,
|
|
|
|
D3DFMT_A16B16G16R16F,
|
|
|
|
D3DFMT_R32F,
|
|
|
|
D3DFMT_G32R32F,
|
|
|
|
D3DFMT_A32B32G32R32F,
|
2012-04-29 21:43:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(known_fourcc) / sizeof(known_fourcc[0]); i++)
|
|
|
|
{
|
|
|
|
if (known_fourcc[i] == fourcc)
|
|
|
|
return fourcc;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Unknown FourCC %#x\n", fourcc);
|
|
|
|
return D3DFMT_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2012-09-24 13:46:40 +02:00
|
|
|
static const struct {
|
|
|
|
DWORD bpp;
|
|
|
|
DWORD rmask;
|
|
|
|
DWORD gmask;
|
|
|
|
DWORD bmask;
|
|
|
|
DWORD amask;
|
|
|
|
D3DFORMAT format;
|
|
|
|
} rgb_pixel_formats[] = {
|
|
|
|
{ 8, 0xe0, 0x1c, 0x03, 0, D3DFMT_R3G3B2 },
|
|
|
|
{ 16, 0xf800, 0x07e0, 0x001f, 0x0000, D3DFMT_R5G6B5 },
|
|
|
|
{ 16, 0x7c00, 0x03e0, 0x001f, 0x8000, D3DFMT_A1R5G5B5 },
|
|
|
|
{ 16, 0x7c00, 0x03e0, 0x001f, 0x0000, D3DFMT_X1R5G5B5 },
|
|
|
|
{ 16, 0x0f00, 0x00f0, 0x000f, 0xf000, D3DFMT_A4R4G4B4 },
|
|
|
|
{ 16, 0x0f00, 0x00f0, 0x000f, 0x0000, D3DFMT_X4R4G4B4 },
|
|
|
|
{ 16, 0x00e0, 0x001c, 0x0003, 0xff00, D3DFMT_A8R3G3B2 },
|
|
|
|
{ 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000, D3DFMT_R8G8B8 },
|
|
|
|
{ 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, D3DFMT_A8R8G8B8 },
|
|
|
|
{ 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000, D3DFMT_X8R8G8B8 },
|
|
|
|
{ 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000, D3DFMT_A2B10G10R10 },
|
|
|
|
{ 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000, D3DFMT_A2R10G10B10 },
|
|
|
|
{ 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000, D3DFMT_G16R16 },
|
|
|
|
{ 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000, D3DFMT_A8B8G8R8 },
|
|
|
|
{ 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000, D3DFMT_X8B8G8R8 },
|
|
|
|
};
|
|
|
|
|
2012-04-29 21:43:10 +02:00
|
|
|
static D3DFORMAT dds_rgb_to_d3dformat(const struct dds_pixel_format *pixel_format)
|
|
|
|
{
|
2013-01-03 23:46:48 +01:00
|
|
|
unsigned int i;
|
2012-04-29 21:43:10 +02:00
|
|
|
|
|
|
|
for (i = 0; i < sizeof(rgb_pixel_formats) / sizeof(rgb_pixel_formats[0]); i++)
|
|
|
|
{
|
|
|
|
if (rgb_pixel_formats[i].bpp == pixel_format->bpp
|
|
|
|
&& rgb_pixel_formats[i].rmask == pixel_format->rmask
|
|
|
|
&& rgb_pixel_formats[i].gmask == pixel_format->gmask
|
|
|
|
&& rgb_pixel_formats[i].bmask == pixel_format->bmask)
|
|
|
|
{
|
|
|
|
if ((pixel_format->flags & DDS_PF_ALPHA) && rgb_pixel_formats[i].amask == pixel_format->amask)
|
|
|
|
return rgb_pixel_formats[i].format;
|
|
|
|
if (rgb_pixel_formats[i].amask == 0)
|
|
|
|
return rgb_pixel_formats[i].format;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Unknown RGB pixel format (%#x, %#x, %#x, %#x)\n",
|
|
|
|
pixel_format->rmask, pixel_format->gmask, pixel_format->bmask, pixel_format->amask);
|
|
|
|
return D3DFMT_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static D3DFORMAT dds_luminance_to_d3dformat(const struct dds_pixel_format *pixel_format)
|
|
|
|
{
|
|
|
|
if (pixel_format->bpp == 8)
|
|
|
|
{
|
|
|
|
if (pixel_format->rmask == 0xff)
|
|
|
|
return D3DFMT_L8;
|
|
|
|
if ((pixel_format->flags & DDS_PF_ALPHA) && pixel_format->rmask == 0x0f && pixel_format->amask == 0xf0)
|
|
|
|
return D3DFMT_A4L4;
|
|
|
|
}
|
|
|
|
if (pixel_format->bpp == 16)
|
|
|
|
{
|
2012-05-13 23:00:03 +02:00
|
|
|
if (pixel_format->rmask == 0xffff)
|
|
|
|
return D3DFMT_L16;
|
2012-04-29 21:43:10 +02:00
|
|
|
if ((pixel_format->flags & DDS_PF_ALPHA) && pixel_format->rmask == 0x00ff && pixel_format->amask == 0xff00)
|
|
|
|
return D3DFMT_A8L8;
|
|
|
|
}
|
|
|
|
|
2013-07-22 08:48:07 +02:00
|
|
|
WARN("Unknown luminance pixel format (bpp %u, l %#x, a %#x)\n",
|
2012-04-29 21:43:10 +02:00
|
|
|
pixel_format->bpp, pixel_format->rmask, pixel_format->amask);
|
|
|
|
return D3DFMT_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static D3DFORMAT dds_alpha_to_d3dformat(const struct dds_pixel_format *pixel_format)
|
|
|
|
{
|
|
|
|
if (pixel_format->bpp == 8 && pixel_format->amask == 0xff)
|
|
|
|
return D3DFMT_A8;
|
|
|
|
|
2013-07-22 08:48:07 +02:00
|
|
|
WARN("Unknown Alpha pixel format (%u, %#x)\n", pixel_format->bpp, pixel_format->rmask);
|
2012-04-29 21:43:10 +02:00
|
|
|
return D3DFMT_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2012-05-13 23:00:03 +02:00
|
|
|
static D3DFORMAT dds_bump_to_d3dformat(const struct dds_pixel_format *pixel_format)
|
|
|
|
{
|
|
|
|
if (pixel_format->bpp == 16 && pixel_format->rmask == 0x00ff && pixel_format->gmask == 0xff00)
|
|
|
|
return D3DFMT_V8U8;
|
|
|
|
if (pixel_format->bpp == 32 && pixel_format->rmask == 0x0000ffff && pixel_format->gmask == 0xffff0000)
|
|
|
|
return D3DFMT_V16U16;
|
|
|
|
|
2013-07-22 08:48:07 +02:00
|
|
|
WARN("Unknown bump pixel format (%u, %#x, %#x, %#x, %#x)\n", pixel_format->bpp,
|
2012-05-13 23:00:03 +02:00
|
|
|
pixel_format->rmask, pixel_format->gmask, pixel_format->bmask, pixel_format->amask);
|
|
|
|
return D3DFMT_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2012-04-29 21:43:08 +02:00
|
|
|
static D3DFORMAT dds_pixel_format_to_d3dformat(const struct dds_pixel_format *pixel_format)
|
|
|
|
{
|
2014-02-14 15:53:11 +01:00
|
|
|
TRACE("pixel_format: size %u, flags %#x, fourcc %#x, bpp %u.\n", pixel_format->size,
|
|
|
|
pixel_format->flags, pixel_format->fourcc, pixel_format->bpp);
|
|
|
|
TRACE("rmask %#x, gmask %#x, bmask %#x, amask %#x.\n", pixel_format->rmask, pixel_format->gmask,
|
|
|
|
pixel_format->bmask, pixel_format->amask);
|
|
|
|
|
2012-04-29 21:43:10 +02:00
|
|
|
if (pixel_format->flags & DDS_PF_FOURCC)
|
|
|
|
return dds_fourcc_to_d3dformat(pixel_format->fourcc);
|
|
|
|
if (pixel_format->flags & DDS_PF_RGB)
|
|
|
|
return dds_rgb_to_d3dformat(pixel_format);
|
|
|
|
if (pixel_format->flags & DDS_PF_LUMINANCE)
|
|
|
|
return dds_luminance_to_d3dformat(pixel_format);
|
|
|
|
if (pixel_format->flags & DDS_PF_ALPHA_ONLY)
|
|
|
|
return dds_alpha_to_d3dformat(pixel_format);
|
2012-05-13 23:00:03 +02:00
|
|
|
if (pixel_format->flags & DDS_PF_BUMPDUDV)
|
|
|
|
return dds_bump_to_d3dformat(pixel_format);
|
2012-04-29 21:43:10 +02:00
|
|
|
|
2013-07-22 08:48:07 +02:00
|
|
|
WARN("Unknown pixel format (flags %#x, fourcc %#x, bpp %u, r %#x, g %#x, b %#x, a %#x)\n",
|
2012-05-13 23:00:03 +02:00
|
|
|
pixel_format->flags, pixel_format->fourcc, pixel_format->bpp,
|
|
|
|
pixel_format->rmask, pixel_format->gmask, pixel_format->bmask, pixel_format->amask);
|
2012-04-29 21:43:08 +02:00
|
|
|
return D3DFMT_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2012-09-24 13:46:38 +02:00
|
|
|
static HRESULT d3dformat_to_dds_pixel_format(struct dds_pixel_format *pixel_format, D3DFORMAT d3dformat)
|
|
|
|
{
|
2013-01-03 23:46:48 +01:00
|
|
|
unsigned int i;
|
2012-09-24 13:46:40 +02:00
|
|
|
|
2012-09-24 13:46:38 +02:00
|
|
|
memset(pixel_format, 0, sizeof(*pixel_format));
|
|
|
|
|
|
|
|
pixel_format->size = sizeof(*pixel_format);
|
|
|
|
|
2012-09-24 13:46:40 +02:00
|
|
|
for (i = 0; i < sizeof(rgb_pixel_formats) / sizeof(rgb_pixel_formats[0]); i++)
|
2012-09-24 13:46:38 +02:00
|
|
|
{
|
2012-09-24 13:46:40 +02:00
|
|
|
if (rgb_pixel_formats[i].format == d3dformat)
|
|
|
|
{
|
|
|
|
pixel_format->flags |= DDS_PF_RGB;
|
|
|
|
pixel_format->bpp = rgb_pixel_formats[i].bpp;
|
|
|
|
pixel_format->rmask = rgb_pixel_formats[i].rmask;
|
|
|
|
pixel_format->gmask = rgb_pixel_formats[i].gmask;
|
|
|
|
pixel_format->bmask = rgb_pixel_formats[i].bmask;
|
|
|
|
pixel_format->amask = rgb_pixel_formats[i].amask;
|
|
|
|
if (pixel_format->amask) pixel_format->flags |= DDS_PF_ALPHA;
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
2012-09-24 13:46:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Unknown pixel format %#x\n", d3dformat);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-09-24 13:46:36 +02:00
|
|
|
static HRESULT calculate_dds_surface_size(D3DFORMAT format, UINT width, UINT height,
|
|
|
|
UINT *pitch, UINT *size)
|
2012-05-13 23:00:04 +02:00
|
|
|
{
|
2012-09-24 13:46:36 +02:00
|
|
|
const struct pixel_format_desc *format_desc = get_format_info(format);
|
2012-10-22 17:20:27 +02:00
|
|
|
if (format_desc->type == FORMAT_UNKNOWN)
|
2012-05-13 23:00:04 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
|
|
|
|
if (format_desc->block_width != 1 || format_desc->block_height != 1)
|
|
|
|
{
|
|
|
|
*pitch = format_desc->block_byte_count
|
|
|
|
* max(1, (width + format_desc->block_width - 1) / format_desc->block_width);
|
|
|
|
*size = *pitch
|
|
|
|
* max(1, (height + format_desc->block_height - 1) / format_desc->block_height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*pitch = width * format_desc->bytes_per_pixel;
|
|
|
|
*size = *pitch * height;
|
|
|
|
}
|
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-24 13:46:36 +02:00
|
|
|
static UINT calculate_dds_file_size(D3DFORMAT format, UINT width, UINT height, UINT depth,
|
|
|
|
UINT miplevels, UINT faces)
|
|
|
|
{
|
|
|
|
UINT i, file_size = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < miplevels; i++)
|
|
|
|
{
|
|
|
|
UINT pitch, size = 0;
|
|
|
|
calculate_dds_surface_size(format, width, height, &pitch, &size);
|
|
|
|
size *= depth;
|
|
|
|
file_size += size;
|
|
|
|
width = max(1, width / 2);
|
|
|
|
height = max(1, height / 2);
|
|
|
|
depth = max(1, depth / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
file_size *= faces;
|
|
|
|
file_size += sizeof(struct dds_header);
|
|
|
|
return file_size;
|
|
|
|
}
|
|
|
|
|
2012-04-29 21:43:08 +02:00
|
|
|
/************************************************************
|
|
|
|
* get_image_info_from_dds
|
|
|
|
*
|
|
|
|
* Fills a D3DXIMAGE_INFO structure with information
|
|
|
|
* about a DDS file stored in the memory.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* buffer [I] pointer to DDS data
|
|
|
|
* length [I] size of DDS data
|
|
|
|
* info [O] pointer to D3DXIMAGE_INFO structure
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: D3D_OK
|
|
|
|
* Failure: D3DXERR_INVALIDDATA
|
|
|
|
*
|
|
|
|
*/
|
2012-05-13 23:00:04 +02:00
|
|
|
static HRESULT get_image_info_from_dds(const void *buffer, UINT length, D3DXIMAGE_INFO *info)
|
2012-04-29 21:43:08 +02:00
|
|
|
{
|
2012-09-24 13:46:37 +02:00
|
|
|
UINT faces = 1;
|
|
|
|
UINT expected_length;
|
|
|
|
const struct dds_header *header = buffer;
|
|
|
|
|
|
|
|
if (length < sizeof(*header) || !info)
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
|
|
|
|
if (header->pixel_format.size != sizeof(header->pixel_format))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
|
|
|
|
info->Width = header->width;
|
|
|
|
info->Height = header->height;
|
|
|
|
info->Depth = 1;
|
|
|
|
info->MipLevels = (header->flags & DDS_MIPMAPCOUNT) ? header->miplevels : 1;
|
|
|
|
|
|
|
|
info->Format = dds_pixel_format_to_d3dformat(&header->pixel_format);
|
|
|
|
if (info->Format == D3DFMT_UNKNOWN)
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
|
|
|
|
TRACE("Pixel format is %#x\n", info->Format);
|
|
|
|
|
|
|
|
if (header->caps2 & DDS_CAPS2_VOLUME)
|
|
|
|
{
|
|
|
|
info->Depth = header->depth;
|
|
|
|
info->ResourceType = D3DRTYPE_VOLUMETEXTURE;
|
|
|
|
}
|
|
|
|
else if (header->caps2 & DDS_CAPS2_CUBEMAP)
|
|
|
|
{
|
|
|
|
DWORD face;
|
|
|
|
faces = 0;
|
|
|
|
for (face = DDS_CAPS2_CUBEMAP_POSITIVEX; face <= DDS_CAPS2_CUBEMAP_NEGATIVEZ; face <<= 1)
|
|
|
|
{
|
|
|
|
if (header->caps2 & face)
|
|
|
|
faces++;
|
|
|
|
}
|
|
|
|
info->ResourceType = D3DRTYPE_CUBETEXTURE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
info->ResourceType = D3DRTYPE_TEXTURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
expected_length = calculate_dds_file_size(info->Format, info->Width, info->Height, info->Depth,
|
2012-09-24 13:46:36 +02:00
|
|
|
info->MipLevels, faces);
|
2012-09-24 13:46:37 +02:00
|
|
|
if (length < expected_length)
|
|
|
|
{
|
|
|
|
WARN("File is too short %u, expected at least %u bytes\n", length, expected_length);
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->ImageFileFormat = D3DXIFF_DDS;
|
|
|
|
return D3D_OK;
|
2012-04-29 21:43:08 +02:00
|
|
|
}
|
|
|
|
|
2012-05-13 23:00:08 +02:00
|
|
|
static HRESULT load_surface_from_dds(IDirect3DSurface9 *dst_surface, const PALETTEENTRY *dst_palette,
|
|
|
|
const RECT *dst_rect, const void *src_data, const RECT *src_rect, DWORD filter, D3DCOLOR color_key,
|
|
|
|
const D3DXIMAGE_INFO *src_info)
|
|
|
|
{
|
|
|
|
UINT size;
|
|
|
|
UINT src_pitch;
|
|
|
|
const struct dds_header *header = src_data;
|
|
|
|
const BYTE *pixels = (BYTE *)(header + 1);
|
|
|
|
|
|
|
|
if (src_info->ResourceType != D3DRTYPE_TEXTURE)
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
|
2012-09-24 13:46:36 +02:00
|
|
|
if (FAILED(calculate_dds_surface_size(src_info->Format, src_info->Width, src_info->Height, &src_pitch, &size)))
|
2012-05-13 23:00:08 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
|
|
|
|
return D3DXLoadSurfaceFromMemory(dst_surface, dst_palette, dst_rect, pixels, src_info->Format,
|
|
|
|
src_pitch, NULL, src_rect, filter, color_key);
|
|
|
|
}
|
|
|
|
|
2012-09-24 13:46:38 +02:00
|
|
|
static HRESULT save_dds_surface_to_memory(ID3DXBuffer **dst_buffer, IDirect3DSurface9 *src_surface, const RECT *src_rect)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
UINT dst_pitch, surface_size, file_size;
|
|
|
|
D3DSURFACE_DESC src_desc;
|
|
|
|
D3DLOCKED_RECT locked_rect;
|
|
|
|
ID3DXBuffer *buffer;
|
|
|
|
struct dds_header *header;
|
|
|
|
BYTE *pixels;
|
|
|
|
struct volume volume;
|
|
|
|
const struct pixel_format_desc *pixel_format;
|
|
|
|
|
|
|
|
if (src_rect)
|
|
|
|
{
|
|
|
|
FIXME("Saving a part of a surface to a DDS file is not implemented yet\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IDirect3DSurface9_GetDesc(src_surface, &src_desc);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
pixel_format = get_format_info(src_desc.Format);
|
2012-10-28 22:59:56 +01:00
|
|
|
if (pixel_format->type == FORMAT_UNKNOWN) return E_NOTIMPL;
|
2012-09-24 13:46:38 +02:00
|
|
|
|
|
|
|
file_size = calculate_dds_file_size(src_desc.Format, src_desc.Width, src_desc.Height, 1, 1, 1);
|
|
|
|
|
|
|
|
hr = calculate_dds_surface_size(src_desc.Format, src_desc.Width, src_desc.Height, &dst_pitch, &surface_size);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = D3DXCreateBuffer(file_size, &buffer);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
header = ID3DXBuffer_GetBufferPointer(buffer);
|
|
|
|
pixels = (BYTE *)(header + 1);
|
|
|
|
|
2012-09-26 01:38:32 +02:00
|
|
|
memset(header, 0, sizeof(*header));
|
2012-09-24 13:46:38 +02:00
|
|
|
header->signature = MAKEFOURCC('D','D','S',' ');
|
|
|
|
header->size = sizeof(*header);
|
|
|
|
header->flags = DDS_CAPS | DDS_HEIGHT | DDS_WIDTH | DDS_PITCH | DDS_PIXELFORMAT | DDS_MIPMAPCOUNT;
|
|
|
|
header->height = src_desc.Height;
|
|
|
|
header->width = src_desc.Width;
|
|
|
|
header->pitch_or_linear_size = dst_pitch;
|
|
|
|
header->depth = 1;
|
|
|
|
header->miplevels = 1;
|
|
|
|
header->caps = DDS_CAPS_TEXTURE;
|
|
|
|
hr = d3dformat_to_dds_pixel_format(&header->pixel_format, src_desc.Format);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ID3DXBuffer_Release(buffer);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IDirect3DSurface9_LockRect(src_surface, &locked_rect, NULL, D3DLOCK_READONLY);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ID3DXBuffer_Release(buffer);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
volume.width = src_desc.Width;
|
|
|
|
volume.height = src_desc.Height;
|
|
|
|
volume.depth = 1;
|
2012-10-28 22:59:56 +01:00
|
|
|
copy_pixels(locked_rect.pBits, locked_rect.Pitch, 0, pixels, dst_pitch, 0,
|
|
|
|
&volume, pixel_format);
|
2012-09-24 13:46:38 +02:00
|
|
|
|
|
|
|
IDirect3DSurface9_UnlockRect(src_surface);
|
|
|
|
|
|
|
|
*dst_buffer = buffer;
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-03 16:06:45 +02:00
|
|
|
HRESULT load_volume_from_dds(IDirect3DVolume9 *dst_volume, const PALETTEENTRY *dst_palette,
|
|
|
|
const D3DBOX *dst_box, const void *src_data, const D3DBOX *src_box, DWORD filter, D3DCOLOR color_key,
|
|
|
|
const D3DXIMAGE_INFO *src_info)
|
|
|
|
{
|
|
|
|
UINT row_pitch, slice_pitch;
|
|
|
|
const struct dds_header *header = src_data;
|
|
|
|
const BYTE *pixels = (BYTE *)(header + 1);
|
|
|
|
|
|
|
|
if (src_info->ResourceType != D3DRTYPE_VOLUMETEXTURE)
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
|
2012-09-24 13:46:36 +02:00
|
|
|
if (FAILED(calculate_dds_surface_size(src_info->Format, src_info->Width, src_info->Height, &row_pitch, &slice_pitch)))
|
2012-07-03 16:06:45 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
|
|
|
|
return D3DXLoadVolumeFromMemory(dst_volume, dst_palette, dst_box, pixels, src_info->Format,
|
|
|
|
row_pitch, slice_pitch, NULL, src_box, filter, color_key);
|
|
|
|
}
|
|
|
|
|
2012-05-13 23:00:07 +02:00
|
|
|
HRESULT load_texture_from_dds(IDirect3DTexture9 *texture, const void *src_data, const PALETTEENTRY *palette,
|
2014-03-05 18:35:18 +01:00
|
|
|
DWORD filter, D3DCOLOR color_key, const D3DXIMAGE_INFO *src_info, unsigned int skip_levels,
|
2014-03-03 17:48:14 +01:00
|
|
|
unsigned int *loaded_miplevels)
|
2012-05-13 23:00:07 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
RECT src_rect;
|
|
|
|
UINT src_pitch;
|
|
|
|
UINT mip_level;
|
|
|
|
UINT mip_levels;
|
|
|
|
UINT mip_level_size;
|
|
|
|
UINT width, height;
|
|
|
|
IDirect3DSurface9 *surface;
|
|
|
|
const struct dds_header *header = src_data;
|
|
|
|
const BYTE *pixels = (BYTE *)(header + 1);
|
|
|
|
|
2014-03-03 17:48:14 +01:00
|
|
|
/* Loading a cube texture as a simple texture is also supported
|
|
|
|
* (only first face texture is taken). Same with volume textures. */
|
|
|
|
if ((src_info->ResourceType != D3DRTYPE_TEXTURE)
|
|
|
|
&& (src_info->ResourceType != D3DRTYPE_CUBETEXTURE)
|
|
|
|
&& (src_info->ResourceType != D3DRTYPE_VOLUMETEXTURE))
|
|
|
|
{
|
|
|
|
WARN("Trying to load a %u resource as a 2D texture, returning failure.\n", src_info->ResourceType);
|
2012-05-13 23:00:07 +02:00
|
|
|
return D3DXERR_INVALIDDATA;
|
2014-03-03 17:48:14 +01:00
|
|
|
}
|
2012-05-13 23:00:07 +02:00
|
|
|
|
|
|
|
width = src_info->Width;
|
|
|
|
height = src_info->Height;
|
|
|
|
mip_levels = min(src_info->MipLevels, IDirect3DTexture9_GetLevelCount(texture));
|
2014-03-03 17:48:14 +01:00
|
|
|
if (src_info->ResourceType == D3DRTYPE_VOLUMETEXTURE)
|
|
|
|
mip_levels = 1;
|
2014-03-05 18:35:18 +01:00
|
|
|
for (mip_level = 0; mip_level < mip_levels + skip_levels; ++mip_level)
|
2012-05-13 23:00:07 +02:00
|
|
|
{
|
2012-09-24 13:46:36 +02:00
|
|
|
hr = calculate_dds_surface_size(src_info->Format, width, height, &src_pitch, &mip_level_size);
|
2012-05-13 23:00:07 +02:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
2014-03-05 18:35:18 +01:00
|
|
|
if (mip_level >= skip_levels)
|
|
|
|
{
|
|
|
|
SetRect(&src_rect, 0, 0, width, height);
|
|
|
|
|
|
|
|
IDirect3DTexture9_GetSurfaceLevel(texture, mip_level - skip_levels, &surface);
|
|
|
|
hr = D3DXLoadSurfaceFromMemory(surface, palette, NULL, pixels, src_info->Format, src_pitch,
|
|
|
|
NULL, &src_rect, filter, color_key);
|
|
|
|
IDirect3DSurface9_Release(surface);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
}
|
2012-05-13 23:00:07 +02:00
|
|
|
|
|
|
|
pixels += mip_level_size;
|
|
|
|
width = max(1, width / 2);
|
|
|
|
height = max(1, height / 2);
|
|
|
|
}
|
|
|
|
|
2014-03-05 18:35:18 +01:00
|
|
|
*loaded_miplevels = mip_levels - skip_levels;
|
2014-03-03 17:48:14 +01:00
|
|
|
|
2012-05-13 23:00:07 +02:00
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-13 23:00:06 +02:00
|
|
|
HRESULT load_cube_texture_from_dds(IDirect3DCubeTexture9 *cube_texture, const void *src_data,
|
|
|
|
const PALETTEENTRY *palette, DWORD filter, DWORD color_key, const D3DXIMAGE_INFO *src_info)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
int face;
|
2013-01-03 23:46:48 +01:00
|
|
|
UINT mip_level;
|
2012-05-13 23:00:06 +02:00
|
|
|
UINT size;
|
|
|
|
RECT src_rect;
|
|
|
|
UINT src_pitch;
|
|
|
|
UINT mip_levels;
|
|
|
|
UINT mip_level_size;
|
|
|
|
IDirect3DSurface9 *surface;
|
|
|
|
const struct dds_header *header = src_data;
|
|
|
|
const BYTE *pixels = (BYTE *)(header + 1);
|
|
|
|
|
|
|
|
if (src_info->ResourceType != D3DRTYPE_CUBETEXTURE)
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
|
|
|
|
if ((header->caps2 & DDS_CAPS2_CUBEMAP_ALL_FACES) != DDS_CAPS2_CUBEMAP_ALL_FACES)
|
|
|
|
{
|
|
|
|
WARN("Only full cubemaps are supported\n");
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
mip_levels = min(src_info->MipLevels, IDirect3DCubeTexture9_GetLevelCount(cube_texture));
|
|
|
|
for (face = D3DCUBEMAP_FACE_POSITIVE_X; face <= D3DCUBEMAP_FACE_NEGATIVE_Z; face++)
|
|
|
|
{
|
|
|
|
size = src_info->Width;
|
|
|
|
for (mip_level = 0; mip_level < src_info->MipLevels; mip_level++)
|
|
|
|
{
|
2012-09-24 13:46:36 +02:00
|
|
|
hr = calculate_dds_surface_size(src_info->Format, size, size, &src_pitch, &mip_level_size);
|
2012-05-13 23:00:06 +02:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
/* if texture has fewer mip levels than DDS file, skip excessive mip levels */
|
|
|
|
if (mip_level < mip_levels)
|
|
|
|
{
|
|
|
|
SetRect(&src_rect, 0, 0, size, size);
|
|
|
|
|
|
|
|
IDirect3DCubeTexture9_GetCubeMapSurface(cube_texture, face, mip_level, &surface);
|
|
|
|
hr = D3DXLoadSurfaceFromMemory(surface, palette, NULL, pixels, src_info->Format, src_pitch,
|
|
|
|
NULL, &src_rect, filter, color_key);
|
|
|
|
IDirect3DSurface9_Release(surface);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
pixels += mip_level_size;
|
|
|
|
size = max(1, size / 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-29 14:17:01 +02:00
|
|
|
HRESULT load_volume_texture_from_dds(IDirect3DVolumeTexture9 *volume_texture, const void *src_data,
|
|
|
|
const PALETTEENTRY *palette, DWORD filter, DWORD color_key, const D3DXIMAGE_INFO *src_info)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
UINT mip_level;
|
|
|
|
UINT mip_levels;
|
|
|
|
UINT src_slice_pitch;
|
|
|
|
UINT src_row_pitch;
|
|
|
|
D3DBOX src_box;
|
|
|
|
UINT width, height, depth;
|
|
|
|
IDirect3DVolume9 *volume;
|
|
|
|
const struct dds_header *header = src_data;
|
|
|
|
const BYTE *pixels = (BYTE *)(header + 1);
|
|
|
|
|
|
|
|
if (src_info->ResourceType != D3DRTYPE_VOLUMETEXTURE)
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
|
|
|
|
width = src_info->Width;
|
|
|
|
height = src_info->Height;
|
|
|
|
depth = src_info->Depth;
|
|
|
|
mip_levels = min(src_info->MipLevels, IDirect3DVolumeTexture9_GetLevelCount(volume_texture));
|
|
|
|
|
|
|
|
for (mip_level = 0; mip_level < mip_levels; mip_level++)
|
|
|
|
{
|
2012-09-24 13:46:36 +02:00
|
|
|
hr = calculate_dds_surface_size(src_info->Format, width, height, &src_row_pitch, &src_slice_pitch);
|
2012-06-29 14:17:01 +02:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = IDirect3DVolumeTexture9_GetVolumeLevel(volume_texture, mip_level, &volume);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
src_box.Left = 0;
|
|
|
|
src_box.Top = 0;
|
|
|
|
src_box.Right = width;
|
|
|
|
src_box.Bottom = height;
|
|
|
|
src_box.Front = 0;
|
|
|
|
src_box.Back = depth;
|
|
|
|
|
|
|
|
hr = D3DXLoadVolumeFromMemory(volume, palette, NULL, pixels, src_info->Format,
|
|
|
|
src_row_pitch, src_slice_pitch, NULL, &src_box, filter, color_key);
|
|
|
|
|
|
|
|
IDirect3DVolume9_Release(volume);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
pixels += depth * src_slice_pitch;
|
|
|
|
width = max(1, width / 2);
|
|
|
|
height = max(1, height / 2);
|
|
|
|
depth = max(1, depth / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-24 23:40:19 +02:00
|
|
|
static BOOL convert_dib_to_bmp(void **data, UINT *size)
|
|
|
|
{
|
|
|
|
ULONG header_size;
|
|
|
|
ULONG count = 0;
|
|
|
|
ULONG offset;
|
|
|
|
BITMAPFILEHEADER *header;
|
|
|
|
BYTE *new_data;
|
|
|
|
UINT new_size;
|
|
|
|
|
|
|
|
if ((*size < 4) || (*size < (header_size = *(ULONG*)*data)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if ((header_size == sizeof(BITMAPINFOHEADER)) ||
|
|
|
|
(header_size == sizeof(BITMAPV4HEADER)) ||
|
|
|
|
(header_size == sizeof(BITMAPV5HEADER)) ||
|
|
|
|
(header_size == 64 /* sizeof(BITMAPCOREHEADER2) */))
|
|
|
|
{
|
|
|
|
/* All structures begin with the same memory layout as BITMAPINFOHEADER */
|
|
|
|
BITMAPINFOHEADER *info_header = (BITMAPINFOHEADER*)*data;
|
|
|
|
count = info_header->biClrUsed;
|
|
|
|
|
|
|
|
if (!count && info_header->biBitCount <= 8)
|
|
|
|
count = 1 << info_header->biBitCount;
|
|
|
|
|
|
|
|
offset = sizeof(BITMAPFILEHEADER) + header_size + sizeof(RGBQUAD) * count;
|
|
|
|
|
|
|
|
/* For BITMAPINFOHEADER with BI_BITFIELDS compression, there are 3 additional color masks after header */
|
|
|
|
if ((info_header->biSize == sizeof(BITMAPINFOHEADER)) && (info_header->biCompression == BI_BITFIELDS))
|
|
|
|
offset += 3 * sizeof(DWORD);
|
|
|
|
}
|
|
|
|
else if (header_size == sizeof(BITMAPCOREHEADER))
|
|
|
|
{
|
|
|
|
BITMAPCOREHEADER *core_header = (BITMAPCOREHEADER*)*data;
|
|
|
|
|
|
|
|
if (core_header->bcBitCount <= 8)
|
|
|
|
count = 1 << core_header->bcBitCount;
|
|
|
|
|
|
|
|
offset = sizeof(BITMAPFILEHEADER) + header_size + sizeof(RGBTRIPLE) * count;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Converting DIB file to BMP\n");
|
|
|
|
|
|
|
|
new_size = *size + sizeof(BITMAPFILEHEADER);
|
|
|
|
new_data = HeapAlloc(GetProcessHeap(), 0, new_size);
|
|
|
|
CopyMemory(new_data + sizeof(BITMAPFILEHEADER), *data, *size);
|
|
|
|
|
|
|
|
/* Add BMP header */
|
|
|
|
header = (BITMAPFILEHEADER*)new_data;
|
|
|
|
header->bfType = 0x4d42; /* BM */
|
|
|
|
header->bfSize = new_size;
|
|
|
|
header->bfReserved1 = 0;
|
|
|
|
header->bfReserved2 = 0;
|
|
|
|
header->bfOffBits = offset;
|
|
|
|
|
|
|
|
/* Update input data */
|
|
|
|
*data = new_data;
|
|
|
|
*size = new_size;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*
|
|
|
|
*/
|
2013-04-24 23:40:19 +02:00
|
|
|
HRESULT WINAPI D3DXGetImageInfoFromFileInMemory(const void *data, UINT datasize, D3DXIMAGE_INFO *info)
|
2009-05-23 12:56:19 +02:00
|
|
|
{
|
2010-04-09 08:43:17 +02:00
|
|
|
IWICImagingFactory *factory;
|
|
|
|
IWICBitmapDecoder *decoder = NULL;
|
|
|
|
IWICStream *stream;
|
|
|
|
HRESULT hr;
|
|
|
|
HRESULT initresult;
|
2013-04-24 23:40:19 +02:00
|
|
|
BOOL dib;
|
2010-04-09 08:43:17 +02:00
|
|
|
|
2012-02-09 01:09:32 +01:00
|
|
|
TRACE("(%p, %d, %p)\n", data, datasize, info);
|
2010-04-09 08:43:17 +02:00
|
|
|
|
|
|
|
if (!data || !datasize)
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
if (!info)
|
|
|
|
return D3D_OK;
|
|
|
|
|
2012-05-13 23:00:10 +02:00
|
|
|
if ((datasize >= 4) && !strncmp(data, "DDS ", 4)) {
|
|
|
|
TRACE("File type is DDS\n");
|
2012-04-29 21:43:08 +02:00
|
|
|
return get_image_info_from_dds(data, datasize, info);
|
2012-05-13 23:00:10 +02:00
|
|
|
}
|
2012-04-29 21:43:08 +02:00
|
|
|
|
2013-04-24 23:40:19 +02:00
|
|
|
/* In case of DIB file, convert it to BMP */
|
|
|
|
dib = convert_dib_to_bmp((void**)&data, &datasize);
|
|
|
|
|
2010-04-09 08:43:17 +02:00
|
|
|
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);
|
2012-08-28 11:10:56 +02:00
|
|
|
IWICStream_Release(stream);
|
2010-04-09 08:43:17 +02:00
|
|
|
IWICImagingFactory_Release(factory);
|
|
|
|
}
|
|
|
|
|
2012-02-10 14:18:39 +01:00
|
|
|
if (FAILED(hr)) {
|
2012-04-29 21:43:08 +02:00
|
|
|
if ((datasize >= 2) && (!strncmp(data, "P3", 2) || !strncmp(data, "P6", 2)))
|
2012-02-10 14:18:39 +01:00
|
|
|
FIXME("File type PPM is not supported yet\n");
|
|
|
|
else if ((datasize >= 10) && !strncmp(data, "#?RADIANCE", 10))
|
|
|
|
FIXME("File type HDR is not supported yet\n");
|
|
|
|
else if ((datasize >= 2) && (!strncmp(data, "PF", 2) || !strncmp(data, "Pf", 2)))
|
|
|
|
FIXME("File type PFM is not supported yet\n");
|
|
|
|
}
|
|
|
|
|
2010-04-09 08:43:17 +02:00
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
GUID container_format;
|
|
|
|
UINT frame_count;
|
|
|
|
|
|
|
|
hr = IWICBitmapDecoder_GetContainerFormat(decoder, &container_format);
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
if (IsEqualGUID(&container_format, &GUID_ContainerFormatBmp)) {
|
2013-04-24 23:40:19 +02:00
|
|
|
if (dib) {
|
|
|
|
TRACE("File type is DIB\n");
|
|
|
|
info->ImageFileFormat = D3DXIFF_DIB;
|
|
|
|
} else {
|
|
|
|
TRACE("File type is BMP\n");
|
|
|
|
info->ImageFileFormat = D3DXIFF_BMP;
|
|
|
|
}
|
2010-04-09 08:43:17 +02:00
|
|
|
} 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)) {
|
2012-05-04 13:01:19 +02:00
|
|
|
info->Format = wic_guid_to_d3dformat(&pixel_format);
|
|
|
|
if (info->Format == D3DFMT_UNKNOWN) {
|
2010-04-09 08:43:17 +02:00
|
|
|
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
|
|
|
|
2013-04-24 23:40:19 +02:00
|
|
|
if (dib)
|
|
|
|
HeapFree(GetProcessHeap(), 0, (void*)data);
|
|
|
|
|
2010-04-09 08:43:17 +02:00
|
|
|
if (FAILED(hr)) {
|
2012-02-10 14:18:39 +01:00
|
|
|
TRACE("Invalid or unsupported image file\n");
|
2010-04-09 08:43:17 +02:00
|
|
|
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
|
|
|
|
*
|
|
|
|
*/
|
2013-09-02 09:45:44 +02:00
|
|
|
HRESULT WINAPI D3DXGetImageInfoFromFileA(const char *file, D3DXIMAGE_INFO *info)
|
2009-05-23 12:56:19 +02:00
|
|
|
{
|
2013-09-02 09:45:43 +02:00
|
|
|
WCHAR *widename;
|
2009-06-01 18:30:15 +02:00
|
|
|
HRESULT hr;
|
|
|
|
int strlength;
|
2010-04-05 20:28:07 +02:00
|
|
|
|
2013-09-02 09:45:43 +02:00
|
|
|
TRACE("file %s, info %p.\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);
|
2012-05-25 16:10:29 +02:00
|
|
|
widename = HeapAlloc(GetProcessHeap(), 0, strlength * sizeof(*widename));
|
2009-06-01 18:30:15 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-08-30 08:42:48 +02:00
|
|
|
HRESULT WINAPI D3DXGetImageInfoFromFileW(const WCHAR *file, D3DXIMAGE_INFO *info)
|
2009-05-23 12:56:19 +02:00
|
|
|
{
|
2013-08-30 08:42:48 +02:00
|
|
|
void *buffer;
|
2009-06-01 18:30:15 +02:00
|
|
|
HRESULT hr;
|
|
|
|
DWORD size;
|
2010-04-05 20:28:07 +02:00
|
|
|
|
2013-08-30 08:42:48 +02:00
|
|
|
TRACE("file %s, info %p.\n", debugstr_w(file), info);
|
2009-06-01 18:30:15 +02:00
|
|
|
|
2013-08-30 08:42:48 +02:00
|
|
|
if (!file)
|
|
|
|
return D3DERR_INVALIDCALL;
|
2009-06-01 18:30:15 +02:00
|
|
|
|
2013-08-30 08:42:48 +02:00
|
|
|
if (FAILED(map_view_of_file(file, &buffer, &size)))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
2009-06-01 18:30:15 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
*/
|
2013-08-27 08:45:00 +02:00
|
|
|
HRESULT WINAPI D3DXGetImageInfoFromResourceA(HMODULE module, const char *resource, D3DXIMAGE_INFO *info)
|
2009-05-23 12:56:19 +02:00
|
|
|
{
|
2009-06-01 18:30:15 +02:00
|
|
|
HRSRC resinfo;
|
2013-08-27 08:45:00 +02:00
|
|
|
void *buffer;
|
|
|
|
DWORD size;
|
2010-04-05 20:28:07 +02:00
|
|
|
|
2013-08-27 08:45:00 +02:00
|
|
|
TRACE("module %p, resource %s, info %p.\n", module, debugstr_a(resource), info);
|
2013-01-07 09:40:08 +01:00
|
|
|
|
2013-08-27 08:45:00 +02:00
|
|
|
if (!(resinfo = FindResourceA(module, resource, (const char *)RT_RCDATA))
|
|
|
|
/* Try loading the resource as bitmap data (which is in DIB format D3DXIFF_DIB) */
|
|
|
|
&& !(resinfo = FindResourceA(module, resource, (const char *)RT_BITMAP)))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
2009-06-01 18:30:15 +02:00
|
|
|
|
2013-08-27 08:45:00 +02:00
|
|
|
if (FAILED(load_resource_into_memory(module, resinfo, &buffer, &size)))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
2009-06-01 18:30:15 +02:00
|
|
|
|
2013-08-27 08:45:00 +02:00
|
|
|
return D3DXGetImageInfoFromFileInMemory(buffer, size, info);
|
2009-05-23 12:56:19 +02:00
|
|
|
}
|
|
|
|
|
2013-08-27 08:45:01 +02:00
|
|
|
HRESULT WINAPI D3DXGetImageInfoFromResourceW(HMODULE module, const WCHAR *resource, D3DXIMAGE_INFO *info)
|
2009-05-23 12:56:19 +02:00
|
|
|
{
|
2009-06-01 18:30:15 +02:00
|
|
|
HRSRC resinfo;
|
2013-08-27 08:45:01 +02:00
|
|
|
void *buffer;
|
|
|
|
DWORD size;
|
2010-04-05 20:28:07 +02:00
|
|
|
|
2013-08-27 08:45:01 +02:00
|
|
|
TRACE("module %p, resource %s, info %p.\n", module, debugstr_w(resource), info);
|
2013-01-07 09:40:08 +01:00
|
|
|
|
2013-08-27 08:45:01 +02:00
|
|
|
if (!(resinfo = FindResourceW(module, resource, (const WCHAR *)RT_RCDATA))
|
|
|
|
/* Try loading the resource as bitmap data (which is in DIB format D3DXIFF_DIB) */
|
|
|
|
&& !(resinfo = FindResourceW(module, resource, (const WCHAR *)RT_BITMAP)))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
2009-06-01 18:30:15 +02:00
|
|
|
|
2013-08-27 08:45:01 +02:00
|
|
|
if (FAILED(load_resource_into_memory(module, resinfo, &buffer, &size)))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
2009-06-01 18:30:15 +02:00
|
|
|
|
2013-08-27 08:45:01 +02:00
|
|
|
return D3DXGetImageInfoFromFileInMemory(buffer, size, info);
|
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
|
|
|
|
*
|
|
|
|
*/
|
2012-06-01 17:22:50 +02:00
|
|
|
HRESULT WINAPI D3DXLoadSurfaceFromFileInMemory(IDirect3DSurface9 *pDestSurface,
|
|
|
|
const PALETTEENTRY *pDestPalette, const RECT *pDestRect, const void *pSrcData, UINT SrcDataSize,
|
|
|
|
const RECT *pSrcRect, DWORD dwFilter, D3DCOLOR Colorkey, D3DXIMAGE_INFO *pSrcInfo)
|
2009-06-22 17:21:30 +02:00
|
|
|
{
|
2010-08-31 17:43:35 +02:00
|
|
|
D3DXIMAGE_INFO imginfo;
|
2014-02-24 19:18:49 +01:00
|
|
|
HRESULT hr, com_init;
|
2010-08-31 17:43:35 +02:00
|
|
|
|
2013-05-19 22:32:18 +02:00
|
|
|
IWICImagingFactory *factory = NULL;
|
2010-11-08 19:57:45 +01:00
|
|
|
IWICBitmapDecoder *decoder;
|
|
|
|
IWICBitmapFrameDecode *bitmapframe;
|
|
|
|
IWICStream *stream;
|
|
|
|
|
2012-09-03 09:57:41 +02:00
|
|
|
const struct pixel_format_desc *formatdesc;
|
2010-11-08 19:57:45 +01:00
|
|
|
WICRect wicrect;
|
|
|
|
RECT rect;
|
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_data %p, src_data_size %u, "
|
|
|
|
"src_rect %s, filter %#x, color_key 0x%08x, src_info %p.\n",
|
|
|
|
pDestSurface, pDestPalette, wine_dbgstr_rect(pDestRect), pSrcData, SrcDataSize,
|
|
|
|
wine_dbgstr_rect(pSrcRect), dwFilter, Colorkey, pSrcInfo);
|
2010-08-31 17:43:35 +02:00
|
|
|
|
2011-08-27 18:42:33 +02:00
|
|
|
if (!pDestSurface || !pSrcData || !SrcDataSize)
|
2010-08-31 17:43:35 +02:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
hr = D3DXGetImageInfoFromFileInMemory(pSrcData, SrcDataSize, &imginfo);
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2012-05-13 23:00:08 +02: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetRect(&rect, 0, 0, wicrect.Width, wicrect.Height);
|
|
|
|
|
|
|
|
if (imginfo.ImageFileFormat == D3DXIFF_DDS)
|
|
|
|
{
|
|
|
|
hr = load_surface_from_dds(pDestSurface, pDestPalette, pDestRect, pSrcData, &rect,
|
|
|
|
dwFilter, Colorkey, &imginfo);
|
|
|
|
if (SUCCEEDED(hr) && pSrcInfo)
|
|
|
|
*pSrcInfo = imginfo;
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2013-04-22 23:08:09 +02:00
|
|
|
if (imginfo.ImageFileFormat == D3DXIFF_DIB)
|
|
|
|
convert_dib_to_bmp((void**)&pSrcData, &SrcDataSize);
|
|
|
|
|
2014-02-24 19:18:49 +01:00
|
|
|
com_init = 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);
|
2013-05-19 22:32:18 +02:00
|
|
|
factory = NULL;
|
2010-11-08 19:57:45 +01:00
|
|
|
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
|
|
|
|
2012-08-28 11:10:56 +02:00
|
|
|
IWICStream_Release(stream);
|
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
|
|
|
formatdesc = get_format_info(imginfo.Format);
|
2010-08-31 17:43:35 +02:00
|
|
|
|
2012-10-22 17:20:27 +02:00
|
|
|
if (formatdesc->type == FORMAT_UNKNOWN)
|
2010-11-08 19:57:45 +01:00
|
|
|
{
|
|
|
|
FIXME("Unsupported pixel format\n");
|
|
|
|
hr = D3DXERR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BYTE *buffer;
|
|
|
|
DWORD pitch;
|
2013-05-19 22:32:18 +02:00
|
|
|
PALETTEENTRY *palette = NULL;
|
|
|
|
WICColor *colors = NULL;
|
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
|
|
|
|
2013-05-19 22:32:18 +02:00
|
|
|
if (SUCCEEDED(hr) && (formatdesc->type == FORMAT_INDEX))
|
|
|
|
{
|
|
|
|
IWICPalette *wic_palette = NULL;
|
|
|
|
UINT nb_colors;
|
|
|
|
|
|
|
|
hr = IWICImagingFactory_CreatePalette(factory, &wic_palette);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IWICBitmapFrameDecode_CopyPalette(bitmapframe, wic_palette);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IWICPalette_GetColorCount(wic_palette, &nb_colors);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2013-05-25 09:04:37 +02:00
|
|
|
colors = HeapAlloc(GetProcessHeap(), 0, nb_colors * sizeof(colors[0]));
|
|
|
|
palette = HeapAlloc(GetProcessHeap(), 0, nb_colors * sizeof(palette[0]));
|
2013-05-19 22:32:18 +02:00
|
|
|
if (!colors || !palette)
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IWICPalette_GetColors(wic_palette, nb_colors, colors, &nb_colors);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
/* Convert colors from WICColor (ARGB) to PALETTEENTRY (ABGR) */
|
|
|
|
for (i = 0; i < nb_colors; i++)
|
|
|
|
{
|
|
|
|
palette[i].peRed = (colors[i] >> 16) & 0xff;
|
|
|
|
palette[i].peGreen = (colors[i] >> 8) & 0xff;
|
|
|
|
palette[i].peBlue = colors[i] & 0xff;
|
|
|
|
palette[i].peFlags = (colors[i] >> 24) & 0xff; /* peFlags is the alpha component in DX8 and higher */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (wic_palette)
|
|
|
|
IWICPalette_Release(wic_palette);
|
|
|
|
}
|
|
|
|
|
2010-11-08 19:57:45 +01:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = D3DXLoadSurfaceFromMemory(pDestSurface, pDestPalette, pDestRect,
|
|
|
|
buffer, imginfo.Format, pitch,
|
2013-05-19 22:32:18 +02:00
|
|
|
palette, &rect, dwFilter, Colorkey);
|
2010-11-08 19:57:45 +01:00
|
|
|
}
|
|
|
|
|
2013-05-19 22:32:18 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, colors);
|
|
|
|
HeapFree(GetProcessHeap(), 0, palette);
|
2010-11-08 19:57:45 +01:00
|
|
|
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:
|
2013-05-19 22:32:18 +02:00
|
|
|
if (factory)
|
|
|
|
IWICImagingFactory_Release(factory);
|
|
|
|
|
2014-02-24 19:18:49 +01:00
|
|
|
if (SUCCEEDED(com_init))
|
|
|
|
CoUninitialize();
|
2010-08-31 17:43:35 +02:00
|
|
|
|
2013-04-22 23:08:09 +02:00
|
|
|
if (imginfo.ImageFileFormat == D3DXIFF_DIB)
|
|
|
|
HeapFree(GetProcessHeap(), 0, (void*)pSrcData);
|
|
|
|
|
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
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
HRESULT WINAPI D3DXLoadSurfaceFromFileA(IDirect3DSurface9 *dst_surface,
|
|
|
|
const PALETTEENTRY *dst_palette, const RECT *dst_rect, const char *src_file,
|
|
|
|
const RECT *src_rect, DWORD filter, D3DCOLOR color_key, D3DXIMAGE_INFO *src_info)
|
2009-06-22 17:33:48 +02:00
|
|
|
{
|
2013-09-02 09:45:43 +02:00
|
|
|
WCHAR *src_file_w;
|
2009-06-22 17:33:48 +02:00
|
|
|
HRESULT hr;
|
|
|
|
int strlength;
|
2010-04-05 20:28:07 +02:00
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_file %s, "
|
|
|
|
"src_rect %s, filter %#x, color_key 0x%08x, src_info %p.\n",
|
|
|
|
dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), debugstr_a(src_file),
|
|
|
|
wine_dbgstr_rect(src_rect), filter, color_key, src_info);
|
2009-06-22 17:33:48 +02:00
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
if (!src_file || !dst_surface)
|
|
|
|
return D3DERR_INVALIDCALL;
|
2009-06-22 17:33:48 +02:00
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
strlength = MultiByteToWideChar(CP_ACP, 0, src_file, -1, NULL, 0);
|
2013-09-02 09:45:43 +02:00
|
|
|
src_file_w = HeapAlloc(GetProcessHeap(), 0, strlength * sizeof(*src_file_w));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, src_file, -1, src_file_w, strlength);
|
2009-06-22 17:33:48 +02:00
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
hr = D3DXLoadSurfaceFromFileW(dst_surface, dst_palette, dst_rect,
|
2013-09-02 09:45:43 +02:00
|
|
|
src_file_w, src_rect, filter, color_key, src_info);
|
|
|
|
HeapFree(GetProcessHeap(), 0, src_file_w);
|
2009-06-22 17:33:48 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
HRESULT WINAPI D3DXLoadSurfaceFromFileW(IDirect3DSurface9 *dst_surface,
|
|
|
|
const PALETTEENTRY *dst_palette, const RECT *dst_rect, const WCHAR *src_file,
|
|
|
|
const RECT *src_rect, DWORD filter, D3DCOLOR color_key, D3DXIMAGE_INFO *src_info)
|
2009-06-22 17:33:48 +02:00
|
|
|
{
|
2012-06-01 17:22:50 +02:00
|
|
|
UINT data_size;
|
|
|
|
void *data;
|
2009-06-22 17:33:48 +02:00
|
|
|
HRESULT hr;
|
2010-04-05 20:28:07 +02:00
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_file %s, "
|
|
|
|
"src_rect %s, filter %#x, color_key 0x%08x, src_info %p.\n",
|
|
|
|
dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), debugstr_w(src_file),
|
|
|
|
wine_dbgstr_rect(src_rect), filter, color_key, src_info);
|
2009-06-22 17:33:48 +02:00
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
if (!src_file || !dst_surface)
|
|
|
|
return D3DERR_INVALIDCALL;
|
2009-06-22 17:33:48 +02:00
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
if (FAILED(map_view_of_file(src_file, &data, &data_size)))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
2009-06-22 17:33:48 +02:00
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
hr = D3DXLoadSurfaceFromFileInMemory(dst_surface, dst_palette, dst_rect,
|
|
|
|
data, data_size, src_rect, filter, color_key, src_info);
|
|
|
|
UnmapViewOfFile(data);
|
2009-06-22 17:33:48 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
2009-06-22 17:38:15 +02:00
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
HRESULT WINAPI D3DXLoadSurfaceFromResourceA(IDirect3DSurface9 *dst_surface,
|
|
|
|
const PALETTEENTRY *dst_palette, const RECT *dst_rect, HMODULE src_module, const char *resource,
|
|
|
|
const RECT *src_rect, DWORD filter, D3DCOLOR color_key, D3DXIMAGE_INFO *src_info)
|
2009-06-22 17:38:15 +02:00
|
|
|
{
|
2013-08-28 10:09:59 +02:00
|
|
|
UINT data_size;
|
|
|
|
HRSRC resinfo;
|
|
|
|
void *data;
|
2010-04-05 20:28:07 +02:00
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_module %p, resource %s, "
|
|
|
|
"src_rect %s, filter %#x, color_key 0x%08x, src_info %p.\n",
|
|
|
|
dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), src_module, debugstr_a(resource),
|
|
|
|
wine_dbgstr_rect(src_rect), filter, color_key, src_info);
|
2009-06-22 17:38:15 +02:00
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
if (!dst_surface)
|
|
|
|
return D3DERR_INVALIDCALL;
|
2009-06-22 17:38:15 +02:00
|
|
|
|
2013-08-28 10:09:59 +02:00
|
|
|
if (!(resinfo = FindResourceA(src_module, resource, (const char *)RT_RCDATA))
|
|
|
|
/* Try loading the resource as bitmap data (which is in DIB format D3DXIFF_DIB) */
|
|
|
|
&& !(resinfo = FindResourceA(src_module, resource, (const char *)RT_BITMAP)))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
2012-06-01 17:22:50 +02:00
|
|
|
|
2013-08-28 10:09:59 +02:00
|
|
|
if (FAILED(load_resource_into_memory(src_module, resinfo, &data, &data_size)))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
2009-06-22 17:38:15 +02:00
|
|
|
|
2013-08-28 10:09:59 +02:00
|
|
|
return D3DXLoadSurfaceFromFileInMemory(dst_surface, dst_palette, dst_rect,
|
|
|
|
data, data_size, src_rect, filter, color_key, src_info);
|
2009-06-22 17:38:15 +02:00
|
|
|
}
|
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
HRESULT WINAPI D3DXLoadSurfaceFromResourceW(IDirect3DSurface9 *dst_surface,
|
|
|
|
const PALETTEENTRY *dst_palette, const RECT *dst_rect, HMODULE src_module, const WCHAR *resource,
|
|
|
|
const RECT *src_rect, DWORD filter, D3DCOLOR color_key, D3DXIMAGE_INFO *src_info)
|
2009-06-22 17:38:15 +02:00
|
|
|
{
|
2013-08-28 10:10:00 +02:00
|
|
|
UINT data_size;
|
|
|
|
HRSRC resinfo;
|
|
|
|
void *data;
|
2010-04-05 20:28:07 +02:00
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_module %p, resource %s, "
|
|
|
|
"src_rect %s, filter %#x, color_key 0x%08x, src_info %p.\n",
|
|
|
|
dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), src_module, debugstr_w(resource),
|
|
|
|
wine_dbgstr_rect(src_rect), filter, color_key, src_info);
|
2009-06-22 17:38:15 +02:00
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
if (!dst_surface)
|
|
|
|
return D3DERR_INVALIDCALL;
|
2009-06-22 17:38:15 +02:00
|
|
|
|
2013-08-28 10:10:00 +02:00
|
|
|
if (!(resinfo = FindResourceW(src_module, resource, (const WCHAR *)RT_RCDATA))
|
|
|
|
/* Try loading the resource as bitmap data (which is in DIB format D3DXIFF_DIB) */
|
|
|
|
&& !(resinfo = FindResourceW(src_module, resource, (const WCHAR *)RT_BITMAP)))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
2012-06-01 17:22:50 +02:00
|
|
|
|
2013-08-28 10:10:00 +02:00
|
|
|
if (FAILED(load_resource_into_memory(src_module, resinfo, &data, &data_size)))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
2009-06-22 17:38:15 +02:00
|
|
|
|
2013-08-28 10:10:00 +02:00
|
|
|
return D3DXLoadSurfaceFromFileInMemory(dst_surface, dst_palette, dst_rect,
|
|
|
|
data, data_size, src_rect, filter, color_key, src_info);
|
2009-06-22 17:38:15 +02:00
|
|
|
}
|
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
|
|
|
{
|
2012-09-03 09:57:41 +02:00
|
|
|
const struct pixel_format_desc *srcformat;
|
|
|
|
const struct pixel_format_desc *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
|
|
|
|
2012-09-03 09:57:41 +02:00
|
|
|
static void init_argb_conversion_info(const struct pixel_format_desc *srcformat, const struct pixel_format_desc *destformat, struct argb_conversion_info *info)
|
2010-07-28 21:33:14 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************
|
|
|
|
* 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.
|
|
|
|
*/
|
2013-09-20 10:41:46 +02:00
|
|
|
static void get_relevant_argb_components(const struct argb_conversion_info *info, DWORD col, DWORD *out)
|
2010-07-28 21:33:14 +02:00
|
|
|
{
|
|
|
|
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.
|
|
|
|
*/
|
2013-09-20 10:41:46 +02: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
|
|
|
}
|
|
|
|
|
2014-02-14 17:36:38 +01:00
|
|
|
/* It doesn't work for components bigger than 32 bits (or somewhat smaller but unaligned). */
|
|
|
|
static void format_to_vec4(const struct pixel_format_desc *format, const BYTE *src, struct vec4 *dst)
|
2012-03-08 20:27:12 +01:00
|
|
|
{
|
2014-02-14 17:36:38 +01:00
|
|
|
DWORD mask, tmp;
|
|
|
|
unsigned int c;
|
2012-03-08 20:27:12 +01:00
|
|
|
|
2014-02-14 17:36:38 +01:00
|
|
|
for (c = 0; c < 4; ++c)
|
2012-03-08 20:27:12 +01:00
|
|
|
{
|
2014-02-14 17:36:38 +01:00
|
|
|
static const unsigned int component_offsets[4] = {3, 0, 1, 2};
|
|
|
|
float *dst_component = (float *)dst + component_offsets[c];
|
2012-03-08 20:27:12 +01:00
|
|
|
|
2014-02-14 17:36:38 +01:00
|
|
|
if (format->bits[c])
|
|
|
|
{
|
|
|
|
mask = ~0u >> (32 - format->bits[c]);
|
2012-03-08 20:27:12 +01:00
|
|
|
|
2014-02-14 17:36:38 +01:00
|
|
|
memcpy(&tmp, src + format->shift[c] / 8,
|
|
|
|
min(sizeof(DWORD), (format->shift[c] % 8 + format->bits[c] + 7) / 8));
|
2012-03-08 20:27:12 +01:00
|
|
|
|
2014-02-14 17:36:38 +01:00
|
|
|
if (format->type == FORMAT_ARGBF16)
|
|
|
|
*dst_component = float_16_to_32(tmp);
|
|
|
|
else if (format->type == FORMAT_ARGBF)
|
|
|
|
*dst_component = *(float *)&tmp;
|
|
|
|
else
|
|
|
|
*dst_component = (float)((tmp >> format->shift[c] % 8) & mask) / mask;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*dst_component = 1.0f;
|
2012-03-08 20:27:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-14 17:36:38 +01:00
|
|
|
/* It doesn't work for components bigger than 32 bits. */
|
|
|
|
static void format_from_vec4(const struct pixel_format_desc *format, const struct vec4 *src, BYTE *dst)
|
2012-03-08 20:27:12 +01:00
|
|
|
{
|
2014-02-14 17:36:38 +01:00
|
|
|
DWORD v, mask32;
|
|
|
|
unsigned int c, i;
|
|
|
|
|
|
|
|
memset(dst, 0, format->bytes_per_pixel);
|
|
|
|
|
|
|
|
for (c = 0; c < 4; ++c)
|
|
|
|
{
|
|
|
|
static const unsigned int component_offsets[4] = {3, 0, 1, 2};
|
|
|
|
const float src_component = *((const float *)src + component_offsets[c]);
|
|
|
|
|
|
|
|
if (!format->bits[c])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
mask32 = ~0u >> (32 - format->bits[c]);
|
|
|
|
|
|
|
|
if (format->type == FORMAT_ARGBF16)
|
|
|
|
v = float_32_to_16(src_component);
|
|
|
|
else if (format->type == FORMAT_ARGBF)
|
|
|
|
v = *(DWORD *)&src_component;
|
|
|
|
else
|
|
|
|
v = (DWORD)(src_component * ((1 << format->bits[c]) - 1) + 0.5f);
|
|
|
|
|
|
|
|
for (i = format->shift[c] / 8 * 8; i < format->shift[c] + format->bits[c]; i += 8)
|
|
|
|
{
|
|
|
|
BYTE mask, byte;
|
|
|
|
|
|
|
|
if (format->shift[c] > i)
|
|
|
|
{
|
|
|
|
mask = mask32 << (format->shift[c] - i);
|
|
|
|
byte = (v << (format->shift[c] - i)) & mask;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mask = mask32 >> (i - format->shift[c]);
|
|
|
|
byte = (v >> (i - format->shift[c])) & mask;
|
|
|
|
}
|
|
|
|
dst[i / 8] |= byte;
|
|
|
|
}
|
|
|
|
}
|
2012-03-08 20:27:12 +01:00
|
|
|
}
|
|
|
|
|
2012-10-28 22:59:56 +01:00
|
|
|
/************************************************************
|
|
|
|
* copy_pixels
|
|
|
|
*
|
|
|
|
* Copies the source buffer to the destination buffer.
|
|
|
|
* Works for any pixel format.
|
|
|
|
* The source and the destination must be block-aligned.
|
|
|
|
*/
|
|
|
|
void copy_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch,
|
|
|
|
BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *size,
|
|
|
|
const struct pixel_format_desc *format)
|
|
|
|
{
|
|
|
|
UINT row, slice;
|
|
|
|
BYTE *dst_addr;
|
|
|
|
const BYTE *src_addr;
|
|
|
|
UINT row_block_count = (size->width + format->block_width - 1) / format->block_width;
|
|
|
|
UINT row_count = (size->height + format->block_height - 1) / format->block_height;
|
|
|
|
|
|
|
|
for (slice = 0; slice < size->depth; slice++)
|
|
|
|
{
|
|
|
|
src_addr = src + slice * src_slice_pitch;
|
|
|
|
dst_addr = dst + slice * dst_slice_pitch;
|
|
|
|
|
|
|
|
for (row = 0; row < row_count; row++)
|
|
|
|
{
|
|
|
|
memcpy(dst_addr, src_addr, row_block_count * format->block_byte_count);
|
|
|
|
src_addr += src_row_pitch;
|
|
|
|
dst_addr += dst_row_pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-28 21:33:14 +02:00
|
|
|
/************************************************************
|
2012-10-28 22:59:54 +01:00
|
|
|
* convert_argb_pixels
|
2010-07-28 21:33:14 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-10-28 22:59:54 +01:00
|
|
|
void convert_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, const struct volume *src_size,
|
2012-09-03 09:57:41 +02:00
|
|
|
const struct pixel_format_desc *src_format, BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch,
|
2013-05-19 22:32:18 +02:00
|
|
|
const struct volume *dst_size, const struct pixel_format_desc *dst_format, D3DCOLOR color_key,
|
|
|
|
const PALETTEENTRY *palette)
|
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;
|
2012-09-03 09:57:41 +02:00
|
|
|
const struct pixel_format_desc *ck_format = NULL;
|
2014-02-14 17:36:38 +01:00
|
|
|
DWORD channels[4];
|
2012-07-13 17:21:52 +02:00
|
|
|
UINT min_width, min_height, min_depth;
|
|
|
|
UINT x, y, z;
|
2010-07-28 21:33:14 +02:00
|
|
|
|
|
|
|
ZeroMemory(channels, sizeof(channels));
|
2012-07-13 17:21:52 +02:00
|
|
|
init_argb_conversion_info(src_format, dst_format, &conv_info);
|
2009-10-13 13:58:29 +02:00
|
|
|
|
2012-07-13 17:21:54 +02:00
|
|
|
min_width = min(src_size->width, dst_size->width);
|
|
|
|
min_height = min(src_size->height, dst_size->height);
|
|
|
|
min_depth = min(src_size->depth, dst_size->depth);
|
2009-10-13 13:58:29 +02:00
|
|
|
|
2012-07-13 17:21:52 +02:00
|
|
|
if (color_key)
|
2012-03-08 20:27:12 +01:00
|
|
|
{
|
|
|
|
/* Color keys are always represented in D3DFMT_A8R8G8B8 format. */
|
|
|
|
ck_format = get_format_info(D3DFMT_A8R8G8B8);
|
2012-07-13 17:21:52 +02:00
|
|
|
init_argb_conversion_info(src_format, ck_format, &ck_conv_info);
|
2010-11-11 22:13:06 +01:00
|
|
|
}
|
|
|
|
|
2012-07-13 17:21:52 +02:00
|
|
|
for (z = 0; z < min_depth; z++) {
|
|
|
|
const BYTE *src_slice_ptr = src + z * src_slice_pitch;
|
|
|
|
BYTE *dst_slice_ptr = dst + z * dst_slice_pitch;
|
2011-02-16 02:39:21 +01:00
|
|
|
|
2012-07-13 17:21:52 +02:00
|
|
|
for (y = 0; y < min_height; y++) {
|
|
|
|
const BYTE *src_ptr = src_slice_ptr + y * src_row_pitch;
|
|
|
|
BYTE *dst_ptr = dst_slice_ptr + y * dst_row_pitch;
|
2009-10-13 13:58:29 +02:00
|
|
|
|
2012-07-13 17:21:52 +02:00
|
|
|
for (x = 0; x < min_width; x++) {
|
2014-02-14 17:36:38 +01:00
|
|
|
if (!src_format->to_rgba && !dst_format->from_rgba
|
|
|
|
&& src_format->bytes_per_pixel <= 4 && dst_format->bytes_per_pixel <= 4)
|
2012-03-08 20:27:12 +01:00
|
|
|
{
|
2014-02-14 17:36:38 +01:00
|
|
|
DWORD val;
|
|
|
|
|
|
|
|
get_relevant_argb_components(&conv_info, *(DWORD *)src_ptr, channels);
|
2012-07-13 17:21:52 +02:00
|
|
|
val = make_argb_color(&conv_info, channels);
|
|
|
|
|
|
|
|
if (color_key)
|
|
|
|
{
|
2014-02-14 17:36:38 +01:00
|
|
|
DWORD ck_pixel;
|
|
|
|
|
|
|
|
get_relevant_argb_components(&ck_conv_info, *(DWORD *)src_ptr, channels);
|
|
|
|
ck_pixel = make_argb_color(&ck_conv_info, channels);
|
|
|
|
if (ck_pixel == color_key)
|
2012-07-13 17:21:52 +02:00
|
|
|
val &= ~conv_info.destmask[0];
|
|
|
|
}
|
2014-02-14 17:36:38 +01:00
|
|
|
memcpy(dst_ptr, &val, dst_format->bytes_per_pixel);
|
2012-03-08 20:27:12 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-13 17:21:52 +02:00
|
|
|
struct vec4 color, tmp;
|
|
|
|
|
2014-02-14 17:36:38 +01:00
|
|
|
format_to_vec4(src_format, src_ptr, &color);
|
2012-07-13 17:21:52 +02:00
|
|
|
if (src_format->to_rgba)
|
2013-05-19 22:32:18 +02:00
|
|
|
src_format->to_rgba(&color, &tmp, palette);
|
2012-07-13 17:21:52 +02:00
|
|
|
else
|
|
|
|
tmp = color;
|
|
|
|
|
|
|
|
if (ck_format)
|
|
|
|
{
|
2014-02-14 17:36:38 +01:00
|
|
|
DWORD ck_pixel;
|
|
|
|
|
|
|
|
format_from_vec4(ck_format, &tmp, (BYTE *)&ck_pixel);
|
|
|
|
if (ck_pixel == color_key)
|
2012-07-13 17:21:52 +02:00
|
|
|
tmp.w = 0.0f;
|
|
|
|
}
|
2012-03-08 20:27:12 +01:00
|
|
|
|
2012-07-13 17:21:52 +02:00
|
|
|
if (dst_format->from_rgba)
|
|
|
|
dst_format->from_rgba(&tmp, &color);
|
|
|
|
else
|
|
|
|
color = tmp;
|
2010-07-28 21:33:14 +02:00
|
|
|
|
2014-02-14 17:36:38 +01:00
|
|
|
format_from_vec4(dst_format, &color, dst_ptr);
|
2012-07-13 17:21:52 +02:00
|
|
|
}
|
|
|
|
|
2014-02-14 17:36:38 +01:00
|
|
|
src_ptr += src_format->bytes_per_pixel;
|
2012-07-13 17:21:52 +02:00
|
|
|
dst_ptr += dst_format->bytes_per_pixel;
|
2010-11-11 22:13:06 +01:00
|
|
|
}
|
|
|
|
|
2012-07-13 17:21:54 +02:00
|
|
|
if (src_size->width < dst_size->width) /* black out remaining pixels */
|
|
|
|
memset(dst_ptr, 0, dst_format->bytes_per_pixel * (dst_size->width - src_size->width));
|
2009-10-13 13:58:29 +02:00
|
|
|
}
|
2010-08-21 12:54:38 +02:00
|
|
|
|
2012-07-13 17:21:54 +02:00
|
|
|
if (src_size->height < dst_size->height) /* black out remaining pixels */
|
|
|
|
memset(dst + src_size->height * dst_row_pitch, 0, dst_row_pitch * (dst_size->height - src_size->height));
|
2009-10-13 13:58:29 +02:00
|
|
|
}
|
2012-07-13 17:21:54 +02:00
|
|
|
if (src_size->depth < dst_size->depth) /* black out remaining pixels */
|
|
|
|
memset(dst + src_size->depth * dst_slice_pitch, 0, dst_slice_pitch * (dst_size->depth - src_size->depth));
|
2009-10-13 13:58:29 +02:00
|
|
|
}
|
|
|
|
|
2010-07-28 21:56:00 +02:00
|
|
|
/************************************************************
|
2012-10-28 22:59:55 +01:00
|
|
|
* point_filter_argb_pixels
|
2010-07-28 21:56:00 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-10-28 22:59:55 +01:00
|
|
|
void point_filter_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, const struct volume *src_size,
|
2012-09-03 09:57:41 +02:00
|
|
|
const struct pixel_format_desc *src_format, BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch,
|
2013-05-19 22:32:18 +02:00
|
|
|
const struct volume *dst_size, const struct pixel_format_desc *dst_format, D3DCOLOR color_key,
|
|
|
|
const PALETTEENTRY *palette)
|
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;
|
2012-09-03 09:57:41 +02:00
|
|
|
const struct pixel_format_desc *ck_format = NULL;
|
2014-02-14 17:36:38 +01:00
|
|
|
DWORD channels[4];
|
2012-07-13 17:21:53 +02:00
|
|
|
UINT x, y, z;
|
2010-07-28 21:56:00 +02:00
|
|
|
|
|
|
|
ZeroMemory(channels, sizeof(channels));
|
2012-07-13 17:21:53 +02:00
|
|
|
init_argb_conversion_info(src_format, dst_format, &conv_info);
|
2010-07-28 21:56:00 +02:00
|
|
|
|
2012-07-13 17:21:53 +02:00
|
|
|
if (color_key)
|
2012-03-08 20:27:12 +01:00
|
|
|
{
|
|
|
|
/* Color keys are always represented in D3DFMT_A8R8G8B8 format. */
|
|
|
|
ck_format = get_format_info(D3DFMT_A8R8G8B8);
|
2012-07-13 17:21:53 +02:00
|
|
|
init_argb_conversion_info(src_format, ck_format, &ck_conv_info);
|
2010-11-11 22:13:06 +01:00
|
|
|
}
|
|
|
|
|
2012-07-13 17:21:54 +02:00
|
|
|
for (z = 0; z < dst_size->depth; z++)
|
2012-04-29 20:52:05 +02:00
|
|
|
{
|
2012-07-13 17:21:53 +02:00
|
|
|
BYTE *dst_slice_ptr = dst + z * dst_slice_pitch;
|
2012-07-13 17:21:54 +02:00
|
|
|
const BYTE *src_slice_ptr = src + src_slice_pitch * (z * src_size->depth / dst_size->depth);
|
2010-07-28 21:56:00 +02:00
|
|
|
|
2012-07-13 17:21:54 +02:00
|
|
|
for (y = 0; y < dst_size->height; y++)
|
2012-04-29 20:52:05 +02:00
|
|
|
{
|
2012-07-13 17:21:53 +02:00
|
|
|
BYTE *dst_ptr = dst_slice_ptr + y * dst_row_pitch;
|
2012-07-13 17:21:54 +02:00
|
|
|
const BYTE *src_row_ptr = src_slice_ptr + src_row_pitch * (y * src_size->height / dst_size->height);
|
2010-07-28 21:56:00 +02:00
|
|
|
|
2012-07-13 17:21:54 +02:00
|
|
|
for (x = 0; x < dst_size->width; x++)
|
2012-03-08 20:27:12 +01:00
|
|
|
{
|
2012-07-13 17:21:54 +02:00
|
|
|
const BYTE *src_ptr = src_row_ptr + (x * src_size->width / dst_size->width) * src_format->bytes_per_pixel;
|
2012-07-13 17:21:53 +02:00
|
|
|
|
2014-02-14 17:36:38 +01:00
|
|
|
if (!src_format->to_rgba && !dst_format->from_rgba
|
|
|
|
&& src_format->bytes_per_pixel <= 4 && dst_format->bytes_per_pixel <= 4)
|
2012-03-08 20:27:12 +01:00
|
|
|
{
|
2014-02-14 17:36:38 +01:00
|
|
|
DWORD val;
|
|
|
|
|
|
|
|
get_relevant_argb_components(&conv_info, *(DWORD *)src_ptr, channels);
|
2012-07-13 17:21:53 +02:00
|
|
|
val = make_argb_color(&conv_info, channels);
|
2012-03-08 20:27:12 +01:00
|
|
|
|
2012-07-13 17:21:53 +02:00
|
|
|
if (color_key)
|
|
|
|
{
|
2014-02-14 17:36:38 +01:00
|
|
|
DWORD ck_pixel;
|
|
|
|
|
|
|
|
get_relevant_argb_components(&ck_conv_info, *(DWORD *)src_ptr, channels);
|
|
|
|
ck_pixel = make_argb_color(&ck_conv_info, channels);
|
|
|
|
if (ck_pixel == color_key)
|
2012-07-13 17:21:53 +02:00
|
|
|
val &= ~conv_info.destmask[0];
|
|
|
|
}
|
2014-02-14 17:36:38 +01:00
|
|
|
memcpy(dst_ptr, &val, dst_format->bytes_per_pixel);
|
2012-07-13 17:21:53 +02:00
|
|
|
}
|
2012-03-08 20:27:12 +01:00
|
|
|
else
|
|
|
|
{
|
2012-07-13 17:21:53 +02:00
|
|
|
struct vec4 color, tmp;
|
2012-03-08 20:27:12 +01:00
|
|
|
|
2014-02-14 17:36:38 +01:00
|
|
|
format_to_vec4(src_format, src_ptr, &color);
|
2012-07-13 17:21:53 +02:00
|
|
|
if (src_format->to_rgba)
|
2013-05-19 22:32:18 +02:00
|
|
|
src_format->to_rgba(&color, &tmp, palette);
|
2012-07-13 17:21:53 +02:00
|
|
|
else
|
|
|
|
tmp = color;
|
2010-07-28 21:56:00 +02:00
|
|
|
|
2012-07-13 17:21:53 +02:00
|
|
|
if (ck_format)
|
|
|
|
{
|
2014-02-14 17:36:38 +01:00
|
|
|
DWORD ck_pixel;
|
|
|
|
|
|
|
|
format_from_vec4(ck_format, &tmp, (BYTE *)&ck_pixel);
|
|
|
|
if (ck_pixel == color_key)
|
2012-07-13 17:21:53 +02:00
|
|
|
tmp.w = 0.0f;
|
|
|
|
}
|
2010-11-11 22:13:06 +01:00
|
|
|
|
2012-07-13 17:21:53 +02:00
|
|
|
if (dst_format->from_rgba)
|
|
|
|
dst_format->from_rgba(&tmp, &color);
|
|
|
|
else
|
|
|
|
color = tmp;
|
|
|
|
|
2014-02-14 17:36:38 +01:00
|
|
|
format_from_vec4(dst_format, &color, dst_ptr);
|
2012-07-13 17:21:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
dst_ptr += dst_format->bytes_per_pixel;
|
|
|
|
}
|
2010-07-28 21:56:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*
|
|
|
|
*/
|
2012-04-30 21:30:20 +02:00
|
|
|
HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface,
|
|
|
|
const PALETTEENTRY *dst_palette, const RECT *dst_rect, const void *src_memory,
|
|
|
|
D3DFORMAT src_format, UINT src_pitch, const PALETTEENTRY *src_palette, const RECT *src_rect,
|
|
|
|
DWORD filter, D3DCOLOR color_key)
|
2009-06-22 17:45:27 +02:00
|
|
|
{
|
2012-09-03 09:57:41 +02:00
|
|
|
const struct pixel_format_desc *srcformatdesc, *destformatdesc;
|
2009-10-13 13:58:29 +02:00
|
|
|
D3DSURFACE_DESC surfdesc;
|
|
|
|
D3DLOCKED_RECT lockrect;
|
2012-07-13 17:21:54 +02:00
|
|
|
struct volume src_size, dst_size;
|
2010-04-05 20:28:07 +02:00
|
|
|
|
2012-04-30 21:30:20 +02:00
|
|
|
TRACE("(%p, %p, %s, %p, %#x, %u, %p, %s %#x, 0x%08x)\n",
|
|
|
|
dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), src_memory, src_format,
|
|
|
|
src_pitch, src_palette, wine_dbgstr_rect(src_rect), filter, color_key);
|
2009-06-22 17:45:27 +02:00
|
|
|
|
2012-04-30 21:30:20 +02:00
|
|
|
if (!dst_surface || !src_memory || !src_rect)
|
2012-08-28 17:04:53 +02:00
|
|
|
{
|
|
|
|
WARN("Invalid argument specified.\n");
|
2012-04-30 21:30:20 +02:00
|
|
|
return D3DERR_INVALIDCALL;
|
2012-08-28 17:04:53 +02:00
|
|
|
}
|
2012-04-30 21:30:20 +02:00
|
|
|
if (src_format == D3DFMT_UNKNOWN
|
|
|
|
|| src_rect->left >= src_rect->right
|
|
|
|
|| src_rect->top >= src_rect->bottom)
|
2012-08-28 17:04:53 +02:00
|
|
|
{
|
|
|
|
WARN("Invalid src_format or src_rect.\n");
|
2012-04-30 21:30:20 +02:00
|
|
|
return E_FAIL;
|
2012-08-28 17:04:53 +02:00
|
|
|
}
|
2009-10-13 13:58:29 +02:00
|
|
|
|
2012-04-30 21:30:20 +02:00
|
|
|
if (filter == D3DX_DEFAULT)
|
|
|
|
filter = D3DX_FILTER_TRIANGLE | D3DX_FILTER_DITHER;
|
2009-10-13 13:58:29 +02:00
|
|
|
|
2012-04-30 21:30:20 +02:00
|
|
|
IDirect3DSurface9_GetDesc(dst_surface, &surfdesc);
|
2009-10-13 13:58:29 +02:00
|
|
|
|
2012-07-13 17:21:54 +02:00
|
|
|
src_size.width = src_rect->right - src_rect->left;
|
|
|
|
src_size.height = src_rect->bottom - src_rect->top;
|
|
|
|
src_size.depth = 1;
|
2012-04-30 21:30:20 +02:00
|
|
|
if (!dst_rect)
|
2012-04-29 20:52:05 +02:00
|
|
|
{
|
2012-07-13 17:21:54 +02:00
|
|
|
dst_size.width = surfdesc.Width;
|
|
|
|
dst_size.height = surfdesc.Height;
|
2012-04-29 20:52:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-08-28 17:04:53 +02:00
|
|
|
if (dst_rect->left > dst_rect->right || dst_rect->right > surfdesc.Width
|
|
|
|
|| dst_rect->top > dst_rect->bottom || dst_rect->bottom > surfdesc.Height
|
|
|
|
|| dst_rect->left < 0 || dst_rect->top < 0)
|
|
|
|
{
|
|
|
|
WARN("Invalid dst_rect specified.\n");
|
2012-04-30 21:30:20 +02:00
|
|
|
return D3DERR_INVALIDCALL;
|
2012-08-28 17:04:53 +02:00
|
|
|
}
|
2012-07-13 17:21:54 +02:00
|
|
|
dst_size.width = dst_rect->right - dst_rect->left;
|
|
|
|
dst_size.height = dst_rect->bottom - dst_rect->top;
|
|
|
|
if (!dst_size.width || !dst_size.height)
|
2012-04-29 20:52:05 +02:00
|
|
|
return D3D_OK;
|
2009-10-13 13:58:29 +02:00
|
|
|
}
|
2012-07-13 17:21:54 +02:00
|
|
|
dst_size.depth = 1;
|
2009-10-13 13:58:29 +02:00
|
|
|
|
2012-04-30 21:30:20 +02:00
|
|
|
srcformatdesc = get_format_info(src_format);
|
2012-04-26 21:11:54 +02:00
|
|
|
destformatdesc = get_format_info(surfdesc.Format);
|
2012-08-28 17:04:53 +02:00
|
|
|
if (srcformatdesc->type == FORMAT_UNKNOWN || destformatdesc->type == FORMAT_UNKNOWN)
|
|
|
|
{
|
|
|
|
FIXME("Unsupported pixel format conversion %#x -> %#x\n", src_format, surfdesc.Format);
|
2012-04-26 21:11:54 +02:00
|
|
|
return E_NOTIMPL;
|
2012-08-28 17:04:53 +02:00
|
|
|
}
|
2012-04-26 21:11:54 +02:00
|
|
|
|
2012-04-30 21:30:20 +02:00
|
|
|
if (src_format == surfdesc.Format
|
2012-07-13 17:21:54 +02:00
|
|
|
&& dst_size.width == src_size.width
|
2012-10-28 22:59:57 +01:00
|
|
|
&& dst_size.height == src_size.height
|
|
|
|
&& color_key == 0) /* Simple copy. */
|
2012-04-26 21:11:54 +02:00
|
|
|
{
|
2012-04-30 21:30:20 +02:00
|
|
|
if (src_rect->left & (srcformatdesc->block_width - 1)
|
|
|
|
|| src_rect->top & (srcformatdesc->block_height - 1)
|
|
|
|
|| (src_rect->right & (srcformatdesc->block_width - 1)
|
2012-07-13 17:21:54 +02:00
|
|
|
&& src_size.width != surfdesc.Width)
|
2012-04-30 21:30:20 +02:00
|
|
|
|| (src_rect->bottom & (srcformatdesc->block_height - 1)
|
2012-07-13 17:21:54 +02:00
|
|
|
&& src_size.height != surfdesc.Height))
|
2012-04-26 21:11:55 +02:00
|
|
|
{
|
2012-04-30 21:30:20 +02:00
|
|
|
WARN("Source rect %s is misaligned.\n", wine_dbgstr_rect(src_rect));
|
2012-04-26 21:11:55 +02:00
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
}
|
2012-04-26 21:11:54 +02:00
|
|
|
|
2012-10-28 22:59:56 +01:00
|
|
|
if (FAILED(IDirect3DSurface9_LockRect(dst_surface, &lockrect, dst_rect, 0)))
|
2012-04-26 21:11:54 +02:00
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
|
2012-10-28 22:59:56 +01:00
|
|
|
copy_pixels(src_memory, src_pitch, 0, lockrect.pBits, lockrect.Pitch, 0,
|
|
|
|
&src_size, srcformatdesc);
|
2012-04-26 21:11:54 +02:00
|
|
|
|
2012-04-30 21:30:20 +02:00
|
|
|
IDirect3DSurface9_UnlockRect(dst_surface);
|
2012-04-26 21:11:54 +02:00
|
|
|
}
|
|
|
|
else /* Stretching or format conversion. */
|
|
|
|
{
|
2013-05-19 22:32:18 +02:00
|
|
|
if (((srcformatdesc->type != FORMAT_ARGB) && (srcformatdesc->type != FORMAT_INDEX)) ||
|
|
|
|
(destformatdesc->type != FORMAT_ARGB))
|
2012-08-28 17:04:53 +02:00
|
|
|
{
|
|
|
|
FIXME("Format conversion missing %#x -> %#x\n", src_format, surfdesc.Format);
|
2012-04-26 21:11:55 +02:00
|
|
|
return E_NOTIMPL;
|
2012-08-28 17:04:53 +02:00
|
|
|
}
|
2012-04-26 21:11:54 +02:00
|
|
|
|
2012-10-22 17:20:27 +02:00
|
|
|
if (FAILED(IDirect3DSurface9_LockRect(dst_surface, &lockrect, dst_rect, 0)))
|
2012-04-26 21:11:54 +02:00
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
|
2012-04-30 21:30:20 +02:00
|
|
|
if ((filter & 0xf) == D3DX_FILTER_NONE)
|
2012-04-26 21:11:54 +02:00
|
|
|
{
|
2012-10-28 22:59:54 +01:00
|
|
|
convert_argb_pixels(src_memory, src_pitch, 0, &src_size, srcformatdesc,
|
2013-05-19 22:32:18 +02:00
|
|
|
lockrect.pBits, lockrect.Pitch, 0, &dst_size, destformatdesc, color_key, src_palette);
|
2012-04-26 21:11:54 +02:00
|
|
|
}
|
2012-04-30 21:30:20 +02:00
|
|
|
else /* if ((filter & 0xf) == D3DX_FILTER_POINT) */
|
2012-04-26 21:11:54 +02:00
|
|
|
{
|
2012-04-30 21:30:20 +02:00
|
|
|
if ((filter & 0xf) != D3DX_FILTER_POINT)
|
|
|
|
FIXME("Unhandled filter %#x.\n", filter);
|
2012-04-29 20:52:06 +02:00
|
|
|
|
2012-04-26 21:11:54 +02:00
|
|
|
/* Always apply a point filter until D3DX_FILTER_LINEAR,
|
|
|
|
* D3DX_FILTER_TRIANGLE and D3DX_FILTER_BOX are implemented. */
|
2012-10-28 22:59:55 +01:00
|
|
|
point_filter_argb_pixels(src_memory, src_pitch, 0, &src_size, srcformatdesc,
|
2013-05-19 22:32:18 +02:00
|
|
|
lockrect.pBits, lockrect.Pitch, 0, &dst_size, destformatdesc, color_key, src_palette);
|
2012-04-26 21:11:54 +02:00
|
|
|
}
|
2009-10-13 13:58:29 +02:00
|
|
|
|
2012-04-30 21:30:20 +02:00
|
|
|
IDirect3DSurface9_UnlockRect(dst_surface);
|
2010-07-28 21:56:00 +02:00
|
|
|
}
|
2009-10-13 13:58:29 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
*/
|
2012-06-01 17:22:50 +02:00
|
|
|
HRESULT WINAPI D3DXLoadSurfaceFromSurface(IDirect3DSurface9 *dst_surface,
|
|
|
|
const PALETTEENTRY *dst_palette, const RECT *dst_rect, IDirect3DSurface9 *src_surface,
|
|
|
|
const PALETTEENTRY *src_palette, const RECT *src_rect, DWORD filter, D3DCOLOR color_key)
|
2009-06-22 17:57:20 +02:00
|
|
|
{
|
|
|
|
RECT rect;
|
|
|
|
D3DLOCKED_RECT lock;
|
|
|
|
D3DSURFACE_DESC SrcDesc;
|
|
|
|
HRESULT hr;
|
2010-04-05 20:28:07 +02:00
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_surface %p, "
|
|
|
|
"src_palette %p, src_rect %s, filter %#x, color_key 0x%08x.\n",
|
|
|
|
dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), src_surface,
|
|
|
|
src_palette, wine_dbgstr_rect(src_rect), filter, color_key);
|
2009-06-22 17:57:20 +02:00
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
if (!dst_surface || !src_surface)
|
|
|
|
return D3DERR_INVALIDCALL;
|
2009-06-22 17:57:20 +02:00
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
IDirect3DSurface9_GetDesc(src_surface, &SrcDesc);
|
2009-06-22 17:57:20 +02:00
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
if (!src_rect)
|
|
|
|
SetRect(&rect, 0, 0, SrcDesc.Width, SrcDesc.Height);
|
|
|
|
else
|
|
|
|
rect = *src_rect;
|
2009-06-22 17:57:20 +02:00
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
if (FAILED(IDirect3DSurface9_LockRect(src_surface, &lock, NULL, D3DLOCK_READONLY)))
|
|
|
|
return D3DXERR_INVALIDDATA;
|
|
|
|
|
|
|
|
hr = D3DXLoadSurfaceFromMemory(dst_surface, dst_palette, dst_rect,
|
|
|
|
lock.pBits, SrcDesc.Format, lock.Pitch, src_palette, &rect, filter, color_key);
|
2009-06-22 17:57:20 +02:00
|
|
|
|
2012-06-01 17:22:50 +02:00
|
|
|
IDirect3DSurface9_UnlockRect(src_surface);
|
2009-06-22 17:57:20 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
2011-06-24 03:55:15 +02:00
|
|
|
|
|
|
|
|
2012-05-04 13:01:20 +02:00
|
|
|
HRESULT WINAPI D3DXSaveSurfaceToFileA(const char *dst_filename, D3DXIMAGE_FILEFORMAT file_format,
|
|
|
|
IDirect3DSurface9 *src_surface, const PALETTEENTRY *src_palette, const RECT *src_rect)
|
2011-06-24 03:55:15 +02:00
|
|
|
{
|
2012-05-04 13:01:20 +02:00
|
|
|
int len;
|
|
|
|
WCHAR *filename;
|
|
|
|
HRESULT hr;
|
2012-05-29 11:29:22 +02:00
|
|
|
ID3DXBuffer *buffer;
|
2012-05-04 13:01:20 +02:00
|
|
|
|
|
|
|
TRACE("(%s, %#x, %p, %p, %s): relay\n",
|
|
|
|
wine_dbgstr_a(dst_filename), file_format, src_surface, src_palette, wine_dbgstr_rect(src_rect));
|
|
|
|
|
|
|
|
if (!dst_filename) return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, dst_filename, -1, NULL, 0);
|
|
|
|
filename = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
if (!filename) return E_OUTOFMEMORY;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, dst_filename, -1, filename, len);
|
|
|
|
|
2012-05-29 11:29:22 +02:00
|
|
|
hr = D3DXSaveSurfaceToFileInMemory(&buffer, file_format, src_surface, src_palette, src_rect);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = write_buffer_to_file(filename, buffer);
|
|
|
|
ID3DXBuffer_Release(buffer);
|
|
|
|
}
|
2012-05-04 13:01:20 +02:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, filename);
|
|
|
|
return hr;
|
2011-06-24 03:55:15 +02:00
|
|
|
}
|
|
|
|
|
2012-05-04 13:01:21 +02:00
|
|
|
HRESULT WINAPI D3DXSaveSurfaceToFileW(const WCHAR *dst_filename, D3DXIMAGE_FILEFORMAT file_format,
|
|
|
|
IDirect3DSurface9 *src_surface, const PALETTEENTRY *src_palette, const RECT *src_rect)
|
2011-06-24 03:55:15 +02:00
|
|
|
{
|
2012-05-29 11:29:22 +02:00
|
|
|
HRESULT hr;
|
|
|
|
ID3DXBuffer *buffer;
|
|
|
|
|
|
|
|
TRACE("(%s, %#x, %p, %p, %s): relay\n",
|
|
|
|
wine_dbgstr_w(dst_filename), file_format, src_surface, src_palette, wine_dbgstr_rect(src_rect));
|
|
|
|
|
|
|
|
if (!dst_filename) return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
hr = D3DXSaveSurfaceToFileInMemory(&buffer, file_format, src_surface, src_palette, src_rect);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = write_buffer_to_file(dst_filename, buffer);
|
|
|
|
ID3DXBuffer_Release(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI D3DXSaveSurfaceToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE_FILEFORMAT file_format,
|
|
|
|
IDirect3DSurface9 *src_surface, const PALETTEENTRY *src_palette, const RECT *src_rect)
|
|
|
|
{
|
2012-05-04 13:01:21 +02:00
|
|
|
IWICBitmapEncoder *encoder = NULL;
|
|
|
|
IWICBitmapFrameEncode *frame = NULL;
|
|
|
|
IPropertyBag2 *encoder_options = NULL;
|
2012-05-29 11:29:22 +02:00
|
|
|
IStream *stream = NULL;
|
2012-05-04 13:01:21 +02:00
|
|
|
HRESULT hr;
|
|
|
|
HRESULT initresult;
|
|
|
|
const CLSID *encoder_clsid;
|
|
|
|
const GUID *pixel_format_guid;
|
|
|
|
WICPixelFormatGUID wic_pixel_format;
|
|
|
|
D3DFORMAT d3d_pixel_format;
|
|
|
|
D3DSURFACE_DESC src_surface_desc;
|
|
|
|
D3DLOCKED_RECT locked_rect;
|
|
|
|
int width, height;
|
2012-05-29 11:29:22 +02:00
|
|
|
STATSTG stream_stats;
|
|
|
|
HGLOBAL stream_hglobal;
|
|
|
|
ID3DXBuffer *buffer;
|
|
|
|
DWORD size;
|
2012-05-04 13:01:21 +02:00
|
|
|
|
2012-05-29 11:29:22 +02:00
|
|
|
TRACE("(%p, %#x, %p, %p, %s)\n",
|
|
|
|
dst_buffer, file_format, src_surface, src_palette, wine_dbgstr_rect(src_rect));
|
2012-05-04 13:01:21 +02:00
|
|
|
|
2012-05-29 11:29:22 +02:00
|
|
|
if (!dst_buffer || !src_surface) return D3DERR_INVALIDCALL;
|
2012-05-04 13:01:21 +02:00
|
|
|
|
|
|
|
if (src_palette)
|
|
|
|
{
|
|
|
|
FIXME("Saving surfaces with palettized pixel formats not implemented yet\n");
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (file_format)
|
|
|
|
{
|
|
|
|
case D3DXIFF_BMP:
|
2013-04-22 23:08:18 +02:00
|
|
|
case D3DXIFF_DIB:
|
2012-05-04 13:01:21 +02:00
|
|
|
encoder_clsid = &CLSID_WICBmpEncoder;
|
|
|
|
break;
|
|
|
|
case D3DXIFF_PNG:
|
|
|
|
encoder_clsid = &CLSID_WICPngEncoder;
|
|
|
|
break;
|
|
|
|
case D3DXIFF_JPG:
|
|
|
|
encoder_clsid = &CLSID_WICJpegEncoder;
|
|
|
|
break;
|
|
|
|
case D3DXIFF_DDS:
|
2012-09-24 13:46:38 +02:00
|
|
|
return save_dds_surface_to_memory(dst_buffer, src_surface, src_rect);
|
2012-05-04 13:01:21 +02:00
|
|
|
case D3DXIFF_HDR:
|
|
|
|
case D3DXIFF_PFM:
|
|
|
|
case D3DXIFF_TGA:
|
|
|
|
case D3DXIFF_PPM:
|
|
|
|
FIXME("File format %#x is not supported yet\n", file_format);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
default:
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDirect3DSurface9_GetDesc(src_surface, &src_surface_desc);
|
|
|
|
if (src_rect)
|
|
|
|
{
|
|
|
|
if (src_rect->left == src_rect->right || src_rect->top == src_rect->bottom)
|
2012-05-29 11:29:22 +02:00
|
|
|
{
|
|
|
|
WARN("Invalid rectangle with 0 area\n");
|
|
|
|
return D3DXCreateBuffer(64, dst_buffer);
|
|
|
|
}
|
2012-05-04 13:01:21 +02:00
|
|
|
if (src_rect->left < 0 || src_rect->top < 0)
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
if (src_rect->left > src_rect->right || src_rect->top > src_rect->bottom)
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
if (src_rect->right > src_surface_desc.Width || src_rect->bottom > src_surface_desc.Height)
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
width = src_rect->right - src_rect->left;
|
|
|
|
height = src_rect->bottom - src_rect->top;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = src_surface_desc.Width;
|
|
|
|
height = src_surface_desc.Height;
|
|
|
|
}
|
|
|
|
|
|
|
|
initresult = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
|
|
|
|
|
|
hr = CoCreateInstance(encoder_clsid, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IWICBitmapEncoder, (void **)&encoder);
|
|
|
|
if (FAILED(hr)) goto cleanup_err;
|
|
|
|
|
2012-05-29 11:29:22 +02:00
|
|
|
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
|
|
|
|
if (FAILED(hr)) goto cleanup_err;
|
|
|
|
|
|
|
|
hr = IWICBitmapEncoder_Initialize(encoder, stream, WICBitmapEncoderNoCache);
|
2012-05-04 13:01:21 +02:00
|
|
|
if (FAILED(hr)) goto cleanup_err;
|
|
|
|
|
|
|
|
hr = IWICBitmapEncoder_CreateNewFrame(encoder, &frame, &encoder_options);
|
|
|
|
if (FAILED(hr)) goto cleanup_err;
|
|
|
|
|
|
|
|
hr = IWICBitmapFrameEncode_Initialize(frame, encoder_options);
|
|
|
|
if (FAILED(hr)) goto cleanup_err;
|
|
|
|
|
|
|
|
hr = IWICBitmapFrameEncode_SetSize(frame, width, height);
|
|
|
|
if (FAILED(hr)) goto cleanup_err;
|
|
|
|
|
|
|
|
pixel_format_guid = d3dformat_to_wic_guid(src_surface_desc.Format);
|
|
|
|
if (!pixel_format_guid)
|
|
|
|
{
|
|
|
|
FIXME("Pixel format %#x is not supported yet\n", src_surface_desc.Format);
|
|
|
|
hr = E_NOTIMPL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&wic_pixel_format, pixel_format_guid, sizeof(GUID));
|
|
|
|
hr = IWICBitmapFrameEncode_SetPixelFormat(frame, &wic_pixel_format);
|
|
|
|
d3d_pixel_format = wic_guid_to_d3dformat(&wic_pixel_format);
|
|
|
|
if (SUCCEEDED(hr) && d3d_pixel_format != D3DFMT_UNKNOWN)
|
|
|
|
{
|
|
|
|
TRACE("Using pixel format %s %#x\n", debugstr_guid(&wic_pixel_format), d3d_pixel_format);
|
|
|
|
|
|
|
|
if (src_surface_desc.Format == d3d_pixel_format) /* Simple copy */
|
|
|
|
{
|
|
|
|
hr = IDirect3DSurface9_LockRect(src_surface, &locked_rect, src_rect, D3DLOCK_READONLY);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
IWICBitmapFrameEncode_WritePixels(frame, height,
|
|
|
|
locked_rect.Pitch, height * locked_rect.Pitch, locked_rect.pBits);
|
|
|
|
IDirect3DSurface9_UnlockRect(src_surface);
|
|
|
|
}
|
|
|
|
}
|
2012-05-04 13:01:22 +02:00
|
|
|
else /* Pixel format conversion */
|
|
|
|
{
|
2012-09-03 09:57:41 +02:00
|
|
|
const struct pixel_format_desc *src_format_desc, *dst_format_desc;
|
2012-07-13 17:21:54 +02:00
|
|
|
struct volume size;
|
2012-05-04 13:01:22 +02:00
|
|
|
DWORD dst_pitch;
|
|
|
|
void *dst_data;
|
|
|
|
|
|
|
|
src_format_desc = get_format_info(src_surface_desc.Format);
|
|
|
|
dst_format_desc = get_format_info(d3d_pixel_format);
|
2012-10-22 17:20:27 +02:00
|
|
|
if (src_format_desc->type != FORMAT_ARGB || dst_format_desc->type != FORMAT_ARGB)
|
2012-05-04 13:01:22 +02:00
|
|
|
{
|
|
|
|
FIXME("Unsupported pixel format conversion %#x -> %#x\n",
|
2012-05-11 13:18:43 +02:00
|
|
|
src_surface_desc.Format, d3d_pixel_format);
|
2012-05-04 13:01:22 +02:00
|
|
|
hr = E_NOTIMPL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-07-13 17:21:54 +02:00
|
|
|
size.width = width;
|
|
|
|
size.height = height;
|
|
|
|
size.depth = 1;
|
2012-05-04 13:01:22 +02:00
|
|
|
dst_pitch = width * dst_format_desc->bytes_per_pixel;
|
|
|
|
dst_data = HeapAlloc(GetProcessHeap(), 0, dst_pitch * height);
|
|
|
|
if (!dst_data)
|
|
|
|
{
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IDirect3DSurface9_LockRect(src_surface, &locked_rect, src_rect, D3DLOCK_READONLY);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2012-10-28 22:59:54 +01:00
|
|
|
convert_argb_pixels(locked_rect.pBits, locked_rect.Pitch, 0, &size, src_format_desc,
|
2013-05-19 22:32:18 +02:00
|
|
|
dst_data, dst_pitch, 0, &size, dst_format_desc, 0, NULL);
|
2012-05-04 13:01:22 +02:00
|
|
|
IDirect3DSurface9_UnlockRect(src_surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
IWICBitmapFrameEncode_WritePixels(frame, height, dst_pitch, dst_pitch * height, dst_data);
|
|
|
|
HeapFree(GetProcessHeap(), 0, dst_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IWICBitmapFrameEncode_Commit(frame);
|
|
|
|
if (SUCCEEDED(hr)) hr = IWICBitmapEncoder_Commit(encoder);
|
2012-05-04 13:01:21 +02:00
|
|
|
}
|
|
|
|
else WARN("Unsupported pixel format %#x\n", src_surface_desc.Format);
|
|
|
|
|
2012-05-29 11:29:22 +02:00
|
|
|
/* copy data from stream to ID3DXBuffer */
|
|
|
|
hr = IStream_Stat(stream, &stream_stats, STATFLAG_NONAME);
|
|
|
|
if (FAILED(hr)) goto cleanup_err;
|
|
|
|
|
|
|
|
if (stream_stats.cbSize.u.HighPart != 0)
|
|
|
|
{
|
|
|
|
hr = D3DXERR_INVALIDDATA;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
size = stream_stats.cbSize.u.LowPart;
|
|
|
|
|
2013-04-22 23:08:18 +02:00
|
|
|
/* Remove BMP header for DIB */
|
|
|
|
if (file_format == D3DXIFF_DIB)
|
|
|
|
size -= sizeof(BITMAPFILEHEADER);
|
|
|
|
|
2012-05-29 11:29:22 +02:00
|
|
|
hr = D3DXCreateBuffer(size, &buffer);
|
|
|
|
if (FAILED(hr)) goto cleanup;
|
|
|
|
|
|
|
|
hr = GetHGlobalFromStream(stream, &stream_hglobal);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
void *buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
|
|
|
|
void *stream_data = GlobalLock(stream_hglobal);
|
2013-04-22 23:08:18 +02:00
|
|
|
/* Remove BMP header for DIB */
|
|
|
|
if (file_format == D3DXIFF_DIB)
|
|
|
|
stream_data = (void*)((BYTE*)stream_data + sizeof(BITMAPFILEHEADER));
|
2012-05-29 11:29:22 +02:00
|
|
|
memcpy(buffer_pointer, stream_data, size);
|
|
|
|
GlobalUnlock(stream_hglobal);
|
|
|
|
*dst_buffer = buffer;
|
|
|
|
}
|
|
|
|
else ID3DXBuffer_Release(buffer);
|
|
|
|
|
2012-05-04 13:01:21 +02:00
|
|
|
cleanup_err:
|
2012-05-29 11:29:22 +02:00
|
|
|
if (FAILED(hr) && hr != E_OUTOFMEMORY)
|
|
|
|
hr = D3DERR_INVALIDCALL;
|
2012-05-04 13:01:21 +02:00
|
|
|
|
|
|
|
cleanup:
|
2012-05-29 11:29:22 +02:00
|
|
|
if (stream) IStream_Release(stream);
|
2012-05-04 13:01:21 +02:00
|
|
|
|
|
|
|
if (frame) IWICBitmapFrameEncode_Release(frame);
|
|
|
|
if (encoder_options) IPropertyBag2_Release(encoder_options);
|
|
|
|
|
|
|
|
if (encoder) IWICBitmapEncoder_Release(encoder);
|
|
|
|
|
|
|
|
if (SUCCEEDED(initresult)) CoUninitialize();
|
|
|
|
|
|
|
|
return hr;
|
2011-06-24 03:55:15 +02:00
|
|
|
}
|