ReactOS  0.4.15-dev-425-gc40b086
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)
 
HRESULT WINAPI WICCreateImagingFactory_Proxy (UINT, IWICImagingFactory **)
 
 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)
 
HRESULT lock_surface (IDirect3DSurface9 *surface, D3DLOCKED_RECT *lock, IDirect3DSurface9 **temp_surface, BOOL write)
 
HRESULT unlock_surface (IDirect3DSurface9 *surface, D3DLOCKED_RECT *lock, IDirect3DSurface9 *temp_surface, BOOL update)
 
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 82 of file surface.c.

◆ DDS_CAPS2_CUBEMAP

#define DDS_CAPS2_CUBEMAP   0x200

Definition at line 97 of file surface.c.

◆ DDS_CAPS2_CUBEMAP_ALL_FACES

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

Definition at line 104 of file surface.c.

◆ DDS_CAPS2_CUBEMAP_NEGATIVEX

#define DDS_CAPS2_CUBEMAP_NEGATIVEX   0x800

Definition at line 99 of file surface.c.

◆ DDS_CAPS2_CUBEMAP_NEGATIVEY

#define DDS_CAPS2_CUBEMAP_NEGATIVEY   0x2000

Definition at line 101 of file surface.c.

◆ DDS_CAPS2_CUBEMAP_NEGATIVEZ

#define DDS_CAPS2_CUBEMAP_NEGATIVEZ   0x8000

Definition at line 103 of file surface.c.

◆ DDS_CAPS2_CUBEMAP_POSITIVEX

#define DDS_CAPS2_CUBEMAP_POSITIVEX   0x400

Definition at line 98 of file surface.c.

◆ DDS_CAPS2_CUBEMAP_POSITIVEY

#define DDS_CAPS2_CUBEMAP_POSITIVEY   0x1000

Definition at line 100 of file surface.c.

◆ DDS_CAPS2_CUBEMAP_POSITIVEZ

#define DDS_CAPS2_CUBEMAP_POSITIVEZ   0x4000

Definition at line 102 of file surface.c.

◆ DDS_CAPS2_VOLUME

#define DDS_CAPS2_VOLUME   0x200000

Definition at line 107 of file surface.c.

◆ DDS_CAPS_COMPLEX

#define DDS_CAPS_COMPLEX   0x8

Definition at line 92 of file surface.c.

◆ DDS_CAPS_MIPMAP

#define DDS_CAPS_MIPMAP   0x400000

Definition at line 94 of file surface.c.

◆ DDS_CAPS_TEXTURE

#define DDS_CAPS_TEXTURE   0x1000

Definition at line 93 of file surface.c.

◆ DDS_DEPTH

#define DDS_DEPTH   0x800000

Definition at line 89 of file surface.c.

◆ DDS_HEIGHT

#define DDS_HEIGHT   0x2

Definition at line 83 of file surface.c.

◆ DDS_LINEARSIZE

#define DDS_LINEARSIZE   0x80000

Definition at line 88 of file surface.c.

◆ DDS_MIPMAPCOUNT

#define DDS_MIPMAPCOUNT   0x20000

Definition at line 87 of file surface.c.

◆ DDS_PF_ALPHA

#define DDS_PF_ALPHA   0x1

Definition at line 110 of file surface.c.

◆ DDS_PF_ALPHA_ONLY

#define DDS_PF_ALPHA_ONLY   0x2

Definition at line 111 of file surface.c.

◆ DDS_PF_BUMPDUDV

#define DDS_PF_BUMPDUDV   0x80000

Definition at line 117 of file surface.c.

◆ DDS_PF_BUMPLUMINANCE

#define DDS_PF_BUMPLUMINANCE   0x40000

Definition at line 116 of file surface.c.

◆ DDS_PF_FOURCC

#define DDS_PF_FOURCC   0x4

Definition at line 112 of file surface.c.

◆ DDS_PF_LUMINANCE

#define DDS_PF_LUMINANCE   0x20000

Definition at line 115 of file surface.c.

◆ DDS_PF_RGB

#define DDS_PF_RGB   0x40

Definition at line 113 of file surface.c.

◆ DDS_PF_YUV

#define DDS_PF_YUV   0x200

Definition at line 114 of file surface.c.

◆ DDS_PITCH

#define DDS_PITCH   0x8

Definition at line 85 of file surface.c.

◆ DDS_PIXELFORMAT

#define DDS_PIXELFORMAT   0x1000

Definition at line 86 of file surface.c.

◆ DDS_WIDTH

#define DDS_WIDTH   0x4

Definition at line 84 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 1881 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 435 of file surface.c.

437 {
438  UINT i, file_size = 0;
439 
440  for (i = 0; i < miplevels; i++)
441  {
442  UINT pitch, size = 0;
444  size *= depth;
445  file_size += size;
446  width = max(1, width / 2);
447  height = max(1, height / 2);
448  depth = max(1, depth / 2);
449  }
450 
451  file_size *= faces;
452  file_size += sizeof(struct dds_header);
453  return file_size;
454 }
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:412
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 412 of file surface.c.

414 {
415  const struct pixel_format_desc *format_desc = get_format_info(format);
416  if (format_desc->type == FORMAT_UNKNOWN)
417  return E_NOTIMPL;
418 
419  if (format_desc->block_width != 1 || format_desc->block_height != 1)
420  {
421  *pitch = format_desc->block_byte_count
422  * max(1, (width + format_desc->block_width - 1) / format_desc->block_width);
423  *size = *pitch
424  * max(1, (height + format_desc->block_height - 1) / format_desc->block_height);
425  }
426  else
427  {
428  *pitch = width * format_desc->bytes_per_pixel;
429  *size = *pitch * height;
430  }
431 
432  return D3D_OK;
433 }
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 1691 of file surface.c.

1695 {
1696  struct argb_conversion_info conv_info, ck_conv_info;
1697  const struct pixel_format_desc *ck_format = NULL;
1698  DWORD channels[4];
1699  UINT min_width, min_height, min_depth;
1700  UINT x, y, z;
1701 
1702  ZeroMemory(channels, sizeof(channels));
1703  init_argb_conversion_info(src_format, dst_format, &conv_info);
1704 
1705  min_width = min(src_size->width, dst_size->width);
1706  min_height = min(src_size->height, dst_size->height);
1707  min_depth = min(src_size->depth, dst_size->depth);
1708 
1709  if (color_key)
1710  {
1711  /* Color keys are always represented in D3DFMT_A8R8G8B8 format. */
1712  ck_format = get_format_info(D3DFMT_A8R8G8B8);
1713  init_argb_conversion_info(src_format, ck_format, &ck_conv_info);
1714  }
1715 
1716  for (z = 0; z < min_depth; z++) {
1717  const BYTE *src_slice_ptr = src + z * src_slice_pitch;
1718  BYTE *dst_slice_ptr = dst + z * dst_slice_pitch;
1719 
1720  for (y = 0; y < min_height; y++) {
1721  const BYTE *src_ptr = src_slice_ptr + y * src_row_pitch;
1722  BYTE *dst_ptr = dst_slice_ptr + y * dst_row_pitch;
1723 
1724  for (x = 0; x < min_width; x++) {
1725  if (!src_format->to_rgba && !dst_format->from_rgba
1726  && src_format->type == dst_format->type
1727  && src_format->bytes_per_pixel <= 4 && dst_format->bytes_per_pixel <= 4)
1728  {
1729  DWORD val;
1730 
1731  get_relevant_argb_components(&conv_info, src_ptr, channels);
1732  val = make_argb_color(&conv_info, channels);
1733 
1734  if (color_key)
1735  {
1736  DWORD ck_pixel;
1737 
1738  get_relevant_argb_components(&ck_conv_info, src_ptr, channels);
1739  ck_pixel = make_argb_color(&ck_conv_info, channels);
1740  if (ck_pixel == color_key)
1741  val &= ~conv_info.destmask[0];
1742  }
1743  memcpy(dst_ptr, &val, dst_format->bytes_per_pixel);
1744  }
1745  else
1746  {
1747  struct vec4 color, tmp;
1748 
1749  format_to_vec4(src_format, src_ptr, &color);
1750  if (src_format->to_rgba)
1751  src_format->to_rgba(&color, &tmp, palette);
1752  else
1753  tmp = color;
1754 
1755  if (ck_format)
1756  {
1757  DWORD ck_pixel;
1758 
1759  format_from_vec4(ck_format, &tmp, (BYTE *)&ck_pixel);
1760  if (ck_pixel == color_key)
1761  tmp.w = 0.0f;
1762  }
1763 
1764  if (dst_format->from_rgba)
1765  dst_format->from_rgba(&tmp, &color);
1766  else
1767  color = tmp;
1768 
1769  format_from_vec4(dst_format, &color, dst_ptr);
1770  }
1771 
1772  src_ptr += src_format->bytes_per_pixel;
1773  dst_ptr += dst_format->bytes_per_pixel;
1774  }
1775 
1776  if (src_size->width < dst_size->width) /* black out remaining pixels */
1777  memset(dst_ptr, 0, dst_format->bytes_per_pixel * (dst_size->width - src_size->width));
1778  }
1779 
1780  if (src_size->height < dst_size->height) /* black out remaining pixels */
1781  memset(dst + src_size->height * dst_row_pitch, 0, dst_row_pitch * (dst_size->height - src_size->height));
1782  }
1783  if (src_size->depth < dst_size->depth) /* black out remaining pixels */
1784  memset(dst + src_size->depth * dst_slice_pitch, 0, dst_slice_pitch * (dst_size->depth - src_size->depth));
1785 }
UINT width
Definition: d3dx9_private.h:42
static const char * dst_format
Definition: dib.c:1133
#define ZeroMemory
Definition: winbase.h:1648
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
GLenum src
Definition: glext.h:6340
unsigned char BYTE
Definition: xxhash.c:193
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:1610
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:1499
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:1532
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:1580
#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:1562

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

◆ convert_dib_to_bmp()

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

Definition at line 859 of file surface.c.

860 {
861  ULONG header_size;
862  ULONG count = 0;
863  ULONG offset;
865  BYTE *new_data;
866  UINT new_size;
867 
868  if ((*size < 4) || (*size < (header_size = *(ULONG*)*data)))
869  return FALSE;
870 
871  if ((header_size == sizeof(BITMAPINFOHEADER)) ||
872  (header_size == sizeof(BITMAPV4HEADER)) ||
873  (header_size == sizeof(BITMAPV5HEADER)) ||
874  (header_size == 64 /* sizeof(BITMAPCOREHEADER2) */))
875  {
876  /* All structures begin with the same memory layout as BITMAPINFOHEADER */
877  BITMAPINFOHEADER *info_header = (BITMAPINFOHEADER*)*data;
878  count = info_header->biClrUsed;
879 
880  if (!count && info_header->biBitCount <= 8)
881  count = 1 << info_header->biBitCount;
882 
883  offset = sizeof(BITMAPFILEHEADER) + header_size + sizeof(RGBQUAD) * count;
884 
885  /* For BITMAPINFOHEADER with BI_BITFIELDS compression, there are 3 additional color masks after header */
886  if ((info_header->biSize == sizeof(BITMAPINFOHEADER)) && (info_header->biCompression == BI_BITFIELDS))
887  offset += 3 * sizeof(DWORD);
888  }
889  else if (header_size == sizeof(BITMAPCOREHEADER))
890  {
891  BITMAPCOREHEADER *core_header = (BITMAPCOREHEADER*)*data;
892 
893  if (core_header->bcBitCount <= 8)
894  count = 1 << core_header->bcBitCount;
895 
896  offset = sizeof(BITMAPFILEHEADER) + header_size + sizeof(RGBTRIPLE) * count;
897  }
898  else
899  {
900  return FALSE;
901  }
902 
903  TRACE("Converting DIB file to BMP\n");
904 
905  new_size = *size + sizeof(BITMAPFILEHEADER);
906  new_data = HeapAlloc(GetProcessHeap(), 0, new_size);
907  CopyMemory(new_data + sizeof(BITMAPFILEHEADER), *data, *size);
908 
909  /* Add BMP header */
910  header = (BITMAPFILEHEADER*)new_data;
911  header->bfType = 0x4d42; /* BM */
912  header->bfSize = new_size;
913  header->bfReserved1 = 0;
914  header->bfReserved2 = 0;
915  header->bfOffBits = offset;
916 
917  /* Update input data */
918  *data = new_data;
919  *size = new_size;
920 
921  return TRUE;
922 }
#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:404
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
ULONG RGBQUAD
Definition: precomp.h:50
#define CopyMemory
Definition: winbase.h:1646
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: xxhash.c:193
struct tagBITMAPFILEHEADER BITMAPFILEHEADER
unsigned int UINT
Definition: ndis.h:50
unsigned int ULONG
Definition: retypes.h:1
struct CFHEADER header
Definition: fdi.c:101

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

1663 {
1664  UINT row, slice;
1665  BYTE *dst_addr;
1666  const BYTE *src_addr;
1667  UINT row_block_count = (size->width + format->block_width - 1) / format->block_width;
1668  UINT row_count = (size->height + format->block_height - 1) / format->block_height;
1669 
1670  for (slice = 0; slice < size->depth; slice++)
1671  {
1672  src_addr = src + slice * src_slice_pitch;
1673  dst_addr = dst + slice * dst_slice_pitch;
1674 
1675  for (row = 0; row < row_count; row++)
1676  {
1677  memcpy(dst_addr, src_addr, row_block_count * format->block_byte_count);
1678  src_addr += src_row_pitch;
1679  dst_addr += dst_row_pitch;
1680  }
1681  }
1682 }
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
GLenum src
Definition: glext.h:6340
unsigned char BYTE
Definition: xxhash.c:193
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 377 of file surface.c.

378 {
379  unsigned int i;
380 
381  memset(pixel_format, 0, sizeof(*pixel_format));
382 
383  pixel_format->size = sizeof(*pixel_format);
384 
385  for (i = 0; i < ARRAY_SIZE(rgb_pixel_formats); i++)
386  {
388  {
389  pixel_format->flags |= DDS_PF_RGB;
390  pixel_format->bpp = rgb_pixel_formats[i].bpp;
391  pixel_format->rmask = rgb_pixel_formats[i].rmask;
392  pixel_format->gmask = rgb_pixel_formats[i].gmask;
393  pixel_format->bmask = rgb_pixel_formats[i].bmask;
394  pixel_format->amask = rgb_pixel_formats[i].amask;
395  if (pixel_format->amask) pixel_format->flags |= DDS_PF_ALPHA;
396  return D3D_OK;
397  }
398  }
399 
400  /* Reuse dds_fourcc_to_d3dformat as D3DFORMAT and FOURCC are DWORD with same values */
402  {
403  pixel_format->flags |= DDS_PF_FOURCC;
404  pixel_format->fourcc = d3dformat;
405  return D3D_OK;
406  }
407 
408  WARN("Unknown pixel format %#x\n", d3dformat);
409  return E_NOTIMPL;
410 }
#define DDS_PF_FOURCC
Definition: surface.c:112
#define WARN(fmt,...)
Definition: debug.h:112
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:42
static D3DFORMAT dds_fourcc_to_d3dformat(DWORD fourcc)
Definition: surface.c:150
#define D3D_OK
Definition: d3d.h:106
#define DDS_PF_RGB
Definition: surface.c:113
#define ARRAY_SIZE(a)
Definition: main.h:24
#define E_NOTIMPL
Definition: ddrawi.h:99
#define DDS_PF_ALPHA
Definition: surface.c:110
static const struct @247 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 68 of file surface.c.

69 {
70  unsigned int i;
71 
72  for (i = 0; i < ARRAY_SIZE(wic_pixel_formats); i++)
73  {
75  return wic_pixel_formats[i].wic_guid;
76  }
77 
78  return NULL;
79 }
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:42
static const struct @246 wic_pixel_formats[]
#define ARRAY_SIZE(a)
Definition: main.h:24

Referenced by D3DXSaveSurfaceToFileInMemory().

◆ D3DXGetImageInfoFromFileA()

HRESULT WINAPI D3DXGetImageInfoFromFileA ( const char file,
D3DXIMAGE_INFO info 
)

Definition at line 1095 of file surface.c.

1096 {
1097  WCHAR *widename;
1098  HRESULT hr;
1099  int strlength;
1100 
1101  TRACE("file %s, info %p.\n", debugstr_a(file), info);
1102 
1103  if( !file ) return D3DERR_INVALIDCALL;
1104 
1105  strlength = MultiByteToWideChar(CP_ACP, 0, file, -1, NULL, 0);
1106  widename = HeapAlloc(GetProcessHeap(), 0, strlength * sizeof(*widename));
1107  MultiByteToWideChar(CP_ACP, 0, file, -1, widename, strlength);
1108 
1109  hr = D3DXGetImageInfoFromFileW(widename, info);
1110  HeapFree(GetProcessHeap(), 0, widename);
1111 
1112  return hr;
1113 }
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:404
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:78
HRESULT WINAPI D3DXGetImageInfoFromFileW(const WCHAR *file, D3DXIMAGE_INFO *info)
Definition: surface.c:1115
#define MultiByteToWideChar
Definition: compat.h:100
#define HeapFree(x, y, z)
Definition: compat.h:403
Definition: fci.c:126

Referenced by test_D3DXGetImageInfo().

◆ D3DXGetImageInfoFromFileInMemory()

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

Definition at line 945 of file surface.c.

946 {
948  IWICBitmapDecoder *decoder = NULL;
950  HRESULT hr;
951  BOOL dib;
952 
953  TRACE("(%p, %d, %p)\n", data, datasize, info);
954 
955  if (!data || !datasize)
956  return D3DERR_INVALIDCALL;
957 
958  if (!info)
959  return D3D_OK;
960 
961  if ((datasize >= 4) && !strncmp(data, "DDS ", 4)) {
962  TRACE("File type is DDS\n");
964  }
965 
966  /* In case of DIB file, convert it to BMP */
967  dib = convert_dib_to_bmp((void**)&data, &datasize);
968 
969  hr = WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION, &factory);
970 
971  if (SUCCEEDED(hr)) {
972  IWICImagingFactory_CreateStream(factory, &stream);
973  IWICStream_InitializeFromMemory(stream, (BYTE*)data, datasize);
974  hr = IWICImagingFactory_CreateDecoderFromStream(factory, (IStream*)stream, NULL, 0, &decoder);
975  IWICStream_Release(stream);
976  IWICImagingFactory_Release(factory);
977  }
978 
979  if (FAILED(hr)) {
980  if ((datasize >= 2) && (!strncmp(data, "P3", 2) || !strncmp(data, "P6", 2)))
981  FIXME("File type PPM is not supported yet\n");
982  else if ((datasize >= 10) && !strncmp(data, "#?RADIANCE", 10))
983  FIXME("File type HDR is not supported yet\n");
984  else if ((datasize >= 2) && (!strncmp(data, "PF", 2) || !strncmp(data, "Pf", 2)))
985  FIXME("File type PFM is not supported yet\n");
986  }
987 
988  if (SUCCEEDED(hr)) {
989  GUID container_format;
990  UINT frame_count;
991 
992  hr = IWICBitmapDecoder_GetContainerFormat(decoder, &container_format);
993  if (SUCCEEDED(hr)) {
994  if (IsEqualGUID(&container_format, &GUID_ContainerFormatBmp)) {
995  if (dib) {
996  TRACE("File type is DIB\n");
997  info->ImageFileFormat = D3DXIFF_DIB;
998  } else {
999  TRACE("File type is BMP\n");
1000  info->ImageFileFormat = D3DXIFF_BMP;
1001  }
1002  } else if (IsEqualGUID(&container_format, &GUID_ContainerFormatPng)) {
1003  TRACE("File type is PNG\n");
1004  info->ImageFileFormat = D3DXIFF_PNG;
1005  } else if(IsEqualGUID(&container_format, &GUID_ContainerFormatJpeg)) {
1006  TRACE("File type is JPG\n");
1007  info->ImageFileFormat = D3DXIFF_JPG;
1008  } else if(IsEqualGUID(&container_format, &GUID_WineContainerFormatTga)) {
1009  TRACE("File type is TGA\n");
1010  info->ImageFileFormat = D3DXIFF_TGA;
1011  } else {
1012  WARN("Unsupported image file format %s\n", debugstr_guid(&container_format));
1014  }
1015  }
1016 
1017  if (SUCCEEDED(hr))
1018  hr = IWICBitmapDecoder_GetFrameCount(decoder, &frame_count);
1019  if (SUCCEEDED(hr) && !frame_count)
1021 
1022  if (SUCCEEDED(hr)) {
1023  IWICBitmapFrameDecode *frame = NULL;
1024 
1025  hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
1026 
1027  if (SUCCEEDED(hr))
1028  hr = IWICBitmapFrameDecode_GetSize(frame, &info->Width, &info->Height);
1029 
1030  if (SUCCEEDED(hr)) {
1032 
1033  hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &pixel_format);
1034  if (SUCCEEDED(hr)) {
1036  if (info->Format == D3DFMT_UNKNOWN) {
1037  WARN("Unsupported pixel format %s\n", debugstr_guid(&pixel_format));
1039  }
1040  }
1041  }
1042 
1043  /* For 32 bpp BMP, windowscodecs.dll never returns a format with alpha while
1044  * d3dx9_xx.dll returns one if at least 1 pixel has a non zero alpha component */
1045  if (SUCCEEDED(hr) && (info->Format == D3DFMT_X8R8G8B8) && (info->ImageFileFormat == D3DXIFF_BMP)) {
1046  DWORD size = sizeof(DWORD) * info->Width * info->Height;
1048  hr = IWICBitmapFrameDecode_CopyPixels(frame, NULL, sizeof(DWORD) * info->Width, size, buffer);
1049  if (SUCCEEDED(hr)) {
1050  DWORD i;
1051  for (i = 0; i < info->Width * info->Height; i++) {
1052  if (buffer[i*4+3]) {
1053  info->Format = D3DFMT_A8R8G8B8;
1054  break;
1055  }
1056  }
1057  }
1059  }
1060 
1061  if (frame)
1062  IWICBitmapFrameDecode_Release(frame);
1063 
1064  info->Depth = 1;
1065  info->MipLevels = 1;
1066  info->ResourceType = D3DRTYPE_TEXTURE;
1067  }
1068  }
1069 
1070  if (decoder)
1071  IWICBitmapDecoder_Release(decoder);
1072 
1073  if (dib)
1074  HeapFree(GetProcessHeap(), 0, (void*)data);
1075 
1076  if (FAILED(hr)) {
1077  TRACE("Invalid or unsupported image file\n");
1078  return D3DXERR_INVALIDDATA;
1079  }
1080 
1081  return D3D_OK;
1082 }
HRESULT hr
Definition: shlfolder.c:183
#define WARN(fmt,...)
Definition: debug.h:112
#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:438
#define FIXME(fmt,...)
Definition: debug.h:111
smooth NULL
Definition: ftsmooth.c:416
static SIZE_T datasize
Definition: asm.c:30
#define debugstr_guid
Definition: kernel32.h:35
static D3DFORMAT wic_guid_to_d3dformat(const GUID *guid)
Definition: surface.c:55
HRESULT WINAPI WICCreateImagingFactory_Proxy(UINT, IWICImagingFactory **)
Definition: proxy.c:651
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:404
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG HRESULT
Definition: typedefs.h:78
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: xxhash.c:193
#define D3D_OK
Definition: d3d.h:106
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
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:472
static ClassFactoryImpl factory
Definition: ole_server.c:234
static BOOL convert_dib_to_bmp(void **data, UINT *size)
Definition: surface.c:859
#define HeapFree(x, y, z)
Definition: compat.h:403
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by check_dds_pixel_format_(), D3DXCreateCubeTextureFromFileInMemoryEx(), D3DXCreateTextureFromFileInMemoryEx(), D3DXCreateVolumeTextureFromFileInMemoryEx(), D3DXGetImageInfoFromFileW(), D3DXGetImageInfoFromResourceA(), D3DXGetImageInfoFromResourceW(), D3DXLoadSurfaceFromFileInMemory(), D3DXLoadVolumeFromFileInMemory(), test_D3DXGetImageInfo(), test_D3DXSaveTextureToFileInMemory(), and test_dds_header_handling().

◆ D3DXGetImageInfoFromFileW()

HRESULT WINAPI D3DXGetImageInfoFromFileW ( const WCHAR file,
D3DXIMAGE_INFO info 
)

Definition at line 1115 of file surface.c.

1116 {
1117  void *buffer;
1118  HRESULT hr;
1119  DWORD size;
1120 
1121  TRACE("file %s, info %p.\n", debugstr_w(file), info);
1122 
1123  if (!file)
1124  return D3DERR_INVALIDCALL;
1125 
1127  return D3DXERR_INVALIDDATA;
1128 
1131 
1132  return hr;
1133 }
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:78
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:945
#define UnmapViewOfFile
Definition: compat.h:412
Definition: fci.c:126

Referenced by D3DXGetImageInfoFromFileA().

◆ D3DXGetImageInfoFromResourceA()

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

Definition at line 1144 of file surface.c.

1145 {
1146  HRSRC resinfo;
1147  void *buffer;
1148  DWORD size;
1149 
1150  TRACE("module %p, resource %s, info %p.\n", module, debugstr_a(resource), info);
1151 
1152  if (!(resinfo = FindResourceA(module, resource, (const char *)RT_RCDATA))
1153  /* Try loading the resource as bitmap data (which is in DIB format D3DXIFF_DIB) */
1154  && !(resinfo = FindResourceA(module, resource, (const char *)RT_BITMAP)))
1155  return D3DXERR_INVALIDDATA;
1156 
1157  if (FAILED(load_resource_into_memory(module, resinfo, &buffer, &size)))
1158  return D3DXERR_INVALIDDATA;
1159 
1161 }
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:945
#define RT_BITMAP
Definition: pedump.c:364

Referenced by test_D3DXGetImageInfo().

◆ D3DXGetImageInfoFromResourceW()

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

Definition at line 1163 of file surface.c.

1164 {
1165  HRSRC resinfo;
1166  void *buffer;
1167  DWORD size;
1168 
1169  TRACE("module %p, resource %s, info %p.\n", module, debugstr_w(resource), info);
1170 
1171  if (!(resinfo = FindResourceW(module, resource, (const WCHAR *)RT_RCDATA))
1172  /* Try loading the resource as bitmap data (which is in DIB format D3DXIFF_DIB) */
1173  && !(resinfo = FindResourceW(module, resource, (const WCHAR *)RT_BITMAP)))
1174  return D3DXERR_INVALIDDATA;
1175 
1176  if (FAILED(load_resource_into_memory(module, resinfo, &buffer, &size)))
1177  return D3DXERR_INVALIDDATA;
1178 
1180 }
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:945
#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 1376 of file surface.c.

1379 {
1380  WCHAR *src_file_w;
1381  HRESULT hr;
1382  int strlength;
1383 
1384  TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_file %s, "
1385  "src_rect %s, filter %#x, color_key 0x%08x, src_info %p.\n",
1386  dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), debugstr_a(src_file),
1387  wine_dbgstr_rect(src_rect), filter, color_key, src_info);
1388 
1389  if (!src_file || !dst_surface)
1390  return D3DERR_INVALIDCALL;
1391 
1392  strlength = MultiByteToWideChar(CP_ACP, 0, src_file, -1, NULL, 0);
1393  src_file_w = HeapAlloc(GetProcessHeap(), 0, strlength * sizeof(*src_file_w));
1394  MultiByteToWideChar(CP_ACP, 0, src_file, -1, src_file_w, strlength);
1395 
1396  hr = D3DXLoadSurfaceFromFileW(dst_surface, dst_palette, dst_rect,
1397  src_file_w, src_rect, filter, color_key, src_info);
1398  HeapFree(GetProcessHeap(), 0, src_file_w);
1399 
1400  return hr;
1401 }
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:1403
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:404
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:78
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:403

Referenced by test_D3DXLoadSurface(), and test_D3DXSaveSurfaceToFile().

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

1208 {
1209  D3DXIMAGE_INFO imginfo;
1210  HRESULT hr;
1211 
1213  IWICBitmapDecoder *decoder;
1214  IWICBitmapFrameDecode *bitmapframe;
1215  IWICStream *stream;
1216 
1217  const struct pixel_format_desc *formatdesc;
1218  WICRect wicrect;
1219  RECT rect;
1220 
1221  TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_data %p, src_data_size %u, "
1222  "src_rect %s, filter %#x, color_key 0x%08x, src_info %p.\n",
1223  pDestSurface, pDestPalette, wine_dbgstr_rect(pDestRect), pSrcData, SrcDataSize,
1224  wine_dbgstr_rect(pSrcRect), dwFilter, Colorkey, pSrcInfo);
1225 
1226  if (!pDestSurface || !pSrcData || !SrcDataSize)
1227  return D3DERR_INVALIDCALL;
1228 
1229  hr = D3DXGetImageInfoFromFileInMemory(pSrcData, SrcDataSize, &imginfo);
1230 
1231  if (FAILED(hr))
1232  return hr;
1233 
1234  if (pSrcRect)
1235  {
1236  wicrect.X = pSrcRect->left;
1237  wicrect.Y = pSrcRect->top;
1238  wicrect.Width = pSrcRect->right - pSrcRect->left;
1239  wicrect.Height = pSrcRect->bottom - pSrcRect->top;
1240  }
1241  else
1242  {
1243  wicrect.X = 0;
1244  wicrect.Y = 0;
1245  wicrect.Width = imginfo.Width;
1246  wicrect.Height = imginfo.Height;
1247  }
1248 
1249  SetRect(&rect, 0, 0, wicrect.Width, wicrect.Height);
1250 
1251  if (imginfo.ImageFileFormat == D3DXIFF_DDS)
1252  {
1253  hr = load_surface_from_dds(pDestSurface, pDestPalette, pDestRect, pSrcData, &rect,
1254  dwFilter, Colorkey, &imginfo);
1255  if (SUCCEEDED(hr) && pSrcInfo)
1256  *pSrcInfo = imginfo;
1257  return hr;
1258  }
1259 
1260  if (imginfo.ImageFileFormat == D3DXIFF_DIB)
1261  convert_dib_to_bmp((void**)&pSrcData, &SrcDataSize);
1262 
1263  if (FAILED(WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION, &factory)))
1264  goto cleanup_err;
1265 
1266  if (FAILED(IWICImagingFactory_CreateStream(factory, &stream)))
1267  {
1268  IWICImagingFactory_Release(factory);
1269  factory = NULL;
1270  goto cleanup_err;
1271  }
1272 
1273  IWICStream_InitializeFromMemory(stream, (BYTE*)pSrcData, SrcDataSize);
1274 
1275  hr = IWICImagingFactory_CreateDecoderFromStream(factory, (IStream*)stream, NULL, 0, &decoder);
1276 
1277  IWICStream_Release(stream);
1278 
1279  if (FAILED(hr))
1280  goto cleanup_err;
1281 
1282  hr = IWICBitmapDecoder_GetFrame(decoder, 0, &bitmapframe);
1283 
1284  if (FAILED(hr))
1285  goto cleanup_bmp;
1286 
1287  formatdesc = get_format_info(imginfo.Format);
1288 
1289  if (formatdesc->type == FORMAT_UNKNOWN)
1290  {
1291  FIXME("Unsupported pixel format\n");
1293  }
1294  else
1295  {
1296  BYTE *buffer;
1297  DWORD pitch;
1299  WICColor *colors = NULL;
1300 
1301  pitch = formatdesc->bytes_per_pixel * wicrect.Width;
1302  buffer = HeapAlloc(GetProcessHeap(), 0, pitch * wicrect.Height);
1303 
1304  hr = IWICBitmapFrameDecode_CopyPixels(bitmapframe, &wicrect, pitch,
1305  pitch * wicrect.Height, buffer);
1306 
1307  if (SUCCEEDED(hr) && (formatdesc->type == FORMAT_INDEX))
1308  {
1309  IWICPalette *wic_palette = NULL;
1310  UINT nb_colors;
1311 
1312  hr = IWICImagingFactory_CreatePalette(factory, &wic_palette);
1313  if (SUCCEEDED(hr))
1314  hr = IWICBitmapFrameDecode_CopyPalette(bitmapframe, wic_palette);
1315  if (SUCCEEDED(hr))
1316  hr = IWICPalette_GetColorCount(wic_palette, &nb_colors);
1317  if (SUCCEEDED(hr))
1318  {
1319  colors = HeapAlloc(GetProcessHeap(), 0, nb_colors * sizeof(colors[0]));
1320  palette = HeapAlloc(GetProcessHeap(), 0, nb_colors * sizeof(palette[0]));
1321  if (!colors || !palette)
1322  hr = E_OUTOFMEMORY;
1323  }
1324  if (SUCCEEDED(hr))
1325  hr = IWICPalette_GetColors(wic_palette, nb_colors, colors, &nb_colors);
1326  if (SUCCEEDED(hr))
1327  {
1328  UINT i;
1329 
1330  /* Convert colors from WICColor (ARGB) to PALETTEENTRY (ABGR) */
1331  for (i = 0; i < nb_colors; i++)
1332  {
1333  palette[i].peRed = (colors[i] >> 16) & 0xff;
1334  palette[i].peGreen = (colors[i] >> 8) & 0xff;
1335  palette[i].peBlue = colors[i] & 0xff;
1336  palette[i].peFlags = (colors[i] >> 24) & 0xff; /* peFlags is the alpha component in DX8 and higher */
1337  }
1338  }
1339  if (wic_palette)
1340  IWICPalette_Release(wic_palette);
1341  }
1342 
1343  if (SUCCEEDED(hr))
1344  {
1345  hr = D3DXLoadSurfaceFromMemory(pDestSurface, pDestPalette, pDestRect,
1346  buffer, imginfo.Format, pitch,
1347  palette, &rect, dwFilter, Colorkey);
1348  }
1349 
1350  HeapFree(GetProcessHeap(), 0, colors);
1353  }
1354 
1355  IWICBitmapFrameDecode_Release(bitmapframe);
1356 
1357 cleanup_bmp:
1358  IWICBitmapDecoder_Release(decoder);
1359 
1360 cleanup_err:
1361  if (factory)
1362  IWICImagingFactory_Release(factory);
1363 
1364  if (imginfo.ImageFileFormat == D3DXIFF_DIB)
1365  HeapFree(GetProcessHeap(), 0, (void*)pSrcData);
1366 
1367  if (FAILED(hr))
1368  return D3DXERR_INVALIDDATA;
1369 
1370  if (pSrcInfo)
1371  *pSrcInfo = imginfo;
1372 
1373  return D3D_OK;
1374 }
HRESULT hr
Definition: shlfolder.c:183
LONG top
Definition: windef.h:307
#define D3DERR_INVALIDCALL
GLuint buffer
Definition: glext.h:5915
LONG left
Definition: windef.h:306
LONG right
Definition: windef.h:308
& 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:438
#define FIXME(fmt,...)
Definition: debug.h:111
smooth NULL
Definition: ftsmooth.c:416
INT Height
Definition: wincodec.idl:239
HRESULT WINAPI WICCreateImagingFactory_Proxy(UINT, IWICImagingFactory **)
Definition: proxy.c:651
D3DXIMAGE_FILEFORMAT ImageFileFormat
Definition: d3dx9tex.h:84
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:404
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
D3DFORMAT Format
Definition: d3dx9tex.h:82
LONG HRESULT
Definition: typedefs.h:78
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: xxhash.c:193
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:1931
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:528
INT Width
Definition: wincodec.idl:238
HRESULT WINAPI D3DXGetImageInfoFromFileInMemory(const void *data, UINT datasize, D3DXIMAGE_INFO *info)
Definition: surface.c:945
LONG bottom
Definition: windef.h:309
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:859
#define HeapFree(x, y, z)
Definition: compat.h:403
#define SUCCEEDED(hr)
Definition: intsafe.h:57

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

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

1406 {
1407  UINT data_size;
1408  void *data;
1409  HRESULT hr;
1410 
1411  TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_file %s, "
1412  "src_rect %s, filter %#x, color_key 0x%08x, src_info %p.\n",
1413  dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), debugstr_w(src_file),
1414  wine_dbgstr_rect(src_rect), filter, color_key, src_info);
1415 
1416  if (!src_file || !dst_surface)
1417  return D3DERR_INVALIDCALL;
1418 
1419  if (FAILED(map_view_of_file(src_file, &data, &data_size)))
1420  return D3DXERR_INVALIDDATA;
1421 
1422  hr = D3DXLoadSurfaceFromFileInMemory(dst_surface, dst_palette, dst_rect,
1423  data, data_size, src_rect, filter, color_key, src_info);
1425 
1426  return hr;
1427 }
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:78
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:412
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:1205

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

1935 {
1936  const struct pixel_format_desc *srcformatdesc, *destformatdesc;
1937  IDirect3DSurface9 *surface;
1938  void *tmp_src_memory = NULL, *tmp_dst_memory = NULL;
1939  dxtn_conversion_func pre_convert = NULL, post_convert = NULL;
1940  D3DSURFACE_DESC surfdesc;
1941  D3DLOCKED_RECT lockrect;
1942  struct volume src_size, dst_size;
1943  HRESULT hr = D3D_OK;
1944 
1945  TRACE("(%p, %p, %s, %p, %#x, %u, %p, %s, %#x, 0x%08x)\n",
1946  dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), src_memory, src_format,
1947  src_pitch, src_palette, wine_dbgstr_rect(src_rect), filter, color_key);
1948 
1949  if (!dst_surface || !src_memory || !src_rect)
1950  {
1951  WARN("Invalid argument specified.\n");
1952  return D3DERR_INVALIDCALL;
1953  }
1954  if (src_format == D3DFMT_UNKNOWN
1955  || src_rect->left >= src_rect->right
1956  || src_rect->top >= src_rect->bottom)
1957  {
1958  WARN("Invalid src_format or src_rect.\n");
1959  return E_FAIL;
1960  }
1961 
1962  if (filter == D3DX_DEFAULT)
1964 
1965  IDirect3DSurface9_GetDesc(dst_surface, &surfdesc);
1966 
1967  src_size.width = src_rect->right - src_rect->left;
1968  src_size.height = src_rect->bottom - src_rect->top;
1969  src_size.depth = 1;
1970  if (!dst_rect)
1971  {
1972  dst_size.width = surfdesc.Width;
1973  dst_size.height = surfdesc.Height;
1974  }
1975  else
1976  {
1977  if (dst_rect->left > dst_rect->right || dst_rect->right > surfdesc.Width
1978  || dst_rect->top > dst_rect->bottom || dst_rect->bottom > surfdesc.Height
1979  || dst_rect->left < 0 || dst_rect->top < 0)
1980  {
1981  WARN("Invalid dst_rect specified.\n");
1982  return D3DERR_INVALIDCALL;
1983  }
1984  dst_size.width = dst_rect->right - dst_rect->left;
1985  dst_size.height = dst_rect->bottom - dst_rect->top;
1986  if (!dst_size.width || !dst_size.height)
1987  return D3D_OK;
1988  }
1989  dst_size.depth = 1;
1990 
1991  srcformatdesc = get_format_info(src_format);
1992  destformatdesc = get_format_info(surfdesc.Format);
1993  if (srcformatdesc->type == FORMAT_UNKNOWN || destformatdesc->type == FORMAT_UNKNOWN)
1994  {
1995  FIXME("Unsupported pixel format conversion %#x -> %#x\n", src_format, surfdesc.Format);
1996  return E_NOTIMPL;
1997  }
1998 
1999  if (FAILED(hr = lock_surface(dst_surface, &lockrect, &surface, TRUE)))
2000  return hr;
2001 
2002  if (src_format == surfdesc.Format
2003  && dst_size.width == src_size.width
2004  && dst_size.height == src_size.height
2005  && color_key == 0) /* Simple copy. */
2006  {
2007  if (src_rect->left & (srcformatdesc->block_width - 1)
2008  || src_rect->top & (srcformatdesc->block_height - 1)
2009  || (src_rect->right & (srcformatdesc->block_width - 1)
2010  && src_size.width != surfdesc.Width)
2011  || (src_rect->bottom & (srcformatdesc->block_height - 1)
2012  && src_size.height != surfdesc.Height))
2013  {
2014  WARN("Source rect %s is misaligned.\n", wine_dbgstr_rect(src_rect));
2015  unlock_surface(dst_surface, &lockrect, surface, FALSE);
2016  return D3DXERR_INVALIDDATA;
2017  }
2018 
2019  copy_pixels(src_memory, src_pitch, 0, lockrect.pBits, lockrect.Pitch, 0,
2020  &src_size, srcformatdesc);
2021  }
2022  else /* Stretching or format conversion. */
2023  {
2024  UINT tmp_src_pitch, tmp_dst_pitch;
2025 
2026  pre_convert = get_dxtn_conversion_func(srcformatdesc->format, FALSE);
2027  post_convert = get_dxtn_conversion_func(destformatdesc->format, TRUE);
2028 
2029  if ((!pre_convert && !is_conversion_from_supported(srcformatdesc)) ||
2030  (!post_convert && !is_conversion_to_supported(destformatdesc)))
2031  {
2032  FIXME("Unsupported format conversion %#x -> %#x.\n", src_format, surfdesc.Format);
2033  unlock_surface(dst_surface, &lockrect, surface, FALSE);
2034  return E_NOTIMPL;
2035  }
2036 
2037  /* handle pre-conversion */
2038  if (pre_convert)
2039  {
2040  tmp_src_memory = HeapAlloc(GetProcessHeap(), 0, src_size.width * src_size.height * sizeof(DWORD));
2041  if (!tmp_src_memory)
2042  {
2043  hr = E_OUTOFMEMORY;
2044  goto done;
2045  }
2046  tmp_src_pitch = src_size.width * sizeof(DWORD);
2047  if (!pre_convert(src_memory, tmp_src_memory, src_pitch, tmp_src_pitch,
2048  WINED3DFMT_B8G8R8A8_UNORM, src_size.width, src_size.height))
2049  {
2050  hr = E_FAIL;
2051  goto done;
2052  }
2053  srcformatdesc = get_format_info(D3DFMT_A8R8G8B8);
2054  }
2055  else
2056  {
2057  tmp_src_memory = (void *)src_memory;
2058  tmp_src_pitch = src_pitch;
2059  }
2060 
2061  /* handle post-conversion */
2062  if (post_convert)
2063  {
2064  tmp_dst_memory = HeapAlloc(GetProcessHeap(), 0, dst_size.width * dst_size.height * sizeof(DWORD));
2065  if (!tmp_dst_memory)
2066  {
2067  hr = E_OUTOFMEMORY;
2068  goto done;
2069  }
2070  tmp_dst_pitch = dst_size.width * sizeof(DWORD);
2071  destformatdesc = get_format_info(D3DFMT_A8R8G8B8);
2072  }
2073  else
2074  {
2075  tmp_dst_memory = lockrect.pBits;
2076  tmp_dst_pitch = lockrect.Pitch;
2077  }
2078 
2079  if ((filter & 0xf) == D3DX_FILTER_NONE)
2080  {
2081  convert_argb_pixels(tmp_src_memory, tmp_src_pitch, 0, &src_size, srcformatdesc,
2082  tmp_dst_memory, tmp_dst_pitch, 0, &dst_size, destformatdesc, color_key, src_palette);
2083  }
2084  else /* if ((filter & 0xf) == D3DX_FILTER_POINT) */
2085  {
2086  if ((filter & 0xf) != D3DX_FILTER_POINT)
2087  FIXME("Unhandled filter %#x.\n", filter);
2088 
2089  /* Always apply a point filter until D3DX_FILTER_LINEAR,
2090  * D3DX_FILTER_TRIANGLE and D3DX_FILTER_BOX are implemented. */
2091  point_filter_argb_pixels(tmp_src_memory, tmp_src_pitch, 0, &src_size, srcformatdesc,
2092  tmp_dst_memory, tmp_dst_pitch, 0, &dst_size, destformatdesc, color_key, src_palette);
2093  }
2094 
2095  /* handle post-conversion */
2096  if (post_convert)
2097  {
2098  if (!post_convert(tmp_dst_memory, lockrect.pBits, tmp_dst_pitch, lockrect.Pitch,
2099  WINED3DFMT_B8G8R8A8_UNORM, dst_size.width, dst_size.height))
2100  {
2101  hr = E_FAIL;
2102  }
2103  }
2104  }
2105 
2106 done:
2107  if (pre_convert)
2108  HeapFree(GetProcessHeap(), 0, tmp_src_memory);
2109  if (post_convert)
2110  HeapFree(GetProcessHeap(), 0, tmp_dst_memory);
2111 
2112  unlock_surface(dst_surface, &lockrect, surface, TRUE);
2113  return hr;
2114 }
#define TRUE
Definition: types.h:120
HRESULT hr
Definition: shlfolder.c:183
D3DFORMAT Format
Definition: d3d8types.h:1170
HRESULT lock_surface(IDirect3DSurface9 *surface, D3DLOCKED_RECT *lock, IDirect3DSurface9 **temp_surface, BOOL write)
Definition: surface.c:206
#define WARN(fmt,...)
Definition: debug.h:112
HRESULT unlock_surface(IDirect3DSurface9 *surface, D3DLOCKED_RECT *lock, IDirect3DSurface9 *temp_surface, BOOL update)
Definition: surface.c:252
#define D3DX_FILTER_NONE
Definition: d3dx9tex.h:27
LONG top
Definition: windef.h:307
#define D3DERR_INVALIDCALL
LONG left
Definition: windef.h:306
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:1881
LONG right
Definition: windef.h:308
#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:1691
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define FIXME(fmt,...)
Definition: debug.h:111
#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
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:404
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG HRESULT
Definition: typedefs.h:78
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:1884
#define D3D_OK
Definition: d3d.h:106
#define D3DX_FILTER_DITHER
Definition: d3dx9tex.h:36
#define E_NOTIMPL
Definition: ddrawi.h:99
unsigned int UINT
Definition: ndis.h:50
static BOOL is_conversion_to_supported(const struct pixel_format_desc *format)
Definition: d3dx9_private.h:86
#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:1794
LONG bottom
Definition: windef.h:309
const struct pixel_format_desc * get_format_info(D3DFORMAT format) DECLSPEC_HIDDEN
Definition: util.c:213
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:1660
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
#define HeapFree(x, y, z)
Definition: compat.h:403

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

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

1432 {
1433  UINT data_size;
1434  HRSRC resinfo;
1435  void *data;
1436 
1437  TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_module %p, resource %s, "
1438  "src_rect %s, filter %#x, color_key 0x%08x, src_info %p.\n",
1439  dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), src_module, debugstr_a(resource),
1440  wine_dbgstr_rect(src_rect), filter, color_key, src_info);
1441 
1442  if (!dst_surface)
1443  return D3DERR_INVALIDCALL;
1444 
1445  if (!(resinfo = FindResourceA(src_module, resource, (const char *)RT_RCDATA))
1446  /* Try loading the resource as bitmap data (which is in DIB format D3DXIFF_DIB) */
1447  && !(resinfo = FindResourceA(src_module, resource, (const char *)RT_BITMAP)))
1448  return D3DXERR_INVALIDDATA;
1449 
1450  if (FAILED(load_resource_into_memory(src_module, resinfo, &data, &data_size)))
1451  return D3DXERR_INVALIDDATA;
1452 
1453  return D3DXLoadSurfaceFromFileInMemory(dst_surface, dst_palette, dst_rect,
1454  data, data_size, src_rect, filter, color_key, src_info);
1455 }
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:1205

Referenced by test_D3DXLoadSurface().

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

1460 {
1461  UINT data_size;
1462  HRSRC resinfo;
1463  void *data;
1464 
1465  TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_module %p, resource %s, "
1466  "src_rect %s, filter %#x, color_key 0x%08x, src_info %p.\n",
1467  dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), src_module, debugstr_w(resource),
1468  wine_dbgstr_rect(src_rect), filter, color_key, src_info);
1469 
1470  if (!dst_surface)
1471  return D3DERR_INVALIDCALL;
1472 
1473  if (!(resinfo = FindResourceW(src_module, resource, (const WCHAR *)RT_RCDATA))
1474  /* Try loading the resource as bitmap data (which is in DIB format D3DXIFF_DIB) */
1475  && !(resinfo = FindResourceW(src_module, resource, (const WCHAR *)RT_BITMAP)))
1476  return D3DXERR_INVALIDDATA;
1477 
1478  if (FAILED(load_resource_into_memory(src_module, resinfo, &data, &data_size)))
1479  return D3DXERR_INVALIDDATA;
1480 
1481  return D3DXLoadSurfaceFromFileInMemory(dst_surface, dst_palette, dst_rect,
1482  data, data_size, src_rect, filter, color_key, src_info);
1483 }
#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:1205

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

2141 {
2142  IDirect3DSurface9 *temp_surface;
2143  D3DTEXTUREFILTERTYPE d3d_filter;
2144  IDirect3DDevice9 *device;
2145  D3DSURFACE_DESC src_desc;
2147  HRESULT hr;
2148  RECT s;
2149 
2150  TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_surface %p, "
2151  "src_palette %p, src_rect %s, filter %#x, color_key 0x%08x.\n",
2152  dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), src_surface,
2153  src_palette, wine_dbgstr_rect(src_rect), filter, color_key);
2154 
2155  if (!dst_surface || !src_surface)
2156  return D3DERR_INVALIDCALL;
2157 
2158  if (!dst_palette && !src_palette && !color_key)
2159  {
2160  switch (filter)
2161  {
2162  case D3DX_FILTER_NONE:
2163  d3d_filter = D3DTEXF_NONE;
2164  break;
2165 
2166  case D3DX_FILTER_POINT:
2167  d3d_filter = D3DTEXF_POINT;
2168  break;
2169 
2170  case D3DX_FILTER_LINEAR:
2171  d3d_filter = D3DTEXF_LINEAR;
2172  break;
2173 
2174  default:
2175  d3d_filter = ~0u;
2176  break;
2177  }
2178 
2179  if (d3d_filter != ~0u)
2180  {
2181  IDirect3DSurface9_GetDevice(src_surface, &device);
2182  hr = IDirect3DDevice9_StretchRect(device, src_surface, src_rect, dst_surface, dst_rect, d3d_filter);
2184  if (SUCCEEDED(hr))
2185  return D3D_OK;
2186  }
2187  }
2188 
2189  IDirect3DSurface9_GetDesc(src_surface, &src_desc);
2190 
2191  if (!src_rect)
2192  {
2193  SetRect(&s, 0, 0, src_desc.Width, src_desc.Height);
2194  src_rect = &s;
2195  }
2196 
2197  if (FAILED(lock_surface(src_surface, &lock, &temp_surface, FALSE)))
2198  return D3DXERR_INVALIDDATA;
2199 
2200  hr = D3DXLoadSurfaceFromMemory(dst_surface, dst_palette, dst_rect, lock.pBits,
2201  src_desc.Format, lock.Pitch, src_palette, src_rect, filter, color_key);
2202 
2203  if (FAILED(unlock_surface(src_surface, &lock, temp_surface, FALSE)))
2204  return D3DXERR_INVALIDDATA;
2205 
2206  return hr;
2207 }
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
rwlock_t lock
Definition: tcpcore.h:1163
HRESULT hr
Definition: shlfolder.c:183
D3DFORMAT Format
Definition: d3d8types.h:1170
HRESULT lock_surface(IDirect3DSurface9 *surface, D3DLOCKED_RECT *lock, IDirect3DSurface9 **temp_surface, BOOL write)
Definition: surface.c:206
HRESULT unlock_surface(IDirect3DSurface9 *surface, D3DLOCKED_RECT *lock, IDirect3DSurface9 *temp_surface, BOOL update)
Definition: surface.c:252
#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
Definition: devices.h:37
#define IDirect3DDevice9_Release(p)
Definition: d3d9.h:1508
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:78
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:1931
enum _D3DTEXTUREFILTERTYPE D3DTEXTUREFILTERTYPE
#define D3DX_FILTER_POINT
Definition: d3dx9tex.h:28
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(), D3DXRenderToSurface_EndScene(), and test_D3DXLoadSurface().

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

2212 {
2213  int len;
2214  WCHAR *filename;
2215  HRESULT hr;
2217 
2218  TRACE("(%s, %#x, %p, %p, %s): relay\n",
2219  wine_dbgstr_a(dst_filename), file_format, src_surface, src_palette, wine_dbgstr_rect(src_rect));
2220 
2221  if (!dst_filename) return D3DERR_INVALIDCALL;
2222 
2223  len = MultiByteToWideChar(CP_ACP, 0, dst_filename, -1, NULL, 0);
2224  filename = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
2225  if (!filename) return E_OUTOFMEMORY;
2226  MultiByteToWideChar(CP_ACP, 0, dst_filename, -1, filename, len);
2227 
2228  hr = D3DXSaveSurfaceToFileInMemory(&buffer, file_format, src_surface, src_palette, src_rect);
2229  if (SUCCEEDED(hr))
2230  {
2233  }
2234 
2236  return hr;
2237 }
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:404
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:78
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:2260
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:403
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by test_D3DXSaveSurfaceToFile().

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

2262 {
2263  IWICBitmapEncoder *encoder = NULL;
2264  IWICBitmapFrameEncode *frame = NULL;
2265  IPropertyBag2 *encoder_options = NULL;
2266  IStream *stream = NULL;
2267  HRESULT hr;
2268  const GUID *container_format;
2269  const GUID *pixel_format_guid;
2270  WICPixelFormatGUID wic_pixel_format;
2272  D3DFORMAT d3d_pixel_format;
2273  D3DSURFACE_DESC src_surface_desc;
2274  IDirect3DSurface9 *temp_surface;
2275  D3DLOCKED_RECT locked_rect;
2276  int width, height;
2277  STATSTG stream_stats;
2278  HGLOBAL stream_hglobal;
2280  DWORD size;
2281 
2282  TRACE("dst_buffer %p, file_format %#x, src_surface %p, src_palette %p, src_rect %s.\n",
2283  dst_buffer, file_format, src_surface, src_palette, wine_dbgstr_rect(src_rect));
2284 
2285  if (!dst_buffer || !src_surface) return D3DERR_INVALIDCALL;
2286 
2287  if (src_palette)
2288  {
2289  FIXME("Saving surfaces with palettized pixel formats is not implemented yet\n");
2290  return D3DERR_INVALIDCALL;
2291  }
2292 
2293  switch (file_format)
2294  {
2295  case D3DXIFF_BMP:
2296  case D3DXIFF_DIB:
2297  container_format = &GUID_ContainerFormatBmp;
2298  break;
2299  case D3DXIFF_PNG:
2300  container_format = &GUID_ContainerFormatPng;
2301  break;
2302  case D3DXIFF_JPG:
2303  container_format = &GUID_ContainerFormatJpeg;
2304  break;
2305  case D3DXIFF_DDS:
2306  return save_dds_surface_to_memory(dst_buffer, src_surface, src_rect);
2307  case D3DXIFF_HDR:
2308  case D3DXIFF_PFM:
2309  case D3DXIFF_TGA:
2310  case D3DXIFF_PPM:
2311  FIXME("File format %#x is not supported yet\n", file_format);
2312  return E_NOTIMPL;
2313  default:
2314  return D3DERR_INVALIDCALL;
2315  }
2316 
2317  IDirect3DSurface9_GetDesc(src_surface, &src_surface_desc);
2318  if (src_rect)
2319  {
2320  if (src_rect->left == src_rect->right || src_rect->top == src_rect->bottom)
2321  {
2322  WARN("Invalid rectangle with 0 area\n");
2323  return D3DXCreateBuffer(64, dst_buffer);
2324  }
2325  if (src_rect->left < 0 || src_rect->top < 0)
2326  return D3DERR_INVALIDCALL;
2327  if (src_rect->left > src_rect->right || src_rect->top > src_rect->bottom)
2328  return D3DERR_INVALIDCALL;
2329  if (src_rect->right > src_surface_desc.Width || src_rect->bottom > src_surface_desc.Height)
2330  return D3DERR_INVALIDCALL;
2331 
2332  width = src_rect->right - src_rect->left;
2333  height = src_rect->bottom - src_rect->top;
2334  }
2335  else
2336  {
2337  width = src_surface_desc.Width;
2338  height = src_surface_desc.Height;
2339  }
2340 
2341  hr = WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION, &factory);
2342  if (FAILED(hr)) goto cleanup_err;
2343 
2344  hr = IWICImagingFactory_CreateEncoder(factory, container_format, NULL, &encoder);
2345  IWICImagingFactory_Release(factory);
2346  if (FAILED(hr)) goto cleanup_err;
2347 
2349  if (FAILED(hr)) goto cleanup_err;
2350 
2351  hr = IWICBitmapEncoder_Initialize(encoder, stream, WICBitmapEncoderNoCache);
2352  if (FAILED(hr)) goto cleanup_err;
2353 
2354  hr = IWICBitmapEncoder_CreateNewFrame(encoder, &frame, &encoder_options);
2355  if (FAILED(hr)) goto cleanup_err;
2356 
2357  hr = IWICBitmapFrameEncode_Initialize(frame, encoder_options);
2358  if (FAILED(hr)) goto cleanup_err;
2359 
2360  hr = IWICBitmapFrameEncode_SetSize(frame, width, height);
2361  if (FAILED(hr)) goto cleanup_err;
2362 
2363  pixel_format_guid = d3dformat_to_wic_guid(src_surface_desc.Format);
2364  if (!pixel_format_guid)
2365  {
2366  FIXME("Pixel format %#x is not supported yet\n", src_surface_desc.Format);
2367  hr = E_NOTIMPL;
2368  goto cleanup;
2369  }
2370 
2371  memcpy(&wic_pixel_format, pixel_format_guid, sizeof(GUID));
2372  hr = IWICBitmapFrameEncode_SetPixelFormat(frame, &wic_pixel_format);
2373  d3d_pixel_format = wic_guid_to_d3dformat(&wic_pixel_format);
2374  if (SUCCEEDED(hr) && d3d_pixel_format != D3DFMT_UNKNOWN)
2375  {
2376  TRACE("Using pixel format %s %#x\n", debugstr_guid(&wic_pixel_format), d3d_pixel_format);
2377  if (src_surface_desc.Format == d3d_pixel_format) /* Simple copy */
2378  {
2379  if (FAILED(hr = lock_surface(src_surface, &locked_rect, &temp_surface, FALSE)))
2380  goto cleanup;
2381 
2382  IWICBitmapFrameEncode_WritePixels(frame, height,
2383  locked_rect.Pitch, height * locked_rect.Pitch, locked_rect.pBits);
2384  unlock_surface(src_surface, &locked_rect, temp_surface, FALSE);
2385  }
2386  else /* Pixel format conversion */
2387  {
2388  const struct pixel_format_desc *src_format_desc, *dst_format_desc;
2389  struct volume size;
2390  DWORD dst_pitch;
2391  void *dst_data;
2392 
2393  src_format_desc = get_format_info(src_surface_desc.Format);
2394  dst_format_desc = get_format_info(d3d_pixel_format);
2395  if (!is_conversion_from_supported(src_format_desc)
2396  || !is_conversion_to_supported(dst_format_desc))
2397  {
2398  FIXME("Unsupported format conversion %#x -> %#x.\n",
2399  src_surface_desc.Format, d3d_pixel_format);
2400  hr = E_NOTIMPL;
2401  goto cleanup;
2402  }
2403 
2404  size.width = width;
2405  size.height = height;
2406  size.depth = 1;
2407  dst_pitch = width * dst_format_desc->bytes_per_pixel;
2408  dst_data = HeapAlloc(GetProcessHeap(), 0, dst_pitch * height);
2409  if (!dst_data)
2410  {
2411  hr = E_OUTOFMEMORY;
2412  goto cleanup;
2413  }
2414  if (FAILED(hr = lock_surface(src_surface, &locked_rect, &temp_surface, FALSE)))
2415  {
2416  HeapFree(GetProcessHeap(), 0, dst_data);
2417  goto cleanup;
2418  }
2419  convert_argb_pixels(locked_rect.pBits, locked_rect.Pitch, 0, &size, src_format_desc,
2420  dst_data, dst_pitch, 0, &size, dst_format_desc, 0, NULL);
2421  unlock_surface(src_surface, &locked_rect, temp_surface, FALSE);
2422 
2423  IWICBitmapFrameEncode_WritePixels(frame, height, dst_pitch, dst_pitch * height, dst_data);
2424  HeapFree(GetProcessHeap(), 0, dst_data);
2425  }
2426 
2427  hr = IWICBitmapFrameEncode_Commit(frame);
2428  if (SUCCEEDED(hr)) hr = IWICBitmapEncoder_Commit(encoder);
2429  }
2430  else WARN("Unsupported pixel format %#x\n", src_surface_desc.Format);
2431 
2432  /* copy data from stream to ID3DXBuffer */
2433  hr = IStream_Stat(stream, &stream_stats, STATFLAG_NONAME);
2434  if (FAILED(hr)) goto cleanup_err;
2435 
2436  if (stream_stats.cbSize.u.HighPart != 0)
2437  {
2439  goto cleanup;
2440  }
2441  size = stream_stats.cbSize.u.LowPart;
2442 
2443  /* Remove BMP header for DIB */
2444  if (file_format == D3DXIFF_DIB)
2445  size -= sizeof(BITMAPFILEHEADER);
2446 
2448  if (FAILED(hr)) goto cleanup;
2449 
2450  hr = GetHGlobalFromStream(stream, &stream_hglobal);
2451  if (SUCCEEDED(hr))
2452  {
2453  void *buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
2454  void *stream_data = GlobalLock(stream_hglobal);
2455  /* Remove BMP header for DIB */
2456  if (file_format == D3DXIFF_DIB)
2457  stream_data = (void*)((BYTE*)stream_data + sizeof(BITMAPFILEHEADER));
2458  memcpy(buffer_pointer, stream_data, size);
2459  GlobalUnlock(stream_hglobal);
2460  *dst_buffer = buffer;
2461  }
2463 
2464 cleanup_err:
2465  if (FAILED(hr) && hr != E_OUTOFMEMORY)
2467 
2468 cleanup:
2469  if (stream) IStream_Release(stream);
2470 
2471  if (frame) IWICBitmapFrameEncode_Release(frame);
2472  if (encoder_options) IPropertyBag2_Release(encoder_options);
2473 
2474  if (encoder) IWICBitmapEncoder_Release(encoder);
2475 
2476  return hr;
2477 }
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:68
HRESULT hr
Definition: shlfolder.c:183
D3DFORMAT Format
Definition: d3d8types.h:1170
HRESULT lock_surface(IDirect3DSurface9 *surface, D3DLOCKED_RECT *lock, IDirect3DSurface9 **temp_surface, BOOL write)
Definition: surface.c:206
#define WARN(fmt,...)
Definition: debug.h:112
HRESULT unlock_surface(IDirect3DSurface9 *surface, D3DLOCKED_RECT *lock, IDirect3DSurface9 *temp_surface, BOOL update)
Definition: surface.c:252
HRESULT WINAPI D3DXCreateBuffer(DWORD size, ID3DXBuffer **buffer)
Definition: core.c:129
LONG top
Definition: windef.h:307
#define D3DERR_INVALIDCALL
GLuint buffer
Definition: glext.h:5915
HRESULT WINAPI CreateStreamOnHGlobal(HGLOBAL hGlobal, BOOL fDeleteOnRelease, LPSTREAM *ppstm)
LONG left
Definition: windef.h:306
LONG right
Definition: windef.h:308
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:1691
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
Definition: main.c:438
#define FIXME(fmt,...)
Definition: debug.h:111
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:55
HRESULT WINAPI WICCreateImagingFactory_Proxy(UINT, IWICImagingFactory **)
Definition: proxy.c:651
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:404
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG HRESULT
Definition: typedefs.h:78
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
#define IDirect3DSurface9_GetDesc(p, a)
Definition: d3d9.h:634
unsigned char BYTE
Definition: xxhash.c:193
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
#define ID3DXBuffer_Release(p)
Definition: d3dx9core.h:83
struct tagBITMAPFILEHEADER BITMAPFILEHEADER
#define E_NOTIMPL
Definition: ddrawi.h:99
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
static ClassFactoryImpl factory
Definition: ole_server.c:234
LONG bottom
Definition: windef.h:309
char * cleanup(char *str)
Definition: wpickclick.c:99
const struct pixel_format_desc * get_format_info(D3DFORMAT format) DECLSPEC_HIDDEN
Definition: util.c:213
static HRESULT save_dds_surface_to_memory(ID3DXBuffer **dst_buffer, IDirect3DSurface9 *src_surface, const RECT *src_rect)
Definition: surface.c:547
static const char stream_data[]
Definition: mlang.c:2327
#define HeapFree(x, y, z)
Definition: compat.h:403
#define ID3DXBuffer_GetBufferPointer(p)
Definition: d3dx9core.h:85
#define SUCCEEDED(hr)
Definition: intsafe.h:57

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

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

2241 {
2242  HRESULT hr;
2244 
2245  TRACE("(%s, %#x, %p, %p, %s): relay\n",
2246  wine_dbgstr_w(dst_filename), file_format, src_surface, src_palette, wine_dbgstr_rect(src_rect));
2247 
2248  if (!dst_filename) return D3DERR_INVALIDCALL;
2249 
2250  hr = D3DXSaveSurfaceToFileInMemory(&buffer, file_format, src_surface, src_palette, src_rect);
2251  if (SUCCEEDED(hr))
2252  {
2253  hr = write_buffer_to_file(dst_filename, buffer);
2255  }
2256 
2257  return hr;
2258 }
HRESULT hr
Definition: shlfolder.c:183
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
#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:78
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:2260
#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 319 of file surface.c.

320 {
321  if (pixel_format->bpp == 8 && pixel_format->amask == 0xff)
322  return D3DFMT_A8;
323 
324  WARN("Unknown Alpha pixel format (%u, %#x)\n", pixel_format->bpp, pixel_format->rmask);
325  return D3DFMT_UNKNOWN;
326 }
#define WARN(fmt,...)
Definition: debug.h:112

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

341 {
342  if (pixel_format->bpp == 32 && pixel_format->rmask == 0x000000ff && pixel_format->gmask == 0x0000ff00
343  && pixel_format->bmask == 0x00ff0000)
344  return D3DFMT_X8L8V8U8;
345 
346  WARN("Unknown bump pixel format (%u, %#x, %#x, %#x, %#x)\n", pixel_format->bpp,
347  pixel_format->rmask, pixel_format->gmask, pixel_format->bmask, pixel_format->amask);
348  return D3DFMT_UNKNOWN;
349 }
#define WARN(fmt,...)
Definition: debug.h:112

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

329 {
330  if (pixel_format->bpp == 16 && pixel_format->rmask == 0x00ff && pixel_format->gmask == 0xff00)
331  return D3DFMT_V8U8;
332  if (pixel_format->bpp == 32 && pixel_format->rmask == 0x0000ffff && pixel_format->gmask == 0xffff0000)
333  return D3DFMT_V16U16;
334 
335  WARN("Unknown bump pixel format (%u, %#x, %#x, %#x, %#x)\n", pixel_format->bpp,
336  pixel_format->rmask, pixel_format->gmask, pixel_format->bmask, pixel_format->amask);
337  return D3DFMT_UNKNOWN;
338 }
#define WARN(fmt,...)
Definition: debug.h:112

Referenced by dds_pixel_format_to_d3dformat().

◆ dds_fourcc_to_d3dformat()

static D3DFORMAT dds_fourcc_to_d3dformat ( DWORD  fourcc)
static

Definition at line 150 of file surface.c.

151 {
152  unsigned int i;
153  static const DWORD known_fourcc[] = {
154  D3DFMT_UYVY,
155  D3DFMT_YUY2,
158  D3DFMT_DXT1,
159  D3DFMT_DXT2,
160  D3DFMT_DXT3,
161  D3DFMT_DXT4,
162  D3DFMT_DXT5,
163  D3DFMT_R16F,
166  D3DFMT_R32F,
169  };
170 
171  for (i = 0; i < ARRAY_SIZE(known_fourcc); i++)
172  {
173  if (known_fourcc[i] == fourcc)
174  return fourcc;
175  }
176 
177  WARN("Unknown FourCC %#x\n", fourcc);
178  return D3DFMT_UNKNOWN;
179 }
#define WARN(fmt,...)
Definition: debug.h:112
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 297 of file surface.c.

298 {
299  if (pixel_format->bpp == 8)
300  {
301  if (pixel_format->rmask == 0xff)
302  return D3DFMT_L8;
303  if ((pixel_format->flags & DDS_PF_ALPHA) && pixel_format->rmask == 0x0f && pixel_format->amask == 0xf0)
304  return D3DFMT_A4L4;
305  }
306  if (pixel_format->bpp == 16)
307  {
308  if (pixel_format->rmask == 0xffff)
309  return D3DFMT_L16;
310  if ((pixel_format->flags & DDS_PF_ALPHA) && pixel_format->rmask == 0x00ff && pixel_format->amask == 0xff00)
311  return D3DFMT_A8L8;
312  }
313 
314  WARN("Unknown luminance pixel format (bpp %u, l %#x, a %#x)\n",
315  pixel_format->bpp, pixel_format->rmask, pixel_format->amask);
316  return D3DFMT_UNKNOWN;
317 }
#define WARN(fmt,...)
Definition: debug.h:112
#define DDS_PF_ALPHA
Definition: surface.c:110

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

352 {
353  TRACE("pixel_format: size %u, flags %#x, fourcc %#x, bpp %u.\n", pixel_format->size,
354  pixel_format->flags, pixel_format->fourcc, pixel_format->bpp);
355  TRACE("rmask %#x, gmask %#x, bmask %#x, amask %#x.\n", pixel_format->rmask, pixel_format->gmask,
356  pixel_format->bmask, pixel_format->amask);
357 
358  if (pixel_format->flags & DDS_PF_FOURCC)
359  return dds_fourcc_to_d3dformat(pixel_format->fourcc);
360  if (pixel_format->flags & DDS_PF_RGB)
362  if (pixel_format->flags & DDS_PF_LUMINANCE)
364  if (pixel_format->flags & DDS_PF_ALPHA_ONLY)
366  if (pixel_format->flags & DDS_PF_BUMPDUDV)
368  if (pixel_format->flags & DDS_PF_BUMPLUMINANCE)
370 
371  WARN("Unknown pixel format (flags %#x, fourcc %#x, bpp %u, r %#x, g %#x, b %#x, a %#x)\n",
372  pixel_format->flags, pixel_format->fourcc, pixel_format->bpp,
373  pixel_format->rmask, pixel_format->gmask, pixel_format->bmask, pixel_format->amask);
374  return D3DFMT_UNKNOWN;
375 }
static D3DFORMAT dds_bump_luminance_to_d3dformat(const struct dds_pixel_format *pixel_format)
Definition: surface.c:340
#define DDS_PF_FOURCC
Definition: surface.c:112
#define WARN(fmt,...)
Definition: debug.h:112
static D3DFORMAT dds_alpha_to_d3dformat(const struct dds_pixel_format *pixel_format)
Definition: surface.c:319
#define DDS_PF_BUMPDUDV
Definition: surface.c:117
static D3DFORMAT dds_rgb_to_d3dformat(const struct dds_pixel_format *pixel_format)
Definition: surface.c:274
#define TRACE(s)
Definition: solgame.cpp:4
static D3DFORMAT dds_fourcc_to_d3dformat(DWORD fourcc)
Definition: surface.c:150
#define DDS_PF_BUMPLUMINANCE
Definition: surface.c:116
#define DDS_PF_LUMINANCE
Definition: surface.c:115
static D3DFORMAT dds_luminance_to_d3dformat(const struct dds_pixel_format *pixel_format)
Definition: surface.c:297
#define DDS_PF_RGB
Definition: surface.c:113
static D3DFORMAT dds_bump_to_d3dformat(const struct dds_pixel_format *pixel_format)
Definition: surface.c:328
#define DDS_PF_ALPHA_ONLY
Definition: surface.c:111

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

275 {
276  unsigned int i;
277 
278  for (i = 0; i < ARRAY_SIZE(rgb_pixel_formats); i++)
279  {
280  if (rgb_pixel_formats[i].bpp == pixel_format->bpp
281  && rgb_pixel_formats[i].rmask == pixel_format->rmask
282  && rgb_pixel_formats[i].gmask == pixel_format->gmask
283  && rgb_pixel_formats[i].bmask == pixel_format->bmask)
284  {
285  if ((pixel_format->flags & DDS_PF_ALPHA) && rgb_pixel_formats[i].amask == pixel_format->amask)
286  return rgb_pixel_formats[i].format;
287  if (rgb_pixel_formats[i].amask == 0)
288  return rgb_pixel_formats[i].format;
289  }
290  }
291 
292  WARN("Unknown RGB pixel format (%#x, %#x, %#x, %#x)\n",
293  pixel_format->rmask, pixel_format->gmask, pixel_format->bmask, pixel_format->amask);
294  return D3DFMT_UNKNOWN;
295 }
DWORD amask
Definition: surface.c:186
#define WARN(fmt,...)
Definition: debug.h:112
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:110
DWORD bpp
Definition: surface.c:182
static const struct @247 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 1610 of file surface.c.

1611 {
1612  DWORD v, mask32;
1613  unsigned int c, i;
1614 
1615  memset(dst, 0, format->bytes_per_pixel);
1616 
1617  for (c = 0; c < 4; ++c)
1618  {
1619  static const unsigned int component_offsets[4] = {3, 0, 1, 2};
1620  const float src_component = *((const float *)src + component_offsets[c]);
1621 
1622  if (!format->bits[c])
1623  continue;
1624 
1625  mask32 = ~0u >> (32 - format->bits[c]);
1626 
1627  if (format->type == FORMAT_ARGBF16)
1628  v = float_32_to_16(src_component);
1629  else if (format->type == FORMAT_ARGBF)
1630  v = *(DWORD *)&src_component;
1631  else
1632  v = (DWORD)(src_component * ((1 << format->bits[c]) - 1) + 0.5f);
1633 
1634  for (i = format->shift[c] / 8 * 8; i < format->shift[c] + format->bits[c]; i += 8)
1635  {
1636  BYTE mask, byte;
1637 
1638  if (format->shift[c] > i)
1639  {
1640  mask = mask32 << (format->shift[c] - i);
1641  byte = (v << (format->shift[c] - i)) & mask;
1642  }
1643  else
1644  {
1645  mask = mask32 >> (i - format->shift[c]);
1646  byte = (v >> (i - format->shift[c])) & mask;
1647  }
1648  dst[i / 8] |= byte;
1649  }
1650  }
1651 }
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:1756
#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
GLenum src
Definition: glext.h:6340
unsigned char BYTE
Definition: xxhash.c:193
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:1062
#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 1580 of file surface.c.

1581 {
1582  DWORD mask, tmp;
1583  unsigned int c;
1584 
1585  for (c = 0; c < 4; ++c)
1586  {
1587  static const unsigned int component_offsets[4] = {3, 0, 1, 2};
1588  float *dst_component = (float *)dst + component_offsets[c];
1589 
1590  if (format->bits[c])
1591  {
1592  mask = ~0u >> (32 - format->bits[c]);
1593 
1594  memcpy(&tmp, src + format->shift[c] / 8,
1595  min(sizeof(DWORD), (format->shift[c] % 8 + format->bits[c] + 7) / 8));
1596 
1597  if (format->type == FORMAT_ARGBF16)
1598  *dst_component = float_16_to_32(tmp);
1599  else if (format->type == FORMAT_ARGBF)
1600  *dst_component = *(float *)&tmp;
1601  else
1602  *dst_component = (float)((tmp >> format->shift[c] % 8) & mask) / mask;
1603  }
1604  else
1605  *dst_component = 1.0f;
1606  }
1607 }
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:2199
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
static float(__cdecl *square_half_float)(float x
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 1884 of file surface.c.

1885 {
1886  switch (format)
1887  {
1888  case D3DFMT_DXT1:
1889  return encode ? wined3d_dxt1_encode : wined3d_dxt1_decode;
1890  case D3DFMT_DXT3:
1891  return encode ? wined3d_dxt3_encode : wined3d_dxt3_decode;
1892  case D3DFMT_DXT5:
1893  return encode ? wined3d_dxt5_encode : wined3d_dxt5_decode;
1894  default:
1895  return NULL;
1896  }
1897 }
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 472 of file surface.c.

473 {
474  UINT faces = 1;
475  UINT expected_length;
476  const struct dds_header *header = buffer;
477 
478  if (length < sizeof(*header) || !info)
479  return D3DXERR_INVALIDDATA;
480 
481  if (header->pixel_format.size != sizeof(header->pixel_format))
482  return D3DXERR_INVALIDDATA;
483 
484  info->Width = header->width;
485  info->Height = header->height;
486  info->Depth = 1;
487  info->MipLevels = header->miplevels ? header->miplevels : 1;
488 
489  info->Format = dds_pixel_format_to_d3dformat(&header->pixel_format);
490  if (info->Format == D3DFMT_UNKNOWN)
491  return D3DXERR_INVALIDDATA;
492 
493  TRACE("Pixel format is %#x\n", info->Format);
494 
495  if (header->caps2 & DDS_CAPS2_VOLUME)
496  {
497  info->Depth = header->depth;
498  info->ResourceType = D3DRTYPE_VOLUMETEXTURE;
499  }
500  else if (header->caps2 & DDS_CAPS2_CUBEMAP)
501  {
502  DWORD face;
503  faces = 0;
505  {
506  if (header->caps2 & face)
507  faces++;
508  }
509  info->ResourceType = D3DRTYPE_CUBETEXTURE;
510  }
511  else
512  {
513  info->ResourceType = D3DRTYPE_TEXTURE;
514  }
515 
516  expected_length = calculate_dds_file_size(info->Format, info->Width, info->Height, info->Depth,
517  info->MipLevels, faces);
518  if (length < expected_length)
519  {
520  WARN("File is too short %u, expected at least %u bytes\n", length, expected_length);
521  return D3DXERR_INVALIDDATA;
522  }
523 
524  info->ImageFileFormat = D3DXIFF_DDS;
525  return D3D_OK;
526 }
#define WARN(fmt,...)
Definition: debug.h:112
#define DDS_CAPS2_VOLUME
Definition: surface.c:107
GLuint buffer
Definition: glext.h:5915
#define TRACE(s)
Definition: solgame.cpp:4
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
unsigned long DWORD
Definition: ntddk_ex.h:95
WORD face[3]
Definition: mesh.c:4747
static UINT calculate_dds_file_size(D3DFORMAT format, UINT width, UINT height, UINT depth, UINT miplevels, UINT faces)
Definition: surface.c:435
#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:351
#define DDS_CAPS2_CUBEMAP_NEGATIVEZ
Definition: surface.c:103
#define DDS_CAPS2_CUBEMAP
Definition: surface.c:97
#define DDS_CAPS2_CUBEMAP_POSITIVEX
Definition: surface.c:98
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 1532 of file surface.c.

1533 {
1534  unsigned int i, j;
1535  unsigned int component, mask;
1536 
1537  for (i = 0; i < 4; ++i)
1538  {
1539  if (!info->process_channel[i])
1540  continue;
1541 
1542  component = 0;
1543  mask = info->srcmask[i];
1544  for (j = 0; j < 4 && mask; ++j)
1545  {
1546  if (info->srcshift[i] < j * 8)
1547  component |= (col[j] & mask) << (j * 8 - info->srcshift[i]);
1548  else
1549  component |= (col[j] & mask) >> (info->srcshift[i] - j * 8);
1550  mask >>= 8;
1551  }
1552  out[i] = component;
1553  }
1554 }
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 617 of file surface.c.

619 {
620  switch (type)
621  {
622  case D3DRTYPE_TEXTURE:
623  return IDirect3DTexture9_GetSurfaceLevel((IDirect3DTexture9*) tex, level, surf);
625  return IDirect3DCubeTexture9_GetCubeMapSurface((IDirect3DCubeTexture9*) tex, face, level, surf);
626  default:
627  ERR("Unexpected texture type\n");
628  return E_NOTIMPL;
629  }
630 }
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:110
#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 1499 of file surface.c.

1500 {
1501  UINT i;
1502  ZeroMemory(info->process_channel, 4 * sizeof(BOOL));
1503  info->channelmask = 0;
1504 
1505  info->srcformat = srcformat;
1506  info->destformat = destformat;
1507 
1508  for(i = 0;i < 4;i++) {
1509  /* srcshift is used to extract the _relevant_ components */
1510  info->srcshift[i] = srcformat->shift[i] + max( srcformat->bits[i] - destformat->bits[i], 0);
1511 
1512  /* destshift is used to move the components to the correct position */
1513  info->destshift[i] = destformat->shift[i] + max(destformat->bits[i] - srcformat->bits[i], 0);
1514 
1515  info->srcmask[i] = ((1 << srcformat->bits[i]) - 1) << srcformat->shift[i];
1516  info->destmask[i] = ((1 << destformat->bits[i]) - 1) << destformat->shift[i];
1517 
1518  /* channelmask specifies bits which aren't used in the source format but in the destination one */
1519  if(destformat->bits[i]) {
1520  if(srcformat->bits[i]) info->process_channel[i] = TRUE;
1521  else info->channelmask |= info->destmask[i];
1522  }
1523  }
1524 }
#define max(a, b)
Definition: svc.c:63
#define TRUE
Definition: types.h:120
#define ZeroMemory
Definition: winbase.h:1648
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 754 of file surface.c.

756 {
757  HRESULT hr;
758  int face;
759  UINT mip_level;
760  UINT size;
761  RECT src_rect;
762  UINT src_pitch;
763  UINT mip_levels;
764  UINT mip_level_size;
765  IDirect3DSurface9 *surface;
766  const struct dds_header *header = src_data;
767  const BYTE *pixels = (BYTE *)(header + 1);
768 
769  if (src_info->ResourceType != D3DRTYPE_CUBETEXTURE)
770  return D3DXERR_INVALIDDATA;
771 
773  {
774  WARN("Only full cubemaps are supported\n");
775  return D3DXERR_INVALIDDATA;
776  }
777 
778  mip_levels = min(src_info->MipLevels, IDirect3DCubeTexture9_GetLevelCount(cube_texture));
780  {
781  size = src_info->Width;
782  for (mip_level = 0; mip_level < src_info->MipLevels; mip_level++)
783  {
784  hr = calculate_dds_surface_size(src_info->Format, size, size, &src_pitch, &mip_level_size);
785  if (FAILED(hr)) return hr;
786 
787  /* if texture has fewer mip levels than DDS file, skip excessive mip levels */
788  if (mip_level < mip_levels)
789  {
790  SetRect(&src_rect, 0, 0, size, size);
791 
792  IDirect3DCubeTexture9_GetCubeMapSurface(cube_texture, face, mip_level, &surface);
793  hr = D3DXLoadSurfaceFromMemory(surface, palette, NULL, pixels, src_info->Format, src_pitch,
794  NULL, &src_rect, filter, color_key);
795  IDirect3DSurface9_Release(surface);
796  if (FAILED(hr)) return hr;
797  }
798 
799  pixels += mip_level_size;
800  size = max(1, size / 2);
801  }
802  }
803 
804  return D3D_OK;
805 }
#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:112
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:104
LONG HRESULT
Definition: typedefs.h:78
static HRESULT calculate_dds_surface_size(D3DFORMAT format, UINT width, UINT height, UINT *pitch, UINT *size)
Definition: surface.c:412
WORD face[3]
Definition: mesh.c:4747
#define IDirect3DCubeTexture9_GetCubeMapSurface(p, a, b, c)
Definition: d3d9.h:938
unsigned char BYTE
Definition: xxhash.c:193
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:1931
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
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 528 of file surface.c.

531 {
532  UINT size;
533  UINT src_pitch;
534  const struct dds_header *header = src_data;
535  const BYTE *pixels = (BYTE *)(header + 1);
536 
537  if (src_info->ResourceType != D3DRTYPE_TEXTURE)
538  return D3DXERR_INVALIDDATA;
539 
540  if (FAILED(calculate_dds_surface_size(src_info->Format, src_info->Width, src_info->Height, &src_pitch, &size)))
541  return E_NOTIMPL;
542 
543  return D3DXLoadSurfaceFromMemory(dst_surface, dst_palette, dst_rect, pixels, src_info->Format,
544  src_pitch, NULL, src_rect, filter, color_key);
545 }
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:412
unsigned char BYTE
Definition: xxhash.c:193
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:1931
#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

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

700 {
701  HRESULT hr;
702  RECT src_rect;
703  UINT src_pitch;
704  UINT mip_level;
705  UINT mip_levels;
706  UINT mip_level_size;
707  UINT width, height;
708  IDirect3DSurface9 *surface;
709  const struct dds_header *header = src_data;
710  const BYTE *pixels = (BYTE *)(header + 1);
711 
712  /* Loading a cube texture as a simple texture is also supported
713  * (only first face texture is taken). Same with volume textures. */
714  if ((src_info->ResourceType != D3DRTYPE_TEXTURE)
715  && (src_info->ResourceType != D3DRTYPE_CUBETEXTURE)
716  && (src_info->ResourceType != D3DRTYPE_VOLUMETEXTURE))
717  {
718  WARN("Trying to load a %u resource as a 2D texture, returning failure.\n", src_info->ResourceType);
719  return D3DXERR_INVALIDDATA;
720  }
721 
722  width = src_info->Width;
723  height = src_info->Height;
724  mip_levels = min(src_info->MipLevels, IDirect3DTexture9_GetLevelCount(texture));
725  if (src_info->ResourceType == D3DRTYPE_VOLUMETEXTURE)
726  mip_levels = 1;
727  for (mip_level = 0; mip_level < mip_levels + skip_levels; ++mip_level)
728  {
729  hr = calculate_dds_surface_size(src_info->Format, width, height, &src_pitch, &mip_level_size);
730  if (FAILED(hr)) return hr;
731 
732  if (mip_level >= skip_levels)
733  {
734  SetRect(&src_rect, 0, 0, width, height);
735 
736  IDirect3DTexture9_GetSurfaceLevel(texture, mip_level - skip_levels, &surface);
737  hr = D3DXLoadSurfaceFromMemory(surface, palette, NULL, pixels, src_info->Format, src_pitch,
738  NULL, &src_rect, filter, color_key);
739  IDirect3DSurface9_Release(surface);
740  if (FAILED(hr))
741  return hr;
742  }
743 
744  pixels += mip_level_size;
745  width = max(1, width / 2);
746  height = max(1, height / 2);
747  }
748 
749  *loaded_miplevels = mip_levels - skip_levels;
750 
751  return D3D_OK;
752 }
#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:112
#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:78
static HRESULT calculate_dds_surface_size(D3DFORMAT format, UINT width, UINT height, UINT *pitch, UINT *size)
Definition: surface.c:412
unsigned char BYTE
Definition: xxhash.c:193
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:1931
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

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

682 {
683  UINT row_pitch, slice_pitch;
684  const struct dds_header *header = src_data;
685  const BYTE *pixels = (BYTE *)(header + 1);
686 
687  if (src_info->ResourceType != D3DRTYPE_VOLUMETEXTURE)
688  return D3DXERR_INVALIDDATA;
689 
690  if (FAILED(calculate_dds_surface_size(src_info->Format, src_info->Width, src_info->Height, &row_pitch, &slice_pitch)))
691  return E_NOTIMPL;
692 
693  return D3DXLoadVolumeFromMemory(dst_volume, dst_palette, dst_box, pixels, src_info->Format,
694  row_pitch, slice_pitch, NULL, src_box, filter, color_key);
695 }
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:412
unsigned char BYTE
Definition: xxhash.c:193
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

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

809 {
810  HRESULT hr;
811  UINT mip_level;
812  UINT mip_levels;
813  UINT src_slice_pitch;
814  UINT src_row_pitch;
815  D3DBOX src_box;
817  IDirect3DVolume9 *volume;
818  const struct dds_header *header = src_data;
819  const BYTE *pixels = (BYTE *)(header + 1);
820 
821  if (src_info->ResourceType != D3DRTYPE_VOLUMETEXTURE)
822  return D3DXERR_INVALIDDATA;
823 
824  width = src_info->Width;
825  height = src_info->Height;
826  depth = src_info->Depth;
827  mip_levels = min(src_info->MipLevels, IDirect3DVolumeTexture9_GetLevelCount(volume_texture));
828 
829  for (mip_level = 0; mip_level < mip_levels; mip_level++)
830  {
831  hr = calculate_dds_surface_size(src_info->Format, width, height, &src_row_pitch, &src_slice_pitch);
832  if (FAILED(hr)) return hr;
833 
834  hr = IDirect3DVolumeTexture9_GetVolumeLevel(volume_texture, mip_level, &volume);
835  if (FAILED(hr)) return hr;
836 
837  src_box.Left = 0;
838  src_box.Top = 0;
839  src_box.Right = width;
840  src_box.Bottom = height;
841  src_box.Front = 0;
842  src_box.Back = depth;
843 
845  src_row_pitch, src_slice_pitch, NULL, &src_box, filter, color_key);
846 
848  if (FAILED(hr)) return hr;
849 
850  pixels += depth * src_slice_pitch;
851  width = max(1, width / 2);
852  height = max(1, height / 2);
853  depth = max(1, depth / 2);
854  }
855 
856  return D3D_OK;
857 }
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:78
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:412
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
#define IDirect3DVolume9_Release(p)
Definition: d3d9.h:383
unsigned char BYTE
Definition: xxhash.c:193
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

Referenced by D3DXCreateVolumeTextureFromFileInMemoryEx().

◆ lock_surface()

HRESULT lock_surface ( IDirect3DSurface9 *  surface,
D3DLOCKED_RECT lock,
IDirect3DSurface9 **  temp_surface,
BOOL  write 
)

Definition at line 206 of file surface.c.

208 {
209  IDirect3DDevice9 *device;
211  DWORD lock_flag;
212  HRESULT hr;
213 
214  lock_flag = write ? D3DLOCK_DISCARD : D3DLOCK_READONLY;
215  *temp_surface = NULL;
216  if (FAILED(hr = IDirect3DSurface9_LockRect(surface, lock, NULL, lock_flag)))
217  {
219  IDirect3DSurface9_GetDesc(surface, &desc);
220 
222  desc.Format, D3DPOOL_SYSTEMMEM, temp_surface, NULL)
224  desc.Format, D3DMULTISAMPLE_NONE, 0, TRUE, temp_surface, NULL);
225  if (FAILED(hr))
226  {
227  WARN("Failed to create temporary surface, surface %p, format %#x,"
228  " usage %#x, pool %#x, write %#x, width %u, height %u.\n",
229  surface, desc.Format, desc.Usage, desc.Pool, write, desc.Width, desc.Height);
231  return hr;
232  }
233 
235  *temp_surface, NULL, D3DTEXF_NONE)))
236  hr = IDirect3DSurface9_LockRect(*temp_surface, lock, NULL, lock_flag);
237 
239  if (FAILED(hr))
240  {
241  WARN("Failed to lock surface %p, write %#x, usage %#x, pool %#x.\n",
242  surface, write, desc.Usage, desc.Pool);
243  IDirect3DSurface9_Release(*temp_surface);
244  *temp_surface = NULL;
245  return hr;
246  }
247  TRACE("Created temporary surface %p.\n", surface);
248  }
249  return hr;
250 }
#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
#define WARN(fmt,...)
Definition: debug.h:112
#define D3DLOCK_DISCARD
Definition: d3d8types.h:72
#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
#define IDirect3DDevice9_CreateOffscreenPlainSurface(p, a, b, c, d, e, f)
Definition: d3d9.h:1543
#define write
Definition: acwin.h:97
Definition: devices.h:37
static const WCHAR desc[]
Definition: protectdata.c:36
#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:78
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IDirect3DSurface9_GetDesc(p, a)
Definition: d3d9.h:634