ReactOS  0.4.13-dev-235-g7373cb3
surface.c File Reference
#include "config.h"
#include "wine/port.h"
#include "d3dx9_private.h"
#include "initguid.h"
#include "ole2.h"
#include "wincodec.h"
#include "wine/wined3d.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_BUMPLUMINANCE   0x40000
 
#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

 WINE_DEFAULT_DEBUG_CHANNEL (d3dx)
 
 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_bump_luminance_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

◆ DDS_CAPS

#define DDS_CAPS   0x1

Definition at line 81 of file surface.c.

◆ DDS_CAPS2_CUBEMAP

#define DDS_CAPS2_CUBEMAP   0x200

Definition at line 96 of file surface.c.

◆ DDS_CAPS2_CUBEMAP_ALL_FACES

#define DDS_CAPS2_CUBEMAP_ALL_FACES
Value:
#define DDS_CAPS2_CUBEMAP_NEGATIVEX
Definition: surface.c:98
#define DDS_CAPS2_CUBEMAP_POSITIVEY
Definition: surface.c:99
#define DDS_CAPS2_CUBEMAP_NEGATIVEZ
Definition: surface.c:102
#define DDS_CAPS2_CUBEMAP_NEGATIVEY
Definition: surface.c:100
#define DDS_CAPS2_CUBEMAP_POSITIVEX
Definition: surface.c:97
#define DDS_CAPS2_CUBEMAP_POSITIVEZ
Definition: surface.c:101

Definition at line 103 of file surface.c.

◆ DDS_CAPS2_CUBEMAP_NEGATIVEX

#define DDS_CAPS2_CUBEMAP_NEGATIVEX   0x800

Definition at line 98 of file surface.c.

◆ DDS_CAPS2_CUBEMAP_NEGATIVEY

#define DDS_CAPS2_CUBEMAP_NEGATIVEY   0x2000

Definition at line 100 of file surface.c.

◆ DDS_CAPS2_CUBEMAP_NEGATIVEZ

#define DDS_CAPS2_CUBEMAP_NEGATIVEZ   0x8000

Definition at line 102 of file surface.c.

◆ DDS_CAPS2_CUBEMAP_POSITIVEX

#define DDS_CAPS2_CUBEMAP_POSITIVEX   0x400

Definition at line 97 of file surface.c.

◆ DDS_CAPS2_CUBEMAP_POSITIVEY

#define DDS_CAPS2_CUBEMAP_POSITIVEY   0x1000

Definition at line 99 of file surface.c.

◆ DDS_CAPS2_CUBEMAP_POSITIVEZ

#define DDS_CAPS2_CUBEMAP_POSITIVEZ   0x4000

Definition at line 101 of file surface.c.

◆ DDS_CAPS2_VOLUME

#define DDS_CAPS2_VOLUME   0x200000

Definition at line 106 of file surface.c.

◆ DDS_CAPS_COMPLEX

#define DDS_CAPS_COMPLEX   0x8

Definition at line 91 of file surface.c.

◆ DDS_CAPS_MIPMAP

#define DDS_CAPS_MIPMAP   0x400000

Definition at line 93 of file surface.c.

◆ DDS_CAPS_TEXTURE

#define DDS_CAPS_TEXTURE   0x1000

Definition at line 92 of file surface.c.

◆ DDS_DEPTH

#define DDS_DEPTH   0x800000

Definition at line 88 of file surface.c.

◆ DDS_HEIGHT

#define DDS_HEIGHT   0x2

Definition at line 82 of file surface.c.

◆ DDS_LINEARSIZE

#define DDS_LINEARSIZE   0x80000

Definition at line 87 of file surface.c.

◆ DDS_MIPMAPCOUNT

#define DDS_MIPMAPCOUNT   0x20000

Definition at line 86 of file surface.c.

◆ DDS_PF_ALPHA

#define DDS_PF_ALPHA   0x1

Definition at line 109 of file surface.c.

◆ DDS_PF_ALPHA_ONLY

#define DDS_PF_ALPHA_ONLY   0x2

Definition at line 110 of file surface.c.

◆ DDS_PF_BUMPDUDV

#define DDS_PF_BUMPDUDV   0x80000

Definition at line 116 of file surface.c.

◆ DDS_PF_BUMPLUMINANCE

#define DDS_PF_BUMPLUMINANCE   0x40000

Definition at line 115 of file surface.c.

◆ DDS_PF_FOURCC

#define DDS_PF_FOURCC   0x4

Definition at line 111 of file surface.c.

◆ DDS_PF_LUMINANCE

#define DDS_PF_LUMINANCE   0x20000

Definition at line 114 of file surface.c.

◆ DDS_PF_RGB

#define DDS_PF_RGB   0x40

Definition at line 112 of file surface.c.

◆ DDS_PF_YUV

#define DDS_PF_YUV   0x200

Definition at line 113 of file surface.c.

◆ DDS_PITCH

#define DDS_PITCH   0x8

Definition at line 84 of file surface.c.

◆ DDS_PIXELFORMAT

#define DDS_PIXELFORMAT   0x1000

Definition at line 85 of file surface.c.

◆ DDS_WIDTH

#define DDS_WIDTH   0x4

Definition at line 83 of file surface.c.

Typedef Documentation

◆ dxtn_conversion_func

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 1822 of file surface.c.

Function Documentation

◆ calculate_dds_file_size()

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

Definition at line 366 of file surface.c.

368 {
369  UINT i, file_size = 0;
370 
371  for (i = 0; i < miplevels; i++)
372  {
373  UINT pitch, size = 0;
375  size *= depth;
376  file_size += size;
377  width = max(1, width / 2);
378  height = max(1, height / 2);
379  depth = max(1, depth / 2);
380  }
381 
382  file_size *= faces;
383  file_size += sizeof(struct dds_header);
384  return file_size;
385 }
GLint GLint GLsizei width
Definition: gl.h:1546
#define max(a, b)
Definition: svc.c:63
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLsizei GLenum const GLvoid GLsizei GLenum 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 const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizeiptr size
Definition: glext.h:5919
static HRESULT calculate_dds_surface_size(D3DFORMAT format, UINT width, UINT height, UINT *pitch, UINT *size)
Definition: surface.c:343
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
unsigned int UINT
Definition: ndis.h:50
#define file_size(inode)
Definition: reiserfs_fs.h:1869

Referenced by get_image_info_from_dds(), and save_dds_surface_to_memory().

◆ calculate_dds_surface_size()

static HRESULT calculate_dds_surface_size ( D3DFORMAT  format,
UINT  width,
UINT  height,
UINT pitch,
UINT size 
)
static

Definition at line 343 of file surface.c.

345 {
346  const struct pixel_format_desc *format_desc = get_format_info(format);
347  if (format_desc->type == FORMAT_UNKNOWN)
348  return E_NOTIMPL;
349 
350  if (format_desc->block_width != 1 || format_desc->block_height != 1)
351  {
352  *pitch = format_desc->block_byte_count
353  * max(1, (width + format_desc->block_width - 1) / format_desc->block_width);
354  *size = *pitch
355  * max(1, (height + format_desc->block_height - 1) / format_desc->block_height);
356  }
357  else
358  {
359  *pitch = width * format_desc->bytes_per_pixel;
360  *size = *pitch * height;
361  }
362 
363  return D3D_OK;
364 }
GLint GLint GLsizei width
Definition: gl.h:1546
#define max(a, b)
Definition: svc.c:63
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLsizeiptr size
Definition: glext.h:5919
enum format_type type
Definition: d3dx9_private.h:65
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
#define D3D_OK
Definition: d3d.h:106
#define E_NOTIMPL
Definition: ddrawi.h:99
const struct pixel_format_desc * get_format_info(D3DFORMAT format) DECLSPEC_HIDDEN
Definition: util.c:213

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().

◆ convert_argb_pixels()

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 1632 of file surface.c.

1636 {
1637  struct argb_conversion_info conv_info, ck_conv_info;
1638  const struct pixel_format_desc *ck_format = NULL;
1639  DWORD channels[4];
1640  UINT min_width, min_height, min_depth;
1641  UINT x, y, z;
1642 
1643  ZeroMemory(channels, sizeof(channels));
1644  init_argb_conversion_info(src_format, dst_format, &conv_info);
1645 
1646  min_width = min(src_size->width, dst_size->width);
1647  min_height = min(src_size->height, dst_size->height);
1648  min_depth = min(src_size->depth, dst_size->depth);
1649 
1650  if (color_key)
1651  {
1652  /* Color keys are always represented in D3DFMT_A8R8G8B8 format. */
1653  ck_format = get_format_info(D3DFMT_A8R8G8B8);
1654  init_argb_conversion_info(src_format, ck_format, &ck_conv_info);
1655  }
1656 
1657  for (z = 0; z < min_depth; z++) {
1658  const BYTE *src_slice_ptr = src + z * src_slice_pitch;
1659  BYTE *dst_slice_ptr = dst + z * dst_slice_pitch;
1660 
1661  for (y = 0; y < min_height; y++) {
1662  const BYTE *src_ptr = src_slice_ptr + y * src_row_pitch;
1663  BYTE *dst_ptr = dst_slice_ptr + y * dst_row_pitch;
1664 
1665  for (x = 0; x < min_width; x++) {
1666  if (!src_format->to_rgba && !dst_format->from_rgba
1667  && src_format->type == dst_format->type
1668  && src_format->bytes_per_pixel <= 4 && dst_format->bytes_per_pixel <= 4)
1669  {
1670  DWORD val;
1671 
1672  get_relevant_argb_components(&conv_info, src_ptr, channels);
1673  val = make_argb_color(&conv_info, channels);
1674 
1675  if (color_key)
1676  {
1677  DWORD ck_pixel;
1678 
1679  get_relevant_argb_components(&ck_conv_info, src_ptr, channels);
1680  ck_pixel = make_argb_color(&ck_conv_info, channels);
1681  if (ck_pixel == color_key)
1682  val &= ~conv_info.destmask[0];
1683  }
1684  memcpy(dst_ptr, &val, dst_format->bytes_per_pixel);
1685  }
1686  else
1687  {
1688  struct vec4 color, tmp;
1689 
1690  format_to_vec4(src_format, src_ptr, &color);
1691  if (src_format->to_rgba)
1692  src_format->to_rgba(&color, &tmp, palette);
1693  else
1694  tmp = color;
1695 
1696  if (ck_format)
1697  {
1698  DWORD ck_pixel;
1699 
1700  format_from_vec4(ck_format, &tmp, (BYTE *)&ck_pixel);
1701  if (ck_pixel == color_key)
1702  tmp.w = 0.0f;
1703  }
1704 
1705  if (dst_format->from_rgba)
1706  dst_format->from_rgba(&tmp, &color);
1707  else
1708  color = tmp;
1709 
1710  format_from_vec4(dst_format, &color, dst_ptr);
1711  }
1712 
1713  src_ptr += src_format->bytes_per_pixel;
1714  dst_ptr += dst_format->bytes_per_pixel;
1715  }
1716 
1717  if (src_size->width < dst_size->width) /* black out remaining pixels */
1718  memset(dst_ptr, 0, dst_format->bytes_per_pixel * (dst_size->width - src_size->width));
1719  }
1720 
1721  if (src_size->height < dst_size->height) /* black out remaining pixels */
1722  memset(dst + src_size->height * dst_row_pitch, 0, dst_row_pitch * (dst_size->height - src_size->height));
1723  }
1724  if (src_size->depth < dst_size->depth) /* black out remaining pixels */
1725  memset(dst + src_size->depth * dst_slice_pitch, 0, dst_slice_pitch * (dst_size->depth - src_size->depth));
1726 }
UINT width
Definition: d3dx9_private.h:42
static const char * dst_format
Definition: dib.c:1133
#define ZeroMemory
Definition: winbase.h:1635
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
int This channels
Definition: rdpsnd_libao.c:37
void(* to_rgba)(const struct vec4 *src, struct vec4 *dst, const PALETTEENTRY *palette)
Definition: d3dx9_private.h:67
GLuint color
Definition: glext.h:6243
GLdouble GLdouble z
Definition: glext.h:5874
UINT height
Definition: d3dx9_private.h:43
smooth NULL
Definition: ftsmooth.c:416
GLuint GLfloat * val
Definition: glext.h:7180
UINT depth
Definition: d3dx9_private.h:44
enum format_type type
Definition: d3dx9_private.h:65
unsigned long DWORD
Definition: ntddk_ex.h:95
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
GLenum src
Definition: glext.h:6340
static HPALETTE palette
Definition: clipboard.c:1345
static void format_from_vec4(const struct pixel_format_desc *format, const struct vec4 *src, BYTE *dst)
Definition: surface.c:1551
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:1440
GLenum GLenum dst
Definition: glext.h:6340
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
static void get_relevant_argb_components(const struct argb_conversion_info *info, const BYTE *col, DWORD *out)
Definition: surface.c:1473
const struct pixel_format_desc * get_format_info(D3DFORMAT format) DECLSPEC_HIDDEN
Definition: util.c:213
static void format_to_vec4(const struct pixel_format_desc *format, const BYTE *src, struct vec4 *dst)
Definition: surface.c:1521
#define memset(x, y, z)
Definition: compat.h:39
static DWORD make_argb_color(const struct argb_conversion_info *info, const DWORD *in)
Definition: surface.c:1503

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

◆ convert_dib_to_bmp()

static BOOL convert_dib_to_bmp ( void **  data,
UINT size 
)
static

Definition at line 789 of file surface.c.

790 {
791  ULONG header_size;
792  ULONG count = 0;
793  ULONG offset;
795  BYTE *new_data;
796  UINT new_size;
797 
798  if ((*size < 4) || (*size < (header_size = *(ULONG*)*data)))
799  return FALSE;
800 
801  if ((header_size == sizeof(BITMAPINFOHEADER)) ||
802  (header_size == sizeof(BITMAPV4HEADER)) ||
803  (header_size == sizeof(BITMAPV5HEADER)) ||
804  (header_size == 64 /* sizeof(BITMAPCOREHEADER2) */))
805  {
806  /* All structures begin with the same memory layout as BITMAPINFOHEADER */
807  BITMAPINFOHEADER *info_header = (BITMAPINFOHEADER*)*data;
808  count = info_header->biClrUsed;
809 
810  if (!count && info_header->biBitCount <= 8)
811  count = 1 << info_header->biBitCount;
812 
813  offset = sizeof(BITMAPFILEHEADER) + header_size + sizeof(RGBQUAD) * count;
814 
815  /* For BITMAPINFOHEADER with BI_BITFIELDS compression, there are 3 additional color masks after header */
816  if ((info_header->biSize == sizeof(BITMAPINFOHEADER)) && (info_header->biCompression == BI_BITFIELDS))
817  offset += 3 * sizeof(DWORD);
818  }
819  else if (header_size == sizeof(BITMAPCOREHEADER))
820  {
821  BITMAPCOREHEADER *core_header = (BITMAPCOREHEADER*)*data;
822 
823  if (core_header->bcBitCount <= 8)
824  count = 1 << core_header->bcBitCount;
825 
826  offset = sizeof(BITMAPFILEHEADER) + header_size + sizeof(RGBTRIPLE) * count;
827  }
828  else
829  {
830  return FALSE;
831  }
832 
833  TRACE("Converting DIB file to BMP\n");
834 
835  new_size = *size + sizeof(BITMAPFILEHEADER);
836  new_data = HeapAlloc(GetProcessHeap(), 0, new_size);
837  CopyMemory(new_data + sizeof(BITMAPFILEHEADER), *data, *size);
838 
839  /* Add BMP header */
840  header = (BITMAPFILEHEADER*)new_data;
841  header->bfType = 0x4d42; /* BM */
842  header->bfSize = new_size;
843  header->bfReserved1 = 0;
844  header->bfReserved2 = 0;
845  header->bfOffBits = offset;
846 
847  /* Update input data */
848  *data = new_data;
849  *size = new_size;
850 
851  return TRUE;
852 }
#define TRUE
Definition: types.h:120
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLintptr offset
Definition: glext.h:5920
#define BI_BITFIELDS
Definition: mmreg.h:507
DWORD biCompression
Definition: amvideo.idl:35
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define CopyMemory
Definition: winbase.h:1633
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
unsigned char BYTE
Definition: mem.h:68
struct tagBITMAPFILEHEADER BITMAPFILEHEADER
unsigned int UINT
Definition: ndis.h:50
unsigned int ULONG
Definition: retypes.h:1
struct CFHEADER header
Definition: fdi.c:109

Referenced by D3DXGetImageInfoFromFileInMemory(), and D3DXLoadSurfaceFromFileInMemory().

◆ copy_pixels()

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 1601 of file surface.c.

1604 {
1605  UINT row, slice;
1606  BYTE *dst_addr;
1607  const BYTE *src_addr;
1608  UINT row_block_count = (size->width + format->block_width - 1) / format->block_width;
1609  UINT row_count = (size->height + format->block_height - 1) / format->block_height;
1610 
1611  for (slice = 0; slice < size->depth; slice++)
1612  {
1613  src_addr = src + slice * src_slice_pitch;
1614  dst_addr = dst + slice * dst_slice_pitch;
1615 
1616  for (row = 0; row < row_count; row++)
1617  {
1618  memcpy(dst_addr, src_addr, row_block_count * format->block_byte_count);
1619  src_addr += src_row_pitch;
1620  dst_addr += dst_row_pitch;
1621  }
1622  }
1623 }
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLsizeiptr size
Definition: glext.h:5919
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
unsigned int UINT
Definition: ndis.h:50
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:78

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

◆ d3dformat_to_dds_pixel_format()

static HRESULT d3dformat_to_dds_pixel_format ( struct dds_pixel_format pixel_format,
D3DFORMAT  d3dformat 
)
static

Definition at line 308 of file surface.c.

309 {
310  unsigned int i;
311 
312  memset(pixel_format, 0, sizeof(*pixel_format));
313 
314  pixel_format->size = sizeof(*pixel_format);
315 
316  for (i = 0; i < ARRAY_SIZE(rgb_pixel_formats); i++)
317  {
319  {
320  pixel_format->flags |= DDS_PF_RGB;
321  pixel_format->bpp = rgb_pixel_formats[i].bpp;
322  pixel_format->rmask = rgb_pixel_formats[i].rmask;
323  pixel_format->gmask = rgb_pixel_formats[i].gmask;
324  pixel_format->bmask = rgb_pixel_formats[i].bmask;
325  pixel_format->amask = rgb_pixel_formats[i].amask;
326  if (pixel_format->amask) pixel_format->flags |= DDS_PF_ALPHA;
327  return D3D_OK;
328  }
329  }
330 
331  /* Reuse dds_fourcc_to_d3dformat as D3DFORMAT and FOURCC are DWORD with same values */
333  {
334  pixel_format->flags |= DDS_PF_FOURCC;
335  pixel_format->fourcc = d3dformat;
336  return D3D_OK;
337  }
338 
339  WARN("Unknown pixel format %#x\n", d3dformat);
340  return E_NOTIMPL;
341 }
#define DDS_PF_FOURCC
Definition: surface.c:111
#define WARN(fmt,...)
Definition: debug.h:111
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLsizei GLenum const GLvoid GLsizei GLenum 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 const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
D3DFORMAT d3dformat
Definition: surface.c:41
static D3DFORMAT dds_fourcc_to_d3dformat(DWORD fourcc)
Definition: surface.c:149
#define D3D_OK
Definition: d3d.h:106
#define DDS_PF_RGB
Definition: surface.c:112
#define ARRAY_SIZE(a)
Definition: main.h:24
#define E_NOTIMPL
Definition: ddrawi.h:99
#define DDS_PF_ALPHA
Definition: surface.c:109
static const struct @242 rgb_pixel_formats[]
#define memset(x, y, z)
Definition: compat.h:39

Referenced by save_dds_surface_to_memory().

◆ d3dformat_to_wic_guid()

static const GUID* d3dformat_to_wic_guid ( D3DFORMAT  format)
static

Definition at line 67 of file surface.c.

68 {
69  unsigned int i;
70 
71  for (i = 0; i < ARRAY_SIZE(wic_pixel_formats); i++)
72  {
74  return wic_pixel_formats[i].wic_guid;
75  }
76 
77  return NULL;
78 }
static const struct @241 wic_pixel_formats[]
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLsizei GLenum const GLvoid GLsizei GLenum 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 const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
D3DFORMAT d3dformat
Definition: surface.c:41
#define ARRAY_SIZE(a)
Definition: main.h:24

Referenced by D3DXSaveSurfaceToFileInMemory().

◆ D3DXGetImageInfoFromFileA()

HRESULT WINAPI D3DXGetImageInfoFromFileA ( const char file,
D3DXIMAGE_INFO info 
)

Definition at line 1031 of file surface.c.

1032 {
1033  WCHAR *widename;
1034  HRESULT hr;
1035  int strlength;
1036 
1037  TRACE("file %s, info %p.\n", debugstr_a(file), info);
1038 
1039  if( !file ) return D3DERR_INVALIDCALL;
1040 
1041  strlength = MultiByteToWideChar(CP_ACP, 0, file, -1, NULL, 0);
1042  widename = HeapAlloc(GetProcessHeap(), 0, strlength * sizeof(*widename));
1043  MultiByteToWideChar(CP_ACP, 0, file, -1, widename, strlength);
1044 
1045  hr = D3DXGetImageInfoFromFileW(widename, info);
1046  HeapFree(GetProcessHeap(), 0, widename);
1047 
1048  return hr;
1049 }
HRESULT hr
Definition: shlfolder.c:183
#define CP_ACP
Definition: compat.h:99
#define D3DERR_INVALIDCALL
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#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:1051
#define MultiByteToWideChar
Definition: compat.h:100
#define HeapFree(x, y, z)
Definition: compat.h:394
Definition: fci.c:126

◆ D3DXGetImageInfoFromFileInMemory()

HRESULT WINAPI D3DXGetImageInfoFromFileInMemory ( const void data,
UINT  datasize,
D3DXIMAGE_INFO info 
)

Definition at line 875 of file surface.c.

876 {
878  IWICBitmapDecoder *decoder = NULL;
880  HRESULT hr;
881  HRESULT initresult;
882  BOOL dib;
883 
884  TRACE("(%p, %d, %p)\n", data, datasize, info);
885 
886  if (!data || !datasize)
887  return D3DERR_INVALIDCALL;
888 
889  if (!info)
890  return D3D_OK;
891 
892  if ((datasize >= 4) && !strncmp(data, "DDS ", 4)) {
893  TRACE("File type is DDS\n");
894  return get_image_info_from_dds(data, datasize, info);
895  }
896 
897  /* In case of DIB file, convert it to BMP */
898  dib = convert_dib_to_bmp((void**)&data, &datasize);
899 
901 
902  hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, &IID_IWICImagingFactory, (void**)&factory);
903 
904  if (SUCCEEDED(hr)) {
905  IWICImagingFactory_CreateStream(factory, &stream);
906  IWICStream_InitializeFromMemory(stream, (BYTE*)data, datasize);
907  hr = IWICImagingFactory_CreateDecoderFromStream(factory, (IStream*)stream, NULL, 0, &decoder);
908  IWICStream_Release(stream);
909  IWICImagingFactory_Release(factory);
910  }
911 
912  if (FAILED(hr)) {
913  if ((datasize >= 2) && (!strncmp(data, "P3", 2) || !strncmp(data, "P6", 2)))
914  FIXME("File type PPM is not supported yet\n");
915  else if ((datasize >= 10) && !strncmp(data, "#?RADIANCE", 10))
916  FIXME("File type HDR is not supported yet\n");
917  else if ((datasize >= 2) && (!strncmp(data, "PF", 2) || !strncmp(data, "Pf", 2)))
918  FIXME("File type PFM is not supported yet\n");
919  }
920 
921  if (SUCCEEDED(hr)) {
922  GUID container_format;
923  UINT frame_count;
924 
925  hr = IWICBitmapDecoder_GetContainerFormat(decoder, &container_format);
926  if (SUCCEEDED(hr)) {
927  if (IsEqualGUID(&container_format, &GUID_ContainerFormatBmp)) {
928  if (dib) {
929  TRACE("File type is DIB\n");
930  info->ImageFileFormat = D3DXIFF_DIB;
931  } else {
932  TRACE("File type is BMP\n");
933  info->ImageFileFormat = D3DXIFF_BMP;
934  }
935  } else if (IsEqualGUID(&container_format, &GUID_ContainerFormatPng)) {
936  TRACE("File type is PNG\n");
937  info->ImageFileFormat = D3DXIFF_PNG;
938  } else if(IsEqualGUID(&container_format, &GUID_ContainerFormatJpeg)) {
939  TRACE("File type is JPG\n");
940  info->ImageFileFormat = D3DXIFF_JPG;
941  } else if(IsEqualGUID(&container_format, &GUID_WineContainerFormatTga)) {
942  TRACE("File type is TGA\n");
943  info->ImageFileFormat = D3DXIFF_TGA;
944  } else {
945  WARN("Unsupported image file format %s\n", debugstr_guid(&container_format));
947  }
948  }
949 
950  if (SUCCEEDED(hr))
951  hr = IWICBitmapDecoder_GetFrameCount(decoder, &frame_count);
952  if (SUCCEEDED(hr) && !frame_count)
954 
955  if (SUCCEEDED(hr)) {
956  IWICBitmapFrameDecode *frame = NULL;
957 
958  hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
959 
960  if (SUCCEEDED(hr))
961  hr = IWICBitmapFrameDecode_GetSize(frame, &info->Width, &info->Height);
962 
963  if (SUCCEEDED(hr)) {
965 
966  hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &pixel_format);
967  if (SUCCEEDED(hr)) {
969  if (info->Format == D3DFMT_UNKNOWN) {
970  WARN("Unsupported pixel format %s\n", debugstr_guid(&pixel_format));
972  }
973  }
974  }
975 
976  /* For 32 bpp BMP, windowscodecs.dll never returns a format with alpha while
977  * d3dx9_xx.dll returns one if at least 1 pixel has a non zero alpha component */
978  if (SUCCEEDED(hr) && (info->Format == D3DFMT_X8R8G8B8) && (info->ImageFileFormat == D3DXIFF_BMP)) {
979  DWORD size = sizeof(DWORD) * info->Width * info->Height;
981  hr = IWICBitmapFrameDecode_CopyPixels(frame, NULL, sizeof(DWORD) * info->Width, size, buffer);
982  if (SUCCEEDED(hr)) {
983  DWORD i;
984  for (i = 0; i < info->Width * info->Height; i++) {
985  if (buffer[i*4+3]) {
986  info->Format = D3DFMT_A8R8G8B8;
987  break;
988  }
989  }
990  }
992  }
993 
994  if (frame)
995  IWICBitmapFrameDecode_Release(frame);
996 
997  info->Depth = 1;
998  info->MipLevels = 1;
999  info->ResourceType = D3DRTYPE_TEXTURE;
1000  }
1001  }
1002 
1003  if (decoder)
1004  IWICBitmapDecoder_Release(decoder);
1005 
1006  if (SUCCEEDED(initresult))
1007  CoUninitialize();
1008 
1009  if (dib)
1010  HeapFree(GetProcessHeap(), 0, (void*)data);
1011 
1012  if (FAILED(hr)) {
1013  TRACE("Invalid or unsupported image file\n");
1014  return D3DXERR_INVALIDDATA;
1015  }
1016 
1017  return D3D_OK;
1018 }
HRESULT hr
Definition: shlfolder.c:183
#define WARN(fmt,...)
Definition: debug.h:111
#define D3DERR_INVALIDCALL
GLuint buffer
Definition: glext.h:5915
#define DWORD
Definition: nt_native.h:44
GLsizei GLenum const GLvoid GLsizei GLenum 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 const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int BOOL
Definition: ntddk_ex.h:94
Definition: main.c:440
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:416
#define debugstr_guid
Definition: kernel32.h:35
static D3DFORMAT wic_guid_to_d3dformat(const GUID *guid)
Definition: surface.c:54
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG HRESULT
Definition: typedefs.h:77
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
Definition: parse.h:22
GLuint GLuint stream
Definition: glext.h:7522
unsigned char BYTE
Definition: mem.h:68
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3234
#define D3D_OK
Definition: d3d.h:106
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:1991
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:1935
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4021
static const BYTE dib[]
Definition: ole2.c:201
static HRESULT get_image_info_from_dds(const void *buffer, UINT length, D3DXIMAGE_INFO *info)
Definition: surface.c:403
static ClassFactoryImpl factory
Definition: ole_server.c:234
static BOOL convert_dib_to_bmp(void **data, UINT *size)
Definition: surface.c:789
#define HeapFree(x, y, z)
Definition: compat.h:394
#define SUCCEEDED(hr)
Definition: intsafe.h:57

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

◆ D3DXGetImageInfoFromFileW()

HRESULT WINAPI D3DXGetImageInfoFromFileW ( const WCHAR file,
D3DXIMAGE_INFO info 
)

Definition at line 1051 of file surface.c.

1052 {
1053  void *buffer;
1054  HRESULT hr;
1055  DWORD size;
1056 
1057  TRACE("file %s, info %p.\n", debugstr_w(file), info);
1058 
1059  if (!file)
1060  return D3DERR_INVALIDCALL;
1061 
1063  return D3DXERR_INVALIDDATA;
1064 
1067 
1068  return hr;
1069 }
HRESULT hr
Definition: shlfolder.c:183
#define D3DERR_INVALIDCALL
GLuint buffer
Definition: glext.h:5915
#define debugstr_w
Definition: kernel32.h:32
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
LONG HRESULT
Definition: typedefs.h:77
unsigned long DWORD
Definition: ntddk_ex.h:95
HRESULT map_view_of_file(const WCHAR *filename, void **buffer, DWORD *length) DECLSPEC_HIDDEN
Definition: util.c:118
HRESULT WINAPI D3DXGetImageInfoFromFileInMemory(const void *data, UINT datasize, D3DXIMAGE_INFO *info)
Definition: surface.c:875
#define UnmapViewOfFile
Definition: compat.h:403
Definition: fci.c:126

Referenced by D3DXGetImageInfoFromFileA().

◆ D3DXGetImageInfoFromResourceA()

HRESULT WINAPI D3DXGetImageInfoFromResourceA ( HMODULE  module,
const char resource,
D3DXIMAGE_INFO info 
)

Definition at line 1080 of file surface.c.

1081 {
1082  HRSRC resinfo;
1083  void *buffer;
1084  DWORD size;
1085 
1086  TRACE("module %p, resource %s, info %p.\n", module, debugstr_a(resource), info);
1087 
1088  if (!(resinfo = FindResourceA(module, resource, (const char *)RT_RCDATA))
1089  /* Try loading the resource as bitmap data (which is in DIB format D3DXIFF_DIB) */
1090  && !(resinfo = FindResourceA(module, resource, (const char *)RT_BITMAP)))
1091  return D3DXERR_INVALIDDATA;
1092 
1093  if (FAILED(load_resource_into_memory(module, resinfo, &buffer, &size)))
1094  return D3DXERR_INVALIDDATA;
1095 
1097 }
HRSRC WINAPI FindResourceA(HMODULE hModule, LPCSTR name, LPCSTR type)
Definition: res.c:155
GLuint buffer
Definition: glext.h:5915
HRESULT load_resource_into_memory(HMODULE module, HRSRC resinfo, void **buffer, DWORD *length) DECLSPEC_HIDDEN
Definition: util.c:166
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
#define debugstr_a
Definition: kernel32.h:31
unsigned long DWORD
Definition: ntddk_ex.h:95
#define RT_RCDATA
Definition: pedump.c:372
HRESULT WINAPI D3DXGetImageInfoFromFileInMemory(const void *data, UINT datasize, D3DXIMAGE_INFO *info)
Definition: surface.c:875
#define RT_BITMAP
Definition: pedump.c:364

◆ D3DXGetImageInfoFromResourceW()

HRESULT WINAPI D3DXGetImageInfoFromResourceW ( HMODULE  module,
const WCHAR resource,
D3DXIMAGE_INFO info 
)

Definition at line 1099 of file surface.c.

1100 {
1101  HRSRC resinfo;
1102  void *buffer;
1103  DWORD size;
1104 
1105  TRACE("module %p, resource %s, info %p.\n", module, debugstr_w(resource), info);
1106 
1107  if (!(resinfo = FindResourceW(module, resource, (const WCHAR *)RT_RCDATA))
1108  /* Try loading the resource as bitmap data (which is in DIB format D3DXIFF_DIB) */
1109  && !(resinfo = FindResourceW(module, resource, (const WCHAR *)RT_BITMAP)))
1110  return D3DXERR_INVALIDDATA;
1111 
1112  if (FAILED(load_resource_into_memory(module, resinfo, &buffer, &size)))
1113  return D3DXERR_INVALIDDATA;
1114 
1116 }
GLuint buffer
Definition: glext.h:5915
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
#define debugstr_w
Definition: kernel32.h:32
HRESULT load_resource_into_memory(HMODULE module, HRSRC resinfo, void **buffer, DWORD *length) DECLSPEC_HIDDEN
Definition: util.c:166
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define RT_RCDATA
Definition: pedump.c:372
HRESULT WINAPI D3DXGetImageInfoFromFileInMemory(const void *data, UINT datasize, D3DXIMAGE_INFO *info)
Definition: surface.c:875
#define RT_BITMAP
Definition: pedump.c:364

◆ D3DXLoadSurfaceFromFileA()

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 1317 of file surface.c.

1320 {
1321  WCHAR *src_file_w;
1322  HRESULT hr;
1323  int strlength;
1324 
1325  TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_file %s, "
1326  "src_rect %s, filter %#x, color_key 0x%08x, src_info %p.\n",
1327  dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), debugstr_a(src_file),
1328  wine_dbgstr_rect(src_rect), filter, color_key, src_info);
1329 
1330  if (!src_file || !dst_surface)
1331  return D3DERR_INVALIDCALL;
1332 
1333  strlength = MultiByteToWideChar(CP_ACP, 0, src_file, -1, NULL, 0);
1334  src_file_w = HeapAlloc(GetProcessHeap(), 0, strlength * sizeof(*src_file_w));
1335  MultiByteToWideChar(CP_ACP, 0, src_file, -1, src_file_w, strlength);
1336 
1337  hr = D3DXLoadSurfaceFromFileW(dst_surface, dst_palette, dst_rect,
1338  src_file_w, src_rect, filter, color_key, src_info);
1339  HeapFree(GetProcessHeap(), 0, src_file_w);
1340 
1341  return hr;
1342 }
HRESULT hr
Definition: shlfolder.c:183
#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:1344
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#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

◆ D3DXLoadSurfaceFromFileInMemory()

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 1141 of file surface.c.

1144 {
1145  D3DXIMAGE_INFO imginfo;
1146  HRESULT hr, com_init;
1147 
1149  IWICBitmapDecoder *decoder;
1150  IWICBitmapFrameDecode *bitmapframe;
1151  IWICStream *stream;
1152 
1153  const struct pixel_format_desc *formatdesc;
1154  WICRect wicrect;
1155  RECT rect;
1156 
1157  TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_data %p, src_data_size %u, "
1158  "src_rect %s, filter %#x, color_key 0x%08x, src_info %p.\n",
1159  pDestSurface, pDestPalette, wine_dbgstr_rect(pDestRect), pSrcData, SrcDataSize,
1160  wine_dbgstr_rect(pSrcRect), dwFilter, Colorkey, pSrcInfo);
1161 
1162  if (!pDestSurface || !pSrcData || !SrcDataSize)
1163  return D3DERR_INVALIDCALL;
1164 
1165  hr = D3DXGetImageInfoFromFileInMemory(pSrcData, SrcDataSize, &imginfo);
1166 
1167  if (FAILED(hr))
1168  return hr;
1169 
1170  if (pSrcRect)
1171  {
1172  wicrect.X = pSrcRect->left;
1173  wicrect.Y = pSrcRect->top;
1174  wicrect.Width = pSrcRect->right - pSrcRect->left;
1175  wicrect.Height = pSrcRect->bottom - pSrcRect->top;
1176  }
1177  else
1178  {
1179  wicrect.X = 0;
1180  wicrect.Y = 0;
1181  wicrect.Width = imginfo.Width;
1182  wicrect.Height = imginfo.Height;
1183  }
1184 
1185  SetRect(&rect, 0, 0, wicrect.Width, wicrect.Height);
1186 
1187  if (imginfo.ImageFileFormat == D3DXIFF_DDS)
1188  {
1189  hr = load_surface_from_dds(pDestSurface, pDestPalette, pDestRect, pSrcData, &rect,
1190  dwFilter, Colorkey, &imginfo);
1191  if (SUCCEEDED(hr) && pSrcInfo)
1192  *pSrcInfo = imginfo;
1193  return hr;
1194  }
1195 
1196  if (imginfo.ImageFileFormat == D3DXIFF_DIB)
1197  convert_dib_to_bmp((void**)&pSrcData, &SrcDataSize);
1198 
1200 
1201  if (FAILED(CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, &IID_IWICImagingFactory, (void**)&factory)))
1202  goto cleanup_err;
1203 
1204  if (FAILED(IWICImagingFactory_CreateStream(factory, &stream)))
1205  {
1206  IWICImagingFactory_Release(factory);
1207  factory = NULL;
1208  goto cleanup_err;
1209  }
1210 
1211  IWICStream_InitializeFromMemory(stream, (BYTE*)pSrcData, SrcDataSize);
1212 
1213  hr = IWICImagingFactory_CreateDecoderFromStream(factory, (IStream*)stream, NULL, 0, &decoder);
1214 
1215  IWICStream_Release(stream);
1216 
1217  if (FAILED(hr))
1218  goto cleanup_err;
1219 
1220  hr = IWICBitmapDecoder_GetFrame(decoder, 0, &bitmapframe);
1221 
1222  if (FAILED(hr))
1223  goto cleanup_bmp;
1224 
1225  formatdesc = get_format_info(imginfo.Format);
1226 
1227  if (formatdesc->type == FORMAT_UNKNOWN)
1228  {
1229  FIXME("Unsupported pixel format\n");
1231  }
1232  else
1233  {
1234  BYTE *buffer;
1235  DWORD pitch;
1237  WICColor *colors = NULL;
1238 
1239  pitch = formatdesc->bytes_per_pixel * wicrect.Width;
1240  buffer = HeapAlloc(GetProcessHeap(), 0, pitch * wicrect.Height);
1241 
1242  hr = IWICBitmapFrameDecode_CopyPixels(bitmapframe, &wicrect, pitch,
1243  pitch * wicrect.Height, buffer);
1244 
1245  if (SUCCEEDED(hr) && (formatdesc->type == FORMAT_INDEX))
1246  {
1247  IWICPalette *wic_palette = NULL;
1248  UINT nb_colors;
1249 
1250  hr = IWICImagingFactory_CreatePalette(factory, &wic_palette);
1251  if (SUCCEEDED(hr))
1252  hr = IWICBitmapFrameDecode_CopyPalette(bitmapframe, wic_palette);
1253  if (SUCCEEDED(hr))
1254  hr = IWICPalette_GetColorCount(wic_palette, &nb_colors);
1255  if (SUCCEEDED(hr))
1256  {
1257  colors = HeapAlloc(GetProcessHeap(), 0, nb_colors * sizeof(colors[0]));
1258  palette = HeapAlloc(GetProcessHeap(), 0, nb_colors * sizeof(palette[0]));
1259  if (!colors || !palette)
1260  hr = E_OUTOFMEMORY;
1261  }
1262  if (SUCCEEDED(hr))
1263  hr = IWICPalette_GetColors(wic_palette, nb_colors, colors, &nb_colors);
1264  if (SUCCEEDED(hr))
1265  {
1266  UINT i;
1267 
1268  /* Convert colors from WICColor (ARGB) to PALETTEENTRY (ABGR) */
1269  for (i = 0; i < nb_colors; i++)
1270  {
1271  palette[i].peRed = (colors[i] >> 16) & 0xff;
1272  palette[i].peGreen = (colors[i] >> 8) & 0xff;
1273  palette[i].peBlue = colors[i] & 0xff;
1274  palette[i].peFlags = (colors[i] >> 24) & 0xff; /* peFlags is the alpha component in DX8 and higher */
1275  }
1276  }
1277  if (wic_palette)
1278  IWICPalette_Release(wic_palette);
1279  }
1280 
1281  if (SUCCEEDED(hr))
1282  {
1283  hr = D3DXLoadSurfaceFromMemory(pDestSurface, pDestPalette, pDestRect,
1284  buffer, imginfo.Format, pitch,
1285  palette, &rect, dwFilter, Colorkey);
1286  }
1287 
1288  HeapFree(GetProcessHeap(), 0, colors);
1291  }
1292 
1293  IWICBitmapFrameDecode_Release(bitmapframe);
1294 
1295 cleanup_bmp:
1296  IWICBitmapDecoder_Release(decoder);
1297 
1298 cleanup_err:
1299  if (factory)
1300  IWICImagingFactory_Release(factory);
1301 
1302  if (SUCCEEDED(com_init))
1303  CoUninitialize();
1304 
1305  if (imginfo.ImageFileFormat == D3DXIFF_DIB)
1306  HeapFree(GetProcessHeap(), 0, (void*)pSrcData);
1307 
1308  if (FAILED(hr))
1309  return D3DXERR_INVALIDDATA;
1310 
1311  if (pSrcInfo)
1312  *pSrcInfo = imginfo;
1313 
1314  return D3D_OK;
1315 }
HRESULT hr
Definition: shlfolder.c:183
LONG top
Definition: windef.h:292
#define D3DERR_INVALIDCALL
GLuint buffer
Definition: glext.h:5915
LONG left
Definition: windef.h:291
LONG right
Definition: windef.h:293
& rect
Definition: startmenu.cpp:1413
GLsizei GLenum const GLvoid GLsizei GLenum 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 const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
Definition: main.c:440
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:416
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
Definition: d3dx9_private.h:65
unsigned long DWORD
Definition: ntddk_ex.h:95
Definition: parse.h:22
GLuint GLuint stream
Definition: glext.h:7522
unsigned char BYTE
Definition: mem.h:68
static HPALETTE palette
Definition: clipboard.c:1345
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3234
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:1872
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:1991
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:1935
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:459
INT Width
Definition: wincodec.idl:238
HRESULT WINAPI D3DXGetImageInfoFromFileInMemory(const void *data, UINT datasize, D3DXIMAGE_INFO *info)
Definition: surface.c:875
LONG bottom
Definition: windef.h:294
const struct pixel_format_desc * get_format_info(D3DFORMAT format) DECLSPEC_HIDDEN
Definition: util.c:213
UINT32 WICColor
Definition: wincodec.idl:250
static BOOL convert_dib_to_bmp(void **data, UINT *size)
Definition: surface.c:789
#define HeapFree(x, y, z)
Definition: compat.h:394
#define SUCCEEDED(hr)
Definition: intsafe.h:57

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

◆ D3DXLoadSurfaceFromFileW()

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 1344 of file surface.c.

1347 {
1348  UINT data_size;
1349  void *data;
1350  HRESULT hr;
1351 
1352  TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_file %s, "
1353  "src_rect %s, filter %#x, color_key 0x%08x, src_info %p.\n",
1354  dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), debugstr_w(src_file),
1355  wine_dbgstr_rect(src_rect), filter, color_key, src_info);
1356 
1357  if (!src_file || !dst_surface)
1358  return D3DERR_INVALIDCALL;
1359 
1360  if (FAILED(map_view_of_file(src_file, &data, &data_size)))
1361  return D3DXERR_INVALIDDATA;
1362 
1363  hr = D3DXLoadSurfaceFromFileInMemory(dst_surface, dst_palette, dst_rect,
1364  data, data_size, src_rect, filter, color_key, src_info);
1366 
1367  return hr;
1368 }
HRESULT hr
Definition: shlfolder.c:183
#define D3DERR_INVALIDCALL
#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
HRESULT map_view_of_file(const WCHAR *filename, void **buffer, DWORD *length) DECLSPEC_HIDDEN
Definition: util.c:118
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:1141

Referenced by D3DXLoadSurfaceFromFileA().

◆ D3DXLoadSurfaceFromMemory()

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 1872 of file surface.c.

1876 {
1877  const struct pixel_format_desc *srcformatdesc, *destformatdesc;
1878  void *tmp_src_memory = NULL, *tmp_dst_memory = NULL;
1879  dxtn_conversion_func pre_convert = NULL, post_convert = NULL;
1880  IDirect3DSurface9 *surface = dst_surface;
1881  IDirect3DDevice9 *device;
1882  D3DSURFACE_DESC surfdesc;
1883  D3DLOCKED_RECT lockrect;
1884  struct volume src_size, dst_size;
1885  HRESULT hr = D3D_OK;
1886 
1887  TRACE("(%p, %p, %s, %p, %#x, %u, %p, %s, %#x, 0x%08x)\n",
1888  dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), src_memory, src_format,
1889  src_pitch, src_palette, wine_dbgstr_rect(src_rect), filter, color_key);
1890 
1891  if (!dst_surface || !src_memory || !src_rect)
1892  {
1893  WARN("Invalid argument specified.\n");
1894  return D3DERR_INVALIDCALL;
1895  }
1896  if (src_format == D3DFMT_UNKNOWN
1897  || src_rect->left >= src_rect->right
1898  || src_rect->top >= src_rect->bottom)
1899  {
1900  WARN("Invalid src_format or src_rect.\n");
1901  return E_FAIL;
1902  }
1903 
1904  if (filter == D3DX_DEFAULT)
1906 
1907  IDirect3DSurface9_GetDesc(dst_surface, &surfdesc);
1908 
1909  src_size.width = src_rect->right - src_rect->left;
1910  src_size.height = src_rect->bottom - src_rect->top;
1911  src_size.depth = 1;
1912  if (!dst_rect)
1913  {
1914  dst_size.width = surfdesc.Width;
1915  dst_size.height = surfdesc.Height;
1916  }
1917  else
1918  {
1919  if (dst_rect->left > dst_rect->right || dst_rect->right > surfdesc.Width
1920  || dst_rect->top > dst_rect->bottom || dst_rect->bottom > surfdesc.Height
1921  || dst_rect->left < 0 || dst_rect->top < 0)
1922  {
1923  WARN("Invalid dst_rect specified.\n");
1924  return D3DERR_INVALIDCALL;
1925  }
1926  dst_size.width = dst_rect->right - dst_rect->left;
1927  dst_size.height = dst_rect->bottom - dst_rect->top;
1928  if (!dst_size.width || !dst_size.height)
1929  return D3D_OK;
1930  }
1931  dst_size.depth = 1;
1932 
1933  srcformatdesc = get_format_info(src_format);
1934  destformatdesc = get_format_info(surfdesc.Format);
1935  if (srcformatdesc->type == FORMAT_UNKNOWN || destformatdesc->type == FORMAT_UNKNOWN)
1936  {
1937  FIXME("Unsupported pixel format conversion %#x -> %#x\n", src_format, surfdesc.Format);
1938  return E_NOTIMPL;
1939  }
1940 
1941  if (surfdesc.Pool == D3DPOOL_DEFAULT && !(surfdesc.Usage & D3DUSAGE_DYNAMIC))
1942  {
1943  IDirect3DSurface9_GetDevice(dst_surface, &device);
1945  surfdesc.Height, surfdesc.Format, D3DPOOL_SYSTEMMEM, &surface, NULL);
1947  if (FAILED(hr))
1948  {
1949  WARN("Failed to create staging surface, hr %#x.\n", hr);
1950  return D3DERR_INVALIDCALL;
1951  }
1952  }
1953 
1954  if (FAILED(IDirect3DSurface9_LockRect(surface, &lockrect, dst_rect, 0)))
1955  {
1956  if (surface != dst_surface)
1957  IDirect3DSurface9_Release(surface);
1958  return D3DXERR_INVALIDDATA;
1959  }
1960 
1961  if (src_format == surfdesc.Format
1962  && dst_size.width == src_size.width
1963  && dst_size.height == src_size.height
1964  && color_key == 0) /* Simple copy. */
1965  {
1966  if (src_rect->left & (srcformatdesc->block_width - 1)
1967  || src_rect->top & (srcformatdesc->block_height - 1)
1968  || (src_rect->right & (srcformatdesc->block_width - 1)
1969  && src_size.width != surfdesc.Width)
1970  || (src_rect->bottom & (srcformatdesc->block_height - 1)
1971  && src_size.height != surfdesc.Height))
1972  {
1973  WARN("Source rect %s is misaligned.\n", wine_dbgstr_rect(src_rect));
1975  goto done;
1976  }
1977 
1978  copy_pixels(src_memory, src_pitch, 0, lockrect.pBits, lockrect.Pitch, 0,
1979  &src_size, srcformatdesc);
1980  }
1981  else /* Stretching or format conversion. */
1982  {
1983  UINT tmp_src_pitch, tmp_dst_pitch;
1984 
1985  pre_convert = get_dxtn_conversion_func(srcformatdesc->format, FALSE);
1986  post_convert = get_dxtn_conversion_func(destformatdesc->format, TRUE);
1987 
1988  if ((!pre_convert && !is_conversion_from_supported(srcformatdesc)) ||
1989  (!post_convert && !is_conversion_to_supported(destformatdesc)))
1990  {
1991  FIXME("Unsupported format conversion %#x -> %#x.\n", src_format, surfdesc.Format);
1992  hr = E_NOTIMPL;
1993  goto done;
1994  }
1995 
1996  /* handle pre-conversion */
1997  if (pre_convert)
1998  {
1999  tmp_src_memory = HeapAlloc(GetProcessHeap(), 0, src_size.width * src_size.height * sizeof(DWORD));
2000  if (!tmp_src_memory)
2001  {
2002  hr = E_OUTOFMEMORY;
2003  goto done;
2004  }
2005  tmp_src_pitch = src_size.width * sizeof(DWORD);
2006  if (!pre_convert(src_memory, tmp_src_memory, src_pitch, tmp_src_pitch,
2007  WINED3DFMT_B8G8R8A8_UNORM, src_size.width, src_size.height))
2008  {
2009  hr = E_FAIL;
2010  goto done;
2011  }
2012  srcformatdesc = get_format_info(D3DFMT_A8R8G8B8);
2013  }
2014  else
2015  {
2016  tmp_src_memory = (void *)src_memory;
2017  tmp_src_pitch = src_pitch;
2018  }
2019 
2020  /* handle post-conversion */
2021  if (post_convert)
2022  {
2023  tmp_dst_memory = HeapAlloc(GetProcessHeap(), 0, dst_size.width * dst_size.height * sizeof(DWORD));
2024  if (!tmp_dst_memory)
2025  {
2026  hr = E_OUTOFMEMORY;
2027  goto done;
2028  }
2029  tmp_dst_pitch = dst_size.width * sizeof(DWORD);
2030  destformatdesc = get_format_info(D3DFMT_A8R8G8B8);
2031  }
2032  else
2033  {
2034  tmp_dst_memory = lockrect.pBits;
2035  tmp_dst_pitch = lockrect.Pitch;
2036  }
2037 
2038  if ((filter & 0xf) == D3DX_FILTER_NONE)
2039  {
2040  convert_argb_pixels(tmp_src_memory, tmp_src_pitch, 0, &src_size, srcformatdesc,
2041  tmp_dst_memory, tmp_dst_pitch, 0, &dst_size, destformatdesc, color_key, src_palette);
2042  }
2043  else /* if ((filter & 0xf) == D3DX_FILTER_POINT) */
2044  {
2045  if ((filter & 0xf) != D3DX_FILTER_POINT)
2046  FIXME("Unhandled filter %#x.\n", filter);
2047 
2048  /* Always apply a point filter until D3DX_FILTER_LINEAR,
2049  * D3DX_FILTER_TRIANGLE and D3DX_FILTER_BOX are implemented. */
2050  point_filter_argb_pixels(tmp_src_memory, tmp_src_pitch, 0, &src_size, srcformatdesc,
2051  tmp_dst_memory, tmp_dst_pitch, 0, &dst_size, destformatdesc, color_key, src_palette);
2052  }
2053 
2054  /* handle post-conversion */
2055  if (post_convert)
2056  {
2057  if (!post_convert(tmp_dst_memory, lockrect.pBits, tmp_dst_pitch, lockrect.Pitch,
2058  WINED3DFMT_B8G8R8A8_UNORM, dst_size.width, dst_size.height))
2059  {
2060  hr = E_FAIL;
2061  goto done;
2062  }
2063  }
2064  }
2065 
2066 done:
2068  if (surface != dst_surface)
2069  {
2070  if (SUCCEEDED(hr))
2071  {
2072  IDirect3DSurface9_GetDevice(dst_surface, &device);
2073  hr = IDirect3DDevice9_UpdateSurface(device, surface, NULL, dst_surface, NULL);
2075  }
2076  IDirect3DSurface9_Release(surface);
2077 
2078  if (pre_convert)
2079  HeapFree(GetProcessHeap(), 0, tmp_src_memory);
2080  if (post_convert)
2081  HeapFree(GetProcessHeap(), 0, tmp_dst_memory);
2082  IDirect3DSurface9_UnlockRect(dst_surface);
2083  }
2084 
2085  return hr;
2086 }
#define D3DUSAGE_DYNAMIC
Definition: d3d8types.h:99
#define IDirect3DSurface9_Release(p)
Definition: d3d9.h:622
#define TRUE
Definition: types.h:120
HRESULT hr
Definition: shlfolder.c:183
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:292
#define D3DERR_INVALIDCALL
#define IDirect3DSurface9_GetDevice(p, a)
Definition: d3d9.h:624
LONG left
Definition: windef.h:291
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:1822
LONG right
Definition: windef.h:293
#define E_FAIL
Definition: ddrawi.h:102
#define DWORD
Definition: nt_native.h:44
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:1632
#define IDirect3DDevice9_CreateOffscreenPlainSurface(p, a, b, c, d, e, f)
Definition: d3d9.h:1543
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
Definition: devices.h:37
#define FIXME(fmt,...)
Definition: debug.h:110
#define D3DX_DEFAULT
Definition: d3dx9.h:24
#define D3DX_FILTER_TRIANGLE
Definition: d3dx9tex.h:30
static BOOL is_conversion_from_supported(const struct pixel_format_desc *format)
Definition: d3dx9_private.h:78
#define IDirect3DDevice9_Release(p)
Definition: d3d9.h:1508
smooth NULL
Definition: ftsmooth.c:416
#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
Definition: d3dx9_private.h:65
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IDirect3DSurface9_GetDesc(p, a)
Definition: d3d9.h:634
static dxtn_conversion_func get_dxtn_conversion_func(D3DFORMAT format, BOOL encode)
Definition: surface.c:1825
#define D3D_OK
Definition: d3d.h:106
#define D3DX_FILTER_DITHER
Definition: d3dx9tex.h:36
#define IDirect3DDevice9_UpdateSurface(p, a, b, c, d)
Definition: d3d9.h:1537
#define E_NOTIMPL
Definition: ddrawi.h:99
unsigned int UINT
Definition: ndis.h:50
static BOOL is_conversion_to_supported(const struct pixel_format_desc *format)
Definition: d3dx9_private.h:86
#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:1735
LONG bottom
Definition: windef.h:294
const struct pixel_format_desc * get_format_info(D3DFORMAT format) DECLSPEC_HIDDEN
Definition: util.c:213
#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:1601
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
#define HeapFree(x, y, z)
Definition: compat.h:394
#define SUCCEEDED(hr)
Definition: intsafe.h:57

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

◆ D3DXLoadSurfaceFromResourceA()

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 1370 of file surface.c.

1373 {
1374  UINT data_size;
1375  HRSRC resinfo;
1376  void *data;
1377 
1378  TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_module %p, resource %s, "
1379  "src_rect %s, filter %#x, color_key 0x%08x, src_info %p.\n",
1380  dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), src_module, debugstr_a(resource),
1381  wine_dbgstr_rect(src_rect), filter, color_key, src_info);
1382 
1383  if (!dst_surface)
1384  return D3DERR_INVALIDCALL;
1385 
1386  if (!(resinfo = FindResourceA(src_module, resource, (const char *)RT_RCDATA))
1387  /* Try loading the resource as bitmap data (which is in DIB format D3DXIFF_DIB) */
1388  && !(resinfo = FindResourceA(src_module, resource, (const char *)RT_BITMAP)))
1389  return D3DXERR_INVALIDDATA;
1390 
1391  if (FAILED(load_resource_into_memory(src_module, resinfo, &data, &data_size)))
1392  return D3DXERR_INVALIDDATA;
1393 
1394  return D3DXLoadSurfaceFromFileInMemory(dst_surface, dst_palette, dst_rect,
1395  data, data_size, src_rect, filter, color_key, src_info);
1396 }
HRSRC WINAPI FindResourceA(HMODULE hModule, LPCSTR name, LPCSTR type)
Definition: res.c:155
#define D3DERR_INVALIDCALL
HRESULT load_resource_into_memory(HMODULE module, HRSRC resinfo, void **buffer, DWORD *length) DECLSPEC_HIDDEN
Definition: util.c:166
#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:1141

◆ D3DXLoadSurfaceFromResourceW()

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 1398 of file surface.c.

1401 {
1402  UINT data_size;
1403  HRSRC resinfo;
1404  void *data;
1405 
1406  TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_module %p, resource %s, "
1407  "src_rect %s, filter %#x, color_key 0x%08x, src_info %p.\n",
1408  dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), src_module, debugstr_w(resource),
1409  wine_dbgstr_rect(src_rect), filter, color_key, src_info);
1410 
1411  if (!dst_surface)
1412  return D3DERR_INVALIDCALL;
1413 
1414  if (!(resinfo = FindResourceW(src_module, resource, (const WCHAR *)RT_RCDATA))
1415  /* Try loading the resource as bitmap data (which is in DIB format D3DXIFF_DIB) */
1416  && !(resinfo = FindResourceW(src_module, resource, (const WCHAR *)RT_BITMAP)))
1417  return D3DXERR_INVALIDDATA;
1418 
1419  if (FAILED(load_resource_into_memory(src_module, resinfo, &data, &data_size)))
1420  return D3DXERR_INVALIDDATA;
1421 
1422  return D3DXLoadSurfaceFromFileInMemory(dst_surface, dst_palette, dst_rect,
1423  data, data_size, src_rect, filter, color_key, src_info);
1424 }
#define D3DERR_INVALIDCALL
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
#define debugstr_w
Definition: kernel32.h:32
HRESULT load_resource_into_memory(HMODULE module, HRSRC resinfo, void **buffer, DWORD *length) DECLSPEC_HIDDEN
Definition: util.c:166
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
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:1141

◆ D3DXLoadSurfaceFromSurface()

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 2110 of file surface.c.

2113 {
2114  IDirect3DSurface9 *surface = src_surface;
2115  D3DTEXTUREFILTERTYPE d3d_filter;
2116  IDirect3DDevice9 *device;
2117  D3DSURFACE_DESC src_desc;
2119  HRESULT hr;
2120  RECT s;
2121 
2122  TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_surface %p, "
2123  "src_palette %p, src_rect %s, filter %#x, color_key 0x%08x.\n",
2124  dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), src_surface,
2125  src_palette, wine_dbgstr_rect(src_rect), filter, color_key);
2126 
2127  if (!dst_surface || !src_surface)
2128  return D3DERR_INVALIDCALL;
2129 
2130  if (!dst_palette && !src_palette && !color_key)
2131  {
2132  switch (filter)
2133  {
2134  case D3DX_FILTER_NONE:
2135  d3d_filter = D3DTEXF_NONE;
2136  break;
2137 
2138  case D3DX_FILTER_POINT:
2139  d3d_filter = D3DTEXF_POINT;
2140  break;
2141 
2142  case D3DX_FILTER_LINEAR:
2143  d3d_filter = D3DTEXF_LINEAR;
2144  break;
2145 
2146  default:
2147  d3d_filter = ~0u;
2148  break;
2149  }
2150 
2151  if (d3d_filter != ~0u)
2152  {
2153  IDirect3DSurface9_GetDevice(src_surface, &device);
2154  hr = IDirect3DDevice9_StretchRect(device, src_surface, src_rect, dst_surface, dst_rect, d3d_filter);
2156  if (SUCCEEDED(hr))
2157  return D3D_OK;
2158  }
2159  }
2160 
2161  IDirect3DSurface9_GetDesc(src_surface, &src_desc);
2162 
2163  if (!src_rect)
2164  {
2165  SetRect(&s, 0, 0, src_desc.Width, src_desc.Height);
2166  src_rect = &s;
2167  }
2168 
2170  {
2171  IDirect3DSurface9_GetDevice(src_surface, &device);
2173  src_desc.Format, D3DMULTISAMPLE_NONE, 0, TRUE, &surface, NULL)))
2174  {
2176  return D3DXERR_INVALIDDATA;
2177  }
2178 
2179  if (SUCCEEDED(hr = IDirect3DDevice9_StretchRect(device, src_surface, NULL, surface, NULL, D3DTEXF_NONE)))
2182  if (FAILED(hr))
2183  {
2184  IDirect3DSurface9_Release(surface);
2185  return D3DXERR_INVALIDDATA;
2186  }
2187  }
2188 
2189  hr = D3DXLoadSurfaceFromMemory(dst_surface, dst_palette, dst_rect, lock.pBits,
2190  src_desc.Format, lock.Pitch, src_palette, src_rect, filter, color_key);
2191 
2193  if (surface != src_surface)
2194  IDirect3DSurface9_Release(surface);
2195 
2196  return hr;
2197 }
GLsizei GLenum const GLvoid GLsizei GLenum 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 const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
#define IDirect3DSurface9_Release(p)
Definition: d3d9.h:622
#define TRUE
Definition: types.h:120
rwlock_t lock
Definition: tcpcore.h:1163
HRESULT hr
Definition: shlfolder.c:183
D3DFORMAT Format
Definition: d3d8types.h:1170
#define D3DX_FILTER_NONE
Definition: d3dx9tex.h:27
#define D3DERR_INVALIDCALL
#define D3DX_FILTER_LINEAR
Definition: d3dx9tex.h:29
#define IDirect3DSurface9_GetDevice(p, a)
Definition: d3d9.h:624
#define IDirect3DDevice9_CreateRenderTarget(p, a, b, c, d, e, f, g, h)
Definition: d3d9.h:1535
Definition: devices.h:37
#define IDirect3DDevice9_Release(p)
Definition: d3d9.h:1508
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
const char * wine_dbgstr_rect(const RECT *rect)
GLdouble s
Definition: gl.h:2039
#define IDirect3DSurface9_GetDesc(p, a)
Definition: d3d9.h:634
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:1872
#define IDirect3DSurface9_UnlockRect(p)
Definition: d3d9.h:636
enum _D3DTEXTUREFILTERTYPE D3DTEXTUREFILTERTYPE
#define D3DX_FILTER_POINT
Definition: d3dx9tex.h:28
#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
#define IDirect3DDevice9_StretchRect(p, a, b, c, d, e)
Definition: d3d9.h:1541
#define SUCCEEDED(hr)
Definition: intsafe.h:57

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

◆ D3DXSaveSurfaceToFileA()

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 2200 of file surface.c.

2202 {
2203  int len;
2204  WCHAR *filename;
2205  HRESULT hr;
2207 
2208  TRACE("(%s, %#x, %p, %p, %s): relay\n",
2209  wine_dbgstr_a(dst_filename), file_format, src_surface, src_palette, wine_dbgstr_rect(src_rect));
2210 
2211  if (!dst_filename) return D3DERR_INVALIDCALL;
2212 
2213  len = MultiByteToWideChar(CP_ACP, 0, dst_filename, -1, NULL, 0);
2214  filename = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
2215  if (!filename) return E_OUTOFMEMORY;
2216  MultiByteToWideChar(CP_ACP, 0, dst_filename, -1, filename, len);
2217 
2218  hr = D3DXSaveSurfaceToFileInMemory(&buffer, file_format, src_surface, src_palette, src_rect);
2219  if (SUCCEEDED(hr))
2220  {
2223  }
2224 
2226  return hr;
2227 }
const char int int int static __inline const char * wine_dbgstr_a(const char *s)
Definition: debug.h:186
HRESULT hr
Definition: shlfolder.c:183
#define CP_ACP
Definition: compat.h:99
#define D3DERR_INVALIDCALL
GLuint buffer
Definition: glext.h:5915
const char * filename
Definition: ioapi.h:135
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
smooth NULL
Definition: ftsmooth.c:416
HRESULT write_buffer_to_file(const WCHAR *filename, ID3DXBuffer *buffer) DECLSPEC_HIDDEN
Definition: util.c:182
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)
__wchar_t WCHAR
Definition: xmlstorage.h:180
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:2250
GLenum GLsizei len
Definition: glext.h:6722
#define ID3DXBuffer_Release(p)
Definition: d3dx9core.h:83
#define MultiByteToWideChar
Definition: compat.h:100
#define HeapFree(x, y, z)
Definition: compat.h:394
#define SUCCEEDED(hr)
Definition: intsafe.h:57

◆ D3DXSaveSurfaceToFileInMemory()

HRESULT WINAPI D3DXSaveSurfaceToFileInMemory ( ID3DXBuffer **  dst_buffer,
D3DXIMAGE_FILEFORMAT  file_format,
IDirect3DSurface9 *  src_surface,
const PALETTEENTRY src_palette,
const RECT src_rect 
)

Definition at line 2250 of file surface.c.

2252 {
2253  IWICBitmapEncoder *encoder = NULL;
2254  IWICBitmapFrameEncode *frame = NULL;
2255  IPropertyBag2 *encoder_options = NULL;
2256  IStream *stream = NULL;
2257  HRESULT hr;
2258  HRESULT initresult;
2259  const CLSID *encoder_clsid;
2260  const GUID *pixel_format_guid;
2261  WICPixelFormatGUID wic_pixel_format;
2262  D3DFORMAT d3d_pixel_format;
2263  D3DSURFACE_DESC src_surface_desc;
2264  D3DLOCKED_RECT locked_rect;
2265  int width, height;
2266  STATSTG stream_stats;
2267  HGLOBAL stream_hglobal;
2269  DWORD size;
2270 
2271  TRACE("(%p, %#x, %p, %p, %s)\n",
2272  dst_buffer, file_format, src_surface, src_palette, wine_dbgstr_rect(src_rect));
2273 
2274  if (!dst_buffer || !src_surface) return D3DERR_INVALIDCALL;
2275 
2276  if (src_palette)
2277  {
2278  FIXME("Saving surfaces with palettized pixel formats is not implemented yet\n");
2279  return D3DERR_INVALIDCALL;
2280  }
2281 
2282  switch (file_format)
2283  {
2284  case D3DXIFF_BMP:
2285  case D3DXIFF_DIB:
2286  encoder_clsid = &CLSID_WICBmpEncoder;
2287  break;
2288  case D3DXIFF_PNG:
2289  encoder_clsid = &CLSID_WICPngEncoder;
2290  break;
2291  case D3DXIFF_JPG:
2292  encoder_clsid = &CLSID_WICJpegEncoder;
2293  break;
2294  case D3DXIFF_DDS:
2295  return save_dds_surface_to_memory(dst_buffer, src_surface, src_rect);
2296  case D3DXIFF_HDR:
2297  case D3DXIFF_PFM:
2298  case D3DXIFF_TGA:
2299  case D3DXIFF_PPM:
2300  FIXME("File format %#x is not supported yet\n", file_format);
2301  return E_NOTIMPL;
2302  default:
2303  return D3DERR_INVALIDCALL;
2304  }
2305 
2306  IDirect3DSurface9_GetDesc(src_surface, &src_surface_desc);
2307  if (src_rect)
2308  {
2309  if (src_rect->left == src_rect->right || src_rect->top == src_rect->bottom)
2310  {
2311  WARN("Invalid rectangle with 0 area\n");
2312  return D3DXCreateBuffer(64, dst_buffer);
2313  }
2314  if (src_rect->left < 0 || src_rect->top < 0)
2315  return D3DERR_INVALIDCALL;
2316  if (src_rect->left > src_rect->right || src_rect->top > src_rect->bottom)
2317  return D3DERR_INVALIDCALL;
2318  if (src_rect->right > src_surface_desc.Width || src_rect->bottom > src_surface_desc.Height)
2319  return D3DERR_INVALIDCALL;
2320 
2321  width = src_rect->right - src_rect->left;
2322  height = src_rect->bottom - src_rect->top;
2323  }
2324  else
2325  {
2326  width = src_surface_desc.Width;
2327  height = src_surface_desc.Height;
2328  }
2329 
2331 
2332  hr = CoCreateInstance(encoder_clsid, NULL, CLSCTX_INPROC_SERVER,
2333  &IID_IWICBitmapEncoder, (void **)&encoder);
2334  if (FAILED(hr)) goto cleanup_err;
2335 
2337  if (FAILED(hr)) goto cleanup_err;
2338 
2339  hr = IWICBitmapEncoder_Initialize(encoder, stream, WICBitmapEncoderNoCache);
2340  if (FAILED(hr)) goto cleanup_err;
2341 
2342  hr = IWICBitmapEncoder_CreateNewFrame(encoder, &frame, &encoder_options);
2343  if (FAILED(hr)) goto cleanup_err;
2344 
2345  hr = IWICBitmapFrameEncode_Initialize(frame, encoder_options);
2346  if (FAILED(hr)) goto cleanup_err;
2347 
2348  hr = IWICBitmapFrameEncode_SetSize(frame, width, height);
2349  if (FAILED(hr)) goto cleanup_err;
2350 
2351  pixel_format_guid = d3dformat_to_wic_guid(src_surface_desc.Format);
2352  if (!pixel_format_guid)
2353  {
2354  FIXME("Pixel format %#x is not supported yet\n", src_surface_desc.Format);
2355  hr = E_NOTIMPL;
2356  goto cleanup;
2357  }
2358 
2359  memcpy(&wic_pixel_format, pixel_format_guid, sizeof(GUID));
2360  hr = IWICBitmapFrameEncode_SetPixelFormat(frame, &wic_pixel_format);
2361  d3d_pixel_format = wic_guid_to_d3dformat(&wic_pixel_format);
2362  if (SUCCEEDED(hr) && d3d_pixel_format != D3DFMT_UNKNOWN)
2363  {
2364  TRACE("Using pixel format %s %#x\n", debugstr_guid(&wic_pixel_format), d3d_pixel_format);
2365 
2366  if (src_surface_desc.Format == d3d_pixel_format) /* Simple copy */
2367  {
2368  hr = IDirect3DSurface9_LockRect(src_surface, &locked_rect, src_rect, D3DLOCK_READONLY);
2369  if (SUCCEEDED(hr))
2370  {
2371  IWICBitmapFrameEncode_WritePixels(frame, height,
2372  locked_rect.Pitch, height * locked_rect.Pitch, locked_rect.pBits);
2373  IDirect3DSurface9_UnlockRect(src_surface);
2374  }
2375  }
2376  else /* Pixel format conversion */
2377  {
2378  const struct pixel_format_desc *src_format_desc, *dst_format_desc;
2379  struct volume size;
2380  DWORD dst_pitch;
2381  void *dst_data;
2382 
2383  src_format_desc = get_format_info(src_surface_desc.Format);
2384  dst_format_desc = get_format_info(d3d_pixel_format);
2385  if (!is_conversion_from_supported(src_format_desc)
2386  || !is_conversion_to_supported(dst_format_desc))
2387  {
2388  FIXME("Unsupported format conversion %#x -> %#x.\n",
2389  src_surface_desc.Format, d3d_pixel_format);
2390  hr = E_NOTIMPL;
2391  goto cleanup;
2392  }
2393 
2394  size.width = width;
2395  size.height = height;
2396  size.depth = 1;
2397  dst_pitch = width * dst_format_desc->bytes_per_pixel;
2398  dst_data = HeapAlloc(GetProcessHeap(), 0, dst_pitch * height);
2399  if (!dst_data)
2400  {
2401  hr = E_OUTOFMEMORY;
2402  goto cleanup;
2403  }
2404 
2405  hr = IDirect3DSurface9_LockRect(src_surface, &locked_rect, src_rect, D3DLOCK_READONLY);
2406  if (SUCCEEDED(hr))
2407  {
2408  convert_argb_pixels(locked_rect.pBits, locked_rect.Pitch, 0, &size, src_format_desc,
2409  dst_data, dst_pitch, 0, &size, dst_format_desc, 0, NULL);
2410  IDirect3DSurface9_UnlockRect(src_surface);
2411  }
2412 
2413  IWICBitmapFrameEncode_WritePixels(frame, height, dst_pitch, dst_pitch * height, dst_data);
2414  HeapFree(GetProcessHeap(), 0, dst_data);
2415  }
2416 
2417  hr = IWICBitmapFrameEncode_Commit(frame);
2418  if (SUCCEEDED(hr)) hr = IWICBitmapEncoder_Commit(encoder);
2419  }
2420  else WARN("Unsupported pixel format %#x\n", src_surface_desc.Format);
2421 
2422  /* copy data from stream to ID3DXBuffer */
2423  hr = IStream_Stat(stream, &stream_stats, STATFLAG_NONAME);
2424  if (FAILED(hr)) goto cleanup_err;
2425 
2426  if (stream_stats.cbSize.u.HighPart != 0)
2427  {
2429  goto cleanup;
2430  }
2431  size = stream_stats.cbSize.u.LowPart;
2432 
2433  /* Remove BMP header for DIB */
2434  if (file_format == D3DXIFF_DIB)
2435  size -= sizeof(BITMAPFILEHEADER);
2436 
2438  if (FAILED(hr)) goto cleanup;
2439 
2440  hr = GetHGlobalFromStream(stream, &stream_hglobal);
2441  if (SUCCEEDED(hr))
2442  {
2443  void *buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
2444  void *stream_data = GlobalLock(stream_hglobal);
2445  /* Remove BMP header for DIB */
2446  if (file_format == D3DXIFF_DIB)
2447  stream_data = (void*)((BYTE*)stream_data + sizeof(BITMAPFILEHEADER));
2448  memcpy(buffer_pointer, stream_data, size);
2449  GlobalUnlock(stream_hglobal);
2450  *dst_buffer = buffer;
2451  }
2453 
2454 cleanup_err:
2455  if (FAILED(hr) && hr != E_OUTOFMEMORY)
2457 
2458 cleanup:
2459  if (stream) IStream_Release(stream);
2460 
2461  if (frame) IWICBitmapFrameEncode_Release(frame);
2462  if (encoder_options) IPropertyBag2_Release(encoder_options);
2463 
2464  if (encoder) IWICBitmapEncoder_Release(encoder);
2465 
2466  if (SUCCEEDED(initresult)) CoUninitialize();
2467 
2468  return hr;
2469 }
GLint GLint GLsizei width
Definition: gl.h:1546
#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:67
HRESULT hr
Definition: shlfolder.c:183
D3DFORMAT Format
Definition: d3d8types.h:1170
#define WARN(fmt,...)
Definition: debug.h:111
LONG top
Definition: windef.h:292
#define D3DERR_INVALIDCALL
GLuint buffer
Definition: glext.h:5915
HRESULT WINAPI CreateStreamOnHGlobal(HGLOBAL hGlobal, BOOL fDeleteOnRelease, LPSTREAM *ppstm)
LONG left
Definition: windef.h:291
LONG right
Definition: windef.h:293
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:1632
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define FIXME(fmt,...)
Definition: debug.h:110
static BOOL is_conversion_from_supported(const struct pixel_format_desc *format)
Definition: d3dx9_private.h:78
smooth NULL
Definition: ftsmooth.c:416
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:54
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
#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)
unsigned long DWORD
Definition: ntddk_ex.h:95
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
Definition: parse.h:22
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char BYTE
Definition: mem.h:68
#define IDirect3DSurface9_GetDesc(p, a)
Definition: d3d9.h:634
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3234
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:1991
#define ID3DXBuffer_Release(p)
Definition: d3dx9core.h:83
struct tagBITMAPFILEHEADER BITMAPFILEHEADER
#define E_NOTIMPL
Definition: ddrawi.h:99
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:1935
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
static BOOL is_conversion_to_supported(const struct pixel_format_desc *format)
Definition: d3dx9_private.h:86
#define IDirect3DSurface9_UnlockRect(p)
Definition: d3d9.h:636
LONG bottom
Definition: windef.h:294
char * cleanup(char *str)
Definition: wpickclick.c:99
const struct pixel_format_desc * get_format_info(D3DFORMAT format) DECLSPEC_HIDDEN
Definition: util.c:213
#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:478
#define D3DLOCK_READONLY
Definition: d3d8types.h:69
static const char stream_data[]
Definition: mlang.c:2327
#define HeapFree(x, y, z)
Definition: compat.h:394
HRESULT WINAPI D3DXCreateBuffer(DWORD size, ID3DXBuffer **buffer)
Definition: core.c:129
#define ID3DXBuffer_GetBufferPointer(p)
Definition: d3dx9core.h:85
#define SUCCEEDED(hr)
Definition: intsafe.h:57

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

◆ D3DXSaveSurfaceToFileW()

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 2229 of file surface.c.

2231 {
2232  HRESULT hr;
2234 
2235  TRACE("(%s, %#x, %p, %p, %s): relay\n",
2236  wine_dbgstr_w(dst_filename), file_format, src_surface, src_palette, wine_dbgstr_rect(src_rect));
2237 
2238  if (!dst_filename) return D3DERR_INVALIDCALL;
2239 
2240  hr = D3DXSaveSurfaceToFileInMemory(&buffer, file_format, src_surface, src_palette, src_rect);
2241  if (SUCCEEDED(hr))
2242  {
2243  hr = write_buffer_to_file(dst_filename, buffer);
2245  }
2246 
2247  return hr;
2248 }
HRESULT hr
Definition: shlfolder.c:183
#define wine_dbgstr_w
Definition: kernel32.h:34
#define D3DERR_INVALIDCALL
GLuint buffer
Definition: glext.h:5915
HRESULT write_buffer_to_file(const WCHAR *filename, ID3DXBuffer *buffer) DECLSPEC_HIDDEN
Definition: util.c:182
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:2250
#define ID3DXBuffer_Release(p)
Definition: d3dx9core.h:83
#define SUCCEEDED(hr)
Definition: intsafe.h:57

◆ dds_alpha_to_d3dformat()

static D3DFORMAT dds_alpha_to_d3dformat ( const struct dds_pixel_format pixel_format)
static

Definition at line 250 of file surface.c.

251 {
252  if (pixel_format->bpp == 8 && pixel_format->amask == 0xff)
253  return D3DFMT_A8;
254 
255  WARN("Unknown Alpha pixel format (%u, %#x)\n", pixel_format->bpp, pixel_format->rmask);
256  return D3DFMT_UNKNOWN;
257 }
#define WARN(fmt,...)
Definition: debug.h:111

Referenced by dds_pixel_format_to_d3dformat().

◆ dds_bump_luminance_to_d3dformat()

static D3DFORMAT dds_bump_luminance_to_d3dformat ( const struct dds_pixel_format pixel_format)
static

Definition at line 271 of file surface.c.

272 {
273  if (pixel_format->bpp == 32 && pixel_format->rmask == 0x000000ff && pixel_format->gmask == 0x0000ff00
274  && pixel_format->bmask == 0x00ff0000)
275  return D3DFMT_X8L8V8U8;
276 
277  WARN("Unknown bump pixel format (%u, %#x, %#x, %#x, %#x)\n", pixel_format->bpp,
278  pixel_format->rmask, pixel_format->gmask, pixel_format->bmask, pixel_format->amask);
279  return D3DFMT_UNKNOWN;
280 }
#define WARN(fmt,...)
Definition: debug.h:111

Referenced by dds_pixel_format_to_d3dformat().

◆ dds_bump_to_d3dformat()

static D3DFORMAT dds_bump_to_d3dformat ( const struct dds_pixel_format pixel_format)
static

Definition at line 259 of file surface.c.

260 {
261  if (pixel_format->bpp == 16 && pixel_format->rmask == 0x00ff && pixel_format->gmask == 0xff00)
262  return D3DFMT_V8U8;
263  if (pixel_format->bpp == 32 && pixel_format->rmask == 0x0000ffff && pixel_format->gmask == 0xffff0000)
264  return D3DFMT_V16U16;
265 
266  WARN("Unknown bump pixel format (%u, %#x, %#x, %#x, %#x)\n", pixel_format->bpp,
267  pixel_format->rmask, pixel_format->gmask, pixel_format->bmask, pixel_format->amask);
268  return D3DFMT_UNKNOWN;
269 }
#define WARN(fmt,...)
Definition: debug.h:111

Referenced by dds_pixel_format_to_d3dformat().

◆ dds_fourcc_to_d3dformat()

static D3DFORMAT dds_fourcc_to_d3dformat ( DWORD  fourcc)
static

Definition at line 149 of file surface.c.

150 {
151  unsigned int i;
152  static const DWORD known_fourcc[] = {
153  D3DFMT_UYVY,
154  D3DFMT_YUY2,
157  D3DFMT_DXT1,
158  D3DFMT_DXT2,
159  D3DFMT_DXT3,
160  D3DFMT_DXT4,
161  D3DFMT_DXT5,
162  D3DFMT_R16F,
165  D3DFMT_R32F,
168  };
169 
170  for (i = 0; i < ARRAY_SIZE(known_fourcc); i++)
171  {
172  if (known_fourcc[i] == fourcc)
173  return fourcc;
174  }
175 
176  WARN("Unknown FourCC %#x\n", fourcc);
177  return D3DFMT_UNKNOWN;
178 }
#define WARN(fmt,...)
Definition: debug.h:111
GLsizei GLenum const GLvoid GLsizei GLenum 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 const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ARRAY_SIZE(a)
Definition: main.h:24

Referenced by d3dformat_to_dds_pixel_format(), and dds_pixel_format_to_d3dformat().

◆ dds_luminance_to_d3dformat()

static D3DFORMAT dds_luminance_to_d3dformat ( const struct dds_pixel_format pixel_format)
static

Definition at line 228 of file surface.c.

229 {
230  if (pixel_format->bpp == 8)
231  {
232  if (pixel_format->rmask == 0xff)
233  return D3DFMT_L8;
234  if ((pixel_format->flags & DDS_PF_ALPHA) && pixel_format->rmask == 0x0f && pixel_format->amask == 0xf0)
235  return D3DFMT_A4L4;
236  }
237  if (pixel_format->bpp == 16)
238  {
239  if (pixel_format->rmask == 0xffff)
240  return D3DFMT_L16;
241  if ((pixel_format->flags & DDS_PF_ALPHA) && pixel_format->rmask == 0x00ff && pixel_format->amask == 0xff00)
242  return D3DFMT_A8L8;
243  }
244 
245  WARN("Unknown luminance pixel format (bpp %u, l %#x, a %#x)\n",
246  pixel_format->bpp, pixel_format->rmask, pixel_format->amask);
247  return D3DFMT_UNKNOWN;
248 }
#define WARN(fmt,...)
Definition: debug.h:111
#define DDS_PF_ALPHA
Definition: surface.c:109

Referenced by dds_pixel_format_to_d3dformat().

◆ dds_pixel_format_to_d3dformat()

static D3DFORMAT dds_pixel_format_to_d3dformat ( const struct dds_pixel_format pixel_format)
static

Definition at line 282 of file surface.c.

283 {
284  TRACE("pixel_format: size %u, flags %#x, fourcc %#x, bpp %u.\n", pixel_format->size,
285  pixel_format->flags, pixel_format->fourcc, pixel_format->bpp);
286  TRACE("rmask %#x, gmask %#x, bmask %#x, amask %#x.\n", pixel_format->rmask, pixel_format->gmask,
287  pixel_format->bmask, pixel_format->amask);
288 
289  if (pixel_format->flags & DDS_PF_FOURCC)
290  return dds_fourcc_to_d3dformat(pixel_format->fourcc);
291  if (pixel_format->flags & DDS_PF_RGB)
293  if (pixel_format->flags & DDS_PF_LUMINANCE)
295  if (pixel_format->flags & DDS_PF_ALPHA_ONLY)
297  if (pixel_format->flags & DDS_PF_BUMPDUDV)
299  if (pixel_format->flags & DDS_PF_BUMPLUMINANCE)
301 
302  WARN("Unknown pixel format (flags %#x, fourcc %#x, bpp %u, r %#x, g %#x, b %#x, a %#x)\n",
303  pixel_format->flags, pixel_format->fourcc, pixel_format->bpp,
304  pixel_format->rmask, pixel_format->gmask, pixel_format->bmask, pixel_format->amask);
305  return D3DFMT_UNKNOWN;
306 }
static D3DFORMAT dds_bump_luminance_to_d3dformat(const struct dds_pixel_format *pixel_format)
Definition: surface.c:271
#define DDS_PF_FOURCC
Definition: surface.c:111
#define WARN(fmt,...)
Definition: debug.h:111
static D3DFORMAT dds_alpha_to_d3dformat(const struct dds_pixel_format *pixel_format)
Definition: surface.c:250
#define DDS_PF_BUMPDUDV
Definition: surface.c:116
static D3DFORMAT dds_rgb_to_d3dformat(const struct dds_pixel_format *pixel_format)
Definition: surface.c:205
#define TRACE(s)
Definition: solgame.cpp:4
static D3DFORMAT dds_fourcc_to_d3dformat(DWORD fourcc)
Definition: surface.c:149
#define DDS_PF_BUMPLUMINANCE
Definition: surface.c:115
#define DDS_PF_LUMINANCE
Definition: surface.c:114
static D3DFORMAT dds_luminance_to_d3dformat(const struct dds_pixel_format *pixel_format)
Definition: surface.c:228
#define DDS_PF_RGB
Definition: surface.c:112
static D3DFORMAT dds_bump_to_d3dformat(const struct dds_pixel_format *pixel_format)
Definition: surface.c:259
#define DDS_PF_ALPHA_ONLY
Definition: surface.c:110

Referenced by get_image_info_from_dds().

◆ dds_rgb_to_d3dformat()

static D3DFORMAT dds_rgb_to_d3dformat ( const struct dds_pixel_format pixel_format)
static

Definition at line 205 of file surface.c.

206 {
207  unsigned int i;
208 
209  for (i = 0; i < ARRAY_SIZE(rgb_pixel_formats); i++)
210  {
211  if (rgb_pixel_formats[i].bpp == pixel_format->bpp
212  && rgb_pixel_formats[i].rmask == pixel_format->rmask
213  && rgb_pixel_formats[i].gmask == pixel_format->gmask
214  && rgb_pixel_formats[i].bmask == pixel_format->bmask)
215  {
216  if ((pixel_format->flags & DDS_PF_ALPHA) && rgb_pixel_formats[i].amask == pixel_format->amask)
217  return rgb_pixel_formats[i].format;
218  if (rgb_pixel_formats[i].amask == 0)
219  return rgb_pixel_formats[i].format;
220  }
221  }
222 
223  WARN("Unknown RGB pixel format (%#x, %#x, %#x, %#x)\n",
224  pixel_format->rmask, pixel_format->gmask, pixel_format->bmask, pixel_format->amask);
225  return D3DFMT_UNKNOWN;
226 }
DWORD amask
Definition: surface.c:185
#define WARN(fmt,...)
Definition: debug.h:111
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLsizei GLenum const GLvoid GLsizei GLenum 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 const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ARRAY_SIZE(a)
Definition: main.h:24
#define DDS_PF_ALPHA
Definition: surface.c:109
DWORD bpp
Definition: surface.c:181
static const struct @242 rgb_pixel_formats[]

Referenced by dds_pixel_format_to_d3dformat().

◆ DEFINE_GUID()

DEFINE_GUID ( GUID_WineContainerFormatTga  ,
0x0c44fda1  ,
0xa5c5  ,
0x4298  ,
0x96  ,
0x85  ,
0x47  ,
0x3f  ,
0xc1  ,
0x7c  ,
0xd3  ,
0x22   
)

◆ format_from_vec4()

static void format_from_vec4 ( const struct pixel_format_desc format,
const struct vec4 src,
BYTE dst 
)
static

Definition at line 1551 of file surface.c.

1552 {
1553  DWORD v, mask32;
1554  unsigned int c, i;
1555 
1556  memset(dst, 0, format->bytes_per_pixel);
1557 
1558  for (c = 0; c < 4; ++c)
1559  {
1560  static const unsigned int component_offsets[4] = {3, 0, 1, 2};
1561  const float src_component = *((const float *)src + component_offsets[c]);
1562 
1563  if (!format->bits[c])
1564  continue;
1565 
1566  mask32 = ~0u >> (32 - format->bits[c]);
1567 
1568  if (format->type == FORMAT_ARGBF16)
1569  v = float_32_to_16(src_component);
1570  else if (format->type == FORMAT_ARGBF)
1571  v = *(DWORD *)&src_component;
1572  else
1573  v = (DWORD)(src_component * ((1 << format->bits[c]) - 1) + 0.5f);
1574 
1575  for (i = format->shift[c] / 8 * 8; i < format->shift[c] + format->bits[c]; i += 8)
1576  {
1577  BYTE mask, byte;
1578 
1579  if (format->shift[c] > i)
1580  {
1581  mask = mask32 << (format->shift[c] - i);
1582  byte = (v << (format->shift[c] - i)) & mask;
1583  }
1584  else
1585  {
1586  mask = mask32 >> (i - format->shift[c]);
1587  byte = (v >> (i - format->shift[c])) & mask;
1588  }
1589  dst[i / 8] |= byte;
1590  }
1591  }
1592 }
GLsizei GLenum const GLvoid GLsizei GLenum 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 const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
#define shift
Definition: input.c:1668
#define DWORD
Definition: nt_native.h:44
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLsizei GLenum const GLvoid GLsizei GLenum 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 const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLenum GLint GLuint mask
Definition: glext.h:6028
GLfloat f
Definition: glext.h:7540
const GLubyte * c
Definition: glext.h:8905
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned char BYTE
Definition: mem.h:68
GLenum src
Definition: glext.h:6340
const GLdouble * v
Definition: gl.h:2040
#define byte(x, n)
Definition: tomcrypt.h:118
GLenum GLenum dst
Definition: glext.h:6340
static unsigned short float_32_to_16(const float *in)
Definition: surface.c:572
#define c
Definition: ke_i.h:80
#define memset(x, y, z)
Definition: compat.h:39

Referenced by convert_argb_pixels(), and point_filter_argb_pixels().

◆ format_to_vec4()

static void format_to_vec4 ( const struct pixel_format_desc format,
const BYTE src,
struct vec4 dst 
)
static

Definition at line 1521 of file surface.c.

1522 {
1523  DWORD mask, tmp;
1524  unsigned int c;
1525 
1526  for (c = 0; c < 4; ++c)
1527  {
1528  static const unsigned int component_offsets[4] = {3, 0, 1, 2};
1529  float *dst_component = (float *)dst + component_offsets[c];
1530 
1531  if (format->bits[c])
1532  {
1533  mask = ~0u >> (32 - format->bits[c]);
1534 
1535  memcpy(&tmp, src + format->shift[c] / 8,
1536  min(sizeof(DWORD), (format->shift[c] % 8 + format->bits[c] + 7) / 8));
1537 
1538  if (format->type == FORMAT_ARGBF16)
1539  *dst_component = float_16_to_32(tmp);
1540  else if (format->type == FORMAT_ARGBF)
1541  *dst_component = *(float *)&tmp;
1542  else
1543  *dst_component = (float)((tmp >> format->shift[c] % 8) & mask) / mask;
1544  }
1545  else
1546  *dst_component = 1.0f;
1547  }
1548 }
GLsizei GLenum const GLvoid GLsizei GLenum 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 const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLenum GLint GLuint mask
Definition: glext.h:6028
float float_16_to_32(const unsigned short in) DECLSPEC_HIDDEN
Definition: math.c:2247
const GLubyte * c
Definition: glext.h:8905
unsigned long DWORD
Definition: ntddk_ex.h:95
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
#define min(a, b)
Definition: monoChain.cc:55
#define c
Definition: ke_i.h:80

Referenced by convert_argb_pixels(), and point_filter_argb_pixels().

◆ get_dxtn_conversion_func()

static dxtn_conversion_func get_dxtn_conversion_func ( D3DFORMAT  format,
BOOL  encode 
)
static

Definition at line 1825 of file surface.c.

1826 {
1827  switch (format)
1828  {
1829  case D3DFMT_DXT1:
1830  return encode ? wined3d_dxt1_encode : wined3d_dxt1_decode;
1831  case D3DFMT_DXT3:
1832  return encode ? wined3d_dxt3_encode : wined3d_dxt3_decode;
1833  case D3DFMT_DXT5:
1834  return encode ? wined3d_dxt5_encode : wined3d_dxt5_decode;
1835  default:
1836  return NULL;
1837  }
1838 }
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:417
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:439
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:317
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
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:389
smooth NULL
Definition: ftsmooth.c:416
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:345
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:369

Referenced by D3DXLoadSurfaceFromMemory().

◆ get_image_info_from_dds()

static HRESULT get_image_info_from_dds ( const void buffer,
UINT  length,
D3DXIMAGE_INFO info 
)
static

Definition at line 403 of file surface.c.

404 {
405  UINT faces = 1;
406  UINT expected_length;
407  const struct dds_header *header = buffer;
408 
409  if (length < sizeof(*header) || !info)
410  return D3DXERR_INVALIDDATA;
411 
412  if (header->pixel_format.size != sizeof(header->pixel_format))
413  return D3DXERR_INVALIDDATA;
414 
415  info->Width = header->width;
416  info->Height = header->height;
417  info->Depth = 1;
418  info->MipLevels = header->miplevels ? header->miplevels : 1;
419 
420  info->Format = dds_pixel_format_to_d3dformat(&header->pixel_format);
421  if (info->Format == D3DFMT_UNKNOWN)
422  return D3DXERR_INVALIDDATA;
423 
424  TRACE("Pixel format is %#x\n", info->Format);
425 
426  if (header->caps2 & DDS_CAPS2_VOLUME)
427  {
428  info->Depth = header->depth;
429  info->ResourceType = D3DRTYPE_VOLUMETEXTURE;
430  }
431  else if (header->caps2 & DDS_CAPS2_CUBEMAP)
432  {
433  DWORD face;
434  faces = 0;
436  {
437  if (header->caps2 & face)
438  faces++;
439  }
440  info->ResourceType = D3DRTYPE_CUBETEXTURE;
441  }
442  else
443  {
444  info->ResourceType = D3DRTYPE_TEXTURE;
445  }
446 
447  expected_length = calculate_dds_file_size(info->Format, info->Width, info->Height, info->Depth,
448  info->MipLevels, faces);
449  if (length < expected_length)
450  {
451  WARN("File is too short %u, expected at least %u bytes\n", length, expected_length);
452  return D3DXERR_INVALIDDATA;
453  }
454 
455  info->ImageFileFormat = D3DXIFF_DDS;
456  return D3D_OK;
457 }
#define WARN(fmt,...)
Definition: debug.h:111
#define DDS_CAPS2_VOLUME
Definition: surface.c:106
GLuint buffer
Definition: glext.h:5915
WORD face[3]
Definition: mesh.c:4747
#define TRACE(s)
Definition: solgame.cpp:4
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
unsigned long DWORD
Definition: ntddk_ex.h:95
static UINT calculate_dds_file_size(D3DFORMAT format, UINT width, UINT height, UINT depth, UINT miplevels, UINT faces)
Definition: surface.c:366
#define D3D_OK
Definition: d3d.h:106
unsigned int UINT
Definition: ndis.h:50
static D3DFORMAT dds_pixel_format_to_d3dformat(const struct dds_pixel_format *pixel_format)
Definition: surface.c:282
#define DDS_CAPS2_CUBEMAP_NEGATIVEZ
Definition: surface.c:102
#define DDS_CAPS2_CUBEMAP
Definition: surface.c:96
#define DDS_CAPS2_CUBEMAP_POSITIVEX
Definition: surface.c:97
struct CFHEADER header
Definition: fdi.c:109
GLenum GLuint GLint GLenum face
Definition: glext.h:7025

Referenced by D3DXGetImageInfoFromFileInMemory().

◆ get_relevant_argb_components()

static void get_relevant_argb_components ( const struct argb_conversion_info info,
const BYTE col,
DWORD out 
)
static

Definition at line 1473 of file surface.c.

1474 {
1475  unsigned int i, j;
1476  unsigned int component, mask;
1477 
1478  for (i = 0; i < 4; ++i)
1479  {
1480  if (!info->process_channel[i])
1481  continue;
1482 
1483  component = 0;
1484  mask = info->srcmask[i];
1485  for (j = 0; j < 4 && mask; ++j)
1486  {
1487  if (info->srcshift[i] < j * 8)
1488  component |= (col[j] & mask) << (j * 8 - info->srcshift[i]);
1489  else
1490  component |= (col[j] & mask) >> (info->srcshift[i] - j * 8);
1491  mask >>= 8;
1492  }
1493  out[i] = component;
1494  }
1495 }
GLsizei GLenum const GLvoid GLsizei GLenum 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 const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLenum GLint GLuint mask
Definition: glext.h:6028
GLsizei GLenum const GLvoid GLsizei GLenum 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 const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
static FILE * out
Definition: regtests2xml.c:44

Referenced by convert_argb_pixels(), and point_filter_argb_pixels().

◆ get_surface()

static HRESULT get_surface ( D3DRESOURCETYPE  type,
struct IDirect3DBaseTexture9 *  tex,
int  face,
UINT  level,
struct IDirect3DSurface9 **  surf 
)
static

Definition at line 547 of file surface.c.

549 {
550  switch (type)
551  {
552  case D3DRTYPE_TEXTURE:
553  return IDirect3DTexture9_GetSurfaceLevel((IDirect3DTexture9*) tex, level, surf);
555  return IDirect3DCubeTexture9_GetCubeMapSurface((IDirect3DCubeTexture9*) tex, face, level, surf);
556  default:
557  ERR("Unexpected texture type\n");
558  return E_NOTIMPL;
559  }
560 }
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

Referenced by save_dds_texture_to_memory().

◆ init_argb_conversion_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

Definition at line 1440 of file surface.c.

1441 {
1442  UINT i;
1443  ZeroMemory(info->process_channel, 4 * sizeof(BOOL));
1444  info->channelmask = 0;
1445 
1446  info->srcformat = srcformat;
1447  info->destformat = destformat;
1448 
1449  for(i = 0;i < 4;i++) {
1450  /* srcshift is used to extract the _relevant_ components */
1451  info->srcshift[i] = srcformat->shift[i] + max( srcformat->bits[i] - destformat->bits[i], 0);
1452 
1453  /* destshift is used to move the components to the correct position */
1454  info->destshift[i] = destformat->shift[i] + max(destformat->bits[i] - srcformat->bits[i], 0);
1455 
1456  info->srcmask[i] = ((1 << srcformat->bits[i]) - 1) << srcformat->shift[i];
1457  info->destmask[i] = ((1 << destformat->bits[i]) - 1) << destformat->shift[i];
1458 
1459  /* channelmask specifies bits which aren't used in the source format but in the destination one */
1460  if(destformat->bits[i]) {
1461  if(srcformat->bits[i]) info->process_channel[i] = TRUE;
1462  else info->channelmask |= info->destmask[i];
1463  }
1464  }
1465 }
#define max(a, b)
Definition: svc.c:63
#define TRUE
Definition: types.h:120
#define ZeroMemory
Definition: winbase.h:1635
GLsizei GLenum const GLvoid GLsizei GLenum 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 const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned int UINT
Definition: ndis.h:50

Referenced by convert_argb_pixels(), and point_filter_argb_pixels().

◆ load_cube_texture_from_dds()

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 684 of file surface.c.

686 {
687  HRESULT hr;
688  int face;
689  UINT mip_level;
690  UINT size;
691  RECT src_rect;
692  UINT src_pitch;
693  UINT mip_levels;
694  UINT mip_level_size;
695  IDirect3DSurface9 *surface;
696  const struct dds_header *header = src_data;
697  const BYTE *pixels = (BYTE *)(header + 1);
698 
699  if (src_info->ResourceType != D3DRTYPE_CUBETEXTURE)
700  return D3DXERR_INVALIDDATA;
701 
703  {
704  WARN("Only full cubemaps are supported\n");
705  return D3DXERR_INVALIDDATA;
706  }
707 
708  mip_levels = min(src_info->MipLevels, IDirect3DCubeTexture9_GetLevelCount(cube_texture));
710  {
711  size = src_info->Width;
712  for (mip_level = 0; mip_level < src_info->MipLevels; mip_level++)
713  {
714  hr = calculate_dds_surface_size(src_info->Format, size, size, &src_pitch, &mip_level_size);
715  if (FAILED(hr)) return hr;
716 
717  /* if texture has fewer mip levels than DDS file, skip excessive mip levels */
718  if (mip_level < mip_levels)
719  {
720  SetRect(&src_rect, 0, 0, size, size);
721 
722  IDirect3DCubeTexture9_GetCubeMapSurface(cube_texture, face, mip_level, &surface);
723  hr = D3DXLoadSurfaceFromMemory(surface, palette, NULL, pixels, src_info->Format, src_pitch,
724  NULL, &src_rect, filter, color_key);
725  IDirect3DSurface9_Release(surface);
726  if (FAILED(hr)) return hr;
727  }
728 
729  pixels += mip_level_size;
730  size = max(1, size / 2);
731  }
732  }
733 
734  return D3D_OK;
735 }
#define IDirect3DSurface9_Release(p)
Definition: d3d9.h:622
#define max(a, b)
Definition: svc.c:63
HRESULT hr
Definition: shlfolder.c:183
#define IDirect3DCubeTexture9_GetLevelCount(p)
Definition: d3d9.h:932
#define WARN(fmt,...)
Definition: debug.h:111
WORD face[3]
Definition: mesh.c:4747
D3DRESOURCETYPE ResourceType
Definition: d3dx9tex.h:83
UINT MipLevels
Definition: d3dx9tex.h:81
smooth NULL
Definition: ftsmooth.c:416
GLsizeiptr size
Definition: glext.h:5919
D3DFORMAT Format
Definition: d3dx9tex.h:82
#define DDS_CAPS2_CUBEMAP_ALL_FACES
Definition: surface.c:103
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:343
#define IDirect3DCubeTexture9_GetCubeMapSurface(p, a, b, c)
Definition: d3d9.h:938
unsigned char BYTE
Definition: mem.h:68
static HPALETTE palette
Definition: clipboard.c:1345
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:1872
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
GLenum GLuint GLint GLenum face
Definition: glext.h:7025

◆ load_surface_from_dds()

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 459 of file surface.c.

462 {
463  UINT size;
464  UINT src_pitch;
465  const struct dds_header *header = src_data;
466  const BYTE *pixels = (BYTE *)(header + 1);
467 
468  if (src_info->ResourceType != D3DRTYPE_TEXTURE)
469  return D3DXERR_INVALIDDATA;
470 
471  if (FAILED(calculate_dds_surface_size(src_info->Format, src_info->Width, src_info->Height, &src_pitch, &size)))
472  return E_NOTIMPL;
473 
474  return D3DXLoadSurfaceFromMemory(dst_surface, dst_palette, dst_rect, pixels, src_info->Format,
475  src_pitch, NULL, src_rect, filter, color_key);
476 }
D3DRESOURCETYPE ResourceType
Definition: d3dx9tex.h:83
smooth NULL
Definition: ftsmooth.c:416
GLsizeiptr size
Definition: glext.h:5919
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:343
unsigned char BYTE
Definition: mem.h:68
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:1872
#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

Referenced by D3DXLoadSurfaceFromFileInMemory().

◆ load_texture_from_dds()

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 627 of file surface.c.

630 {
631  HRESULT hr;
632  RECT src_rect;
633  UINT src_pitch;
634  UINT mip_level;
635  UINT mip_levels;
636  UINT mip_level_size;
637  UINT width, height;
638  IDirect3DSurface9 *surface;
639  const struct dds_header *header = src_data;
640  const BYTE *pixels = (BYTE *)(header + 1);
641 
642  /* Loading a cube texture as a simple texture is also supported
643  * (only first face texture is taken). Same with volume textures. */
644  if ((src_info->ResourceType != D3DRTYPE_TEXTURE)
645  && (src_info->ResourceType != D3DRTYPE_CUBETEXTURE)
646  && (src_info->ResourceType != D3DRTYPE_VOLUMETEXTURE))
647  {
648  WARN("Trying to load a %u resource as a 2D texture, returning failure.\n", src_info->ResourceType);
649  return D3DXERR_INVALIDDATA;
650  }
651 
652  width = src_info->Width;
653  height = src_info->Height;
654  mip_levels = min(src_info->MipLevels, IDirect3DTexture9_GetLevelCount(texture));
655  if (src_info->ResourceType == D3DRTYPE_VOLUMETEXTURE)
656  mip_levels = 1;
657  for (mip_level = 0; mip_level < mip_levels + skip_levels; ++mip_level)
658  {
659  hr = calculate_dds_surface_size(src_info->Format, width, height, &src_pitch, &mip_level_size);
660  if (FAILED(hr)) return hr;
661 
662  if (mip_level >= skip_levels)
663  {
664  SetRect(&src_rect, 0, 0, width, height);
665 
666  IDirect3DTexture9_GetSurfaceLevel(texture, mip_level - skip_levels, &surface);
667  hr = D3DXLoadSurfaceFromMemory(surface, palette, NULL, pixels, src_info->Format, src_pitch,
668  NULL, &src_rect, filter, color_key);
669  IDirect3DSurface9_Release(surface);
670  if (FAILED(hr))
671  return hr;
672  }
673 
674  pixels += mip_level_size;
675  width = max(1, width / 2);
676  height = max(1, height / 2);
677  }
678 
679  *loaded_miplevels = mip_levels - skip_levels;
680 
681  return D3D_OK;
682 }
#define IDirect3DSurface9_Release(p)
Definition: d3d9.h:622
GLint GLint GLsizei width
Definition: gl.h:1546
#define max(a, b)
Definition: svc.c:63
HRESULT hr
Definition: shlfolder.c:183
#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:416
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:343
unsigned char BYTE
Definition: mem.h:68
static HPALETTE palette
Definition: clipboard.c:1345
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
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:1872
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

Referenced by D3DXCreateTextureFromFileInMemoryEx().

◆ load_volume_from_dds()

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 609 of file surface.c.

612 {
613  UINT row_pitch, slice_pitch;
614  const struct dds_header *header = src_data;
615  const BYTE *pixels = (BYTE *)(header + 1);
616 
617  if (src_info->ResourceType != D3DRTYPE_VOLUMETEXTURE)
618  return D3DXERR_INVALIDDATA;
619 
620  if (FAILED(calculate_dds_surface_size(src_info->Format, src_info->Width, src_info->Height, &row_pitch, &slice_pitch)))
621  return E_NOTIMPL;
622 
623  return D3DXLoadVolumeFromMemory(dst_volume, dst_palette, dst_box, pixels, src_info->Format,
624  row_pitch, slice_pitch, NULL, src_box, filter, color_key);
625 }
D3DRESOURCETYPE ResourceType
Definition: d3dx9tex.h:83
smooth NULL
Definition: ftsmooth.c:416
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:343
unsigned char BYTE
Definition: mem.h:68
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:85
#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

Referenced by D3DXLoadVolumeFromFileInMemory().

◆ load_volume_texture_from_dds()

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 737 of file surface.c.

739 {
740  HRESULT hr;
741  UINT mip_level;
742  UINT mip_levels;
743  UINT src_slice_pitch;
744  UINT src_row_pitch;
745  D3DBOX src_box;
747  IDirect3DVolume9 *volume;
748  const struct dds_header *header = src_data;
749  const BYTE *pixels = (BYTE *)(header + 1);
750 
751  if (src_info->ResourceType != D3DRTYPE_VOLUMETEXTURE)
752  return D3DXERR_INVALIDDATA;
753 
754  width = src_info->Width;
755  height = src_info->Height;
756  depth = src_info->Depth;
757  mip_levels = min(src_info->MipLevels, IDirect3DVolumeTexture9_GetLevelCount(volume_texture));
758 
759  for (mip_level = 0; mip_level < mip_levels; mip_level++)
760  {
761  hr = calculate_dds_surface_size(src_info->Format, width, height, &src_row_pitch, &src_slice_pitch);
762  if (FAILED(hr)) return hr;
763 
764  hr = IDirect3DVolumeTexture9_GetVolumeLevel(volume_texture, mip_level, &volume);
765  if (FAILED(hr)) return hr;
766 
767  src_box.Left = 0;
768  src_box.Top = 0;
769  src_box.Right = width;
770  src_box.Bottom = height;
771  src_box.Front = 0;
772  src_box.Back = depth;
773 
775  src_row_pitch, src_slice_pitch, NULL, &src_box, filter, color_key);
776 
778  if (FAILED(hr)) return hr;
779 
780  pixels += depth * src_slice_pitch;
781  width = max(1, width / 2);
782  height = max(1, height / 2);
783  depth = max(1, depth / 2);
784  }
785 
786  return D3D_OK;
787 }
GLint GLint GLsizei width
Definition: gl.h:1546
#define max(a, b)
Definition: svc.c:63
HRESULT hr
Definition: shlfolder.c:183
#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:416
UINT Bottom
Definition: d3d8types.h:1014
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:343
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
#define IDirect3DVolume9_Release(p)
Definition: d3d9.h:383
unsigned char BYTE
Definition: mem.h:68
static HPALETTE palette
Definition: clipboard.c:1345
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
#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:85
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
#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

Referenced by D3DXCreateVolumeTextureFromFileInMemoryEx().

◆ make_argb_color()

static DWORD make_argb_color ( const struct argb_conversion_info info,
const DWORD in 
)
static

Definition at line 1503 of file surface.c.

1504 {
1505  UINT i;
1506  DWORD val = 0;
1507 
1508  for(i = 0;i < 4;i++) {
1509  if(info->process_channel[i]) {
1510  /* necessary to make sure that e.g. an X4R4G4B4 white maps to an R8G8B8 white instead of 0xf0f0f0 */
1511  signed