ReactOS  r76032
surface.c File Reference
#include "d3dx9_36_private.h"
#include <ole2.h>
#include <wine/wined3d.h>
#include <initguid.h>
#include <wincodec.h>
Include dependency graph for surface.c:

Go to the source code of this file.

Classes

struct  dds_pixel_format
 
struct  dds_header
 
struct  argb_conversion_info
 

Macros

#define DDS_CAPS   0x1
 
#define DDS_HEIGHT   0x2
 
#define DDS_WIDTH   0x4
 
#define DDS_PITCH   0x8
 
#define DDS_PIXELFORMAT   0x1000
 
#define DDS_MIPMAPCOUNT   0x20000
 
#define DDS_LINEARSIZE   0x80000
 
#define DDS_DEPTH   0x800000
 
#define DDS_CAPS_COMPLEX   0x8
 
#define DDS_CAPS_TEXTURE   0x1000
 
#define DDS_CAPS_MIPMAP   0x400000
 
#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
 
#define DDS_CAPS2_CUBEMAP_ALL_FACES
 
#define DDS_CAPS2_VOLUME   0x200000
 
#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
 
#define DDS_PF_BUMPDUDV   0x80000
 

Typedefs

typedef BOOL(* dxtn_conversion_func )(const BYTE *src, BYTE *dst, DWORD pitch_in, DWORD pitch_out, enum wined3d_format_id format, unsigned int w, unsigned int h)
 

Functions

 DEFINE_GUID (GUID_WineContainerFormatTga, 0x0c44fda1, 0xa5c5, 0x4298, 0x96, 0x85, 0x47, 0x3f, 0xc1, 0x7c, 0xd3, 0x22)
 
static D3DFORMAT wic_guid_to_d3dformat (const GUID *guid)
 
static const GUIDd3dformat_to_wic_guid (D3DFORMAT format)
 
static D3DFORMAT dds_fourcc_to_d3dformat (DWORD fourcc)
 
static D3DFORMAT dds_rgb_to_d3dformat (const struct dds_pixel_format *pixel_format)
 
static D3DFORMAT dds_luminance_to_d3dformat (const struct dds_pixel_format *pixel_format)
 
static D3DFORMAT dds_alpha_to_d3dformat (const struct dds_pixel_format *pixel_format)
 
static D3DFORMAT dds_bump_to_d3dformat (const struct dds_pixel_format *pixel_format)
 
static D3DFORMAT dds_pixel_format_to_d3dformat (const struct dds_pixel_format *pixel_format)
 
static HRESULT d3dformat_to_dds_pixel_format (struct dds_pixel_format *pixel_format, D3DFORMAT d3dformat)
 
static HRESULT calculate_dds_surface_size (D3DFORMAT format, UINT width, UINT height, UINT *pitch, UINT *size)
 
static UINT calculate_dds_file_size (D3DFORMAT format, UINT width, UINT height, UINT depth, UINT miplevels, UINT faces)
 
static HRESULT get_image_info_from_dds (const void *buffer, UINT length, D3DXIMAGE_INFO *info)
 
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)
 
static HRESULT save_dds_surface_to_memory (ID3DXBuffer **dst_buffer, IDirect3DSurface9 *src_surface, const RECT *src_rect)
 
static HRESULT get_surface (D3DRESOURCETYPE type, struct IDirect3DBaseTexture9 *tex, int face, UINT level, struct IDirect3DSurface9 **surf)
 
HRESULT save_dds_texture_to_memory (ID3DXBuffer **dst_buffer, IDirect3DBaseTexture9 *src_texture, const PALETTEENTRY *src_palette)
 
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)
 
HRESULT load_texture_from_dds (IDirect3DTexture9 *texture, const void *src_data, const PALETTEENTRY *palette, DWORD filter, D3DCOLOR color_key, const D3DXIMAGE_INFO *src_info, unsigned int skip_levels, unsigned int *loaded_miplevels)
 
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 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)
 
static BOOL convert_dib_to_bmp (void **data, UINT *size)
 
HRESULT WINAPI D3DXGetImageInfoFromFileInMemory (const void *data, UINT datasize, D3DXIMAGE_INFO *info)
 
HRESULT WINAPI D3DXGetImageInfoFromFileA (const char *file, D3DXIMAGE_INFO *info)
 
HRESULT WINAPI D3DXGetImageInfoFromFileW (const WCHAR *file, D3DXIMAGE_INFO *info)
 
HRESULT WINAPI D3DXGetImageInfoFromResourceA (HMODULE module, const char *resource, D3DXIMAGE_INFO *info)
 
HRESULT WINAPI D3DXGetImageInfoFromResourceW (HMODULE module, const WCHAR *resource, D3DXIMAGE_INFO *info)
 
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)
 
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)
 
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)
 
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)
 
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)
 
static void init_argb_conversion_info (const struct pixel_format_desc *srcformat, const struct pixel_format_desc *destformat, struct argb_conversion_info *info)
 
static void get_relevant_argb_components (const struct argb_conversion_info *info, const BYTE *col, DWORD *out)
 
static DWORD make_argb_color (const struct argb_conversion_info *info, const DWORD *in)
 
static void format_to_vec4 (const struct pixel_format_desc *format, const BYTE *src, struct vec4 *dst)
 
static void format_from_vec4 (const struct pixel_format_desc *format, const struct vec4 *src, BYTE *dst)
 
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)
 
void convert_argb_pixels (const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, const struct volume *src_size, const struct pixel_format_desc *src_format, BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *dst_size, const struct pixel_format_desc *dst_format, D3DCOLOR color_key, const PALETTEENTRY *palette)
 
void point_filter_argb_pixels (const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, const struct volume *src_size, const struct pixel_format_desc *src_format, BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *dst_size, const struct pixel_format_desc *dst_format, D3DCOLOR color_key, const PALETTEENTRY *palette)
 
static dxtn_conversion_func get_dxtn_conversion_func (D3DFORMAT format, BOOL encode)
 
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)
 
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)
 
HRESULT WINAPI D3DXSaveSurfaceToFileA (const char *dst_filename, D3DXIMAGE_FILEFORMAT file_format, IDirect3DSurface9 *src_surface, const PALETTEENTRY *src_palette, const RECT *src_rect)
 
HRESULT WINAPI D3DXSaveSurfaceToFileW (const WCHAR *dst_filename, D3DXIMAGE_FILEFORMAT file_format, IDirect3DSurface9 *src_surface, const PALETTEENTRY *src_palette, const RECT *src_rect)
 
HRESULT WINAPI D3DXSaveSurfaceToFileInMemory (ID3DXBuffer **dst_buffer, D3DXIMAGE_FILEFORMAT file_format, IDirect3DSurface9 *src_surface, const PALETTEENTRY *src_palette, const RECT *src_rect)
 

Variables

struct {
   const GUID *   wic_guid
 
   D3DFORMAT   d3dformat
 
wic_pixel_formats []
 
struct {
   DWORD   bpp
 
   DWORD   rmask
 
   DWORD   gmask
 
   DWORD   bmask
 
   DWORD   amask
 
   D3DFORMAT   format
 
rgb_pixel_formats []
 

Macro Definition Documentation

#define DDS_CAPS   0x1

Definition at line 75 of file surface.c.

Referenced by save_dds_surface_to_memory().

#define DDS_CAPS2_CUBEMAP   0x200

Definition at line 90 of file surface.c.

Referenced by get_image_info_from_dds().

#define DDS_CAPS2_CUBEMAP_ALL_FACES
Value:
#define DDS_CAPS2_CUBEMAP_NEGATIVEX
Definition: surface.c:92
#define DDS_CAPS2_CUBEMAP_POSITIVEY
Definition: surface.c:93
#define DDS_CAPS2_CUBEMAP_NEGATIVEZ
Definition: surface.c:96
#define DDS_CAPS2_CUBEMAP_NEGATIVEY
Definition: surface.c:94
#define DDS_CAPS2_CUBEMAP_POSITIVEX
Definition: surface.c:91
#define DDS_CAPS2_CUBEMAP_POSITIVEZ
Definition: surface.c:95

Definition at line 97 of file surface.c.

Referenced by load_cube_texture_from_dds().

#define DDS_CAPS2_CUBEMAP_NEGATIVEX   0x800

Definition at line 92 of file surface.c.

#define DDS_CAPS2_CUBEMAP_NEGATIVEY   0x2000

Definition at line 94 of file surface.c.

#define DDS_CAPS2_CUBEMAP_NEGATIVEZ   0x8000

Definition at line 96 of file surface.c.

Referenced by get_image_info_from_dds().

#define DDS_CAPS2_CUBEMAP_POSITIVEX   0x400

Definition at line 91 of file surface.c.

Referenced by get_image_info_from_dds().

#define DDS_CAPS2_CUBEMAP_POSITIVEY   0x1000

Definition at line 93 of file surface.c.

#define DDS_CAPS2_CUBEMAP_POSITIVEZ   0x4000

Definition at line 95 of file surface.c.

#define DDS_CAPS2_VOLUME   0x200000

Definition at line 100 of file surface.c.

Referenced by get_image_info_from_dds().

#define DDS_CAPS_COMPLEX   0x8

Definition at line 85 of file surface.c.

#define DDS_CAPS_MIPMAP   0x400000

Definition at line 87 of file surface.c.

#define DDS_CAPS_TEXTURE   0x1000

Definition at line 86 of file surface.c.

Referenced by save_dds_surface_to_memory().

#define DDS_DEPTH   0x800000

Definition at line 82 of file surface.c.

#define DDS_HEIGHT   0x2

Definition at line 76 of file surface.c.

Referenced by save_dds_surface_to_memory().

#define DDS_LINEARSIZE   0x80000

Definition at line 81 of file surface.c.

#define DDS_MIPMAPCOUNT   0x20000

Definition at line 80 of file surface.c.

#define DDS_PF_ALPHA   0x1
#define DDS_PF_ALPHA_ONLY   0x2

Definition at line 104 of file surface.c.

Referenced by dds_pixel_format_to_d3dformat().

#define DDS_PF_BUMPDUDV   0x80000

Definition at line 109 of file surface.c.

Referenced by dds_pixel_format_to_d3dformat().

#define DDS_PF_FOURCC   0x4

Definition at line 105 of file surface.c.

Referenced by d3dformat_to_dds_pixel_format(), and dds_pixel_format_to_d3dformat().

#define DDS_PF_LUMINANCE   0x20000

Definition at line 108 of file surface.c.

Referenced by dds_pixel_format_to_d3dformat().

#define DDS_PF_RGB   0x40

Definition at line 106 of file surface.c.

Referenced by d3dformat_to_dds_pixel_format(), and dds_pixel_format_to_d3dformat().

#define DDS_PF_YUV   0x200

Definition at line 107 of file surface.c.

#define DDS_PITCH   0x8

Definition at line 78 of file surface.c.

#define DDS_PIXELFORMAT   0x1000

Definition at line 79 of file surface.c.

Referenced by save_dds_surface_to_memory().

#define DDS_WIDTH   0x4

Definition at line 77 of file surface.c.

Referenced by save_dds_surface_to_memory().

Typedef Documentation

typedef BOOL(* dxtn_conversion_func)(const BYTE *src, BYTE *dst, DWORD pitch_in, DWORD pitch_out, enum wined3d_format_id format, unsigned int w, unsigned int h)

Definition at line 1784 of file surface.c.

Function Documentation

static UINT calculate_dds_file_size ( D3DFORMAT  format,
UINT  width,
UINT  height,
UINT  depth,
UINT  miplevels,
UINT  faces 
)
static

Definition at line 346 of file surface.c.

Referenced by get_image_info_from_dds(), and save_dds_surface_to_memory().

348 {
349  UINT i, file_size = 0;
350 
351  for (i = 0; i < miplevels; i++)
352  {
353  UINT pitch, size = 0;
354  calculate_dds_surface_size(format, width, height, &pitch, &size);
355  size *= depth;
356  file_size += size;
357  width = max(1, width / 2);
358  height = max(1, height / 2);
359  depth = max(1, depth / 2);
360  }
361 
362  file_size *= faces;
363  file_size += sizeof(struct dds_header);
364  return file_size;
365 }
#define max(a, b)
Definition: svc.c:63
GLenum GLclampf GLint i
Definition: glfuncs.h:14
GLint GLint GLsizei width
Definition: gl.h:1546
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
static HRESULT calculate_dds_surface_size(D3DFORMAT format, UINT width, UINT height, UINT *pitch, UINT *size)
Definition: surface.c:323
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
GLsizeiptr size
Definition: glext.h:5919
unsigned int UINT
Definition: ndis.h:50
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
#define file_size(inode)
Definition: reiserfs_fs.h:1869
static HRESULT calculate_dds_surface_size ( D3DFORMAT  format,
UINT  width,
UINT  height,
UINT pitch,
UINT size 
)
static

Definition at line 323 of file surface.c.

Referenced by calculate_dds_file_size(), load_cube_texture_from_dds(), load_surface_from_dds(), load_texture_from_dds(), load_volume_from_dds(), load_volume_texture_from_dds(), and save_dds_surface_to_memory().

325 {
326  const struct pixel_format_desc *format_desc = get_format_info(format);
327  if (format_desc->type == FORMAT_UNKNOWN)
328  return E_NOTIMPL;
329 
330  if (format_desc->block_width != 1 || format_desc->block_height != 1)
331  {
332  *pitch = format_desc->block_byte_count
333  * max(1, (width + format_desc->block_width - 1) / format_desc->block_width);
334  *size = *pitch
335  * max(1, (height + format_desc->block_height - 1) / format_desc->block_height);
336  }
337  else
338  {
339  *pitch = width * format_desc->bytes_per_pixel;
340  *size = *pitch * height;
341  }
342 
343  return D3D_OK;
344 }
#define max(a, b)
Definition: svc.c:63
GLint GLint GLsizei width
Definition: gl.h:1546
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
enum format_type type
const struct pixel_format_desc * get_format_info(D3DFORMAT format) DECLSPEC_HIDDEN
Definition: util.c:207
#define D3D_OK
Definition: d3d.h:106
GLsizeiptr size
Definition: glext.h:5919
#define E_NOTIMPL
Definition: ddrawi.h:99
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
void convert_argb_pixels ( const BYTE src,
UINT  src_row_pitch,
UINT  src_slice_pitch,
const struct volume src_size,
const struct pixel_format_desc src_format,
BYTE dst,
UINT  dst_row_pitch,
UINT  dst_slice_pitch,
const struct volume dst_size,
const struct pixel_format_desc dst_format,
D3DCOLOR  color_key,
const PALETTEENTRY palette 
)

Definition at line 1594 of file surface.c.

Referenced by D3DXLoadSurfaceFromMemory(), D3DXLoadVolumeFromMemory(), and D3DXSaveSurfaceToFileInMemory().

1598 {
1599  struct argb_conversion_info conv_info, ck_conv_info;
1600  const struct pixel_format_desc *ck_format = NULL;
1601  DWORD channels[4];
1602  UINT min_width, min_height, min_depth;
1603  UINT x, y, z;
1604 
1605  ZeroMemory(channels, sizeof(channels));
1606  init_argb_conversion_info(src_format, dst_format, &conv_info);
1607 
1608  min_width = min(src_size->width, dst_size->width);
1609  min_height = min(src_size->height, dst_size->height);
1610  min_depth = min(src_size->depth, dst_size->depth);
1611 
1612  if (color_key)
1613  {
1614  /* Color keys are always represented in D3DFMT_A8R8G8B8 format. */
1615  ck_format = get_format_info(D3DFMT_A8R8G8B8);
1616  init_argb_conversion_info(src_format, ck_format, &ck_conv_info);
1617  }
1618 
1619  for (z = 0; z < min_depth; z++) {
1620  const BYTE *src_slice_ptr = src + z * src_slice_pitch;
1621  BYTE *dst_slice_ptr = dst + z * dst_slice_pitch;
1622 
1623  for (y = 0; y < min_height; y++) {
1624  const BYTE *src_ptr = src_slice_ptr + y * src_row_pitch;
1625  BYTE *dst_ptr = dst_slice_ptr + y * dst_row_pitch;
1626 
1627  for (x = 0; x < min_width; x++) {
1628  if (!src_format->to_rgba && !dst_format->from_rgba
1629  && src_format->type == dst_format->type
1630  && src_format->bytes_per_pixel <= 4 && dst_format->bytes_per_pixel <= 4)
1631  {
1632  DWORD val;
1633 
1634  get_relevant_argb_components(&conv_info, src_ptr, channels);
1635  val = make_argb_color(&conv_info, channels);
1636 
1637  if (color_key)
1638  {
1639  DWORD ck_pixel;
1640 
1641  get_relevant_argb_components(&ck_conv_info, src_ptr, channels);
1642  ck_pixel = make_argb_color(&ck_conv_info, channels);
1643  if (ck_pixel == color_key)
1644  val &= ~conv_info.destmask[0];
1645  }
1646  memcpy(dst_ptr, &val, dst_format->bytes_per_pixel);
1647  }
1648  else
1649  {
1650  struct vec4 color, tmp;
1651 
1652  format_to_vec4(src_format, src_ptr, &color);
1653  if (src_format->to_rgba)
1654  src_format->to_rgba(&color, &tmp, palette);
1655  else
1656  tmp = color;
1657 
1658  if (ck_format)
1659  {
1660  DWORD ck_pixel;
1661 
1662  format_from_vec4(ck_format, &tmp, (BYTE *)&ck_pixel);
1663  if (ck_pixel == color_key)
1664  tmp.w = 0.0f;
1665  }
1666 
1667  if (dst_format->from_rgba)
1668  dst_format->from_rgba(&tmp, &color);
1669  else
1670  color = tmp;
1671 
1672  format_from_vec4(dst_format, &color, dst_ptr);
1673  }
1674 
1675  src_ptr += src_format->bytes_per_pixel;
1676  dst_ptr += dst_format->bytes_per_pixel;
1677  }
1678 
1679  if (src_size->width < dst_size->width) /* black out remaining pixels */
1680  memset(dst_ptr, 0, dst_format->bytes_per_pixel * (dst_size->width - src_size->width));
1681  }
1682 
1683  if (src_size->height < dst_size->height) /* black out remaining pixels */
1684  memset(dst + src_size->height * dst_row_pitch, 0, dst_row_pitch * (dst_size->height - src_size->height));
1685  }
1686  if (src_size->depth < dst_size->depth) /* black out remaining pixels */
1687  memset(dst + src_size->depth * dst_slice_pitch, 0, dst_slice_pitch * (dst_size->depth - src_size->depth));
1688 }
#define ZeroMemory
Definition: winbase.h:1621
int This channels
Definition: rdpsnd_libao.c:37
DWORD DWORD
Definition: winlogon.h:75
GLuint const GLubyte GLvoid * src
Definition: s_context.h:57
GLuint color
Definition: glext.h:6243
GLdouble GLdouble z
Definition: glext.h:5874
smooth NULL
Definition: ftsmooth.c:557
GLuint GLfloat * val
Definition: glext.h:7180
enum format_type type
const struct pixel_format_desc * get_format_info(D3DFORMAT format) DECLSPEC_HIDDEN
Definition: util.c:207
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: ntddk_ex.h:96
static void format_from_vec4(const struct pixel_format_desc *format, const struct vec4 *src, BYTE *dst)
Definition: surface.c:1513
static void init_argb_conversion_info(const struct pixel_format_desc *srcformat, const struct pixel_format_desc *destformat, struct argb_conversion_info *info)
Definition: surface.c:1402
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
void(* from_rgba)(const struct vec4 *src, struct vec4 *dst)
static void get_relevant_argb_components(const struct argb_conversion_info *info, const BYTE *col, DWORD *out)
Definition: surface.c:1435
static void format_to_vec4(const struct pixel_format_desc *format, const BYTE *src, struct vec4 *dst)
Definition: surface.c:1483
INT INT y
Definition: msvc.h:62
#define memset(x, y, z)
Definition: compat.h:39
void(* to_rgba)(const struct vec4 *src, struct vec4 *dst, const PALETTEENTRY *palette)
static DWORD make_argb_color(const struct argb_conversion_info *info, const DWORD *in)
Definition: surface.c:1465
INT x
Definition: msvc.h:62
static BOOL convert_dib_to_bmp ( void **  data,
UINT size 
)
static

Definition at line 769 of file surface.c.

Referenced by D3DXGetImageInfoFromFileInMemory(), and D3DXLoadSurfaceFromFileInMemory().

770 {
771  ULONG header_size;
772  ULONG count = 0;
773  ULONG offset;
775  BYTE *new_data;
776  UINT new_size;
777 
778  if ((*size < 4) || (*size < (header_size = *(ULONG*)*data)))
779  return FALSE;
780 
781  if ((header_size == sizeof(BITMAPINFOHEADER)) ||
782  (header_size == sizeof(BITMAPV4HEADER)) ||
783  (header_size == sizeof(BITMAPV5HEADER)) ||
784  (header_size == 64 /* sizeof(BITMAPCOREHEADER2) */))
785  {
786  /* All structures begin with the same memory layout as BITMAPINFOHEADER */
787  BITMAPINFOHEADER *info_header = (BITMAPINFOHEADER*)*data;
788  count = info_header->biClrUsed;
789 
790  if (!count && info_header->biBitCount <= 8)
791  count = 1 << info_header->biBitCount;
792 
793  offset = sizeof(BITMAPFILEHEADER) + header_size + sizeof(RGBQUAD) * count;
794 
795  /* For BITMAPINFOHEADER with BI_BITFIELDS compression, there are 3 additional color masks after header */
796  if ((info_header->biSize == sizeof(BITMAPINFOHEADER)) && (info_header->biCompression == BI_BITFIELDS))
797  offset += 3 * sizeof(DWORD);
798  }
799  else if (header_size == sizeof(BITMAPCOREHEADER))
800  {
801  BITMAPCOREHEADER *core_header = (BITMAPCOREHEADER*)*data;
802 
803  if (core_header->bcBitCount <= 8)
804  count = 1 << core_header->bcBitCount;
805 
806  offset = sizeof(BITMAPFILEHEADER) + header_size + sizeof(RGBTRIPLE) * count;
807  }
808  else
809  {
810  return FALSE;
811  }
812 
813  TRACE("Converting DIB file to BMP\n");
814 
815  new_size = *size + sizeof(BITMAPFILEHEADER);
816  new_data = HeapAlloc(GetProcessHeap(), 0, new_size);
817  CopyMemory(new_data + sizeof(BITMAPFILEHEADER), *data, *size);
818 
819  /* Add BMP header */
820  header = (BITMAPFILEHEADER*)new_data;
821  header->bfType = 0x4d42; /* BM */
822  header->bfSize = new_size;
823  header->bfReserved1 = 0;
824  header->bfReserved2 = 0;
825  header->bfOffBits = offset;
826 
827  /* Update input data */
828  *data = new_data;
829  *size = new_size;
830 
831  return TRUE;
832 }
#define TRUE
Definition: types.h:120
#define BI_BITFIELDS
Definition: mmreg.h:505
DWORD DWORD
Definition: winlogon.h:75
#define FALSE
Definition: types.h:117
DWORD biCompression
Definition: amvideo.idl:35
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define CopyMemory
Definition: winbase.h:1619
GLuint GLuint GLsizei count
Definition: gl.h:1545
unsigned char BYTE
Definition: ntddk_ex.h:96
GLsizeiptr size
Definition: glext.h:5919
struct tagBITMAPFILEHEADER BITMAPFILEHEADER
unsigned int UINT
Definition: ndis.h:50
unsigned int ULONG
Definition: retypes.h:1
struct CFHEADER header
Definition: fdi.c:109
GLintptr offset
Definition: glext.h:5920
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 
)

Definition at line 1563 of file surface.c.

Referenced by BitmapImpl_CopyPixels(), BmpFrameDecode_CopyPixels(), BmpFrameEncode_WritePixels(), D3DXLoadSurfaceFromMemory(), D3DXLoadVolumeFromMemory(), GifFrameDecode_CopyPixels(), IcoFrameDecode_CopyPixels(), save_dds_surface_to_memory(), and TgaDecoder_Frame_CopyPixels().

1566 {
1567  UINT row, slice;
1568  BYTE *dst_addr;
1569  const BYTE *src_addr;
1570  UINT row_block_count = (size->width + format->block_width - 1) / format->block_width;
1571  UINT row_count = (size->height + format->block_height - 1) / format->block_height;
1572 
1573  for (slice = 0; slice < size->depth; slice++)
1574  {
1575  src_addr = src + slice * src_slice_pitch;
1576  dst_addr = dst + slice * dst_slice_pitch;
1577 
1578  for (row = 0; row < row_count; row++)
1579  {
1580  memcpy(dst_addr, src_addr, row_block_count * format->block_byte_count);
1581  src_addr += src_row_pitch;
1582  dst_addr += dst_row_pitch;
1583  }
1584  }
1585 }
GLuint const GLubyte GLvoid * src
Definition: s_context.h:57
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: ntddk_ex.h:96
unsigned int UINT
Definition: ndis.h:50
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:76
static HRESULT d3dformat_to_dds_pixel_format ( struct dds_pixel_format pixel_format,
D3DFORMAT  d3dformat 
)
static

Definition at line 288 of file surface.c.

Referenced by save_dds_surface_to_memory().

289 {
290  unsigned int i;
291 
292  memset(pixel_format, 0, sizeof(*pixel_format));
293 
294  pixel_format->size = sizeof(*pixel_format);
295 
296  for (i = 0; i < sizeof(rgb_pixel_formats) / sizeof(rgb_pixel_formats[0]); i++)
297  {
299  {
300  pixel_format->flags |= DDS_PF_RGB;
301  pixel_format->bpp = rgb_pixel_formats[i].bpp;
302  pixel_format->rmask = rgb_pixel_formats[i].rmask;
303  pixel_format->gmask = rgb_pixel_formats[i].gmask;
304  pixel_format->bmask = rgb_pixel_formats[i].bmask;
305  pixel_format->amask = rgb_pixel_formats[i].amask;
306  if (pixel_format->amask) pixel_format->flags |= DDS_PF_ALPHA;
307  return D3D_OK;
308  }
309  }
310 
311  /* Reuse dds_fourcc_to_d3dformat as D3DFORMAT and FOURCC are DWORD with same values */
313  {
314  pixel_format->flags |= DDS_PF_FOURCC;
315  pixel_format->fourcc = d3dformat;
316  return D3D_OK;
317  }
318 
319  WARN("Unknown pixel format %#x\n", d3dformat);
320  return E_NOTIMPL;
321 }
#define DDS_PF_FOURCC
Definition: surface.c:105
#define WARN(fmt,...)
Definition: debug.h:111
static const struct @235 rgb_pixel_formats[]
GLenum GLclampf GLint i
Definition: glfuncs.h:14
D3DFORMAT d3dformat
Definition: surface.c:35
static D3DFORMAT dds_fourcc_to_d3dformat(DWORD fourcc)
Definition: surface.c:142
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
#define D3D_OK
Definition: d3d.h:106
#define DDS_PF_RGB
Definition: surface.c:106
#define E_NOTIMPL
Definition: ddrawi.h:99
#define DDS_PF_ALPHA
Definition: surface.c:103
#define memset(x, y, z)
Definition: compat.h:39
static const GUID* d3dformat_to_wic_guid ( D3DFORMAT  format)
static

Definition at line 61 of file surface.c.

Referenced by D3DXSaveSurfaceToFileInMemory().

62 {
63  unsigned int i;
64 
65  for (i = 0; i < sizeof(wic_pixel_formats) / sizeof(wic_pixel_formats[0]); i++)
66  {
68  return wic_pixel_formats[i].wic_guid;
69  }
70 
71  return NULL;
72 }
GLenum GLclampf GLint i
Definition: glfuncs.h:14
smooth NULL
Definition: ftsmooth.c:557
D3DFORMAT d3dformat
Definition: surface.c:35
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
static const struct @234 wic_pixel_formats[]
HRESULT WINAPI D3DXGetImageInfoFromFileA ( const char file,
D3DXIMAGE_INFO info 
)

Definition at line 993 of file surface.c.

994 {
995  WCHAR *widename;
996  HRESULT hr;
997  int strlength;
998 
999  TRACE("file %s, info %p.\n", debugstr_a(file), info);
1000 
1001  if( !file ) return D3DERR_INVALIDCALL;
1002 
1003  strlength = MultiByteToWideChar(CP_ACP, 0, file, -1, NULL, 0);
1004  widename = HeapAlloc(GetProcessHeap(), 0, strlength * sizeof(*widename));
1005  MultiByteToWideChar(CP_ACP, 0, file, -1, widename, strlength);
1006 
1007  hr = D3DXGetImageInfoFromFileW(widename, info);
1008  HeapFree(GetProcessHeap(), 0, widename);
1009 
1010  return hr;
1011 }
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CP_ACP
Definition: compat.h:99
#define D3DERR_INVALIDCALL
smooth NULL
Definition: ftsmooth.c:557
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define debugstr_a
Definition: kernel32.h:31
LONG HRESULT
Definition: typedefs.h:77
HRESULT WINAPI D3DXGetImageInfoFromFileW(const WCHAR *file, D3DXIMAGE_INFO *info)
Definition: surface.c:1013
#define MultiByteToWideChar
Definition: compat.h:100
#define HeapFree(x, y, z)
Definition: compat.h:394
Definition: fci.c:114
HRESULT WINAPI D3DXGetImageInfoFromFileInMemory ( const void data,
UINT  datasize,
D3DXIMAGE_INFO info 
)

Definition at line 855 of file surface.c.

Referenced by D3DXCreateCubeTextureFromFileInMemoryEx(), D3DXCreateTextureFromFileInMemoryEx(), D3DXCreateVolumeTextureFromFileInMemoryEx(), D3DXGetImageInfoFromFileW(), D3DXGetImageInfoFromResourceA(), D3DXGetImageInfoFromResourceW(), D3DXLoadSurfaceFromFileInMemory(), and D3DXLoadVolumeFromFileInMemory().

856 {
858  IWICBitmapDecoder *decoder = NULL;
860  HRESULT hr;
861  HRESULT initresult;
862  BOOL dib;
863 
864  TRACE("(%p, %d, %p)\n", data, datasize, info);
865 
866  if (!data || !datasize)
867  return D3DERR_INVALIDCALL;
868 
869  if (!info)
870  return D3D_OK;
871 
872  if ((datasize >= 4) && !strncmp(data, "DDS ", 4)) {
873  TRACE("File type is DDS\n");
874  return get_image_info_from_dds(data, datasize, info);
875  }
876 
877  /* In case of DIB file, convert it to BMP */
878  dib = convert_dib_to_bmp((void**)&data, &datasize);
879 
881 
882  hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, &IID_IWICImagingFactory, (void**)&factory);
883 
884  if (SUCCEEDED(hr)) {
885  IWICImagingFactory_CreateStream(factory, &stream);
886  IWICStream_InitializeFromMemory(stream, (BYTE*)data, datasize);
887  hr = IWICImagingFactory_CreateDecoderFromStream(factory, (IStream*)stream, NULL, 0, &decoder);
888  IWICStream_Release(stream);
889  IWICImagingFactory_Release(factory);
890  }
891 
892  if (FAILED(hr)) {
893  if ((datasize >= 2) && (!strncmp(data, "P3", 2) || !strncmp(data, "P6", 2)))
894  FIXME("File type PPM is not supported yet\n");
895  else if ((datasize >= 10) && !strncmp(data, "#?RADIANCE", 10))
896  FIXME("File type HDR is not supported yet\n");
897  else if ((datasize >= 2) && (!strncmp(data, "PF", 2) || !strncmp(data, "Pf", 2)))
898  FIXME("File type PFM is not supported yet\n");
899  }
900 
901  if (SUCCEEDED(hr)) {
902  GUID container_format;
903  UINT frame_count;
904 
905  hr = IWICBitmapDecoder_GetContainerFormat(decoder, &container_format);
906  if (SUCCEEDED(hr)) {
907  if (IsEqualGUID(&container_format, &GUID_ContainerFormatBmp)) {
908  if (dib) {
909  TRACE("File type is DIB\n");
911  } else {
912  TRACE("File type is BMP\n");
914  }
915  } else if (IsEqualGUID(&container_format, &GUID_ContainerFormatPng)) {
916  TRACE("File type is PNG\n");
918  } else if(IsEqualGUID(&container_format, &GUID_ContainerFormatJpeg)) {
919  TRACE("File type is JPG\n");
921  } else if(IsEqualGUID(&container_format, &GUID_WineContainerFormatTga)) {
922  TRACE("File type is TGA\n");
924  } else {
925  WARN("Unsupported image file format %s\n", debugstr_guid(&container_format));
926  hr = D3DXERR_INVALIDDATA;
927  }
928  }
929 
930  if (SUCCEEDED(hr))
931  hr = IWICBitmapDecoder_GetFrameCount(decoder, &frame_count);
932  if (SUCCEEDED(hr) && !frame_count)
933  hr = D3DXERR_INVALIDDATA;
934 
935  if (SUCCEEDED(hr)) {
936  IWICBitmapFrameDecode *frame = NULL;
937 
938  hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
939 
940  if (SUCCEEDED(hr))
941  hr = IWICBitmapFrameDecode_GetSize(frame, &info->Width, &info->Height);
942 
943  if (SUCCEEDED(hr)) {
944  WICPixelFormatGUID pixel_format;
945 
946  hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &pixel_format);
947  if (SUCCEEDED(hr)) {
948  info->Format = wic_guid_to_d3dformat(&pixel_format);
949  if (info->Format == D3DFMT_UNKNOWN) {
950  WARN("Unsupported pixel format %s\n", debugstr_guid(&pixel_format));
951  hr = D3DXERR_INVALIDDATA;
952  }
953  }
954  }
955 
956  if (frame)
957  IWICBitmapFrameDecode_Release(frame);
958 
959  info->Depth = 1;
960  info->MipLevels = 1;
962  }
963  }
964 
965  if (decoder)
966  IWICBitmapDecoder_Release(decoder);
967 
968  if (SUCCEEDED(initresult))
969  CoUninitialize();
970 
971  if (dib)
972  HeapFree(GetProcessHeap(), 0, (void*)data);
973 
974  if (FAILED(hr)) {
975  TRACE("Invalid or unsupported image file\n");
976  return D3DXERR_INVALIDDATA;
977  }
978 
979  return D3D_OK;
980 }
#define WARN(fmt,...)
Definition: debug.h:111
#define D3DERR_INVALIDCALL
D3DRESOURCETYPE ResourceType
Definition: d3dx9tex.h:83
GLuint GLuint stream
Definition: glext.h:7522
UINT MipLevels
Definition: d3dx9tex.h:81
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:557
#define debugstr_guid
Definition: kernel32.h:35
static D3DFORMAT wic_guid_to_d3dformat(const GUID *guid)
Definition: surface.c:48
D3DXIMAGE_FILEFORMAT ImageFileFormat
Definition: d3dx9tex.h:84
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GetProcessHeap()
Definition: compat.h:395
D3DFORMAT Format
Definition: d3dx9tex.h:82
LONG HRESULT
Definition: typedefs.h:77
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
static BYTE dib[]
Definition: ole2.c:1965
unsigned char BYTE
Definition: ntddk_ex.h:96
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3185
#define D3D_OK
Definition: d3d.h:106
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:1944
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:1870
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:3970
static HRESULT get_image_info_from_dds(const void *buffer, UINT length, D3DXIMAGE_INFO *info)
Definition: surface.c:383
static ClassFactoryImpl factory
Definition: ole_server.c:237
static BOOL convert_dib_to_bmp(void **data, UINT *size)
Definition: surface.c:769
#define HeapFree(x, y, z)
Definition: compat.h:394
#define SUCCEEDED(hr)
Definition: intsafe.h:57
HRESULT WINAPI D3DXGetImageInfoFromFileW ( const WCHAR file,
D3DXIMAGE_INFO info 
)

Definition at line 1013 of file surface.c.

Referenced by D3DXGetImageInfoFromFileA().

1014 {
1015  void *buffer;
1016  HRESULT hr;
1017  DWORD size;
1018 
1019  TRACE("file %s, info %p.\n", debugstr_w(file), info);
1020 
1021  if (!file)
1022  return D3DERR_INVALIDCALL;
1023 
1024  if (FAILED(map_view_of_file(file, &buffer, &size)))
1025  return D3DXERR_INVALIDDATA;
1026 
1027  hr = D3DXGetImageInfoFromFileInMemory(buffer, size, info);
1028  UnmapViewOfFile(buffer);
1029 
1030  return hr;
1031 }
#define D3DERR_INVALIDCALL
GLuint buffer
Definition: glext.h:5915
DWORD DWORD
Definition: winlogon.h:75
HRESULT map_view_of_file(const WCHAR *filename, void **buffer, DWORD *length) DECLSPEC_HIDDEN
Definition: util.c:112
#define debugstr_w
Definition: kernel32.h:32
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
GLsizeiptr size
Definition: glext.h:5919
HRESULT WINAPI D3DXGetImageInfoFromFileInMemory(const void *data, UINT datasize, D3DXIMAGE_INFO *info)
Definition: surface.c:855
#define UnmapViewOfFile
Definition: compat.h:403
Definition: fci.c:114
HRESULT WINAPI D3DXGetImageInfoFromResourceA ( HMODULE  module,
const char resource,
D3DXIMAGE_INFO info 
)

Definition at line 1042 of file surface.c.

1043 {
1044  HRSRC resinfo;
1045  void *buffer;
1046  DWORD size;
1047 
1048  TRACE("module %p, resource %s, info %p.\n", module, debugstr_a(resource), info);
1049 
1050  if (!(resinfo = FindResourceA(module, resource, (const char *)RT_RCDATA))
1051  /* Try loading the resource as bitmap data (which is in DIB format D3DXIFF_DIB) */
1052  && !(resinfo = FindResourceA(module, resource, (const char *)RT_BITMAP)))
1053  return D3DXERR_INVALIDDATA;
1054 
1055  if (FAILED(load_resource_into_memory(module, resinfo, &buffer, &size)))
1056  return D3DXERR_INVALIDDATA;
1057 
1058  return D3DXGetImageInfoFromFileInMemory(buffer, size, info);
1059 }
HRESULT load_resource_into_memory(HMODULE module, HRSRC resinfo, void **buffer, DWORD *length) DECLSPEC_HIDDEN
Definition: util.c:160
HRSRC WINAPI FindResourceA(HMODULE hModule, LPCSTR name, LPCSTR type)
Definition: res.c:155
GLuint buffer
Definition: glext.h:5915
DWORD DWORD
Definition: winlogon.h:75
#define TRACE(s)
Definition: solgame.cpp:4
#define debugstr_a
Definition: kernel32.h:31
#define RT_RCDATA
Definition: pedump.c:372
GLsizeiptr size
Definition: glext.h:5919
HRESULT WINAPI D3DXGetImageInfoFromFileInMemory(const void *data, UINT datasize, D3DXIMAGE_INFO *info)
Definition: surface.c:855
#define RT_BITMAP
Definition: pedump.c:364
HRESULT WINAPI D3DXGetImageInfoFromResourceW ( HMODULE  module,
const WCHAR resource,
D3DXIMAGE_INFO info 
)

Definition at line 1061 of file surface.c.

1062 {
1063  HRSRC resinfo;
1064  void *buffer;
1065  DWORD size;
1066 
1067  TRACE("module %p, resource %s, info %p.\n", module, debugstr_w(resource), info);
1068 
1069  if (!(resinfo = FindResourceW(module, resource, (const WCHAR *)RT_RCDATA))
1070  /* Try loading the resource as bitmap data (which is in DIB format D3DXIFF_DIB) */
1071  && !(resinfo = FindResourceW(module, resource, (const WCHAR *)RT_BITMAP)))
1072  return D3DXERR_INVALIDDATA;
1073 
1074  if (FAILED(load_resource_into_memory(module, resinfo, &buffer, &size)))
1075  return D3DXERR_INVALIDDATA;
1076 
1077  return D3DXGetImageInfoFromFileInMemory(buffer, size, info);
1078 }
HRESULT load_resource_into_memory(HMODULE module, HRSRC resinfo, void **buffer, DWORD *length) DECLSPEC_HIDDEN
Definition: util.c:160
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLuint buffer
Definition: glext.h:5915
DWORD DWORD
Definition: winlogon.h:75
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
#define debugstr_w
Definition: kernel32.h:32
#define TRACE(s)
Definition: solgame.cpp:4
#define RT_RCDATA
Definition: pedump.c:372
GLsizeiptr size
Definition: glext.h:5919
HRESULT WINAPI D3DXGetImageInfoFromFileInMemory(const void *data, UINT datasize, D3DXIMAGE_INFO *info)
Definition: surface.c:855
#define RT_BITMAP
Definition: pedump.c:364
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 
)

Definition at line 1279 of file surface.c.

1282 {
1283  WCHAR *src_file_w;
1284  HRESULT hr;
1285  int strlength;
1286 
1287  TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_file %s, "
1288  "src_rect %s, filter %#x, color_key 0x%08x, src_info %p.\n",
1289  dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), debugstr_a(src_file),
1290  wine_dbgstr_rect(src_rect), filter, color_key, src_info);
1291 
1292  if (!src_file || !dst_surface)
1293  return D3DERR_INVALIDCALL;
1294 
1295  strlength = MultiByteToWideChar(CP_ACP, 0, src_file, -1, NULL, 0);
1296  src_file_w = HeapAlloc(GetProcessHeap(), 0, strlength * sizeof(*src_file_w));
1297  MultiByteToWideChar(CP_ACP, 0, src_file, -1, src_file_w, strlength);
1298 
1299  hr = D3DXLoadSurfaceFromFileW(dst_surface, dst_palette, dst_rect,
1300  src_file_w, src_rect, filter, color_key, src_info);
1301  HeapFree(GetProcessHeap(), 0, src_file_w);
1302 
1303  return hr;
1304 }
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CP_ACP
Definition: compat.h:99
#define D3DERR_INVALIDCALL
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)
Definition: surface.c:1306
smooth NULL
Definition: ftsmooth.c:557
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define debugstr_a
Definition: kernel32.h:31
LONG HRESULT
Definition: typedefs.h:77
const char * wine_dbgstr_rect(const RECT *rect)
#define MultiByteToWideChar
Definition: compat.h:100
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
#define HeapFree(x, y, z)
Definition: compat.h:394
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 
)

Definition at line 1103 of file surface.c.

Referenced by D3DXCreateTextureFromFileInMemoryEx(), D3DXLoadSurfaceFromFileW(), D3DXLoadSurfaceFromResourceA(), and D3DXLoadSurfaceFromResourceW().

1106 {
1107  D3DXIMAGE_INFO imginfo;
1108  HRESULT hr, com_init;
1109 
1111  IWICBitmapDecoder *decoder;
1112  IWICBitmapFrameDecode *bitmapframe;
1113  IWICStream *stream;
1114 
1115  const struct pixel_format_desc *formatdesc;
1116  WICRect wicrect;
1117  RECT rect;
1118 
1119  TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_data %p, src_data_size %u, "
1120  "src_rect %s, filter %#x, color_key 0x%08x, src_info %p.\n",
1121  pDestSurface, pDestPalette, wine_dbgstr_rect(pDestRect), pSrcData, SrcDataSize,
1122  wine_dbgstr_rect(pSrcRect), dwFilter, Colorkey, pSrcInfo);
1123 
1124  if (!pDestSurface || !pSrcData || !SrcDataSize)
1125  return D3DERR_INVALIDCALL;
1126 
1127  hr = D3DXGetImageInfoFromFileInMemory(pSrcData, SrcDataSize, &imginfo);
1128 
1129  if (FAILED(hr))
1130  return hr;
1131 
1132  if (pSrcRect)
1133  {
1134  wicrect.X = pSrcRect->left;
1135  wicrect.Y = pSrcRect->top;
1136  wicrect.Width = pSrcRect->right - pSrcRect->left;
1137  wicrect.Height = pSrcRect->bottom - pSrcRect->top;
1138  }
1139  else
1140  {
1141  wicrect.X = 0;
1142  wicrect.Y = 0;
1143  wicrect.Width = imginfo.Width;
1144  wicrect.Height = imginfo.Height;
1145  }
1146 
1147  SetRect(&rect, 0, 0, wicrect.Width, wicrect.Height);
1148 
1149  if (imginfo.ImageFileFormat == D3DXIFF_DDS)
1150  {
1151  hr = load_surface_from_dds(pDestSurface, pDestPalette, pDestRect, pSrcData, &rect,
1152  dwFilter, Colorkey, &imginfo);
1153  if (SUCCEEDED(hr) && pSrcInfo)
1154  *pSrcInfo = imginfo;
1155  return hr;
1156  }
1157 
1158  if (imginfo.ImageFileFormat == D3DXIFF_DIB)
1159  convert_dib_to_bmp((void**)&pSrcData, &SrcDataSize);
1160 
1162 
1163  if (FAILED(CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, &IID_IWICImagingFactory, (void**)&factory)))
1164  goto cleanup_err;
1165 
1166  if (FAILED(IWICImagingFactory_CreateStream(factory, &stream)))
1167  {
1168  IWICImagingFactory_Release(factory);
1169  factory = NULL;
1170  goto cleanup_err;
1171  }
1172 
1173  IWICStream_InitializeFromMemory(stream, (BYTE*)pSrcData, SrcDataSize);
1174 
1175  hr = IWICImagingFactory_CreateDecoderFromStream(factory, (IStream*)stream, NULL, 0, &decoder);
1176 
1177  IWICStream_Release(stream);
1178 
1179  if (FAILED(hr))
1180  goto cleanup_err;
1181 
1182  hr = IWICBitmapDecoder_GetFrame(decoder, 0, &bitmapframe);
1183 
1184  if (FAILED(hr))
1185  goto cleanup_bmp;
1186 
1187  formatdesc = get_format_info(imginfo.Format);
1188 
1189  if (formatdesc->type == FORMAT_UNKNOWN)
1190  {
1191  FIXME("Unsupported pixel format\n");
1192  hr = D3DXERR_INVALIDDATA;
1193  }
1194  else
1195  {
1196  BYTE *buffer;
1197  DWORD pitch;
1199  WICColor *colors = NULL;
1200 
1201  pitch = formatdesc->bytes_per_pixel * wicrect.Width;
1202  buffer = HeapAlloc(GetProcessHeap(), 0, pitch * wicrect.Height);
1203 
1204  hr = IWICBitmapFrameDecode_CopyPixels(bitmapframe, &wicrect, pitch,
1205  pitch * wicrect.Height, buffer);
1206 
1207  if (SUCCEEDED(hr) && (formatdesc->type == FORMAT_INDEX))
1208  {
1209  IWICPalette *wic_palette = NULL;
1210  UINT nb_colors;
1211 
1212  hr = IWICImagingFactory_CreatePalette(factory, &wic_palette);
1213  if (SUCCEEDED(hr))
1214  hr = IWICBitmapFrameDecode_CopyPalette(bitmapframe, wic_palette);
1215  if (SUCCEEDED(hr))
1216  hr = IWICPalette_GetColorCount(wic_palette, &nb_colors);
1217  if (SUCCEEDED(hr))
1218  {
1219  colors = HeapAlloc(GetProcessHeap(), 0, nb_colors * sizeof(colors[0]));
1220  palette = HeapAlloc(GetProcessHeap(), 0, nb_colors * sizeof(palette[0]));
1221  if (!colors || !palette)
1222  hr = E_OUTOFMEMORY;
1223  }
1224  if (SUCCEEDED(hr))
1225  hr = IWICPalette_GetColors(wic_palette, nb_colors, colors, &nb_colors);
1226  if (SUCCEEDED(hr))
1227  {
1228  UINT i;
1229 
1230  /* Convert colors from WICColor (ARGB) to PALETTEENTRY (ABGR) */
1231  for (i = 0; i < nb_colors; i++)
1232  {
1233  palette[i].peRed = (colors[i] >> 16) & 0xff;
1234  palette[i].peGreen = (colors[i] >> 8) & 0xff;
1235  palette[i].peBlue = colors[i] & 0xff;
1236  palette[i].peFlags = (colors[i] >> 24) & 0xff; /* peFlags is the alpha component in DX8 and higher */
1237  }
1238  }
1239  if (wic_palette)
1240  IWICPalette_Release(wic_palette);
1241  }
1242 
1243  if (SUCCEEDED(hr))
1244  {
1245  hr = D3DXLoadSurfaceFromMemory(pDestSurface, pDestPalette, pDestRect,
1246  buffer, imginfo.Format, pitch,
1247  palette, &rect, dwFilter, Colorkey);
1248  }
1249 
1250  HeapFree(GetProcessHeap(), 0, colors);
1251  HeapFree(GetProcessHeap(), 0, palette);
1252  HeapFree(GetProcessHeap(), 0, buffer);
1253  }
1254 
1255  IWICBitmapFrameDecode_Release(bitmapframe);
1256 
1257 cleanup_bmp:
1258  IWICBitmapDecoder_Release(decoder);
1259 
1260 cleanup_err:
1261  if (factory)
1262  IWICImagingFactory_Release(factory);
1263 
1264  if (SUCCEEDED(com_init))
1265  CoUninitialize();
1266 
1267  if (imginfo.ImageFileFormat == D3DXIFF_DIB)
1268  HeapFree(GetProcessHeap(), 0, (void*)pSrcData);
1269 
1270  if (FAILED(hr))
1271  return D3DXERR_INVALIDDATA;
1272 
1273  if (pSrcInfo)
1274  *pSrcInfo = imginfo;
1275 
1276  return D3D_OK;
1277 }
LONG top
Definition: windef.h:320
#define D3DERR_INVALIDCALL
GLuint buffer
Definition: glext.h:5915
LONG left
Definition: windef.h:319
LONG right
Definition: windef.h:321
& rect
Definition: startmenu.cpp:1413
DWORD DWORD
Definition: winlogon.h:75
GLuint GLuint stream
Definition: glext.h:7522
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
Definition: main.c:426
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:557
INT Height
Definition: wincodec.idl:239
D3DXIMAGE_FILEFORMAT ImageFileFormat
Definition: d3dx9tex.h:84
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
D3DFORMAT Format
Definition: d3dx9tex.h:82
LONG HRESULT
Definition: typedefs.h:77
const char * wine_dbgstr_rect(const RECT *rect)
enum format_type type
const struct pixel_format_desc * get_format_info(D3DFORMAT format) DECLSPEC_HIDDEN
Definition: util.c:207
static HPALETTE palette
Definition: clipboard.c:1622
unsigned char BYTE
Definition: ntddk_ex.h:96
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3185
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
#define D3D_OK
Definition: d3d.h:106
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)
Definition: surface.c:1837
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:1944
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:1870
unsigned int UINT
Definition: ndis.h:50
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)
Definition: surface.c:439
INT Width
Definition: wincodec.idl:238
HRESULT WINAPI D3DXGetImageInfoFromFileInMemory(const void *data, UINT datasize, D3DXIMAGE_INFO *info)
Definition: surface.c:855
LONG bottom
Definition: windef.h:322
UINT32 WICColor
Definition: wincodec.idl:250
static BOOL convert_dib_to_bmp(void **data, UINT *size)
Definition: surface.c:769
#define HeapFree(x, y, z)
Definition: compat.h:394
#define SUCCEEDED(hr)
Definition: intsafe.h:57
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 
)

Definition at line 1306 of file surface.c.

Referenced by D3DXLoadSurfaceFromFileA().

1309 {
1310  UINT data_size;
1311  void *data;
1312  HRESULT hr;
1313 
1314  TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_file %s, "
1315  "src_rect %s, filter %#x, color_key 0x%08x, src_info %p.\n",
1316  dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), debugstr_w(src_file),
1317  wine_dbgstr_rect(src_rect), filter, color_key, src_info);
1318 
1319  if (!src_file || !dst_surface)
1320  return D3DERR_INVALIDCALL;
1321 
1322  if (FAILED(map_view_of_file(src_file, &data, &data_size)))
1323  return D3DXERR_INVALIDDATA;
1324 
1325  hr = D3DXLoadSurfaceFromFileInMemory(dst_surface, dst_palette, dst_rect,
1326  data, data_size, src_rect, filter, color_key, src_info);
1327  UnmapViewOfFile(data);
1328 
1329  return hr;
1330 }
#define D3DERR_INVALIDCALL
HRESULT map_view_of_file(const WCHAR *filename, void **buffer, DWORD *length) DECLSPEC_HIDDEN
Definition: util.c:112
#define debugstr_w
Definition: kernel32.h:32
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
const char * wine_dbgstr_rect(const RECT *rect)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
unsigned int UINT
Definition: ndis.h:50
#define UnmapViewOfFile
Definition: compat.h:403
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
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)
Definition: surface.c:1103
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 
)

Definition at line 1837 of file surface.c.

Referenced by D3DXLoadSurfaceFromFileInMemory(), D3DXLoadSurfaceFromSurface(), load_cube_texture_from_dds(), load_surface_from_dds(), and load_texture_from_dds().

1841 {
1842  const struct pixel_format_desc *srcformatdesc, *destformatdesc;
1843  D3DSURFACE_DESC surfdesc;
1844  D3DLOCKED_RECT lockrect;
1845  struct volume src_size, dst_size;
1846  HRESULT ret = D3D_OK;
1847 
1848  TRACE("(%p, %p, %s, %p, %#x, %u, %p, %s, %#x, 0x%08x)\n",
1849  dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), src_memory, src_format,
1850  src_pitch, src_palette, wine_dbgstr_rect(src_rect), filter, color_key);
1851 
1852  if (!dst_surface || !src_memory || !src_rect)
1853  {
1854  WARN("Invalid argument specified.\n");
1855  return D3DERR_INVALIDCALL;
1856  }
1857  if (src_format == D3DFMT_UNKNOWN
1858  || src_rect->left >= src_rect->right
1859  || src_rect->top >= src_rect->bottom)
1860  {
1861  WARN("Invalid src_format or src_rect.\n");
1862  return E_FAIL;
1863  }
1864 
1865  if (filter == D3DX_DEFAULT)
1867 
1868  IDirect3DSurface9_GetDesc(dst_surface, &surfdesc);
1869 
1870  src_size.width = src_rect->right - src_rect->left;
1871  src_size.height = src_rect->bottom - src_rect->top;
1872  src_size.depth = 1;
1873  if (!dst_rect)
1874  {
1875  dst_size.width = surfdesc.Width;
1876  dst_size.height = surfdesc.Height;
1877  }
1878  else
1879  {
1880  if (dst_rect->left > dst_rect->right || dst_rect->right > surfdesc.Width
1881  || dst_rect->top > dst_rect->bottom || dst_rect->bottom > surfdesc.Height
1882  || dst_rect->left < 0 || dst_rect->top < 0)
1883  {
1884  WARN("Invalid dst_rect specified.\n");
1885  return D3DERR_INVALIDCALL;
1886  }
1887  dst_size.width = dst_rect->right - dst_rect->left;
1888  dst_size.height = dst_rect->bottom - dst_rect->top;
1889  if (!dst_size.width || !dst_size.height)
1890  return D3D_OK;
1891  }
1892  dst_size.depth = 1;
1893 
1894  srcformatdesc = get_format_info(src_format);
1895  destformatdesc = get_format_info(surfdesc.Format);
1896  if (srcformatdesc->type == FORMAT_UNKNOWN || destformatdesc->type == FORMAT_UNKNOWN)
1897  {
1898  FIXME("Unsupported pixel format conversion %#x -> %#x\n", src_format, surfdesc.Format);
1899  return E_NOTIMPL;
1900  }
1901 
1902  if (src_format == surfdesc.Format
1903  && dst_size.width == src_size.width
1904  && dst_size.height == src_size.height
1905  && color_key == 0) /* Simple copy. */
1906  {
1907  if (src_rect->left & (srcformatdesc->block_width - 1)
1908  || src_rect->top & (srcformatdesc->block_height - 1)
1909  || (src_rect->right & (srcformatdesc->block_width - 1)
1910  && src_size.width != surfdesc.Width)
1911  || (src_rect->bottom & (srcformatdesc->block_height - 1)
1912  && src_size.height != surfdesc.Height))
1913  {
1914  WARN("Source rect %s is misaligned.\n", wine_dbgstr_rect(src_rect));
1915  return D3DXERR_INVALIDDATA;
1916  }
1917 
1918  if (FAILED(IDirect3DSurface9_LockRect(dst_surface, &lockrect, dst_rect, 0)))
1919  return D3DXERR_INVALIDDATA;
1920 
1921  copy_pixels(src_memory, src_pitch, 0, lockrect.pBits, lockrect.Pitch, 0,
1922  &src_size, srcformatdesc);
1923 
1924  IDirect3DSurface9_UnlockRect(dst_surface);
1925  }
1926  else /* Stretching or format conversion. */
1927  {
1928  dxtn_conversion_func pre_convert, post_convert;
1929  void *tmp_src_memory = NULL, *tmp_dst_memory = NULL;
1930  UINT tmp_src_pitch, tmp_dst_pitch;
1931 
1932  pre_convert = get_dxtn_conversion_func(srcformatdesc->format, FALSE);
1933  post_convert = get_dxtn_conversion_func(destformatdesc->format, TRUE);
1934 
1935  if ((!pre_convert && (srcformatdesc->type != FORMAT_ARGB) && (srcformatdesc->type != FORMAT_INDEX)) ||
1936  (!post_convert && (destformatdesc->type != FORMAT_ARGB)))
1937  {
1938  FIXME("Format conversion missing %#x -> %#x\n", src_format, surfdesc.Format);
1939  return E_NOTIMPL;
1940  }
1941 
1942  if (FAILED(IDirect3DSurface9_LockRect(dst_surface, &lockrect, dst_rect, 0)))
1943  return D3DXERR_INVALIDDATA;
1944 
1945  /* handle pre-conversion */
1946  if (pre_convert)
1947  {
1948  tmp_src_memory = HeapAlloc(GetProcessHeap(), 0, src_size.width * src_size.height * sizeof(DWORD));
1949  if (!tmp_src_memory)
1950  {
1951  ret = E_OUTOFMEMORY;
1952  goto error;
1953  }
1954  tmp_src_pitch = src_size.width * sizeof(DWORD);
1955  if (!pre_convert(src_memory, tmp_src_memory, src_pitch, tmp_src_pitch,
1956  WINED3DFMT_B8G8R8A8_UNORM, src_size.width, src_size.height))
1957  {
1958  ret = E_FAIL;
1959  goto error;
1960  }
1961  srcformatdesc = get_format_info(D3DFMT_A8R8G8B8);
1962  }
1963  else
1964  {
1965  tmp_src_memory = (void *)src_memory;
1966  tmp_src_pitch = src_pitch;
1967  }
1968 
1969  /* handle post-conversion */
1970  if (post_convert)
1971  {
1972  tmp_dst_memory = HeapAlloc(GetProcessHeap(), 0, dst_size.width * dst_size.height * sizeof(DWORD));
1973  if (!tmp_dst_memory)
1974  {
1975  ret = E_OUTOFMEMORY;
1976  goto error;
1977  }
1978  tmp_dst_pitch = dst_size.width * sizeof(DWORD);
1979  destformatdesc = get_format_info(D3DFMT_A8R8G8B8);
1980  }
1981  else
1982  {
1983  tmp_dst_memory = lockrect.pBits;
1984  tmp_dst_pitch = lockrect.Pitch;
1985  }
1986 
1987  if ((filter & 0xf) == D3DX_FILTER_NONE)
1988  {
1989  convert_argb_pixels(tmp_src_memory, tmp_src_pitch, 0, &src_size, srcformatdesc,
1990  tmp_dst_memory, tmp_dst_pitch, 0, &dst_size, destformatdesc, color_key, src_palette);
1991  }
1992  else /* if ((filter & 0xf) == D3DX_FILTER_POINT) */
1993  {
1994  if ((filter & 0xf) != D3DX_FILTER_POINT)
1995  FIXME("Unhandled filter %#x.\n", filter);
1996 
1997  /* Always apply a point filter until D3DX_FILTER_LINEAR,
1998  * D3DX_FILTER_TRIANGLE and D3DX_FILTER_BOX are implemented. */
1999  point_filter_argb_pixels(tmp_src_memory, tmp_src_pitch, 0, &src_size, srcformatdesc,
2000  tmp_dst_memory, tmp_dst_pitch, 0, &dst_size, destformatdesc, color_key, src_palette);
2001  }
2002 
2003  /* handle post-conversion */
2004  if (post_convert)
2005  {
2006  if (!post_convert(tmp_dst_memory, lockrect.pBits, tmp_dst_pitch, lockrect.Pitch,
2007  WINED3DFMT_B8G8R8A8_UNORM, dst_size.width, dst_size.height))
2008  {
2009  ret = E_FAIL;
2010  goto error;
2011  }
2012  }
2013 
2014 error:
2015  if (pre_convert)
2016  HeapFree(GetProcessHeap(), 0, tmp_src_memory);
2017  if (post_convert)
2018  HeapFree(GetProcessHeap(), 0, tmp_dst_memory);
2019  IDirect3DSurface9_UnlockRect(dst_surface);
2020  }
2021 
2022  return ret;
2023 }
#define TRUE
Definition: types.h:120
#define error(str)
Definition: mkdosfs.c:1605
D3DFORMAT Format
Definition: d3d8types.h:1170
#define WARN(fmt,...)
Definition: debug.h:111
#define D3DX_FILTER_NONE
Definition: d3dx9tex.h:27
LONG top
Definition: windef.h:320
#define D3DERR_INVALIDCALL
LONG left
Definition: windef.h:319
LONG right
Definition: windef.h:321
#define E_FAIL
Definition: ddrawi.h:102
#define DWORD
Definition: msvc.h:34
DWORD DWORD
Definition: winlogon.h:75
void convert_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, const struct volume *src_size, const struct pixel_format_desc *src_format, BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *dst_size, const struct pixel_format_desc *dst_format, D3DCOLOR color_key, const PALETTEENTRY *palette)
Definition: surface.c:1594
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define FALSE
Definition: types.h:117
#define FIXME(fmt,...)
Definition: debug.h:110
#define D3DX_DEFAULT
Definition: d3dx9.h:24
#define D3DX_FILTER_TRIANGLE
Definition: d3dx9tex.h:30
smooth NULL
Definition: ftsmooth.c:557
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG HRESULT
Definition: typedefs.h:77
const char * wine_dbgstr_rect(const RECT *rect)
enum format_type type
const struct pixel_format_desc * get_format_info(D3DFORMAT format) DECLSPEC_HIDDEN
Definition: util.c:207
int ret
BOOL(* dxtn_conversion_func)(const BYTE *src, BYTE *dst, DWORD pitch_in, DWORD pitch_out, enum wined3d_format_id format, unsigned int w, unsigned int h)
Definition: surface.c:1784
#define IDirect3DSurface9_GetDesc(p, a)
Definition: d3d9.h:634
static dxtn_conversion_func get_dxtn_conversion_func(D3DFORMAT format, BOOL encode)
Definition: surface.c:1787
#define D3D_OK
Definition: d3d.h:106
#define D3DX_FILTER_DITHER
Definition: d3dx9tex.h:36
#define E_NOTIMPL
Definition: ddrawi.h:99
unsigned int UINT
Definition: ndis.h:50
#define IDirect3DSurface9_UnlockRect(p)
Definition: d3d9.h:636
#define D3DX_FILTER_POINT
Definition: d3dx9tex.h:28
void point_filter_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, const struct volume *src_size, const struct pixel_format_desc *src_format, BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *dst_size, const struct pixel_format_desc *dst_format, D3DCOLOR color_key, const PALETTEENTRY *palette)
Definition: surface.c:1697
LONG bottom
Definition: windef.h:322
#define IDirect3DSurface9_LockRect(p, a, b, c)
Definition: d3d9.h:635
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)
Definition: surface.c:1563
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
#define HeapFree(x, y, z)
Definition: compat.h:394
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 
)

Definition at line 1332 of file surface.c.

1335 {
1336  UINT data_size;
1337  HRSRC resinfo;
1338  void *data;
1339 
1340  TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_module %p, resource %s, "
1341  "src_rect %s, filter %#x, color_key 0x%08x, src_info %p.\n",
1342  dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), src_module, debugstr_a(resource),
1343  wine_dbgstr_rect(src_rect), filter, color_key, src_info);
1344 
1345  if (!dst_surface)
1346  return D3DERR_INVALIDCALL;
1347 
1348  if (!(resinfo = FindResourceA(src_module, resource, (const char *)RT_RCDATA))
1349  /* Try loading the resource as bitmap data (which is in DIB format D3DXIFF_DIB) */
1350  && !(resinfo = FindResourceA(src_module, resource, (const char *)RT_BITMAP)))
1351  return D3DXERR_INVALIDDATA;
1352 
1353  if (FAILED(load_resource_into_memory(src_module, resinfo, &data, &data_size)))
1354  return D3DXERR_INVALIDDATA;
1355 
1356  return D3DXLoadSurfaceFromFileInMemory(dst_surface, dst_palette, dst_rect,
1357  data, data_size, src_rect, filter, color_key, src_info);
1358 }
HRESULT load_resource_into_memory(HMODULE module, HRSRC resinfo, void **buffer, DWORD *length) DECLSPEC_HIDDEN
Definition: util.c:160
HRSRC WINAPI FindResourceA(HMODULE hModule, LPCSTR name, LPCSTR type)
Definition: res.c:155
#define D3DERR_INVALIDCALL
#define TRACE(s)
Definition: solgame.cpp:4
#define debugstr_a
Definition: kernel32.h:31
const char * wine_dbgstr_rect(const RECT *rect)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define RT_RCDATA
Definition: pedump.c:372
unsigned int UINT
Definition: ndis.h:50
#define RT_BITMAP
Definition: pedump.c:364
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
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)
Definition: surface.c:1103
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 
)

Definition at line 1360 of file surface.c.

1363 {
1364  UINT data_size;
1365  HRSRC resinfo;
1366  void *data;
1367 
1368  TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_module %p, resource %s, "
1369  "src_rect %s, filter %#x, color_key 0x%08x, src_info %p.\n",
1370  dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), src_module, debugstr_w(resource),
1371  wine_dbgstr_rect(src_rect), filter, color_key, src_info);
1372 
1373  if (!dst_surface)
1374  return D3DERR_INVALIDCALL;
1375 
1376  if (!(resinfo = FindResourceW(src_module, resource, (const WCHAR *)RT_RCDATA))
1377  /* Try loading the resource as bitmap data (which is in DIB format D3DXIFF_DIB) */
1378  && !(resinfo = FindResourceW(src_module, resource, (const WCHAR *)RT_BITMAP)))
1379  return D3DXERR_INVALIDDATA;
1380 
1381  if (FAILED(load_resource_into_memory(src_module, resinfo, &data, &data_size)))
1382  return D3DXERR_INVALIDDATA;
1383 
1384  return D3DXLoadSurfaceFromFileInMemory(dst_surface, dst_palette, dst_rect,
1385  data, data_size, src_rect, filter, color_key, src_info);
1386 }
HRESULT load_resource_into_memory(HMODULE module, HRSRC resinfo, void **buffer, DWORD *length) DECLSPEC_HIDDEN
Definition: util.c:160
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define D3DERR_INVALIDCALL
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
#define debugstr_w
Definition: kernel32.h:32
#define TRACE(s)
Definition: solgame.cpp:4
const char * wine_dbgstr_rect(const RECT *rect)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define RT_RCDATA
Definition: pedump.c:372
unsigned int UINT
Definition: ndis.h:50
#define RT_BITMAP
Definition: pedump.c:364
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
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)
Definition: surface.c:1103
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 
)

Definition at line 2047 of file surface.c.

Referenced by copy_render_target_to_cube_texture_face(), D3DXFilterTexture(), and D3DXRenderToSurface_EndScene().

2050 {
2051  RECT rect;
2053  D3DSURFACE_DESC SrcDesc;
2054  HRESULT hr;
2055 
2056  TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_surface %p, "
2057  "src_palette %p, src_rect %s, filter %#x, color_key 0x%08x.\n",
2058  dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), src_surface,
2059  src_palette, wine_dbgstr_rect(src_rect), filter, color_key);
2060 
2061  if (!dst_surface || !src_surface)
2062  return D3DERR_INVALIDCALL;
2063 
2064  IDirect3DSurface9_GetDesc(src_surface, &SrcDesc);
2065 
2066  if (!src_rect)
2067  SetRect(&rect, 0, 0, SrcDesc.Width, SrcDesc.Height);
2068  else
2069  rect = *src_rect;
2070 
2071  if (FAILED(IDirect3DSurface9_LockRect(src_surface, &lock, NULL, D3DLOCK_READONLY)))
2072  return D3DXERR_INVALIDDATA;
2073 
2074  hr = D3DXLoadSurfaceFromMemory(dst_surface, dst_palette, dst_rect,
2075  lock.pBits, SrcDesc.Format, lock.Pitch, src_palette, &rect, filter, color_key);
2076 
2077  IDirect3DSurface9_UnlockRect(src_surface);
2078 
2079  return hr;
2080 }
rwlock_t lock
Definition: tcpcore.h:1163
D3DFORMAT Format
Definition: d3d8types.h:1170
#define D3DERR_INVALIDCALL
& rect
Definition: startmenu.cpp:1413
smooth NULL
Definition: ftsmooth.c:557
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
const char * wine_dbgstr_rect(const RECT *rect)
#define IDirect3DSurface9_GetDesc(p, a)
Definition: d3d9.h:634
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
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)
Definition: surface.c:1837
#define IDirect3DSurface9_UnlockRect(p)
Definition: d3d9.h:636
#define IDirect3DSurface9_LockRect(p, a, b, c)
Definition: d3d9.h:635
#define D3DLOCK_READONLY
Definition: d3d8types.h:69
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
HRESULT WINAPI D3DXSaveSurfaceToFileA ( const char dst_filename,
D3DXIMAGE_FILEFORMAT  file_format,
IDirect3DSurface9 *  src_surface,
const PALETTEENTRY src_palette,
const RECT src_rect 
)

Definition at line 2083 of file surface.c.

2085 {
2086  int len;
2087  WCHAR *filename;
2088  HRESULT hr;
2090 
2091  TRACE("(%s, %#x, %p, %p, %s): relay\n",
2092  wine_dbgstr_a(dst_filename), file_format, src_surface, src_palette, wine_dbgstr_rect(src_rect));
2093 
2094  if (!dst_filename) return D3DERR_INVALIDCALL;
2095 
2096  len = MultiByteToWideChar(CP_ACP, 0, dst_filename, -1, NULL, 0);
2097  filename = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
2098  if (!filename) return E_OUTOFMEMORY;
2099  MultiByteToWideChar(CP_ACP, 0, dst_filename, -1, filename, len);
2100 
2101  hr = D3DXSaveSurfaceToFileInMemory(&buffer, file_format, src_surface, src_palette, src_rect);
2102  if (SUCCEEDED(hr))
2103  {
2104  hr = write_buffer_to_file(filename, buffer);
2105  ID3DXBuffer_Release(buffer);
2106  }
2107 
2108  HeapFree(GetProcessHeap(), 0, filename);
2109  return hr;
2110 }
const char int int int static __inline const char * wine_dbgstr_a(const char *s)
Definition: debug.h:184
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CP_ACP
Definition: compat.h:99
#define D3DERR_INVALIDCALL
GLuint buffer
Definition: glext.h:5915
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
LPCSTR filename
Definition: alphablend.c:63
smooth NULL
Definition: ftsmooth.c:557
struct ID3DXBuffer ID3DXBuffer
Definition: d3dx8core.h:51
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG HRESULT
Definition: typedefs.h:77
const char * wine_dbgstr_rect(const RECT *rect)
HRESULT WINAPI D3DXSaveSurfaceToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE_FILEFORMAT file_format, IDirect3DSurface9 *src_surface, const PALETTEENTRY *src_palette, const RECT *src_rect)
Definition: surface.c:2133
GLenum GLsizei len
Definition: glext.h:6722
#define ID3DXBuffer_Release(p)
Definition: d3dx9core.h:83
#define MultiByteToWideChar
Definition: compat.h:100
HRESULT write_buffer_to_file(const WCHAR *filename, ID3DXBuffer *buffer) DECLSPEC_HIDDEN
Definition: util.c:176
#define HeapFree(x, y, z)
Definition: compat.h:394
#define SUCCEEDED(hr)
Definition: intsafe.h:57
HRESULT WINAPI D3DXSaveSurfaceToFileInMemory ( ID3DXBuffer **  dst_buffer,
D3DXIMAGE_FILEFORMAT  file_format,
IDirect3DSurface9 *  src_surface,
const PALETTEENTRY src_palette,
const RECT src_rect 
)

Definition at line 2133 of file surface.c.

Referenced by D3DXSaveSurfaceToFileA(), D3DXSaveSurfaceToFileW(), and D3DXSaveTextureToFileInMemory().

2135 {
2136  IWICBitmapEncoder *encoder = NULL;
2137  IWICBitmapFrameEncode *frame = NULL;
2138  IPropertyBag2 *encoder_options = NULL;
2139  IStream *stream = NULL;
2140  HRESULT hr;
2141  HRESULT initresult;
2142  const CLSID *encoder_clsid;
2143  const GUID *pixel_format_guid;
2144  WICPixelFormatGUID wic_pixel_format;
2145  D3DFORMAT d3d_pixel_format;
2146  D3DSURFACE_DESC src_surface_desc;
2147  D3DLOCKED_RECT locked_rect;
2148  int width, height;
2149  STATSTG stream_stats;
2150  HGLOBAL stream_hglobal;
2152  DWORD size;
2153 
2154  TRACE("(%p, %#x, %p, %p, %s)\n",
2155  dst_buffer, file_format, src_surface, src_palette, wine_dbgstr_rect(src_rect));
2156 
2157  if (!dst_buffer || !src_surface) return D3DERR_INVALIDCALL;
2158 
2159  if (src_palette)
2160  {
2161  FIXME("Saving surfaces with palettized pixel formats is not implemented yet\n");
2162  return D3DERR_INVALIDCALL;
2163  }
2164 
2165  switch (file_format)
2166  {
2167  case D3DXIFF_BMP:
2168  case D3DXIFF_DIB:
2169  encoder_clsid = &CLSID_WICBmpEncoder;
2170  break;
2171  case D3DXIFF_PNG:
2172  encoder_clsid = &CLSID_WICPngEncoder;
2173  break;
2174  case D3DXIFF_JPG:
2175  encoder_clsid = &CLSID_WICJpegEncoder;
2176  break;
2177  case D3DXIFF_DDS:
2178  return save_dds_surface_to_memory(dst_buffer, src_surface, src_rect);
2179  case D3DXIFF_HDR:
2180  case D3DXIFF_PFM:
2181  case D3DXIFF_TGA:
2182  case D3DXIFF_PPM:
2183  FIXME("File format %#x is not supported yet\n", file_format);
2184  return E_NOTIMPL;
2185  default:
2186  return D3DERR_INVALIDCALL;
2187  }
2188 
2189  IDirect3DSurface9_GetDesc(src_surface, &src_surface_desc);
2190  if (src_rect)
2191  {
2192  if (src_rect->left == src_rect->right || src_rect->top == src_rect->bottom)
2193  {
2194  WARN("Invalid rectangle with 0 area\n");
2195  return D3DXCreateBuffer(64, dst_buffer);
2196  }
2197  if (src_rect->left < 0 || src_rect->top < 0)
2198  return D3DERR_INVALIDCALL;
2199  if (src_rect->left > src_rect->right || src_rect->top > src_rect->bottom)
2200  return D3DERR_INVALIDCALL;
2201  if (src_rect->right > src_surface_desc.Width || src_rect->bottom > src_surface_desc.Height)
2202  return D3DERR_INVALIDCALL;
2203 
2204  width = src_rect->right - src_rect->left;
2205  height = src_rect->bottom - src_rect->top;
2206  }
2207  else
2208  {
2209  width = src_surface_desc.Width;
2210  height = src_surface_desc.Height;
2211  }
2212 
2214 
2215  hr = CoCreateInstance(encoder_clsid, NULL, CLSCTX_INPROC_SERVER,
2216  &IID_IWICBitmapEncoder, (void **)&encoder);
2217  if (FAILED(hr)) goto cleanup_err;
2218 
2219  hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2220  if (FAILED(hr)) goto cleanup_err;
2221 
2222  hr = IWICBitmapEncoder_Initialize(encoder, stream, WICBitmapEncoderNoCache);
2223  if (FAILED(hr)) goto cleanup_err;
2224 
2225  hr = IWICBitmapEncoder_CreateNewFrame(encoder, &frame, &encoder_options);
2226  if (FAILED(hr)) goto cleanup_err;
2227 
2228  hr = IWICBitmapFrameEncode_Initialize(frame, encoder_options);
2229  if (FAILED(hr)) goto cleanup_err;
2230 
2231  hr = IWICBitmapFrameEncode_SetSize(frame, width, height);
2232  if (FAILED(hr)) goto cleanup_err;
2233 
2234  pixel_format_guid = d3dformat_to_wic_guid(src_surface_desc.Format);
2235  if (!pixel_format_guid)
2236  {
2237  FIXME("Pixel format %#x is not supported yet\n", src_surface_desc.Format);
2238  hr = E_NOTIMPL;
2239  goto cleanup;
2240  }
2241 
2242  memcpy(&wic_pixel_format, pixel_format_guid, sizeof(GUID));
2243  hr = IWICBitmapFrameEncode_SetPixelFormat(frame, &wic_pixel_format);
2244  d3d_pixel_format = wic_guid_to_d3dformat(&wic_pixel_format);
2245  if (SUCCEEDED(hr) && d3d_pixel_format != D3DFMT_UNKNOWN)
2246  {
2247  TRACE("Using pixel format %s %#x\n", debugstr_guid(&wic_pixel_format), d3d_pixel_format);
2248 
2249  if (src_surface_desc.Format == d3d_pixel_format) /* Simple copy */
2250  {
2251  hr = IDirect3DSurface9_LockRect(src_surface, &locked_rect, src_rect, D3DLOCK_READONLY);
2252  if (SUCCEEDED(hr))
2253  {
2254  IWICBitmapFrameEncode_WritePixels(frame, height,
2255  locked_rect.Pitch, height * locked_rect.Pitch, locked_rect.pBits);
2256  IDirect3DSurface9_UnlockRect(src_surface);
2257  }
2258  }
2259  else /* Pixel format conversion */
2260  {
2261  const struct pixel_format_desc *src_format_desc, *dst_format_desc;
2262  struct volume size;
2263  DWORD dst_pitch;
2264  void *dst_data;
2265 
2266  src_format_desc = get_format_info(src_surface_desc.Format);
2267  dst_format_desc = get_format_info(d3d_pixel_format);
2268  if (src_format_desc->type != FORMAT_ARGB || dst_format_desc->type != FORMAT_ARGB)
2269  {
2270  FIXME("Unsupported pixel format conversion %#x -> %#x\n",
2271  src_surface_desc.Format, d3d_pixel_format);
2272  hr = E_NOTIMPL;
2273  goto cleanup;
2274  }
2275 
2276  size.width = width;
2277  size.height = height;
2278  size.depth = 1;
2279  dst_pitch = width * dst_format_desc->bytes_per_pixel;
2280  dst_data = HeapAlloc(GetProcessHeap(), 0, dst_pitch * height);
2281  if (!dst_data)
2282  {
2283  hr = E_OUTOFMEMORY;
2284  goto cleanup;
2285  }
2286 
2287  hr = IDirect3DSurface9_LockRect(src_surface, &locked_rect, src_rect, D3DLOCK_READONLY);
2288  if (SUCCEEDED(hr))
2289  {
2290  convert_argb_pixels(locked_rect.pBits, locked_rect.Pitch, 0, &size, src_format_desc,
2291  dst_data, dst_pitch, 0, &size, dst_format_desc, 0, NULL);
2292  IDirect3DSurface9_UnlockRect(src_surface);
2293  }
2294 
2295  IWICBitmapFrameEncode_WritePixels(frame, height, dst_pitch, dst_pitch * height, dst_data);
2296  HeapFree(GetProcessHeap(), 0, dst_data);
2297  }
2298 
2299  hr = IWICBitmapFrameEncode_Commit(frame);
2300  if (SUCCEEDED(hr)) hr = IWICBitmapEncoder_Commit(encoder);
2301  }
2302  else WARN("Unsupported pixel format %#x\n", src_surface_desc.Format);
2303 
2304  /* copy data from stream to ID3DXBuffer */
2305  hr = IStream_Stat(stream, &stream_stats, STATFLAG_NONAME);
2306  if (FAILED(hr)) goto cleanup_err;
2307 
2308  if (stream_stats.cbSize.u.HighPart != 0)
2309  {
2310  hr = D3DXERR_INVALIDDATA;
2311  goto cleanup;
2312  }
2313  size = stream_stats.cbSize.u.LowPart;
2314 
2315  /* Remove BMP header for DIB */
2316  if (file_format == D3DXIFF_DIB)
2317  size -= sizeof(BITMAPFILEHEADER);
2318 
2319  hr = D3DXCreateBuffer(size, &buffer);
2320  if (FAILED(hr)) goto cleanup;
2321 
2322  hr = GetHGlobalFromStream(stream, &stream_hglobal);
2323  if (SUCCEEDED(hr))
2324  {
2325  void *buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
2326  void *stream_data = GlobalLock(stream_hglobal);
2327  /* Remove BMP header for DIB */
2328  if (file_format == D3DXIFF_DIB)
2329  stream_data = (void*)((BYTE*)stream_data + sizeof(BITMAPFILEHEADER));
2330  memcpy(buffer_pointer, stream_data, size);
2331  GlobalUnlock(stream_hglobal);
2332  *dst_buffer = buffer;
2333  }
2334  else ID3DXBuffer_Release(buffer);
2335 
2336 cleanup_err:
2337  if (FAILED(hr) && hr != E_OUTOFMEMORY)
2338  hr = D3DERR_INVALIDCALL;
2339 
2340 cleanup:
2341  if (stream) IStream_Release(stream);
2342 
2343  if (frame) IWICBitmapFrameEncode_Release(frame);
2344  if (encoder_options) IPropertyBag2_Release(encoder_options);
2345 
2346  if (encoder) IWICBitmapEncoder_Release(encoder);
2347 
2348  if (SUCCEEDED(initresult)) CoUninitialize();
2349 
2350  return hr;
2351 }
HANDLE HGLOBAL
Definition: windef.h:266
#define TRUE
Definition: types.h:120
HRESULT WINAPI GetHGlobalFromStream(IStream *pstm, HGLOBAL *phglobal)
static const GUID * d3dformat_to_wic_guid(D3DFORMAT format)
Definition: surface.c:61
D3DFORMAT Format
Definition: d3d8types.h:1170
#define WARN(fmt,...)
Definition: debug.h:111
LONG top
Definition: windef.h:320
#define D3DERR_INVALIDCALL
GLuint buffer
Definition: glext.h:5915
HRESULT WINAPI CreateStreamOnHGlobal(HGLOBAL hGlobal, BOOL fDeleteOnRelease, LPSTREAM *ppstm)
LONG left
Definition: windef.h:319
LONG right
Definition: windef.h:321
DWORD DWORD
Definition: winlogon.h:75
void convert_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, const struct volume *src_size, const struct pixel_format_desc *src_format, BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *dst_size, const struct pixel_format_desc *dst_format, D3DCOLOR color_key, const PALETTEENTRY *palette)
Definition: surface.c:1594
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:557
struct ID3DXBuffer ID3DXBuffer
Definition: d3dx8core.h:51
enum _D3DFORMAT D3DFORMAT
#define debugstr_guid
Definition: kernel32.h:35
static D3DFORMAT wic_guid_to_d3dformat(const GUID *guid)
Definition: surface.c:48
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
GLint GLint GLsizei width
Definition: gl.h:1546
LONG HRESULT
Definition: typedefs.h:77
const char * wine_dbgstr_rect(const RECT *rect)
enum format_type type
const struct pixel_format_desc * get_format_info(D3DFORMAT format) DECLSPEC_HIDDEN
Definition: util.c:207
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
Definition: parse.h:22
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define IDirect3DSurface9_GetDesc(p, a)
Definition: d3d9.h:634
unsigned char BYTE
Definition: ntddk_ex.h:96
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3185
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:1944
#define ID3DXBuffer_Release(p)
Definition: d3dx9core.h:83
GLsizeiptr size
Definition: glext.h:5919
struct tagBITMAPFILEHEADER BITMAPFILEHEADER
#define E_NOTIMPL
Definition: ddrawi.h:99
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:1870
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
#define IDirect3DSurface9_UnlockRect(p)
Definition: d3d9.h:636
LONG bottom
Definition: windef.h:322
char * cleanup(char *str)
Definition: wpickclick.c:99
#define IDirect3DSurface9_LockRect(p, a, b, c)
Definition: d3d9.h:635
static HRESULT save_dds_surface_to_memory(ID3DXBuffer **dst_buffer, IDirect3DSurface9 *src_surface, const RECT *src_rect)
Definition: surface.c:458
#define D3DLOCK_READONLY
Definition: d3d8types.h:69
static const char stream_data[]
Definition: mlang.c:2012
#define HeapFree(x, y, z)
Definition: compat.h:394
HRESULT WINAPI D3DXCreateBuffer(DWORD size, ID3DXBuffer **buffer)
Definition: core.c:124
#define ID3DXBuffer_GetBufferPointer(p)
Definition: d3dx9core.h:85
#define SUCCEEDED(hr)
Definition: intsafe.h:57
HRESULT WINAPI D3DXSaveSurfaceToFileW ( const WCHAR dst_filename,
D3DXIMAGE_FILEFORMAT  file_format,
IDirect3DSurface9 *  src_surface,
const PALETTEENTRY src_palette,
const RECT src_rect 
)

Definition at line 2112 of file surface.c.

2114 {
2115  HRESULT hr;
2117 
2118  TRACE("(%s, %#x, %p, %p, %s): relay\n",
2119  wine_dbgstr_w(dst_filename), file_format, src_surface, src_palette, wine_dbgstr_rect(src_rect));
2120 
2121  if (!dst_filename) return D3DERR_INVALIDCALL;
2122 
2123  hr = D3DXSaveSurfaceToFileInMemory(&buffer, file_format, src_surface, src_palette, src_rect);
2124  if (SUCCEEDED(hr))
2125  {
2126  hr = write_buffer_to_file(dst_filename, buffer);
2127  ID3DXBuffer_Release(buffer);
2128  }
2129 
2130  return hr;
2131 }
#define D3DERR_INVALIDCALL
GLuint buffer
Definition: glext.h:5915
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: CString.cpp:62
struct ID3DXBuffer ID3DXBuffer
Definition: d3dx8core.h:51
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
const char * wine_dbgstr_rect(const RECT *rect)
HRESULT WINAPI D3DXSaveSurfaceToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE_FILEFORMAT file_format, IDirect3DSurface9 *src_surface, const PALETTEENTRY *src_palette, const RECT *src_rect)
Definition: surface.c:2133
#define ID3DXBuffer_Release(p)
Definition: d3dx9core.h:83
HRESULT write_buffer_to_file(const WCHAR *filename, ID3DXBuffer *buffer) DECLSPEC_HIDDEN
Definition: util.c:176
#define SUCCEEDED(hr)
Definition: intsafe.h:57
static D3DFORMAT dds_alpha_to_d3dformat ( const struct dds_pixel_format pixel_format)
static

Definition at line 243 of file surface.c.

Referenced by dds_pixel_format_to_d3dformat().

244 {
245  if (pixel_format->bpp == 8 && pixel_format->amask == 0xff)
246  return D3DFMT_A8;
247 
248  WARN("Unknown Alpha pixel format (%u, %#x)\n", pixel_format->bpp, pixel_format->rmask);
249  return D3DFMT_UNKNOWN;
250 }
#define WARN(fmt,...)
Definition: debug.h:111
static D3DFORMAT dds_bump_to_d3dformat ( const struct dds_pixel_format pixel_format)
static

Definition at line 252 of file surface.c.

Referenced by dds_pixel_format_to_d3dformat().

253 {
254  if (pixel_format->bpp == 16 && pixel_format->rmask == 0x00ff && pixel_format->gmask == 0xff00)
255  return D3DFMT_V8U8;
256  if (pixel_format->bpp == 32 && pixel_format->rmask == 0x0000ffff && pixel_format->gmask == 0xffff0000)
257  return D3DFMT_V16U16;
258 
259  WARN("Unknown bump pixel format (%u, %#x, %#x, %#x, %#x)\n", pixel_format->bpp,
260  pixel_format->rmask, pixel_format->gmask, pixel_format->bmask, pixel_format->amask);
261  return D3DFMT_UNKNOWN;
262 }
#define WARN(fmt,...)
Definition: debug.h:111
static D3DFORMAT dds_fourcc_to_d3dformat ( DWORD  fourcc)
static

Definition at line 142 of file surface.c.

Referenced by d3dformat_to_dds_pixel_format(), and dds_pixel_format_to_d3dformat().

143 {
144  unsigned int i;
145  static const DWORD known_fourcc[] = {
146  D3DFMT_UYVY,
147  D3DFMT_YUY2,
150  D3DFMT_DXT1,
151  D3DFMT_DXT2,
152  D3DFMT_DXT3,
153  D3DFMT_DXT4,
154  D3DFMT_DXT5,
155  D3DFMT_R16F,
158  D3DFMT_R32F,
161  };
162 
163  for (i = 0; i < sizeof(known_fourcc) / sizeof(known_fourcc[0]); i++)
164  {
165  if (known_fourcc[i] == fourcc)
166  return fourcc;
167  }
168 
169  WARN("Unknown FourCC %#x\n", fourcc);
170  return D3DFMT_UNKNOWN;
171 }
#define WARN(fmt,...)
Definition: debug.h:111
DWORD DWORD
Definition: winlogon.h:75
GLenum GLclampf GLint i
Definition: glfuncs.h:14
static D3DFORMAT dds_luminance_to_d3dformat ( const struct dds_pixel_format pixel_format)
static

Definition at line 221 of file surface.c.

Referenced by dds_pixel_format_to_d3dformat().

222 {
223  if (pixel_format->bpp == 8)
224  {
225  if (pixel_format->rmask == 0xff)
226  return D3DFMT_L8;
227  if ((pixel_format->flags & DDS_PF_ALPHA) && pixel_format->rmask == 0x0f && pixel_format->amask == 0xf0)
228  return D3DFMT_A4L4;
229  }
230  if (pixel_format->bpp == 16)
231  {
232  if (pixel_format->rmask == 0xffff)
233  return D3DFMT_L16;
234  if ((pixel_format->flags & DDS_PF_ALPHA) && pixel_format->rmask == 0x00ff && pixel_format->amask == 0xff00)
235  return D3DFMT_A8L8;
236  }
237 
238  WARN("Unknown luminance pixel format (bpp %u, l %#x, a %#x)\n",
239  pixel_format->bpp, pixel_format->rmask, pixel_format->amask);
240  return D3DFMT_UNKNOWN;
241 }
#define WARN(fmt,...)
Definition: debug.h:111
#define DDS_PF_ALPHA
Definition: surface.c:103
static D3DFORMAT dds_pixel_format_to_d3dformat ( const struct dds_pixel_format pixel_format)
static

Definition at line 264 of file surface.c.

Referenced by get_image_info_from_dds().

265 {
266  TRACE("pixel_format: size %u, flags %#x, fourcc %#x, bpp %u.\n", pixel_format->size,
267  pixel_format->flags, pixel_format->fourcc, pixel_format->bpp);
268  TRACE("rmask %#x, gmask %#x, bmask %#x, amask %#x.\n", pixel_format->rmask, pixel_format->gmask,
269  pixel_format->bmask, pixel_format->amask);
270 
271  if (pixel_format->flags & DDS_PF_FOURCC)
272  return dds_fourcc_to_d3dformat(pixel_format->fourcc);
273  if (pixel_format->flags & DDS_PF_RGB)
274  return dds_rgb_to_d3dformat(pixel_format);
275  if (pixel_format->flags & DDS_PF_LUMINANCE)
276  return dds_luminance_to_d3dformat(pixel_format);
277  if (pixel_format->flags & DDS_PF_ALPHA_ONLY)
278  return dds_alpha_to_d3dformat(pixel_format);
279  if (pixel_format->flags & DDS_PF_BUMPDUDV)
280  return dds_bump_to_d3dformat(pixel_format);
281 
282  WARN("Unknown pixel format (flags %#x, fourcc %#x, bpp %u, r %#x, g %#x, b %#x, a %#x)\n",
283  pixel_format->flags, pixel_format->fourcc, pixel_format->bpp,
284  pixel_format->rmask, pixel_format->gmask, pixel_format->bmask, pixel_format->amask);
285  return D3DFMT_UNKNOWN;
286 }
#define DDS_PF_FOURCC
Definition: surface.c:105
#define WARN(fmt,...)
Definition: debug.h:111
static D3DFORMAT dds_alpha_to_d3dformat(const struct dds_pixel_format *pixel_format)
Definition: surface.c:243
#define DDS_PF_BUMPDUDV
Definition: surface.c:109
static D3DFORMAT dds_rgb_to_d3dformat(const struct dds_pixel_format *pixel_format)
Definition: surface.c:198
#define TRACE(s)
Definition: solgame.cpp:4
static D3DFORMAT dds_fourcc_to_d3dformat(DWORD fourcc)
Definition: surface.c:142
#define DDS_PF_LUMINANCE
Definition: surface.c:108
static D3DFORMAT dds_luminance_to_d3dformat(const struct dds_pixel_format *pixel_format)
Definition: surface.c:221
#define DDS_PF_RGB
Definition: surface.c:106
static D3DFORMAT dds_bump_to_d3dformat(const struct dds_pixel_format *pixel_format)
Definition: surface.c:252
#define DDS_PF_ALPHA_ONLY
Definition: surface.c:104
static D3DFORMAT dds_rgb_to_d3dformat ( const struct dds_pixel_format pixel_format)
static

Definition at line 198 of file surface.c.

Referenced by dds_pixel_format_to_d3dformat().

199 {
200  unsigned int i;
201 
202  for (i = 0; i < sizeof(rgb_pixel_formats) / sizeof(rgb_pixel_formats[0]); i++)
203  {
204  if (rgb_pixel_formats[i].bpp == pixel_format->bpp
205  && rgb_pixel_formats[i].rmask == pixel_format->rmask
206  && rgb_pixel_formats[i].gmask == pixel_format->gmask
207  && rgb_pixel_formats[i].bmask == pixel_format->bmask)
208  {
209  if ((pixel_format->flags & DDS_PF_ALPHA) && rgb_pixel_formats[i].amask == pixel_format->amask)
210  return rgb_pixel_formats[i].format;
211  if (rgb_pixel_formats[i].amask == 0)
212  return rgb_pixel_formats[i].format;
213  }
214  }
215 
216  WARN("Unknown RGB pixel format (%#x, %#x, %#x, %#x)\n",
217  pixel_format->rmask, pixel_format->gmask, pixel_format->bmask, pixel_format->amask);
218  return D3DFMT_UNKNOWN;
219 }
DWORD amask
Definition: surface.c:178
#define WARN(fmt,...)
Definition: debug.h:111
static const struct @235 rgb_pixel_formats[]
GLenum GLclampf GLint i
Definition: glfuncs.h:14
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
#define DDS_PF_ALPHA
Definition: surface.c:103
DWORD bpp
Definition: surface.c:174
DEFINE_GUID ( GUID_WineContainerFormatTga  ,
0x0c44fda1  ,
0xa5c5  ,
0x4298  ,
0x96  ,
0x85  ,
0x47  ,
0x3f  ,
0xc1  ,
0x7c  ,
0xd3  ,
0x22   
)
static void format_from_vec4 ( const struct pixel_format_desc format,
const struct vec4 src,
BYTE dst 
)
static

Definition at line 1513 of file surface.c.

Referenced by convert_argb_pixels(), and point_filter_argb_pixels().

1514 {
1515  DWORD v, mask32;
1516  unsigned int c, i;
1517 
1518  memset(dst, 0, format->bytes_per_pixel);
1519 
1520  for (c = 0; c < 4; ++c)
1521  {
1522  static const unsigned int component_offsets[4] = {3, 0, 1, 2};
1523  const float src_component = *((const float *)src + component_offsets[c]);
1524 
1525  if (!format->bits[c])
1526  continue;
1527 
1528  mask32 = ~0u >> (32 - format->bits[c]);
1529 
1530  if (format->type == FORMAT_ARGBF16)
1531  v = float_32_to_16(src_component);
1532  else if (format->type == FORMAT_ARGBF)
1533  v = *(DWORD *)&src_component;
1534  else
1535  v = (DWORD)(src_component * ((1 << format->bits[c]) - 1) + 0.5f);
1536 
1537  for (i = format->shift[c] / 8 * 8; i < format->shift[c] + format->bits[c]; i += 8)
1538  {
1539  BYTE mask, byte;
1540 
1541  if (format->shift[c] > i)
1542  {
1543  mask = mask32 << (format->shift[c] - i);
1544  byte = (v << (format->shift[c] - i)) & mask;
1545  }
1546  else
1547  {
1548  mask = mask32 >> (i - format->shift[c]);
1549  byte = (v >> (i - format->shift[c])) & mask;
1550  }
1551  dst[i / 8] |= byte;
1552  }
1553  }
1554 }
#define shift
Definition: input.c:1594
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble * u
Definition: glfuncs.h:88
#define DWORD
Definition: msvc.h:34
GLuint const GLubyte mask[]
Definition: s_context.h:57
DWORD DWORD
Definition: winlogon.h:75
GLenum GLclampf GLint i
Definition: glfuncs.h:14
GLfloat f
Definition: glext.h:7540
enum format_type type
unsigned char BYTE
Definition: ntddk_ex.h:96
const GLdouble * v
Definition: gl.h:2040
#define byte(x, n)
Definition: tomcrypt.h:118
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
static unsigned short float_32_to_16(const float *in)
Definition: surface.c:984
#define c
Definition: ke_i.h:80
#define memset(x, y, z)
Definition: compat.h:39
static void format_to_vec4 ( const struct pixel_format_desc format,
const BYTE src,
struct vec4 dst 
)
static

Definition at line 1483 of file surface.c.

Referenced by convert_argb_pixels(), and point_filter_argb_pixels().

1484 {
1485  DWORD mask, tmp;
1486  unsigned int c;
1487 
1488  for (c = 0; c < 4; ++c)
1489  {
1490  static const unsigned int component_offsets[4] = {3, 0, 1, 2};
1491  float *dst_component = (float *)dst + component_offsets[c];
1492 
1493  if (format->bits[c])
1494  {
1495  mask = ~0u >> (32 - format->bits[c]);
1496 
1497  memcpy(&tmp, src + format->shift[c] / 8,
1498  min(sizeof(DWORD), (format->shift[c] % 8 + format->bits[c] + 7) / 8));
1499 
1500  if (format->type == FORMAT_ARGBF16)
1501  *dst_component = float_16_to_32(tmp);
1502  else if (format->type == FORMAT_ARGBF)
1503  *dst_component = *(float *)&tmp;
1504  else
1505  *dst_component = (float)((tmp >> format->shift[c] % 8) & mask) / mask;
1506  }
1507  else
1508  *dst_component = 1.0f;
1509  }
1510 }
float float_16_to_32(const unsigned short in) DECLSPEC_HIDDEN
Definition: math.c:2218
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble * u
Definition: glfuncs.h:88
GLuint const GLubyte mask[]
Definition: s_context.h:57
DWORD DWORD
Definition: winlogon.h:75
GLuint const GLubyte GLvoid * src
Definition: s_context.h:57
enum format_type type
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define min(a, b)
Definition: monoChain.cc:55
#define c
Definition: ke_i.h:80
static dxtn_conversion_func get_dxtn_conversion_func ( D3DFORMAT  format,
BOOL  encode 
)
static

Definition at line 1787 of file surface.c.

Referenced by D3DXLoadSurfaceFromMemory().

1788 {
1789  switch (format)
1790  {
1791  case D3DFMT_DXT1:
1792  if (!wined3d_dxtn_supported()) return NULL;
1793  return encode ? wined3d_dxt1_encode : wined3d_dxt1_decode;
1794  case D3DFMT_DXT3:
1795  if (!wined3d_dxtn_supported()) return NULL;
1796  return encode ? wined3d_dxt3_encode : wined3d_dxt3_decode;
1797  case D3DFMT_DXT5:
1798  if (!wined3d_dxtn_supported()) return NULL;
1799  return encode ? wined3d_dxt5_encode : wined3d_dxt5_decode;
1800  default:
1801  return NULL;
1802  }
1803 }
BOOL wined3d_dxt5_encode(const BYTE *src, BYTE *dst, DWORD pitch_in, DWORD pitch_out, enum wined3d_format_id format, unsigned int w, unsigned int h)
Definition: dxtn.c:438
BOOL wined3d_dxt1_encode(const BYTE *src, BYTE *dst, DWORD pitch_in, DWORD pitch_out, enum wined3d_format_id format, unsigned int w, unsigned int h)
Definition: dxtn.c:388
BOOL wined3d_dxtn_supported(void)
Definition: dxtn.c:509
BOOL wined3d_dxt3_encode(const BYTE *src, BYTE *dst, DWORD pitch_in, DWORD pitch_out, enum wined3d_format_id format, unsigned int w, unsigned int h)
Definition: dxtn.c:416
smooth NULL
Definition: ftsmooth.c:557
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
BOOL wined3d_dxt1_decode(const BYTE *src, BYTE *dst, DWORD pitch_in, DWORD pitch_out, enum wined3d_format_id format, unsigned int w, unsigned int h)
Definition: dxtn.c:316
BOOL wined3d_dxt3_decode(const BYTE *src, BYTE *dst, DWORD pitch_in, DWORD pitch_out, enum wined3d_format_id format, unsigned int w, unsigned int h)
Definition: dxtn.c:344
BOOL wined3d_dxt5_decode(const BYTE *src, BYTE *dst, DWORD pitch_in, DWORD pitch_out, enum wined3d_format_id format, unsigned int w, unsigned int h)
Definition: dxtn.c:368
static HRESULT get_image_info_from_dds ( const void buffer,
UINT  length,
D3DXIMAGE_INFO info 
)
static

Definition at line 383 of file surface.c.

Referenced by D3DXGetImageInfoFromFileInMemory().

384 {
385  UINT faces = 1;
386  UINT expected_length;
387  const struct dds_header *header = buffer;
388 
389  if (length < sizeof(*header) || !info)
390  return D3DXERR_INVALIDDATA;
391 
392  if (header->pixel_format.size != sizeof(header->pixel_format))
393  return D3DXERR_INVALIDDATA;
394 
395  info->Width = header->width;
396  info->Height = header->height;
397  info->Depth = 1;
398  info->MipLevels = header->miplevels ? header->miplevels : 1;
399 
401  if (info->Format == D3DFMT_UNKNOWN)
402  return D3DXERR_INVALIDDATA;
403 
404  TRACE("Pixel format is %#x\n", info->Format);
405 
406  if (header->caps2 & DDS_CAPS2_VOLUME)
407  {
408  info->Depth = header->depth;
410  }
411  else if (header->caps2 & DDS_CAPS2_CUBEMAP)
412  {
413  DWORD face;
414  faces = 0;
415  for (face = DDS_CAPS2_CUBEMAP_POSITIVEX; face <= DDS_CAPS2_CUBEMAP_NEGATIVEZ; face <<= 1)
416  {
417  if (header->caps2 & face)
418  faces++;
419  }
421  }
422  else
423  {
425  }
426 
427  expected_length = calculate_dds_file_size(info->Format, info->Width, info->Height, info->Depth,
428  info->MipLevels, faces);
429  if (length < expected_length)
430  {
431  WARN("File is too short %u, expected at least %u bytes\n", length, expected_length);
432  return D3DXERR_INVALIDDATA;
433  }
434 
436  return D3D_OK;
437 }
DWORD miplevels
Definition: surface.c:132
DWORD caps2
Definition: surface.c:136
#define WARN(fmt,...)
Definition: debug.h:111
#define DDS_CAPS2_VOLUME
Definition: surface.c:100
GLuint buffer
Definition: glext.h:5915
WORD face[3]
Definition: mesh.c:4743
DWORD width
Definition: surface.c:129
D3DRESOURCETYPE ResourceType
Definition: d3dx9tex.h:83
DWORD DWORD
Definition: winlogon.h:75
UINT MipLevels
Definition: d3dx9tex.h:81
DWORD height
Definition: surface.c:128
D3DXIMAGE_FILEFORMAT ImageFileFormat
Definition: d3dx9tex.h:84
#define TRACE(s)
Definition: solgame.cpp:4
D3DFORMAT Format
Definition: d3dx9tex.h:82
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
static UINT calculate_dds_file_size(D3DFORMAT format, UINT width, UINT height, UINT depth, UINT miplevels, UINT faces)
Definition: surface.c:346
#define D3D_OK
Definition: d3d.h:106
unsigned int UINT
Definition: ndis.h:50
struct dds_pixel_format pixel_format
Definition: surface.c:134
static D3DFORMAT dds_pixel_format_to_d3dformat(const struct dds_pixel_format *pixel_format)
Definition: surface.c:264
#define DDS_CAPS2_CUBEMAP_NEGATIVEZ
Definition: surface.c:96
DWORD depth
Definition: surface.c:131
#define DDS_CAPS2_CUBEMAP
Definition: surface.c:90
#define DDS_CAPS2_CUBEMAP_POSITIVEX
Definition: surface.c:91
struct CFHEADER header
Definition: fdi.c:109
static void get_relevant_argb_components ( const struct argb_conversion_info info,
const BYTE col,
DWORD out 
)
static

Definition at line 1435 of file surface.c.

Referenced by convert_argb_pixels(), and point_filter_argb_pixels().

1436 {
1437  unsigned int i, j;
1438  unsigned int component, mask;
1439 
1440  for (i = 0; i < 4; ++i)
1441  {
1442  if (!info->process_channel[i])
1443  continue;
1444 
1445  component = 0;
1446  mask = info->srcmask[i];
1447  for (j = 0; j < 4 && mask; ++j)
1448  {
1449  if (info->srcshift[i] < j * 8)
1450  component |= (col[j] & mask) << (j * 8 - info->srcshift[i]);
1451  else
1452  component |= (col[j] & mask) >> (info->srcshift[i] - j * 8);
1453  mask >>= 8;
1454  }
1455  out[i] = component;
1456  }
1457 }
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
GLuint const GLubyte mask[]
Definition: s_context.h:57
GLenum GLclampf GLint i
Definition: glfuncs.h:14
BOOL process_channel[4]
Definition: surface.c:1398
static FILE * out
Definition: regtests2xml.c:44
static HRESULT get_surface ( D3DRESOURCETYPE  type,
struct IDirect3DBaseTexture9 *  tex,
int  face,
UINT  level,
struct IDirect3DSurface9 **  surf 
)
static

Definition at line 527 of file surface.c.

Referenced by save_dds_texture_to_memory().

529 {
530  switch (type)
531  {
532  case D3DRTYPE_TEXTURE:
533  return IDirect3DTexture9_GetSurfaceLevel((IDirect3DTexture9*) tex, level, surf);
535  return IDirect3DCubeTexture9_GetCubeMapSurface((IDirect3DCubeTexture9*) tex, face, level, surf);
536  default:
537  ERR("Unexpected texture type\n");
538  return E_NOTIMPL;
539  }
540 }
GLint level
Definition: gl.h:1546
#define IDirect3DTexture9_GetSurfaceLevel(p, a, b)
Definition: d3d9.h:1033
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define IDirect3DCubeTexture9_GetCubeMapSurface(p, a, b, c)
Definition: d3d9.h:938
#define ERR(fmt,...)
Definition: debug.h:109
#define E_NOTIMPL
Definition: ddrawi.h:99
GLenum GLuint GLint GLenum face
Definition: glext.h:7025
static void init_argb_conversion_info ( const struct pixel_format_desc srcformat,
const struct pixel_format_desc destformat,
struct argb_conversion_info info 
)
static

Definition at line 1402 of file surface.c.

Referenced by convert_argb_pixels(), and point_filter_argb_pixels().

1403 {
1404  UINT i;
1405  ZeroMemory(info->process_channel, 4 * sizeof(BOOL));
1406  info->channelmask = 0;
1407 
1408  info->srcformat = srcformat;
1409  info->destformat = destformat;
1410 
1411  for(i = 0;i < 4;i++) {
1412  /* srcshift is used to extract the _relevant_ components */
1413  info->srcshift[i] = srcformat->shift[i] + max( srcformat->bits[i] - destformat->bits[i], 0);
1414 
1415  /* destshift is used to move the components to the correct position */
1416  info->destshift[i] = destformat->shift[i] + max(destformat->bits[i] - srcformat->bits[i], 0);
1417 
1418  info->srcmask[i] = ((1 << srcformat->bits[i]) - 1) << srcformat->shift[i];
1419  info->destmask[i] = ((1 << destformat->bits[i]) - 1) << destformat->shift[i];
1420 
1421  /* channelmask specifies bits which aren't used in the source format but in the destination one */
1422  if(destformat->bits[i]) {
1423  if(srcformat->bits[i]) info->process_channel[i] = TRUE;
1424  else info->channelmask |= info->destmask[i];
1425  }
1426  }
1427 }
#define max(a, b)
Definition: svc.c:63
#define TRUE
Definition: types.h:120
#define ZeroMemory
Definition: winbase.h:1621
const struct pixel_format_desc * srcformat
Definition: surface.c:1394
GLenum GLclampf GLint i
Definition: glfuncs.h:14
DWORD destshift[4]
Definition: surface.c:1396
BOOL process_channel[4]
Definition: surface.c:1398
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned int UINT
Definition: ndis.h:50
const struct pixel_format_desc * destformat
Definition: surface.c:1395
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 
)

Definition at line 664 of file surface.c.

666 {
667  HRESULT hr;
668  int face;
669  UINT mip_level;
670  UINT size;
671  RECT src_rect;
672  UINT src_pitch;
673  UINT mip_levels;
674  UINT mip_level_size;
675  IDirect3DSurface9 *surface;
676  const struct dds_header *header = src_data;
677  const BYTE *pixels = (BYTE *)(header + 1);
678 
679  if (src_info->ResourceType != D3DRTYPE_CUBETEXTURE)
680  return D3DXERR_INVALIDDATA;
681 
683  {
684  WARN("Only full cubemaps are supported\n");
685  return D3DXERR_INVALIDDATA;
686  }
687 
688  mip_levels = min(src_info->MipLevels, IDirect3DCubeTexture9_GetLevelCount(cube_texture));
689  for (face = D3DCUBEMAP_FACE_POSITIVE_X; face <= D3DCUBEMAP_FACE_NEGATIVE_Z; face++)
690  {
691  size = src_info->Width;
692  for (mip_level = 0; mip_level < src_info->MipLevels; mip_level++)
693  {
694  hr = calculate_dds_surface_size(src_info->Format, size, size, &src_pitch, &mip_level_size);
695  if (FAILED(hr)) return hr;
696 
697  /* if texture has fewer mip levels than DDS file, skip excessive mip levels */
698  if (mip_level < mip_levels)
699  {
700  SetRect(&src_rect, 0, 0, size, size);
701 
702  IDirect3DCubeTexture9_GetCubeMapSurface(cube_texture, face, mip_level, &surface);
703  hr = D3DXLoadSurfaceFromMemory(surface, palette, NULL, pixels, src_info->Format, src_pitch,
704  NULL, &src_rect, filter, color_key);
705  IDirect3DSurface9_Release(surface);
706  if (FAILED(hr)) return hr;
707  }
708 
709  pixels += mip_level_size;
710  size = max(1, size / 2);
711  }
712  }
713 
714  return D3D_OK;
715 }
#define IDirect3DSurface9_Release(p)
Definition: d3d9.h:622
#define max(a, b)
Definition: svc.c:63
#define IDirect3DCubeTexture9_GetLevelCount(p)
Definition: d3d9.h:932
DWORD caps2
Definition: surface.c:136
#define WARN(fmt,...)
Definition: debug.h:111
WORD face[3]
Definition: mesh.c:4743
D3DRESOURCETYPE ResourceType
Definition: d3dx9tex.h:83
UINT MipLevels
Definition: d3dx9tex.h:81
smooth NULL
Definition: ftsmooth.c:557
D3DFORMAT Format
Definition: d3dx9tex.h:82
#define DDS_CAPS2_CUBEMAP_ALL_FACES
Definition: surface.c:97
LONG HRESULT
Definition: typedefs.h:77
static HRESULT calculate_dds_surface_size(D3DFORMAT format, UINT width, UINT height, UINT *pitch, UINT *size)
Definition: surface.c:323
#define IDirect3DCubeTexture9_GetCubeMapSurface(p, a, b, c)
Definition: d3d9.h:938
unsigned char BYTE
Definition: ntddk_ex.h:96
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
#define D3D_OK
Definition: d3d.h:106
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)
Definition: surface.c:1837
GLsizeiptr size
Definition: glext.h:5919
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: gl.h:1546
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
struct CFHEADER header
Definition: fdi.c:109
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 
)
static

Definition at line 439 of file surface.c.

Referenced by D3DXLoadSurfaceFromFileInMemory().

442 {
443  UINT size;
444  UINT src_pitch;
445  const struct dds_header *header = src_data;
446  const BYTE *pixels = (BYTE *)(header + 1);
447 
448  if (src_info->ResourceType != D3DRTYPE_TEXTURE)
449  return D3DXERR_INVALIDDATA;
450 
451  if (FAILED(calculate_dds_surface_size(src_info->Format, src_info->Width, src_info->Height, &src_pitch, &size)))
452  return E_NOTIMPL;
453 
454  return D3DXLoadSurfaceFromMemory(dst_surface, dst_palette, dst_rect, pixels, src_info->Format,
455  src_pitch, NULL, src_rect, filter, color_key);
456 }
D3DRESOURCETYPE ResourceType
Definition: d3dx9tex.h:83
smooth NULL
Definition: ftsmooth.c:557
D3DFORMAT Format
Definition: d3dx9tex.h:82
static HRESULT calculate_dds_surface_size(D3DFORMAT format, UINT width, UINT height, UINT *pitch, UINT *size)
Definition: surface.c:323
unsigned char BYTE
Definition: ntddk_ex.h:96
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)
Definition: surface.c:1837
GLsizeiptr size
Definition: glext.h:5919
#define E_NOTIMPL
Definition: ddrawi.h:99
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: gl.h:1546
unsigned int UINT
Definition: ndis.h:50
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
struct CFHEADER header
Definition: fdi.c:109
HRESULT load_texture_from_dds ( IDirect3DTexture9 *  texture,
const void src_data,
const PALETTEENTRY palette,
DWORD  filter,
D3DCOLOR  color_key,
const D3DXIMAGE_INFO src_info,
unsigned int  skip_levels,
unsigned int loaded_miplevels 
)

Definition at line 607 of file surface.c.

Referenced by D3DXCreateTextureFromFileInMemoryEx().

610 {
611  HRESULT hr;
612  RECT src_rect;
613  UINT src_pitch;
614  UINT mip_level;
615  UINT mip_levels;
616  UINT mip_level_size;
617  UINT width, height;
618  IDirect3DSurface9 *surface;
619  const struct dds_header *header = src_data;
620  const BYTE *pixels = (BYTE *)(header + 1);
621 
622  /* Loading a cube texture as a simple texture is also supported
623  * (only first face texture is taken). Same with volume textures. */
624  if ((src_info->ResourceType != D3DRTYPE_TEXTURE)
625  && (src_info->ResourceType != D3DRTYPE_CUBETEXTURE)
626  && (src_info->ResourceType != D3DRTYPE_VOLUMETEXTURE))
627  {
628  WARN("Trying to load a %u resource as a 2D texture, returning failure.\n", src_info->ResourceType);
629  return D3DXERR_INVALIDDATA;
630  }
631 
632  width = src_info->Width;
633  height = src_info->Height;
634  mip_levels = min(src_info->MipLevels, IDirect3DTexture9_GetLevelCount(texture));
635  if (src_info->ResourceType == D3DRTYPE_VOLUMETEXTURE)
636  mip_levels = 1;
637  for (mip_level = 0; mip_level < mip_levels + skip_levels; ++mip_level)
638  {
639  hr = calculate_dds_surface_size(src_info->Format, width, height, &src_pitch, &mip_level_size);
640  if (FAILED(hr)) return hr;
641 
642  if (mip_level >= skip_levels)
643  {
644  SetRect(&src_rect, 0, 0, width, height);
645 
646  IDirect3DTexture9_GetSurfaceLevel(texture, mip_level - skip_levels, &surface);
647  hr = D3DXLoadSurfaceFromMemory(surface, palette, NULL, pixels, src_info->Format, src_pitch,
648  NULL, &src_rect, filter, color_key);
649  IDirect3DSurface9_Release(surface);
650  if (FAILED(hr))
651  return hr;
652  }
653 
654  pixels += mip_level_size;
655  width = max(1, width / 2);
656  height = max(1, height / 2);
657  }
658 
659  *loaded_miplevels = mip_levels - skip_levels;
660 
661  return D3D_OK;
662 }
#define IDirect3DSurface9_Release(p)
Definition: d3d9.h:622
#define max(a, b)
Definition: svc.c:63
#define IDirect3DTexture9_GetSurfaceLevel(p, a, b)
Definition: d3d9.h:1033
#define WARN(fmt,...)
Definition: debug.h:111
#define IDirect3DTexture9_GetLevelCount(p)
Definition: d3d9.h:1027
D3DRESOURCETYPE ResourceType
Definition: d3dx9tex.h:83
UINT MipLevels
Definition: d3dx9tex.h:81
smooth NULL
Definition: ftsmooth.c:557
GLint GLint GLsizei width
Definition: gl.h:1546
D3DFORMAT Format
Definition: d3dx9tex.h:82
GLenum GLuint texture
Definition: glext.h:6295
LONG HRESULT
Definition: typedefs.h:77
static HRESULT calculate_dds_surface_size(D3DFORMAT format, UINT width, UINT height, UINT *pitch, UINT *size)
Definition: surface.c:323
unsigned char BYTE
Definition: ntddk_ex.h:96
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
#define D3D_OK
Definition: d3d.h:106
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)
Definition: surface.c:1837
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: gl.h:1546
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
struct CFHEADER header
Definition: fdi.c:109
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 
)

Definition at line 589 of file surface.c.

Referenced by D3DXLoadVolumeFromFileInMemory().

592 {
593  UINT row_pitch, slice_pitch;
594  const struct dds_header *header = src_data;
595  const BYTE *pixels = (BYTE *)(header + 1);
596 
597  if (src_info->ResourceType != D3DRTYPE_VOLUMETEXTURE)
598  return D3DXERR_INVALIDDATA;
599 
600  if (FAILED(calculate_dds_surface_size(src_info->Format, src_info->Width, src_info->Height, &row_pitch, &slice_pitch)))
601  return E_NOTIMPL;
602 
603  return D3DXLoadVolumeFromMemory(dst_volume, dst_palette, dst_box, pixels, src_info->Format,
604  row_pitch, slice_pitch, NULL, src_box, filter, color_key);
605 }
D3DRESOURCETYPE ResourceType
Definition: d3dx9tex.h:83
smooth NULL
Definition: ftsmooth.c:557
D3DFORMAT Format
Definition: d3dx9tex.h:82
static HRESULT calculate_dds_surface_size(D3DFORMAT format, UINT width, UINT height, UINT *pitch, UINT *size)
Definition: surface.c:323
unsigned char BYTE
Definition: ntddk_ex.h:96
HRESULT WINAPI D3DXLoadVolumeFromMemory(IDirect3DVolume9 *dst_volume, const PALETTEENTRY *dst_palette, const D3DBOX *dst_box, const void *src_memory, D3DFORMAT src_format, UINT src_row_pitch, UINT src_slice_pitch, const PALETTEENTRY *src_palette, const D3DBOX *src_box, DWORD filter, D3DCOLOR color_key)
Definition: volume.c:80
#define E_NOTIMPL
Definition: ddrawi.h:99
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: gl.h:1546
unsigned int UINT
Definition: ndis.h:50
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
struct CFHEADER header
Definition: fdi.c:109
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 
)

Definition at line 717 of file surface.c.

Referenced by D3DXCreateVolumeTextureFromFileInMemoryEx().

719 {
720  HRESULT hr;
721  UINT mip_level;
722  UINT mip_levels;
723  UINT src_slice_pitch;
724  UINT src_row_pitch;
725  D3DBOX src_box;
727  IDirect3DVolume9 *volume;
728  const struct dds_header *header = src_data;
729  const BYTE *pixels = (BYTE *)(header + 1);
730 
731  if (src_info->ResourceType != D3DRTYPE_VOLUMETEXTURE)
732  return D3DXERR_INVALIDDATA;
733 
734  width = src_info->Width;
735  height = src_info->Height;
736  depth = src_info->Depth;
737  mip_levels = min(src_info->MipLevels, IDirect3DVolumeTexture9_GetLevelCount(volume_texture));
738 
739  for (mip_level = 0; mip_level < mip_levels; mip_level++)
740  {
741  hr = calculate_dds_surface_size(src_info->Format, width, height, &src_row_pitch, &src_slice_pitch);
742  if (FAILED(hr)) return hr;
743 
744  hr = IDirect3DVolumeTexture9_GetVolumeLevel(volume_texture, mip_level, &volume);
745  if (FAILED(hr)) return hr;
746 
747  src_box.Left = 0;
748  src_box.Top = 0;
749  src_box.Right = width;
750  src_box.Bottom = height;
751  src_box.Front = 0;
752  src_box.Back = depth;
753 
754  hr = D3DXLoadVolumeFromMemory(volume, palette, NULL, pixels, src_info->Format,
755  src_row_pitch, src_slice_pitch, NULL, &src_box, filter, color_key);
756 
757  IDirect3DVolume9_Release(volume);
758  if (FAILED(hr)) return hr;
759 
760  pixels += depth * src_slice_pitch;
761  width = max(1, width / 2);
762  height = max(1, height / 2);
763  depth = max(1, depth / 2);
764  }
765 
766  return D3D_OK;
767 }
#define max(a, b)
Definition: svc.c:63
#define IDirect3DVolumeTexture9_GetLevelCount(p)
Definition: d3d9.h:1122
D3DRESOURCETYPE ResourceType
Definition: d3dx9tex.h:83
UINT MipLevels
Definition: d3dx9tex.h:81
UINT Back
Definition: d3d8types.h:1016
smooth NULL
Definition: ftsmooth.c:557
UINT Bottom
Definition: d3d8types.h:1014
GLint GLint GLsizei width
Definition: gl.h:1546
D3DFORMAT Format
Definition: d3dx9tex.h:82
UINT Top
Definition: d3d8types.h:1012
LONG HRESULT
Definition: typedefs.h:77
UINT Left
Definition: d3d8types.h:1011
static HRESULT calculate_dds_surface_size(D3DFORMAT format, UINT width, UINT height, UINT *pitch, UINT *size)
Definition: surface.c:323
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
#define IDirect3DVolume9_Release(p)
Definition: d3d9.h:383
unsigned char BYTE
Definition: ntddk_ex.h:96
#define D3D_OK
Definition: d3d.h:106
HRESULT WINAPI D3DXLoadVolumeFromMemory(IDirect3DVolume9 *dst_volume, const PALETTEENTRY *dst_palette, const D3DBOX *dst_box, const void *src_memory, D3DFORMAT src_format, UINT src_row_pitch, UINT src_slice_pitch, const PALETTEENTRY *src_palette, const D3DBOX *src_box, DWORD filter, D3DCOLOR color_key)
Definition: volume.c:80
UINT Front
Definition: d3d8types.h:1015
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: gl.h:1546
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
#define IDirect3DVolumeTexture9_GetVolumeLevel(p, a, b)
Definition: d3d9.h:1128
UINT Right
Definition: d3d8types.h:1013
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
struct CFHEADER header
Definition: fdi.c:109
static DWORD make_argb_color ( const struct argb_conversion_info info,
const DWORD in 
)
static

Definition at line 1465 of file surface.c.

Referenced by convert_argb_pixels(), and point_filter_argb_pixels().

1466 {
1467  UINT i;
1468  DWORD val = 0;
1469 
1470  for(i = 0;i < 4;i++) {
1471  if(info->process_channel[i]) {
1472  /* necessary to make sure that e.g. an X4R4G4B4 white maps to an R8G8B8 white instead of 0xf0f0f0 */
1473  signed int shift;
1474  for(shift = info->destshift[i]; shift > info->destformat->shift[i]; shift -= info->srcformat->bits[i]) val |= in[i] << shift;
1475  val |= (in[i] >> (info->destformat->shift[i] - shift)) << info->destformat->shift[i];
1476  }
1477  }
1478  val |= info->channelmask; /* new channels are set to their maximal value */
1479  return val;
1480 }
#define shift
Definition: input.c:1594
const struct pixel_format_desc * srcformat
Definition: surface.c:1394
DWORD DWORD
Definition: winlogon.h:75
GLenum GLclampf GLint i
Definition: glfuncs.h:14
DWORD destshift[4]
Definition: surface.c:1396
BOOL process_channel[4]
Definition: surface.c:1398
GLuint GLfloat * val
Definition: glext.h:7180
GLfloat CONST GLvector4f * in
Definition: m_xform.h:122
unsigned int UINT
Definition: ndis.h:50
const struct pixel_format_desc * destformat
Definition: surface.c:1395
void point_filter_argb_pixels ( const BYTE src,
UINT  src_row_pitch,
UINT  src_slice_pitch,
const struct volume src_size,
const struct pixel_format_desc src_format,
BYTE dst,
UINT  dst_row_pitch,
UINT  dst_slice_pitch,
const struct volume dst_size,
const struct pixel_format_desc dst_format,
D3DCOLOR  color_key,
const PALETTEENTRY palette 
)

Definition at line 1697 of file surface.c.

Referenced by D3DXLoadSurfaceFromMemory(), and D3DXLoadVolumeFromMemory().

1701 {
1702  struct argb_conversion_info conv_info, ck_conv_info;
1703  const struct pixel_format_desc *ck_format = NULL;
1704  DWORD channels[4];
1705  UINT x, y, z;
1706 
1707  ZeroMemory(channels, sizeof(channels));
1708  init_argb_conversion_info(src_format, dst_format, &conv_info);
1709 
1710  if (color_key)
1711  {
1712  /* Color keys are always represented in D3DFMT_A8R8G8B8 format. */
1713  ck_format = get_format_info(D3DFMT_A8R8G8B8);
1714  init_argb_conversion_info(src_format, ck_format, &ck_conv_info);
1715  }
1716 
1717  for (z = 0; z < dst_size->depth; z++)
1718  {
1719  BYTE *dst_slice_ptr = dst + z * dst_slice_pitch;
1720  const BYTE *src_slice_ptr = src + src_slice_pitch * (z * src_size->depth / dst_size->depth);
1721 
1722  for (y = 0; y < dst_size->height; y++)
1723  {
1724  BYTE *dst_ptr = dst_slice_ptr + y * dst_row_pitch;
1725  const BYTE *src_row_ptr = src_slice_ptr + src_row_pitch * (y * src_size->height / dst_size->height);
1726 
1727  for (x = 0; x < dst_size->width; x++)
1728  {
1729  const BYTE *src_ptr = src_row_ptr + (x * src_size->width / dst_size->width) * src_format->bytes_per_pixel;
1730 
1731  if (!src_format->to_rgba && !dst_format->from_rgba
1732  && src_format->type == dst_format->type
1733  && src_format->bytes_per_pixel <= 4 && dst_format->bytes_per_pixel <= 4)
1734  {
1735  DWORD val;
1736 
1737  get_relevant_argb_components(&conv_info, src_ptr, channels);
1738  val = make_argb_color(&conv_info, channels);
1739 
1740  if (color_key)
1741  {
1742  DWORD ck_pixel;
1743 
1744  get_relevant_argb_components(&ck_conv_info, src_ptr, channels);
1745  ck_pixel = make_argb_color(&ck_conv_info, channels);
1746  if (ck_pixel == color_key)
1747  val &= ~conv_info.destmask[0];
1748  }
1749  memcpy(dst_ptr, &val, dst_format->bytes_per_pixel);
1750  }
1751  else
1752  {
1753  struct vec4 color, tmp;
1754 
1755  format_to_vec4(src_format, src_ptr, &color);
1756  if (src_format->to_rgba)
1757  src_format->to_rgba(&color, &tmp, palette);
1758  else
1759  tmp = color;
1760 
1761  if (ck_format)
1762  {
1763  DWORD ck_pixel;
1764 
1765  format_from_vec4(ck_format, &tmp, (BYTE *)&ck_pixel);
1766  if (ck_pixel == color_key)
1767  tmp.w = 0.0f;
1768  }
1769 
1770  if (dst_format->from_rgba)
1771  dst_format->from_rgba(&tmp, &color);
1772  else
1773  color = tmp;
1774 
1775  format_from_vec4(dst_format, &color, dst_ptr);
1776  }
1777 
1778  dst_ptr += dst_format->bytes_per_pixel;
1779  }
1780  }
1781  }
1782 }
#define ZeroMemory
Definition: winbase.h:1621
int This channels
Definition: rdpsnd_libao.c:37
DWORD DWORD
Definition: winlogon.h:75
GLuint const GLubyte GLvoid * src
Definition: s_context.h:57
GLuint color
Definition: glext.h:6243
GLdouble GLdouble z
Definition: glext.h:5874
smooth NULL
Definition: ftsmooth.c:557
GLuint GLfloat * val
Definition: glext.h:7180
if(!(yy_init))
Definition: macro.lex.yy.c:704
enum format_type type
const struct pixel_format_desc * get_format_info(D3DFORMAT format) DECLSPEC_HIDDEN
Definition: util.c:207
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: ntddk_ex.h:96
static void format_from_vec4(const struct pixel_format_desc *format, const struct vec4 *src, BYTE *dst)
Definition: surface.c:1513
static void init_argb_conversion_info(const struct pixel_format_desc *srcformat, const struct pixel_format_desc *destformat, struct argb_conversion_info *info)
Definition: surface.c:1402
unsigned int UINT
Definition: ndis.h:50
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
void(* from_rgba)(const struct vec4 *src, struct vec4 *dst)
static void get_relevant_argb_components(const struct argb_conversion_info *info, const BYTE *col, DWORD *out)
Definition: surface.c:1435
static void format_to_vec4(const struct pixel_format_desc *format, const BYTE *src, struct vec4 *dst)
Definition: surface.c:1483
INT INT y
Definition: msvc.h:62
void(* to_rgba)(const struct vec4 *src, struct vec4 *dst, const PALETTEENTRY *palette)
static DWORD make_argb_color(const struct argb_conversion_info *info, const DWORD *in)
Definition: surface.c:1465
INT x
Definition: msvc.h:62
static HRESULT save_dds_surface_to_memory ( ID3DXBuffer **  dst_buffer,
IDirect3DSurface9 *  src_surface,
const RECT src_rect 
)
static

Definition at line 458 of file surface.c.

Referenced by D3DXSaveSurfaceToFileInMemory(), and save_dds_texture_to_memory().

459 {
460  HRESULT hr;
461  UINT dst_pitch, surface_size, file_size;
462  D3DSURFACE_DESC src_desc;
463  D3DLOCKED_RECT locked_rect;
465  struct dds_header *header;
466  BYTE *pixels;
467  struct volume volume;
468  const struct pixel_format_desc *pixel_format;
469 
470  if (src_rect)
471  {
472  FIXME("Saving a part of a surface to a DDS file is not implemented yet\n");
473  return E_NOTIMPL;
474  }
475 
476  hr = IDirect3DSurface9_GetDesc(src_surface, &src_desc);
477  if (FAILED(hr)) return hr;
478 
479  pixel_format = get_format_info(src_desc.Format);
480  if (pixel_format->type == FORMAT_UNKNOWN) return E_NOTIMPL;
481 
482  file_size = calculate_dds_file_size(src_desc.Format, src_desc.Width, src_desc.Height, 1, 1, 1);
483 
484  hr = calculate_dds_surface_size(src_desc.Format, src_desc.Width, src_desc.Height, &dst_pitch, &surface_size);
485  if (FAILED(hr)) return hr;
486 
487  hr = D3DXCreateBuffer(file_size, &buffer);
488  if (FAILED(hr)) return hr;
489 
490  header = ID3DXBuffer_GetBufferPointer(buffer);
491  pixels = (BYTE *)(header + 1);
492 
493  memset(header, 0, sizeof(*header));
494  header->signature = MAKEFOURCC('D','D','S',' ');
495  /* The signature is not really part of the DDS header */
496  header->size = sizeof(*header) - FIELD_OFFSET(struct dds_header, size);
498  header->height = src_desc.Height;
499  header->width = src_desc.Width;
500  header->caps = DDS_CAPS_TEXTURE;
501  hr = d3dformat_to_dds_pixel_format(&header->pixel_format, src_desc.Format);
502  if (FAILED(hr))
503  {
504  ID3DXBuffer_Release(buffer);
505  return hr;
506  }
507 
508  hr = IDirect3DSurface9_LockRect(src_surface, &locked_rect, NULL, D3DLOCK_READONLY);
509  if (FAILED(hr))
510  {
511  ID3DXBuffer_Release(buffer);
512  return hr;
513  }
514 
515  volume.width = src_desc.Width;
516  volume.height = src_desc.Height;
517  volume.depth = 1;
518  copy_pixels(locked_rect.pBits, locked_rect.Pitch, 0, pixels, dst_pitch, 0,
519  &volume, pixel_format);
520 
521  IDirect3DSurface9_UnlockRect(src_surface);
522 
523  *dst_buffer = buffer;
524  return D3D_OK;
525 }
#define DDS_CAPS
Definition: surface.c:75
D3DFORMAT Format
Definition: d3d8types.h:1170
#define DDS_CAPS_TEXTURE
Definition: surface.c:86
GLuint buffer
Definition: glext.h:5915
DWORD flags
Definition: surface.c:127
DWORD width
Definition: surface.c:129
DWORD height
Definition: surface.c:128
#define FIXME(fmt,...)
Definition: debug.h:110
#define DDS_PIXELFORMAT
Definition: surface.c:79
DWORD size
Definition: surface.c:126
smooth NULL
Definition: ftsmooth.c:557
DWORD signature
Definition: surface.c:125
struct ID3DXBuffer ID3DXBuffer
Definition: d3dx8core.h:51
LONG HRESULT
Definition: typedefs.h:77
static HRESULT calculate_dds_surface_size(D3DFORMAT format, UINT width, UINT height, UINT *pitch, UINT *size)
Definition: surface.c:323
enum format_type type
const struct pixel_format_desc * get_format_info(D3DFORMAT format) DECLSPEC_HIDDEN
Definition: util.c:207
static UINT calculate_dds_file_size(D3DFORMAT format, UINT width, UINT height, UINT depth, UINT miplevels, UINT faces)
Definition: surface.c:346
#define IDirect3DSurface9_GetDesc(p, a)
Definition: d3d9.h:634
unsigned char BYTE
Definition: ntddk_ex.h:96
#define D3D_OK
Definition: d3d.h:106
#define ID3DXBuffer_Release(p)
Definition: d3dx9core.h:83
GLsizeiptr size
Definition: glext.h:5919
#define DDS_WIDTH
Definition: surface.c:77
#define E_NOTIMPL
Definition: ddrawi.h:99
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: gl.h:1546
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
unsigned int UINT
Definition: ndis.h:50
struct dds_pixel_format pixel_format
Definition: surface.c:134
#define IDirect3DSurface9_UnlockRect(p)
Definition: d3d9.h:636
#define DDS_HEIGHT
Definition: surface.c:76
static HRESULT d3dformat_to_dds_pixel_format(struct dds_pixel_format *pixel_format, D3DFORMAT d3dformat)
Definition: surface.c:288
#define IDirect3DSurface9_LockRect(p, a, b, c)
Definition: d3d9.h:635
DWORD caps
Definition: surface.c:135
#define D3DLOCK_READONLY
Definition: d3d8types.h:69
#define memset(x, y, z)
Definition: compat.h:39
#define MAKEFOURCC(ch0, ch1, ch2, ch3)
Definition: dmdls.h:24
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)
Definition: surface.c:1563
HRESULT WINAPI D3DXCreateBuffer(DWORD size, ID3DXBuffer **buffer)
Definition: core.c:124
struct CFHEADER header
Definition: fdi.c:109
#define ID3DXBuffer_GetBufferPointer(p)
Definition: d3dx9core.h:85
#define file_size(inode)
Definition: reiserfs_fs.h:1869
HRESULT save_dds_texture_to_memory ( ID3DXBuffer **  dst_buffer,
IDirect3DBaseTexture9 *  src_texture,
const PALETTEENTRY src_palette 
)

Definition at line 542 of file surface.c.

Referenced by D3DXSaveTextureToFileInMemory().

543 {
544  HRESULT hr;
546  UINT mip_levels;
547  IDirect3DSurface9 *surface;
548 
549  type = IDirect3DBaseTexture9_GetType(src_texture);
550 
551  if ((type != D3DRTYPE_TEXTURE) && (type != D3DRTYPE_CUBETEXTURE) && (type != D3DRTYPE_VOLUMETEXTURE))
552  return D3DERR_INVALIDCALL;
553 
554  if (type == D3DRTYPE_CUBETEXTURE)
555  {
556  FIXME("Cube texture not supported yet\n");
557  return E_NOTIMPL;
558  }
559  else if (type == D3DRTYPE_VOLUMETEXTURE)
560  {
561  FIXME("Volume texture not supported yet\n");
562  return E_NOTIMPL;
563  }
564 
565  mip_levels = IDirect3DTexture9_GetLevelCount(src_texture);
566 
567  if (mip_levels > 1)
568  {
569  FIXME("Mipmap not supported yet\n");
570  return E_NOTIMPL;
571  }
572 
573  if (src_palette)
574  {
575  FIXME("Saving surfaces with palettized pixel formats not implemented yet\n");
576  return E_NOTIMPL;
577  }
578 
579  hr = get_surface(type, src_texture, D3DCUBEMAP_FACE_POSITIVE_X, 0, &surface);
580 
581  if (SUCCEEDED(hr))
582  {
583  hr = save_dds_surface_to_memory(dst_buffer, surface, NULL);
584  IDirect3DSurface9_Release(surface);
585  }
586 
587  return hr;
588 }
#define IDirect3DSurface9_Release(p)
Definition: d3d9.h:622
#define D3DERR_INVALIDCALL
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define IDirect3DTexture9_GetLevelCount(p)
Definition: d3d9.h:1027
static HRESULT get_surface(D3DRESOURCETYPE type, struct IDirect3DBaseTexture9 *tex, int face, UINT level, struct IDirect3DSurface9 **surf)
Definition: surface.c:527
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:557
#define IDirect3DBaseTexture9_GetType(p)
Definition: d3d9.h:844
LONG HRESULT
Definition: typedefs.h:77
#define E_NOTIMPL
Definition: ddrawi.h:99
unsigned int UINT
Definition: ndis.h:50