ReactOS 0.4.17-dev-966-gf06eace
surface.c File Reference
#include <assert.h>
#include "wine/test.h"
#include "d3dx9tex.h"
#include "resources.h"
#include <stdint.h>
#include "d3dx9_test_images.h"
#include "ddraw.h"
#include "pshpack1.h"
#include "poppack.h"
Include dependency graph for surface.c:

Go to the source code of this file.

Classes

struct  surface_readback
 
struct  dds_pixel_format
 
struct  dds_header
 
struct  tga_header
 
struct  tga_footer
 

Macros

#define COBJMACROS
 
#define check_release(obj, exp)   _check_release(__LINE__, obj, exp)
 
#define DDS_PF_ALPHA   0x00000001
 
#define DDS_PF_ALPHA_ONLY   0x00000002
 
#define DDS_PF_FOURCC   0x00000004
 
#define DDS_PF_INDEXED   0x00000020
 
#define DDS_PF_RGB   0x00000040
 
#define DDS_PF_LUMINANCE   0x00020000
 
#define DDS_PF_BUMPLUMINANCE   0x00040000
 
#define DDS_PF_BUMPDUDV   0x00080000
 
#define check_dds_pixel_format(flags, fourcc, bpp, rmask, gmask, bmask, amask, format)    check_dds_pixel_format_(__LINE__, flags, fourcc, bpp, rmask, gmask, bmask, amask, format)
 
#define COLORMAP_TYPE_NONE   0
 
#define COLORMAP_TYPE_ONE   1
 
#define IMAGETYPE_COLORMAPPED   1
 
#define IMAGETYPE_TRUECOLOR   2
 
#define IMAGETYPE_GRAYSCALE   3
 
#define IMAGETYPE_RLE   8
 
#define IMAGE_RIGHTTOLEFT   0x10
 
#define IMAGE_TOPTOBOTTOM   0x20
 
#define check_tga_image_info(tga, tga_size, expected_width, expected_height, expected_format, expected_hr)    check_tga_image_info_(__LINE__, tga, tga_size, expected_width, expected_height, expected_format, expected_hr)
 
#define check_pixel_2bpp(lockrect, x, y, color)   _check_pixel_2bpp(__LINE__, lockrect, x, y, color)
 
#define check_pixel_4bpp(lockrect, x, y, color)   _check_pixel_4bpp(__LINE__, lockrect, x, y, color)
 
#define check_pixel_8bpp(lockrect, x, y, color)   _check_pixel_8bpp(__LINE__, lockrect, x, y, color)
 
#define check_pixel_float4(lockrect, x, y, fx, fy, fz, fw, ulps, todo)    _check_pixel_float4(__LINE__, lockrect, x, y, fx, fy, fz, fw, ulps, todo)
 
#define check_readback_pixel_4bpp(rb, x, y, color, todo)   _check_readback_pixel_4bpp(__LINE__, rb, x, y, color, todo)
 
#define check_tga_surface_load(surface, expected, right_to_left, bottom_to_top)    check_tga_surface_load_(__LINE__, surface, expected, right_to_left, bottom_to_top)
 
#define check_dds_pixel_format_struct(pixel_format, expected_pixel_format, wine_todo)    check_dds_pixel_format_struct_(__FILE__, __LINE__, pixel_format, expected_pixel_format, wine_todo)
 
#define check_dds_header(header, flags, height, width, pitch, depth, mip_levels, pixel_format, caps, caps2, wine_todo)
 
#define DDS_FILE_HEADER_SIZE   (sizeof(uint32_t) + sizeof(struct dds_header))
 
#define PALETTED_DDS_FILE_HEADER_SIZE   (DDS_FILE_HEADER_SIZE + (sizeof(PALETTEENTRY) * 256))
 

Functions

static BOOL compare_uint (uint32_t x, uint32_t y, uint32_t max_diff)
 
static BOOL compare_float (float f, float g, uint32_t ulps)
 
static void _check_release (unsigned int line, IUnknown *obj, int exp)
 
static uint32_t get_readback_color (struct surface_readback *rb, uint32_t x, uint32_t y)
 
static void release_surface_readback (struct surface_readback *rb)
 
static void get_surface_readback (IDirect3DDevice9 *device, IDirect3DSurface9 *src_surface, D3DFORMAT rb_format, struct surface_readback *rb)
 
static void get_surface_decompressed_readback (IDirect3DDevice9 *device, IDirect3DSurface9 *compressed_surface, struct surface_readback *rb)
 
static HRESULT create_file (const char *filename, const unsigned char *data, const unsigned int size)
 
static void fill_dds_header (struct dds_header *header)
 
static void check_dds_pixel_format_ (unsigned int line, DWORD flags, DWORD fourcc, DWORD bpp, DWORD rmask, DWORD gmask, DWORD bmask, DWORD amask, D3DFORMAT expected_format)
 
static void test_dds_header_handling (void)
 
static void check_tga_image_info_ (uint32_t line, const void *tga, uint32_t tga_size, uint32_t expected_width, uint32_t expected_height, D3DFORMAT expected_format, HRESULT expected_hr)
 
static void test_tga_header_handling (void)
 
static void test_D3DXGetImageInfo (void)
 
static void _check_pixel_2bpp (unsigned int line, const D3DLOCKED_RECT *lockrect, int x, int y, WORD expected_color)
 
static void _check_pixel_4bpp (unsigned int line, const D3DLOCKED_RECT *lockrect, int x, int y, DWORD expected_color)
 
static void _check_pixel_8bpp (unsigned int line, const D3DLOCKED_RECT *lockrect, int x, int y, uint64_t expected_color)
 
static void _check_pixel_float4 (uint32_t line, const D3DLOCKED_RECT *lockrect, uint32_t x, uint32_t y, float fx, float fy, float fz, float fw, uint32_t ulps, BOOL todo)
 
static void _check_readback_pixel_4bpp (unsigned int line, struct surface_readback *rb, uint32_t x, uint32_t y, uint32_t expected_color, BOOL todo)
 
static uint32_t get_bpp_for_d3dformat (D3DFORMAT format)
 
static void test_format_conversion (IDirect3DDevice9 *device)
 
static void test_dxt_premultiplied_alpha (IDirect3DDevice9 *device)
 
static void check_tga_surface_load_ (uint32_t line, IDirect3DSurface9 *surface, const uint8_t *expected, BOOL right_to_left, BOOL bottom_to_top)
 
static void test_load_surface_from_tga (IDirect3DDevice9 *device)
 
static void test_D3DXLoadSurface (IDirect3DDevice9 *device)
 
static void check_dds_pixel_format_struct_ (const char *file, uint32_t line, const struct dds_pixel_format *pixel_format, const struct dds_pixel_format *expected_pixel_format, BOOL wine_todo)
 
static void check_dds_header_ (const char *file, uint32_t line, const struct dds_header *header, uint32_t flags, uint32_t height, uint32_t width, uint32_t pitch, uint32_t depth, uint32_t mip_levels, const struct dds_pixel_format *pixel_format, uint32_t caps, uint32_t caps2, BOOL wine_todo)
 
static void test_save_surface_to_dds (IDirect3DDevice9 *device)
 
static void test_D3DXSaveSurfaceToFileInMemory (IDirect3DDevice9 *device)
 
static void test_D3DXSaveSurfaceToFile (IDirect3DDevice9 *device)
 
 START_TEST (surface)
 

Variables

static const struct tga_footer default_tga_footer
 
static const PALETTEENTRY test_palette [256]
 
static const uint16_t v16u16_2_2 []
 
static const uint8_t v16u16_2_2_expected []
 
static const uint8_t v16u16_2_2_expected2 []
 
static const uint8_t v8u8_2_2 []
 
static const uint8_t v8u8_2_2_expected []
 
static const uint16_t a16b16g16r16_2_2 []
 
static const uint8_t a16b16g16r16_2_2_expected []
 
static const uint16_t q16w16v16u16_2_2 []
 
static const uint8_t q16w16v16u16_2_2_expected []
 
static const uint8_t p8_2_2 []
 
static const uint8_t p8_2_2_expected []
 
static const uint8_t a8p8_2_2 []
 
static const uint8_t a8p8_2_2_expected []
 
static const uint8_t test_tga_color_map_15bpp []
 
static const uint8_t test_tga_color_map_16bpp []
 
static const uint8_t test_tga_color_map_24bpp []
 
static const uint8_t test_tga_color_map_32bpp []
 
static const uint8_t test_tga_color_map_index_4_4 []
 
static const uint8_t test_tga_color_map_index_4_4_rle []
 
static const uint8_t test_tga_true_color_15bpp_4_4 []
 
static const uint8_t test_tga_true_color_15bpp_4_4_rle []
 
static const uint8_t test_tga_true_color_16bpp_4_4 []
 
static const uint8_t test_tga_true_color_16bpp_4_4_rle []
 
static const uint8_t test_tga_true_color_24bpp_4_4 []
 
static const uint8_t test_tga_true_color_24bpp_4_4_rle []
 
static const uint8_t test_tga_true_color_32bpp_4_4 []
 
static const uint8_t test_tga_true_color_32bpp_4_4_rle []
 
static const uint8_t test_tga_grayscale_8bpp_4_4 []
 
static const uint8_t test_tga_grayscale_8bpp_4_4_rle []
 
static const uint8_t test_tga_color_map_15bpp_expected []
 
static const uint8_t test_tga_color_map_15bpp_rle_expected []
 
static const uint8_t test_tga_color_map_16bpp_expected []
 
static const uint8_t test_tga_color_map_24bpp_expected []
 
static const uint8_t test_tga_color_map_32bpp_expected []
 
static const uint8_t test_tga_color_map_half_32bpp_expected []
 
static const uint8_t test_tga_true_color_15bpp_rle_expected []
 
static const uint8_t test_tga_true_color_16bpp_rle_expected []
 
static const uint8_t test_tga_true_color_24bpp_rle_expected []
 
static const uint8_t test_tga_true_color_32bpp_rle_expected []
 
static const uint8_t test_tga_grayscale_8bpp_rle_expected []
 

Macro Definition Documentation

◆ check_dds_header

#define check_dds_header (   header,
  flags,
  height,
  width,
  pitch,
  depth,
  mip_levels,
  pixel_format,
  caps,
  caps2,
  wine_todo 
)
Value:
check_dds_header_(__FILE__, __LINE__, header, flags, height, width, pitch, depth, mip_levels, pixel_format, \
caps, caps2, wine_todo)
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
GLbitfield flags
Definition: glext.h:7161
static void check_dds_header_(const char *file, uint32_t line, const struct dds_header *header, uint32_t flags, uint32_t height, uint32_t width, uint32_t pitch, uint32_t depth, uint32_t mip_levels, const struct dds_pixel_format *pixel_format, uint32_t caps, uint32_t caps2, BOOL wine_todo)
Definition: surface.c:3466

Definition at line 3463 of file surface.c.

◆ check_dds_pixel_format

#define check_dds_pixel_format (   flags,
  fourcc,
  bpp,
  rmask,
  gmask,
  bmask,
  amask,
  format 
)     check_dds_pixel_format_(__LINE__, flags, fourcc, bpp, rmask, gmask, bmask, amask, format)

Definition at line 213 of file surface.c.

◆ check_dds_pixel_format_struct

#define check_dds_pixel_format_struct (   pixel_format,
  expected_pixel_format,
  wine_todo 
)     check_dds_pixel_format_struct_(__FILE__, __LINE__, pixel_format, expected_pixel_format, wine_todo)

Definition at line 3428 of file surface.c.

◆ check_pixel_2bpp

#define check_pixel_2bpp (   lockrect,
  x,
  y,
  color 
)    _check_pixel_2bpp(__LINE__, lockrect, x, y, color)

Definition at line 1074 of file surface.c.

◆ check_pixel_4bpp

#define check_pixel_4bpp (   lockrect,
  x,
  y,
  color 
)    _check_pixel_4bpp(__LINE__, lockrect, x, y, color)

Definition at line 1081 of file surface.c.

◆ check_pixel_8bpp

#define check_pixel_8bpp (   lockrect,
  x,
  y,
  color 
)    _check_pixel_8bpp(__LINE__, lockrect, x, y, color)

Definition at line 1088 of file surface.c.

◆ check_pixel_float4

#define check_pixel_float4 (   lockrect,
  x,
  y,
  fx,
  fy,
  fz,
  fw,
  ulps,
  todo 
)     _check_pixel_float4(__LINE__, lockrect, x, y, fx, fy, fz, fw, ulps, todo)

Definition at line 1095 of file surface.c.

◆ check_readback_pixel_4bpp

#define check_readback_pixel_4bpp (   rb,
  x,
  y,
  color,
  todo 
)    _check_readback_pixel_4bpp(__LINE__, rb, x, y, color, todo)

Definition at line 1111 of file surface.c.

◆ check_release

#define check_release (   obj,
  exp 
)    _check_release(__LINE__, obj, exp)

Definition at line 58 of file surface.c.

◆ check_tga_image_info

#define check_tga_image_info (   tga,
  tga_size,
  expected_width,
  expected_height,
  expected_format,
  expected_hr 
)     check_tga_image_info_(__LINE__, tga, tga_size, expected_width, expected_height, expected_format, expected_hr)

Definition at line 583 of file surface.c.

◆ check_tga_surface_load

#define check_tga_surface_load (   surface,
  expected,
  right_to_left,
  bottom_to_top 
)     check_tga_surface_load_(__LINE__, surface, expected, right_to_left, bottom_to_top)

Definition at line 1900 of file surface.c.

◆ COBJMACROS

#define COBJMACROS

Definition at line 21 of file surface.c.

◆ COLORMAP_TYPE_NONE

#define COLORMAP_TYPE_NONE   0

Definition at line 542 of file surface.c.

◆ COLORMAP_TYPE_ONE

#define COLORMAP_TYPE_ONE   1

Definition at line 543 of file surface.c.

◆ DDS_FILE_HEADER_SIZE

#define DDS_FILE_HEADER_SIZE   (sizeof(uint32_t) + sizeof(struct dds_header))

Definition at line 3504 of file surface.c.

◆ DDS_PF_ALPHA

#define DDS_PF_ALPHA   0x00000001

Definition at line 153 of file surface.c.

◆ DDS_PF_ALPHA_ONLY

#define DDS_PF_ALPHA_ONLY   0x00000002

Definition at line 154 of file surface.c.

◆ DDS_PF_BUMPDUDV

#define DDS_PF_BUMPDUDV   0x00080000

Definition at line 160 of file surface.c.

◆ DDS_PF_BUMPLUMINANCE

#define DDS_PF_BUMPLUMINANCE   0x00040000

Definition at line 159 of file surface.c.

◆ DDS_PF_FOURCC

#define DDS_PF_FOURCC   0x00000004

Definition at line 155 of file surface.c.

◆ DDS_PF_INDEXED

#define DDS_PF_INDEXED   0x00000020

Definition at line 156 of file surface.c.

◆ DDS_PF_LUMINANCE

#define DDS_PF_LUMINANCE   0x00020000

Definition at line 158 of file surface.c.

◆ DDS_PF_RGB

#define DDS_PF_RGB   0x00000040

Definition at line 157 of file surface.c.

◆ IMAGE_RIGHTTOLEFT

#define IMAGE_RIGHTTOLEFT   0x10

Definition at line 550 of file surface.c.

◆ IMAGE_TOPTOBOTTOM

#define IMAGE_TOPTOBOTTOM   0x20

Definition at line 551 of file surface.c.

◆ IMAGETYPE_COLORMAPPED

#define IMAGETYPE_COLORMAPPED   1

Definition at line 545 of file surface.c.

◆ IMAGETYPE_GRAYSCALE

#define IMAGETYPE_GRAYSCALE   3

Definition at line 547 of file surface.c.

◆ IMAGETYPE_RLE

#define IMAGETYPE_RLE   8

Definition at line 548 of file surface.c.

◆ IMAGETYPE_TRUECOLOR

#define IMAGETYPE_TRUECOLOR   2

Definition at line 546 of file surface.c.

◆ PALETTED_DDS_FILE_HEADER_SIZE

#define PALETTED_DDS_FILE_HEADER_SIZE   (DDS_FILE_HEADER_SIZE + (sizeof(PALETTEENTRY) * 256))

Definition at line 3505 of file surface.c.

Function Documentation

◆ _check_pixel_2bpp()

static void _check_pixel_2bpp ( unsigned int  line,
const D3DLOCKED_RECT *  lockrect,
int  x,
int  y,
WORD  expected_color 
)
inlinestatic

Definition at line 1075 of file surface.c.

1076{
1077 WORD color = ((WORD*)lockrect->pBits)[x + y * lockrect->Pitch / 2];
1078 ok_(__FILE__, line)(color == expected_color, "Got color 0x%04x, expected 0x%04x\n", color, expected_color);
1079}
#define ok_(x1, x2)
Definition: atltest.h:61
unsigned short WORD
Definition: ntddk_ex.h:93
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLuint color
Definition: glext.h:6243
Definition: parser.c:49

◆ _check_pixel_4bpp()

static void _check_pixel_4bpp ( unsigned int  line,
const D3DLOCKED_RECT *  lockrect,
int  x,
int  y,
DWORD  expected_color 
)
inlinestatic

Definition at line 1082 of file surface.c.

1083{
1084 DWORD color = ((DWORD*)lockrect->pBits)[x + y * lockrect->Pitch / 4];
1085 ok_(__FILE__, line)(color == expected_color, "Got color 0x%08lx, expected 0x%08lx\n", color, expected_color);
1086}
unsigned long DWORD
Definition: ntddk_ex.h:95

◆ _check_pixel_8bpp()

static void _check_pixel_8bpp ( unsigned int  line,
const D3DLOCKED_RECT *  lockrect,
int  x,
int  y,
uint64_t  expected_color 
)
inlinestatic

Definition at line 1089 of file surface.c.

1090{
1091 uint64_t color = ((uint64_t *)lockrect->pBits)[x + y * (lockrect->Pitch / 8)];
1092 ok_(__FILE__, line)(color == expected_color, "Got color %#I64x, expected %#I64x.\n", color, expected_color);
1093}
UINT64 uint64_t
Definition: types.h:77

◆ _check_pixel_float4()

static void _check_pixel_float4 ( uint32_t  line,
const D3DLOCKED_RECT *  lockrect,
uint32_t  x,
uint32_t  y,
float  fx,
float  fy,
float  fz,
float  fw,
uint32_t  ulps,
BOOL  todo 
)
inlinestatic

Definition at line 1097 of file surface.c.

1099{
1100 float *ptr = (float *)(((BYTE *)lockrect->pBits) + (y * lockrect->Pitch) + (x * sizeof(float) * 4));
1101
1102 todo_wine_if(todo) ok_(__FILE__, line)(compare_float(fx, ptr[0], ulps)
1103 && compare_float(fy, ptr[1], ulps)
1104 && compare_float(fz, ptr[2], ulps)
1105 && compare_float(fw, ptr[3], ulps),
1106 "Expected (%.8e, %.8e, %.8e, %.8e), got (%.8e, %.8e, %.8e, %.8e)\n",
1107 fx, fy, fz, fw,
1108 ptr[0], ptr[1], ptr[2], ptr[3]);
1109}
#define todo_wine_if(is_todo)
Definition: minitest.h:81
static PVOID ptr
Definition: dispmode.c:27
BOOL todo
Definition: filedlg.c:313
unsigned int ulps
Definition: effect.c:4467
#define compare_float(got, exp)
Definition: mesh.c:43
GLfixed fx
Definition: tritemp.h:484
GLfixed fy
Definition: tritemp.h:490
unsigned char BYTE
Definition: xxhash.c:193

◆ _check_readback_pixel_4bpp()

static void _check_readback_pixel_4bpp ( unsigned int  line,
struct surface_readback *  rb,
uint32_t  x,
uint32_t  y,
uint32_t  expected_color,
BOOL  todo 
)
inlinestatic

Definition at line 1112 of file surface.c.

1114{
1116 todo_wine_if(todo) ok_(__FILE__, line)(color == expected_color, "Got color 0x%08x, expected 0x%08x.\n", color, expected_color);
1117}
UINT32 uint32_t
Definition: types.h:75
static uint32_t get_readback_color(struct surface_readback *rb, uint32_t x, uint32_t y)
Definition: surface.c:71

◆ _check_release()

static void _check_release ( unsigned int  line,
IUnknown *  obj,
int  exp 
)
inlinestatic

Definition at line 59 of file surface.c.

60{
61 int ref = IUnknown_Release(obj);
62 ok_(__FILE__, line)(ref == exp, "Invalid refcount. Expected %d, got %d\n", exp, ref);
63}
DWORD exp
Definition: msg.c:18625
Definition: send.c:48

◆ check_dds_header_()

static void check_dds_header_ ( const char *  file,
uint32_t  line,
const struct dds_header *  header,
uint32_t  flags,
uint32_t  height,
uint32_t  width,
uint32_t  pitch,
uint32_t  depth,
uint32_t  mip_levels,
const struct dds_pixel_format *  pixel_format,
uint32_t  caps,
uint32_t  caps2,
BOOL  wine_todo 
)
static

Definition at line 3466 of file surface.c.

3469{
3470 const struct dds_header expected_header = { sizeof(*header), flags, height, width, pitch, depth, mip_levels, { 0 },
3471 *pixel_format, caps, caps2, 0, 0, 0 };
3472 BOOL matched;
3473
3474 matched = !memcmp(&expected_header, header, sizeof(*header));
3475 todo_wine_if(wine_todo) ok_(file, line)(matched, "Got unexpected dds header values.\n");
3476 if (matched)
3477 return;
3478
3479 todo_wine_if(wine_todo && header->flags != flags)
3480 ok_(file, line)(header->flags == flags, "Unexpected DDS header flags %#lx.\n", header->flags);
3481 todo_wine_if(wine_todo && header->width != width)
3482 ok_(file, line)(header->width == width, "Unexpected DDS header width %#lx.\n", header->width);
3483 todo_wine_if(wine_todo && header->height != height)
3484 ok_(file, line)(header->height == height, "Unexpected DDS header height %#lx.\n", header->height);
3485 todo_wine_if(wine_todo && header->pitch_or_linear_size != pitch)
3486 ok_(file, line)(header->pitch_or_linear_size == pitch, "Unexpected DDS header pitch %#lx.\n",
3487 header->pitch_or_linear_size);
3488 todo_wine_if(wine_todo && header->depth != depth)
3489 ok_(file, line)(header->depth == depth, "Unexpected DDS header depth %#lx.\n", header->depth);
3490 todo_wine_if(wine_todo && header->miplevels != mip_levels)
3491 ok_(file, line)(header->miplevels == mip_levels, "Unexpected DDS header mip levels %#lx.\n", header->miplevels);
3492 ok_(file, line)(!memcmp(header->reserved, expected_header.reserved, sizeof(header->reserved)),
3493 "Unexpected values in DDS header reserved field.");
3495 todo_wine_if(wine_todo && header->caps != caps)
3496 ok_(file, line)(header->caps == caps, "Unexpected DDS header caps %#lx.\n", header->caps);
3497 todo_wine_if(wine_todo && header->caps2 != caps2)
3498 ok_(file, line)(header->caps2 == caps2, "Unexpected DDS header caps2 %#lx.\n", header->caps2);
3499 ok_(file, line)(!header->caps3, "Unexpected DDS header caps3 %#lx.\n", header->caps3);
3500 ok_(file, line)(!header->caps4, "Unexpected DDS header caps4 %#lx.\n", header->caps4);
3501 ok_(file, line)(!header->reserved2, "Unexpected DDS header reserved2 %#lx.\n", header->reserved2);
3502}
#define FALSE
Definition: types.h:117
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2807
unsigned int BOOL
Definition: ntddk_ex.h:94
#define check_dds_pixel_format_struct(pixel_format, expected_pixel_format, wine_todo)
Definition: surface.c:3428
struct dds_pixel_format pixel_format
Definition: surface.c:148
DWORD reserved[11]
Definition: surface.c:147
DWORD caps2
Definition: surface.c:150
DWORD caps
Definition: surface.c:149
Definition: fci.c:123
BOOL matched
Definition: taskkill.c:46

◆ check_dds_pixel_format_()

static void check_dds_pixel_format_ ( unsigned int  line,
DWORD  flags,
DWORD  fourcc,
DWORD  bpp,
DWORD  rmask,
DWORD  gmask,
DWORD  bmask,
DWORD  amask,
D3DFORMAT  expected_format 
)
static

Definition at line 215 of file surface.c.

219{
220 HRESULT hr;
222 struct
223 {
224 DWORD magic;
225 struct dds_header header;
227 BYTE data[256];
228 } dds;
229
230 dds.magic = MAKEFOURCC('D','D','S',' ');
231 fill_dds_header(&dds.header);
232 dds.header.pixel_format.flags = flags;
233 dds.header.pixel_format.fourcc = fourcc;
234 dds.header.pixel_format.bpp = bpp;
235 dds.header.pixel_format.rmask = rmask;
236 dds.header.pixel_format.gmask = gmask;
237 dds.header.pixel_format.bmask = bmask;
238 dds.header.pixel_format.amask = amask;
239 memset(dds.data, 0, sizeof(dds.data));
240
241 hr = D3DXGetImageInfoFromFileInMemory(&dds, sizeof(dds), &info);
242 ok_(__FILE__, line)(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#lx for pixel format %#x, expected %#lx\n",
243 hr, expected_format, D3D_OK);
244 if (SUCCEEDED(hr))
245 {
246 ok_(__FILE__, line)(info.Format == expected_format, "D3DXGetImageInfoFromFileInMemory returned format %#x, expected %#x\n",
247 info.Format, expected_format);
248 }
249
250 /* Test again with unused fields set. */
251 if (flags & DDS_PF_FOURCC)
252 rmask = gmask = bmask = amask = bpp = ~0u;
254 rmask = gmask = bmask = fourcc = ~0u;
255 else if (flags & DDS_PF_INDEXED)
256 rmask = gmask = bmask = amask = fourcc = ~0u;
257 else if ((flags & (DDS_PF_RGB | DDS_PF_ALPHA)) == (DDS_PF_RGB | DDS_PF_ALPHA))
258 fourcc = ~0u;
259 else if (flags & DDS_PF_RGB)
260 fourcc = amask = ~0u;
262 gmask = bmask = fourcc = ~0u;
263 else if (flags & DDS_PF_LUMINANCE)
264 gmask = bmask = amask = fourcc = ~0u;
265 else if (flags & DDS_PF_ALPHA_ONLY)
266 rmask = gmask = bmask = fourcc = ~0u;
267 else if (flags & DDS_PF_BUMPDUDV)
268 fourcc = ~0u;
269 else if (flags & DDS_PF_BUMPLUMINANCE)
270 fourcc = amask = ~0u;
271
272 dds.header.pixel_format.fourcc = fourcc;
273 dds.header.pixel_format.bpp = bpp;
274 dds.header.pixel_format.rmask = rmask;
275 dds.header.pixel_format.gmask = gmask;
276 dds.header.pixel_format.bmask = bmask;
277 dds.header.pixel_format.amask = amask;
278 hr = D3DXGetImageInfoFromFileInMemory(&dds, sizeof(dds), &info);
279 ok_(__FILE__, line)(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
280 if (SUCCEEDED(hr))
281 ok_(__FILE__, line)(info.Format == expected_format, "Unexpected format %#x.\n", info.Format);
282}
#define D3D_OK
Definition: d3d.h:106
HRESULT hr
Definition: delayimp.cpp:582
HRESULT WINAPI D3DXGetImageInfoFromFileInMemory(const void *data, UINT datasize, D3DXIMAGE_INFO *info)
Definition: surface.c:1489
#define DDS_PF_RGB
Definition: surface.c:119
#define DDS_PF_LUMINANCE
Definition: surface.c:121
#define DDS_PF_BUMPLUMINANCE
Definition: surface.c:122
#define DDS_PF_BUMPDUDV
Definition: surface.c:123
#define DDS_PF_INDEXED
Definition: surface.c:118
#define DDS_PF_ALPHA_ONLY
Definition: surface.c:116
#define DDS_PF_FOURCC
Definition: surface.c:117
#define DDS_PF_ALPHA
Definition: surface.c:115
#define MAKEFOURCC(ch0, ch1, ch2, ch3)
Definition: ddsformat.c:45
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
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 SUCCEEDED(hr)
Definition: intsafe.h:50
static const int bmask[16]
Definition: jdhuff.c:579
static void fill_dds_header(struct dds_header *header)
Definition: surface.c:193
static HPALETTE palette
Definition: clipboard.c:1457
#define memset(x, y, z)
Definition: compat.h:39
ULONG bpp[]
Definition: xlate.c:19

◆ check_dds_pixel_format_struct_()

static void check_dds_pixel_format_struct_ ( const char *  file,
uint32_t  line,
const struct dds_pixel_format *  pixel_format,
const struct dds_pixel_format *  expected_pixel_format,
BOOL  wine_todo 
)
static

Definition at line 3430 of file surface.c.

3432{
3433 BOOL matched;
3434
3435 matched = !memcmp(expected_pixel_format, pixel_format, sizeof(*pixel_format));
3436 todo_wine_if(wine_todo) ok_(file, line)(matched, "Got unexpected dds pixel format values.\n");
3437 if (matched)
3438 return;
3439
3440 todo_wine_if(wine_todo && pixel_format->flags != expected_pixel_format->flags)
3441 ok_(file, line)(pixel_format->flags == expected_pixel_format->flags, "Unexpected DDS pixel format flags %#lx.\n",
3442 pixel_format->flags);
3443 todo_wine_if(wine_todo && pixel_format->fourcc != expected_pixel_format->fourcc)
3444 ok_(file, line)(pixel_format->fourcc == expected_pixel_format->fourcc, "Unexpected DDS pixel format fourcc %#lx.\n",
3445 pixel_format->fourcc);
3446 todo_wine_if(wine_todo && pixel_format->bpp != expected_pixel_format->bpp)
3447 ok_(file, line)(pixel_format->bpp == expected_pixel_format->bpp, "Unexpected DDS pixel format bpp %#lx.\n",
3448 pixel_format->bpp);
3449 todo_wine_if(wine_todo && pixel_format->rmask != expected_pixel_format->rmask)
3450 ok_(file, line)(pixel_format->rmask == expected_pixel_format->rmask, "Unexpected DDS pixel format rmask %#lx.\n",
3451 pixel_format->rmask);
3452 todo_wine_if(wine_todo && pixel_format->gmask != expected_pixel_format->gmask)
3453 ok_(file, line)(pixel_format->gmask == expected_pixel_format->gmask, "Unexpected DDS pixel format gmask %#lx.\n",
3454 pixel_format->gmask);
3455 todo_wine_if(wine_todo && pixel_format->bmask != expected_pixel_format->bmask)
3456 ok_(file, line)(pixel_format->bmask == expected_pixel_format->bmask, "Unexpected DDS pixel format bmask %#lx.\n",
3457 pixel_format->bmask);
3458 todo_wine_if(wine_todo && pixel_format->amask != expected_pixel_format->amask)
3459 ok_(file, line)(pixel_format->amask == expected_pixel_format->amask, "Unexpected DDS pixel format amask %#lx.\n",
3460 pixel_format->amask);
3461}

◆ check_tga_image_info_()

static void check_tga_image_info_ ( uint32_t  line,
const void *  tga,
uint32_t  tga_size,
uint32_t  expected_width,
uint32_t  expected_height,
D3DFORMAT  expected_format,
HRESULT  expected_hr 
)
static

Definition at line 585 of file surface.c.

587{
588 D3DXIMAGE_INFO info = { 0 };
589 HRESULT hr;
590
591 hr = D3DXGetImageInfoFromFileInMemory(tga, tga_size, &info);
592 ok_(__FILE__, line)(hr == expected_hr, "Unexpected hr %#lx.\n", hr);
594 {
595 check_image_info_(__FILE__, line, &info, expected_width, expected_height, 1, 1, expected_format,
597 }
598}
@ D3DRTYPE_TEXTURE
Definition: d3d8types.h:812
static void check_image_info_(const char *file, uint32_t line, const D3DXIMAGE_INFO *info, uint32_t width, uint32_t height, uint32_t depth, uint32_t mip_levels, D3DFORMAT format, D3DRESOURCETYPE resource_type, D3DXIMAGE_FILEFORMAT image_file_format, BOOL wine_todo)
HRESULT expected_hr
@ D3DXIFF_TGA
Definition: dx8vb.idl:64

◆ check_tga_surface_load_()

static void check_tga_surface_load_ ( uint32_t  line,
IDirect3DSurface9 *  surface,
const uint8_t *  expected,
BOOL  right_to_left,
BOOL  bottom_to_top 
)
static

Definition at line 1902 of file surface.c.

1904{
1905 uint32_t x, y, fmt_bpp, fmt_pitch;
1906 D3DLOCKED_RECT lock_rect;
1908 HRESULT hr;
1909
1910 hr = IDirect3DSurface9_GetDesc(surface, &desc);
1911 ok_(__FILE__, line)(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1912
1913 fmt_bpp = get_bpp_for_d3dformat(desc.Format);
1914 fmt_pitch = fmt_bpp * desc.Width;
1915 IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
1916 for (y = 0; y < desc.Height; ++y)
1917 {
1918 const uint32_t expected_row_idx = bottom_to_top ? (desc.Height - y - 1) : y;
1919 const uint8_t *row = ((uint8_t *)lock_rect.pBits) + (lock_rect.Pitch * y);
1920 const uint8_t *expected_row = expected + (fmt_pitch * expected_row_idx);
1921
1922 for (x = 0; x < desc.Width; ++x)
1923 {
1924 const uint32_t expected_pixel_idx = right_to_left ? (desc.Width - x - 1) : x;
1925 const uint8_t *expected_pixel = expected_row + (fmt_bpp * expected_pixel_idx);
1926 const uint8_t *pixel = row + (fmt_bpp * x);
1927 BOOL pixel_match = !memcmp(pixel, expected_pixel, fmt_bpp);
1928
1929 ok_(__FILE__, line)(pixel_match, "Pixel mismatch at (%u,%u).\n", x, y);
1930 }
1931 }
1933}
#define D3DLOCK_READONLY
Definition: d3d8types.h:69
#define IDirect3DSurface9_LockRect(p, a, b, c)
Definition: d3d9.h:463
#define IDirect3DSurface9_GetDesc(p, a)
Definition: d3d9.h:462
#define IDirect3DSurface9_UnlockRect(p)
Definition: d3d9.h:464
#define NULL
Definition: types.h:112
unsigned char uint8_t
Definition: stdint.h:33
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
#define S_OK
Definition: intsafe.h:52
BOOL expected
Definition: store.c:2000
D3D11_SHADER_VARIABLE_DESC desc
Definition: reflection.c:1683
static uint32_t get_bpp_for_d3dformat(D3DFORMAT format)
Definition: surface.c:1281

◆ compare_float()

static BOOL compare_float ( float  f,
float  g,
uint32_t  ulps 
)
static

Definition at line 45 of file surface.c.

46{
47 int32_t x = *(int32_t *)&f;
48 int32_t y = *(int32_t *)&g;
49
50 if (x < 0)
51 x = INT_MIN - x;
52 if (y < 0)
53 y = INT_MIN - y;
54
55 return compare_uint(x, y, ulps);
56}
INT32 int32_t
Definition: types.h:71
#define INT_MIN
Definition: limits.h:25
GLfloat f
Definition: glext.h:7540
GLboolean GLboolean g
Definition: glext.h:6204
static BOOL compare_uint(uint32_t x, uint32_t y, uint32_t max_diff)
Definition: surface.c:38

◆ compare_uint()

static BOOL compare_uint ( uint32_t  x,
uint32_t  y,
uint32_t  max_diff 
)
static

Definition at line 38 of file surface.c.

39{
40 uint32_t diff = x > y ? x - y : y - x;
41
42 return diff <= max_diff;
43}

Referenced by compare_float().

◆ create_file()

static HRESULT create_file ( const char *  filename,
const unsigned char *  data,
const unsigned int  size 
)
static

Definition at line 134 of file surface.c.

135{
137 HANDLE hfile;
138
141
142 if(WriteFile(hfile, data, size, &received, NULL))
143 {
144 CloseHandle(hfile);
145 return D3D_OK;
146 }
147
148 CloseHandle(hfile);
149 return D3DERR_INVALIDCALL;
150}
#define D3DERR_INVALIDCALL
Definition: d3d10_private.h:42
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
BOOL WINAPI WriteFile(_In_ HANDLE hFile, _In_reads_bytes_opt_(nNumberOfBytesToWrite) LPCVOID lpBuffer, _In_ DWORD nNumberOfBytesToWrite, _Out_opt_ LPDWORD lpNumberOfBytesWritten, _Inout_opt_ LPOVERLAPPED lpOverlapped)
Definition: rw.c:25
r received
Definition: btrfs.c:3005
GLsizeiptr size
Definition: glext.h:5919
const char * filename
Definition: ioapi.h:137
#define CREATE_ALWAYS
Definition: disk.h:72
#define GENERIC_WRITE
Definition: nt_native.h:90
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210

◆ fill_dds_header()

static void fill_dds_header ( struct dds_header *  header)
static

Definition at line 193 of file surface.c.

194{
195 memset(header, 0, sizeof(*header));
196
197 header->size = sizeof(*header);
199 header->height = 4;
200 header->width = 4;
201 header->pixel_format.size = sizeof(header->pixel_format);
202 /* X8R8G8B8 */
203 header->pixel_format.flags = DDS_PF_RGB;
204 header->pixel_format.fourcc = 0;
205 header->pixel_format.bpp = 32;
206 header->pixel_format.rmask = 0xff0000;
207 header->pixel_format.gmask = 0x00ff00;
208 header->pixel_format.bmask = 0x0000ff;
209 header->pixel_format.amask = 0;
210 header->caps = DDSCAPS_TEXTURE;
211}
#define DDSD_WIDTH
Definition: ddraw.h:212
#define DDSD_PIXELFORMAT
Definition: ddraw.h:218
#define DDSD_HEIGHT
Definition: ddraw.h:211
#define DDSCAPS_TEXTURE
Definition: ddraw.h:264
#define DDSD_CAPS
Definition: ddraw.h:210

Referenced by check_dds_pixel_format_(), and test_dds_header_handling().

◆ get_bpp_for_d3dformat()

static uint32_t get_bpp_for_d3dformat ( D3DFORMAT  format)
static

Definition at line 1281 of file surface.c.

1282{
1283 switch (format)
1284 {
1286 return 16;
1287
1290 return 8;
1291
1292 case D3DFMT_A8B8G8R8:
1293 case D3DFMT_A8R8G8B8:
1294 case D3DFMT_V16U16:
1295 case D3DFMT_G16R16:
1296 return 4;
1297
1298 case D3DFMT_R8G8B8:
1299 return 3;
1300
1301 case D3DFMT_X1R5G5B5:
1302 case D3DFMT_A1R5G5B5:
1303 case D3DFMT_V8U8:
1304 case D3DFMT_A8P8:
1305 return 2;
1306
1307 case D3DFMT_L8:
1308 case D3DFMT_P8:
1309 return 1;
1310
1311 default:
1312 assert(0 && "Need to add format to get_bpp_for_d3dformat().");
1313 return 0;
1314 }
1315}
@ D3DFMT_A1R5G5B5
Definition: d3d8types.h:608
@ D3DFMT_A8P8
Definition: d3d8types.h:617
@ D3DFMT_X1R5G5B5
Definition: d3d8types.h:607
@ D3DFMT_R8G8B8
Definition: d3d8types.h:603
@ D3DFMT_V16U16
Definition: d3d8types.h:628
@ D3DFMT_A8R8G8B8
Definition: d3d8types.h:604
@ D3DFMT_V8U8
Definition: d3d8types.h:624
@ D3DFMT_P8
Definition: d3d8types.h:618
@ D3DFMT_L8
Definition: d3d8types.h:620
@ D3DFMT_G16R16
Definition: d3d8types.h:615
@ D3DFMT_A32B32G32R32F
Definition: d3d9types.h:861
@ D3DFMT_Q16W16V16U16
Definition: d3d9types.h:852
@ D3DFMT_A8B8G8R8
Definition: d3d9types.h:802
@ D3DFMT_A16B16G16R16
Definition: d3d9types.h:806
#define assert(_expr)
Definition: assert.h:32

Referenced by check_tga_surface_load_(), and test_format_conversion().

◆ get_readback_color()

static uint32_t get_readback_color ( struct surface_readback *  rb,
uint32_t  x,
uint32_t  y 
)
static

Definition at line 71 of file surface.c.

72{
73 return rb->locked_rect.pBits
74 ? ((uint32_t *)rb->locked_rect.pBits)[y * rb->locked_rect.Pitch / sizeof(uint32_t) + x] : 0xdeadbeef;
75}
#define uint32_t
Definition: nsiface.idl:61
D3DLOCKED_RECT locked_rect
Definition: shader.c:419

Referenced by _check_readback_pixel_4bpp().

◆ get_surface_decompressed_readback()

static void get_surface_decompressed_readback ( IDirect3DDevice9 *  device,
IDirect3DSurface9 *  compressed_surface,
struct surface_readback *  rb 
)
static

Definition at line 128 of file surface.c.

130{
131 get_surface_readback(device, compressed_surface, D3DFMT_A8R8G8B8, rb);
132}
static void get_surface_readback(IDirect3DDevice9 *device, IDirect3DSurface9 *src_surface, D3DFORMAT rb_format, struct surface_readback *rb)
Definition: surface.c:88
Definition: devices.h:37

Referenced by test_D3DXLoadSurface(), and test_dxt_premultiplied_alpha().

◆ get_surface_readback()

static void get_surface_readback ( IDirect3DDevice9 *  device,
IDirect3DSurface9 *  src_surface,
D3DFORMAT  rb_format,
struct surface_readback *  rb 
)
static

Definition at line 88 of file surface.c.

90{
92 HRESULT hr;
93
94 memset(rb, 0, sizeof(*rb));
95 hr = IDirect3DSurface9_GetDesc(src_surface, &desc);
96 if (FAILED(hr))
97 {
98 trace("Failed to get source surface description, hr %#lx.\n", hr);
99 return;
100 }
101
103 &rb->surface, NULL);
104 if (FAILED(hr))
105 {
106 trace("Can't create the readback surface, hr %#lx.\n", hr);
107 return;
108 }
109
111 if (FAILED(hr))
112 {
113 trace("Can't load the readback surface, hr %#lx.\n", hr);
115 rb->surface = NULL;
116 return;
117 }
118
120 if (FAILED(hr))
121 {
122 trace("Can't lock the offscreen surface, hr %#lx.\n", hr);
124 rb->surface = NULL;
125 }
126}
#define trace
Definition: atltest.h:70
@ D3DPOOL_SYSTEMMEM
Definition: d3d8types.h:711
#define IDirect3DSurface9_Release(p)
Definition: d3d9.h:450
#define IDirect3DDevice9_CreateOffscreenPlainSurface(p, a, b, c, d, e, f)
Definition: d3d9.h:1371
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: surface.c:2765
#define D3DX_FILTER_NONE
Definition: d3dx9tex.h:27
#define FAILED(hr)
Definition: intsafe.h:51
IDirect3DSurface9 * surface
Definition: shader.c:418

Referenced by get_surface_decompressed_readback(), and test_D3DXLoadSurface().

◆ release_surface_readback()

static void release_surface_readback ( struct surface_readback *  rb)
static

Definition at line 77 of file surface.c.

78{
79 HRESULT hr;
80
81 if (!rb->surface)
82 return;
84 trace("Can't unlock the offscreen surface, hr %#lx.\n", hr);
86}

Referenced by test_D3DXLoadSurface(), and test_dxt_premultiplied_alpha().

◆ START_TEST()

START_TEST ( surface  )

Definition at line 4089 of file surface.c.

4090{
4091 HWND wnd;
4092 IDirect3D9 *d3d;
4095 HRESULT hr;
4096
4097 if (!(wnd = CreateWindowA("static", "d3dx9_test", WS_OVERLAPPEDWINDOW, 0, 0,
4098 640, 480, NULL, NULL, NULL, NULL)))
4099 {
4100 skip("Couldn't create application window\n");
4101 return;
4102 }
4104 if (!d3d) {
4105 skip("Couldn't create IDirect3D9 object\n");
4106 DestroyWindow(wnd);
4107 return;
4108 }
4109
4110 ZeroMemory(&d3dpp, sizeof(d3dpp));
4111 d3dpp.Windowed = TRUE;
4114 if(FAILED(hr)) {
4115 skip("Failed to create IDirect3DDevice9 object %#lx\n", hr);
4116 IDirect3D9_Release(d3d);
4117 DestroyWindow(wnd);
4118 return;
4119 }
4120
4125
4127 check_release((IUnknown*)d3d, 0);
4128 DestroyWindow(wnd);
4129}
#define skip(...)
Definition: atltest.h:64
@ D3DSWAPEFFECT_DISCARD
Definition: d3d8types.h:851
@ D3DDEVTYPE_HAL
Definition: d3d8types.h:576
IDirect3D9 *WINAPI Direct3DCreate9(UINT SDKVersion)
Definition: d3d9.c:57
#define IDirect3D9_CreateDevice(p, a, b, c, d, e, f)
Definition: d3d9.h:224
#define IDirect3D9_Release(p)
Definition: d3d9.h:209
#define TRUE
Definition: types.h:120
DWORD IDirect3DDevice9
Definition: dxva2api.idl:22
#define ZeroMemory
Definition: minwinbase.h:31
static void test_D3DXSaveSurfaceToFileInMemory(IDirect3DDevice9 *device)
Definition: surface.c:3829
static void test_D3DXGetImageInfo(void)
Definition: surface.c:769
static void test_D3DXLoadSurface(IDirect3DDevice9 *device)
Definition: surface.c:2157
static void test_D3DXSaveSurfaceToFile(IDirect3DDevice9 *device)
Definition: surface.c:3963
#define check_release(obj, exp)
Definition: surface.c:58
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4469
BOOL WINAPI DestroyWindow(_In_ HWND)
#define D3DADAPTER_DEFAULT
Definition: d3d8.h:53
#define D3D_SDK_VERSION
Definition: d3d8.h:52
#define D3DCREATE_SOFTWARE_VERTEXPROCESSING
Definition: d3d8.h:40
D3DSWAPEFFECT SwapEffect
Definition: d3d8types.h:1128

◆ test_D3DXGetImageInfo()

static void test_D3DXGetImageInfo ( void  )
static

Definition at line 769 of file surface.c.

770{
771 HRESULT hr;
773 BOOL testdummy_ok, testbitmap_ok;
774
775 hr = create_file("testdummy.bmp", noimage, sizeof(noimage)); /* invalid image */
776 testdummy_ok = SUCCEEDED(hr);
777
778 hr = create_file("testbitmap.bmp", bmp_1bpp, sizeof(bmp_1bpp)); /* valid image */
779 testbitmap_ok = SUCCEEDED(hr);
780
781 /* D3DXGetImageInfoFromFile */
782 if(testbitmap_ok) {
783 hr = D3DXGetImageInfoFromFileA("testbitmap.bmp", &info);
784 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#lx, expected %#lx\n", hr, D3D_OK);
785
786 hr = D3DXGetImageInfoFromFileA("testbitmap.bmp", NULL); /* valid image, second parameter is NULL */
787 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#lx, expected %#lx\n", hr, D3D_OK);
788 } else skip("Couldn't create \"testbitmap.bmp\"\n");
789
790 if(testdummy_ok) {
791 hr = D3DXGetImageInfoFromFileA("testdummy.bmp", NULL); /* invalid image, second parameter is NULL */
792 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#lx, expected %#lx\n", hr, D3D_OK);
793
794 hr = D3DXGetImageInfoFromFileA("testdummy.bmp", &info);
795 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#lx, expected %#x\n", hr, D3DXERR_INVALIDDATA);
796 } else skip("Couldn't create \"testdummy.bmp\"\n");
797
798 hr = D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", &info);
799 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#lx, expected %#x\n", hr, D3DXERR_INVALIDDATA);
800
801 hr = D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", NULL);
802 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#lx, expected %#x\n", hr, D3DXERR_INVALIDDATA);
803
805 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#lx, expected %#x\n", hr, D3DXERR_INVALIDDATA);
806
808 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFile returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
809
811 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFile returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
812
813
814 /* D3DXGetImageInfoFromResource */
816 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#lx, expected %#lx\n", hr, D3D_OK);
817
819 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#lx, expected %#lx\n", hr, D3D_OK);
820
822 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#lx, expected %#lx\n", hr, D3D_OK);
823
825 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#lx, expected %#x\n", hr, D3DXERR_INVALIDDATA);
826
828 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#lx, expected %#x\n", hr, D3DXERR_INVALIDDATA);
829
830 hr = D3DXGetImageInfoFromResourceA(NULL, "resourcedoesnotexist", &info);
831 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#lx, expected %#x\n", hr, D3DXERR_INVALIDDATA);
832
833 hr = D3DXGetImageInfoFromResourceA(NULL, "resourcedoesnotexist", NULL);
834 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#lx, expected %#x\n", hr, D3DXERR_INVALIDDATA);
835
837 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#lx, expected %#x\n", hr, D3DXERR_INVALIDDATA);
838
839
840 /* D3DXGetImageInfoFromFileInMemory */
842 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
843
844 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp, sizeof(bmp_1bpp)+5, &info); /* too large size */
845 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
846
848 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
849
851 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#lx, expected %#lx\n", hr, D3D_OK);
852
854 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#x\n", hr, D3DXERR_INVALIDDATA);
855
856 todo_wine {
858 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#x\n", hr, D3DXERR_INVALIDDATA);
859 }
860
862 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#x\n", hr, D3DXERR_INVALIDDATA);
863
865 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
866
868 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
869
871 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
872
874 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
875
877 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
878
880 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
881
883 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
884
886 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
887
888 /* test BMP support */
890 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
891 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
892 ok(info.Format == D3DFMT_P8, "Got format %u, expected %u\n", info.Format, D3DFMT_P8);
894 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#x\n", hr, D3DXERR_INVALIDDATA);
896 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
897 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
898 ok(info.Format == D3DFMT_P8, "Got format %u, expected %u\n", info.Format, D3DFMT_P8);
900 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
901 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
902 ok(info.Format == D3DFMT_P8, "Got format %u, expected %u\n", info.Format, D3DFMT_P8);
903
905 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
906 ok(info.Format == D3DFMT_X8R8G8B8, "Got unexpected format %u.\n", info.Format);
908 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
909 ok(info.Format == D3DFMT_A8R8G8B8, "Got unexpected format %u.\n", info.Format);
910
911 /* Test JPG support. */
913 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
915
917 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
919
920 /* Test PNG support. */
922 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
924
926 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
928
930 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
932
933 /* Grayscale PNG */
935 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
936 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
937 ok(info.Format == D3DFMT_L8, "Got format %u, expected %u\n", info.Format, D3DFMT_L8);
938
939 /* test DDS support */
941 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
942 if (hr == D3D_OK) {
943 ok(info.Width == 2, "Got width %u, expected 2\n", info.Width);
944 ok(info.Height == 2, "Got height %u, expected 2\n", info.Height);
945 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
946 ok(info.MipLevels == 2, "Got miplevels %u, expected 2\n", info.MipLevels);
947 ok(info.Format == D3DFMT_R8G8B8, "Got format %#x, expected %#x\n", info.Format, D3DFMT_R8G8B8);
948 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
949 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
950 } else skip("Couldn't get image info from 24-bit DDS file in memory\n");
951
953 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
954 if (hr == D3D_OK) {
955 ok(info.Width == 2, "Got width %u, expected 2\n", info.Width);
956 ok(info.Height == 2, "Got height %u, expected 2\n", info.Height);
957 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
958 ok(info.MipLevels == 1, "Got miplevels %u, expected 1\n", info.MipLevels);
959 ok(info.Format == D3DFMT_X1R5G5B5, "Got format %#x, expected %#x\n", info.Format, D3DFMT_X1R5G5B5);
960 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
961 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
962 } else skip("Couldn't get image info from 16-bit DDS file in memory\n");
963
964 memset(&info, 0, sizeof(info));
966 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#lx\n", hr);
967 ok(info.Width == 16, "Got width %u.\n", info.Width);
968 ok(info.Height == 4, "Got height %u.\n", info.Height);
969 ok(info.Depth == 1, "Got depth %u.\n", info.Depth);
970 ok(info.MipLevels == 1, "Got miplevels %u.\n", info.MipLevels);
971 ok(info.Format == D3DFMT_P8, "Got format %#x.\n", info.Format);
972 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x.\n", info.ResourceType);
973 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x.\n", info.ImageFileFormat);
974
976 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
977 if (hr == D3D_OK) {
978 ok(info.Width == 4, "Got width %u, expected 4\n", info.Width);
979 ok(info.Height == 4, "Got height %u, expected 4\n", info.Height);
980 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
981 ok(info.MipLevels == 1, "Got miplevels %u, expected 1\n", info.MipLevels);
982 ok(info.Format == D3DFMT_DXT5, "Got format %#x, expected %#x\n", info.Format, D3DFMT_DXT5);
983 ok(info.ResourceType == D3DRTYPE_CUBETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_CUBETEXTURE);
984 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
985 } else skip("Couldn't get image info from cube map in memory\n");
986
988 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
989 if (hr == D3D_OK) {
990 ok(info.Width == 4, "Got width %u, expected 4\n", info.Width);
991 ok(info.Height == 4, "Got height %u, expected 4\n", info.Height);
992 ok(info.Depth == 2, "Got depth %u, expected 2\n", info.Depth);
993 ok(info.MipLevels == 3, "Got miplevels %u, expected 3\n", info.MipLevels);
994 ok(info.Format == D3DFMT_DXT3, "Got format %#x, expected %#x\n", info.Format, D3DFMT_DXT3);
995 ok(info.ResourceType == D3DRTYPE_VOLUMETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_VOLUMETEXTURE);
996 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
997 } else skip("Couldn't get image info from volume map in memory\n");
998
1008 /*
1009 * D3DFMTs that aren't fourCC values, but are supported in the fourCC
1010 * field.
1011 */
1020 check_dds_pixel_format(DDS_PF_RGB, 0, 16, 0xf800, 0x07e0, 0x001f, 0, D3DFMT_R5G6B5);
1021 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x8000, D3DFMT_A1R5G5B5);
1022 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x0f00, 0x00f0, 0x000f, 0xf000, D3DFMT_A4R4G4B4);
1023 check_dds_pixel_format(DDS_PF_RGB, 0, 8, 0xe0, 0x1c, 0x03, 0, D3DFMT_R3G3B2);
1024 check_dds_pixel_format(DDS_PF_ALPHA_ONLY, 0, 8, 0, 0, 0, 0xff, D3DFMT_A8);
1025 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x00e0, 0x001c, 0x0003, 0xff00, D3DFMT_A8R3G3B2);
1026 check_dds_pixel_format(DDS_PF_RGB, 0, 16, 0xf00, 0x0f0, 0x00f, 0, D3DFMT_X4R4G4B4);
1027 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000, D3DFMT_A2B10G10R10);
1028 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000, D3DFMT_A2R10G10B10);
1029 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, D3DFMT_A8R8G8B8);
1030 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000, D3DFMT_A8B8G8R8);
1031 check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0, D3DFMT_X8R8G8B8);
1032 check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0x0000ff, 0x00ff00, 0xff0000, 0, D3DFMT_X8B8G8R8);
1033 check_dds_pixel_format(DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0, D3DFMT_R8G8B8);
1034 check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_G16R16);
1035 check_dds_pixel_format(DDS_PF_LUMINANCE, 0, 8, 0xff, 0, 0, 0, D3DFMT_L8);
1036 check_dds_pixel_format(DDS_PF_LUMINANCE, 0, 16, 0xffff, 0, 0, 0, D3DFMT_L16);
1037 check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 16, 0x00ff, 0, 0, 0xff00, D3DFMT_A8L8);
1038 /* 8bpp works too for D3DFMT_A8L8. */
1039 check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 8, 0x00ff, 0, 0, 0xff00, D3DFMT_A8L8);
1041 check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0, 0, D3DFMT_V8U8);
1042 check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_V16U16);
1043 check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 32, 0xff, 0xff00, 0x00ff0000, 0xff000000, D3DFMT_Q8W8V8U8);
1044 check_dds_pixel_format(DDS_PF_BUMPDUDV | DDS_PF_ALPHA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000, D3DFMT_A2W10V10U10);
1045 check_dds_pixel_format(DDS_PF_BUMPLUMINANCE, 0, 32, 0x0000ff, 0x00ff00, 0xff0000, 0, D3DFMT_X8L8V8U8);
1046 todo_wine check_dds_pixel_format(DDS_PF_BUMPLUMINANCE, 0, 16, 0x001f, 0x03e0, 0xfc00, 0, D3DFMT_L6V5U5);
1049
1052
1054 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#x\n", hr, D3DXERR_INVALIDDATA);
1055
1057 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#x\n", hr, D3DXERR_INVALIDDATA);
1058
1060 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#x\n", hr, D3DXERR_INVALIDDATA);
1061
1063 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#x\n", hr, D3DXERR_INVALIDDATA);
1064
1065 /* Size includes the size of the color palette. */
1066 hr = D3DXGetImageInfoFromFileInMemory(dds_8bit, (sizeof(dds_8bit) - (sizeof(PALETTEENTRY) * 256)), &info);
1067 ok(hr == D3DXERR_INVALIDDATA, "Unexpected hr %#lx.\n", hr);
1068
1069 /* cleanup */
1070 if(testdummy_ok) DeleteFileA("testdummy.bmp");
1071 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
1072}
#define ok(value,...)
Definition: atltest.h:57
#define IDS_STRING
Definition: resource.h:17
@ D3DFMT_L6V5U5
Definition: d3d8types.h:625
@ D3DFMT_DXT5
Definition: d3d8types.h:638
@ D3DFMT_UYVY
Definition: d3d8types.h:632
@ D3DFMT_YUY2
Definition: d3d8types.h:633
@ D3DFMT_DXT2
Definition: d3d8types.h:635
@ D3DFMT_R3G3B2
Definition: d3d8types.h:610
@ D3DFMT_A8L8
Definition: d3d8types.h:621
@ D3DFMT_A2B10G10R10
Definition: d3d8types.h:614
@ D3DFMT_X8L8V8U8
Definition: d3d8types.h:626
@ D3DFMT_A8
Definition: d3d8types.h:611
@ D3DFMT_DXT1
Definition: d3d8types.h:634
@ D3DFMT_X4R4G4B4
Definition: d3d8types.h:613
@ D3DFMT_R5G6B5
Definition: d3d8types.h:606
@ D3DFMT_A8R3G3B2
Definition: d3d8types.h:612
@ D3DFMT_DXT4
Definition: d3d8types.h:637
@ D3DFMT_A4R4G4B4
Definition: d3d8types.h:609
@ D3DFMT_DXT3
Definition: d3d8types.h:636
@ D3DFMT_X8R8G8B8
Definition: d3d8types.h:605
@ D3DFMT_A2W10V10U10
Definition: d3d8types.h:630
@ D3DFMT_Q8W8V8U8
Definition: d3d8types.h:627
@ D3DFMT_A4L4
Definition: d3d8types.h:622
@ D3DRTYPE_VOLUMETEXTURE
Definition: d3d8types.h:813
@ D3DRTYPE_CUBETEXTURE
Definition: d3d8types.h:814
@ D3DFMT_G8R8_G8B8
Definition: d3d9types.h:831
@ D3DFMT_A16B16G16R16F
Definition: d3d9types.h:856
@ D3DFMT_R8G8_B8G8
Definition: d3d9types.h:832
@ D3DFMT_R32F
Definition: d3d9types.h:859
@ D3DFMT_X8B8G8R8
Definition: d3d9types.h:803
@ D3DFMT_A2R10G10B10
Definition: d3d9types.h:805
@ D3DFMT_G32R32F
Definition: d3d9types.h:860
@ D3DFMT_L16
Definition: d3d9types.h:841
@ D3DFMT_G16R16F
Definition: d3d9types.h:855
@ D3DFMT_R16F
Definition: d3d9types.h:854
#define D3DXERR_INVALIDDATA
Definition: compiler.c:53
static const uint8_t dds_16bit[]
#define check_image_info(info, width, height, depth, mip_levels, format, resource_type, image_file_format, wine_todo)
static const uint8_t jpg_grayscale_2_2[]
static const uint8_t png_2_2_64bpp_rgba[]
static const uint8_t jpg_rgb_2_2[]
static const uint8_t png_2_2_24bpp_bgr[]
static const uint8_t bmp_4bpp[]
static const uint8_t dds_24bit[]
static const uint8_t png_2_2_48bpp_rgb[]
static const uint8_t bmp_32bpp_xrgb[]
static const uint8_t dds_cube_map[]
static const uint8_t bmp_2bpp[]
static const uint8_t bmp_8bpp[]
static const uint8_t dds_volume_map[]
static const uint8_t noimage[4]
static const uint8_t png_grayscale[]
static const uint8_t bmp_1bpp[]
static const uint8_t dds_8bit[]
static const uint8_t bmp_32bpp_argb[]
HRESULT WINAPI D3DXGetImageInfoFromResourceA(HMODULE module, const char *resource, D3DXIMAGE_INFO *info)
Definition: surface.c:1572
HRESULT WINAPI D3DXGetImageInfoFromFileA(const char *file, D3DXIMAGE_INFO *info)
Definition: surface.c:1523
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
@ D3DXIFF_JPG
Definition: dx8vb.idl:63
@ D3DXIFF_DDS
Definition: dx8vb.idl:66
@ D3DXIFF_PNG
Definition: dx8vb.idl:65
#define todo_wine
Definition: minitest.h:80
#define IDB_BITMAP_1x1
Definition: resources.h:22
#define IDD_BITMAPDATA_1x1
Definition: resources.h:23
static void test_dds_header_handling(void)
Definition: surface.c:284
#define check_dds_pixel_format(flags, fourcc, bpp, rmask, gmask, bmask, amask, format)
Definition: surface.c:213
static void test_tga_header_handling(void)
Definition: surface.c:600
#define create_file(name, size)
Definition: asmcache.c:811
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581

Referenced by START_TEST().

◆ test_D3DXLoadSurface()

static void test_D3DXLoadSurface ( IDirect3DDevice9 *  device)
static

Definition at line 2157 of file surface.c.

2158{
2159 HRESULT hr;
2160 BOOL testdummy_ok, testbitmap_ok;
2161 IDirect3DTexture9 *tex;
2162 IDirect3DSurface9 *surf, *newsurf;
2163 RECT rect, destrect;
2164 D3DLOCKED_RECT lockrect;
2165 static const WORD pixdata_a8r3g3b2[] = { 0x57df, 0x98fc, 0xacdd, 0xc891 };
2166 static const WORD pixdata_a1r5g5b5[] = { 0x46b5, 0x99c8, 0x06a2, 0x9431 };
2167 static const WORD pixdata_r5g6b5[] = { 0x9ef6, 0x658d, 0x0aee, 0x42ee };
2168 static const WORD pixdata_a8l8[] = { 0xff00, 0x00ff, 0xff30, 0x7f7f };
2169 static const DWORD pixdata_g16r16[] = { 0x07d23fbe, 0xdc7f44a4, 0xe4d8976b, 0x9a84fe89 };
2170 static const DWORD pixdata_a8b8g8r8[] = { 0xc3394cf0, 0x235ae892, 0x09b197fd, 0x8dc32bf6 };
2171 static const DWORD pixdata_a2r10g10b10[] = { 0x57395aff, 0x5b7668fd, 0xb0d856b5, 0xff2c61d6 };
2172 static const uint32_t pixdata_a8r8g8b8[] = { 0x00102030, 0x40506070, 0x8090a0b0, 0xc0d0e0ff };
2173 static const uint32_t pixdata_a8b8g8r8_2[] = { 0x30201000, 0x70605040, 0xb0a09080, 0xffe0d0c0 };
2174 static const uint32_t pixdata_x8l8v8u8[] = { 0x00003000, 0x00557f40, 0x00aa8180, 0x00ffffc0 };
2175 static const uint32_t pixdata_a2w10v10u10[] = { 0x0ba17400, 0x5ff5d117, 0xae880600, 0xfffe8b45 };
2176 static const uint32_t pixdata_q8w8v8u8[] = { 0x30201000, 0x7f605040, 0xb0a08180, 0xffe0d0c0 };
2177 static const float pixdata_a32b32g32r32f[] = { 0.0f, 0.1f, NAN, INFINITY, 1.0f, 1.1f, 1.2f, 1.3f,
2178 -0.1f, -0.2f, -NAN, -INFINITY, -1.0f, -1.1f, -1.2f, -1.3f };
2179 static const uint16_t pixdata_v8u8[] = { 0x3000, 0x7f40, 0x8180, 0xffc0 };
2180 BYTE buffer[4 * 8 * 4];
2181 uint32_t i;
2182
2183 hr = create_file("testdummy.bmp", noimage, sizeof(noimage)); /* invalid image */
2184 testdummy_ok = SUCCEEDED(hr);
2185
2186 hr = create_file("testbitmap.bmp", bmp_1bpp, sizeof(bmp_1bpp)); /* valid image */
2187 testbitmap_ok = SUCCEEDED(hr);
2188
2190 if(FAILED(hr)) {
2191 skip("Failed to create a surface (%#lx)\n", hr);
2192 if(testdummy_ok) DeleteFileA("testdummy.bmp");
2193 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
2194 return;
2195 }
2196
2197 /* D3DXLoadSurfaceFromFile */
2198 if(testbitmap_ok) {
2199 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "testbitmap.bmp", NULL, D3DX_DEFAULT, 0, NULL);
2200 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFile returned %#lx, expected %#lx\n", hr, D3D_OK);
2201
2202 hr = D3DXLoadSurfaceFromFileA(NULL, NULL, NULL, "testbitmap.bmp", NULL, D3DX_DEFAULT, 0, NULL);
2203 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
2204 } else skip("Couldn't create \"testbitmap.bmp\"\n");
2205
2206 if(testdummy_ok) {
2207 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "testdummy.bmp", NULL, D3DX_DEFAULT, 0, NULL);
2208 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#lx, expected %#x\n", hr, D3DXERR_INVALIDDATA);
2209 } else skip("Couldn't create \"testdummy.bmp\"\n");
2210
2212 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
2213
2215 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#lx, expected %#x\n", hr, D3DXERR_INVALIDDATA);
2216
2217
2218 /* D3DXLoadSurfaceFromResource */
2221 ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#lx, expected %#lx\n", hr, D3D_OK);
2222
2225 ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#lx, expected %#lx\n", hr, D3D_OK);
2226
2228 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#lx, expected %#x\n", hr, D3DXERR_INVALIDDATA);
2229
2232 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromResource returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
2233
2236 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#lx, expected %#x\n", hr, D3DXERR_INVALIDDATA);
2237
2238
2239 /* D3DXLoadSurfaceFromFileInMemory */
2241 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
2242
2244 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFileInMemory returned %#lx, expected %#x\n", hr, D3DXERR_INVALIDDATA);
2245
2247 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
2248
2250 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
2251
2253 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
2254
2256 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
2257
2259 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
2260
2261
2262 /* D3DXLoadSurfaceFromMemory */
2263 SetRect(&rect, 0, 0, 2, 2);
2264
2266 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
2267
2269 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
2270
2272 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
2273
2275 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
2276
2278 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
2279
2281 ok(hr == E_FAIL, "D3DXLoadSurfaceFromMemory returned %#lx, expected %#lx\n", hr, E_FAIL);
2282
2283 SetRect(&destrect, -1, -1, 1, 1); /* destination rect is partially outside texture boundaries */
2285 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
2286
2287 SetRect(&destrect, 255, 255, 257, 257); /* destination rect is partially outside texture boundaries */
2289 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
2290
2291 SetRect(&destrect, 1, 1, 0, 0); /* left > right, top > bottom */
2293 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
2294
2295 SetRect(&destrect, 1, 2, 1, 2); /* left = right, top = bottom */
2297 /* fails when debug version of d3d9 is used */
2298 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXLoadSurfaceFromMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
2299
2300 SetRect(&destrect, 257, 257, 257, 257); /* left = right, top = bottom, but invalid values */
2302 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
2303
2304
2305 /* D3DXLoadSurfaceFromSurface */
2307 if(SUCCEEDED(hr)) {
2308 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
2309 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#lx, expected %#lx\n", hr, D3D_OK);
2310
2312 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
2313
2315 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#lx, expected %#lx\n", hr, D3DERR_INVALIDCALL);
2316
2317 check_release((IUnknown*)newsurf, 0);
2318 } else skip("Failed to create a second surface\n");
2319
2321 if (SUCCEEDED(hr))
2322 {
2323 IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
2324
2325 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0);
2326 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#lx, expected %#lx\n", hr, D3D_OK);
2327
2330 } else skip("Failed to create texture\n");
2331
2332 /* non-lockable render target */
2334 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
2336 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
2338
2339 /* non-lockable multisampled render target */
2341 if (SUCCEEDED(hr))
2342 {
2343 struct surface_readback surface_rb;
2344
2345 /* D3DXLoadSurfaceFromMemory should return success with a multisampled render target. */
2346 SetRect(&rect, 0, 0, 2, 2);
2347 hr = D3DXLoadSurfaceFromMemory(newsurf, NULL, &rect, pixdata_a8r8g8b8, D3DFMT_A8R8G8B8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
2348 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
2349
2350 /* The call succeeds, but the surface isn't actually written to. */
2351 get_surface_readback(device, newsurf, D3DFMT_A8R8G8B8, &surface_rb);
2352 check_readback_pixel_4bpp(&surface_rb, 0, 0, 0x00000000, FALSE);
2353 check_readback_pixel_4bpp(&surface_rb, 1, 0, 0x00000000, FALSE);
2354 check_readback_pixel_4bpp(&surface_rb, 0, 1, 0x00000000, FALSE);
2355 check_readback_pixel_4bpp(&surface_rb, 1, 1, 0x00000000, FALSE);
2356 release_surface_readback(&surface_rb);
2357
2358 /*
2359 * Load the data into our non-multisampled render target, then load
2360 * that into the multisampled render target.
2361 */
2362 SetRect(&rect, 0, 0, 2, 2);
2363 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &rect, pixdata_a8r8g8b8, D3DFMT_A8R8G8B8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
2364 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
2365
2366 get_surface_readback(device, surf, D3DFMT_A8R8G8B8, &surface_rb);
2367 check_readback_pixel_4bpp(&surface_rb, 0, 0, pixdata_a8r8g8b8[0], FALSE);
2368 check_readback_pixel_4bpp(&surface_rb, 1, 0, pixdata_a8r8g8b8[1], FALSE);
2369 check_readback_pixel_4bpp(&surface_rb, 0, 1, pixdata_a8r8g8b8[2], FALSE);
2370 check_readback_pixel_4bpp(&surface_rb, 1, 1, pixdata_a8r8g8b8[3], FALSE);
2371 release_surface_readback(&surface_rb);
2372
2373 /*
2374 * Loading from a non-multisampled surface into a multisampled surface
2375 * does change the surface contents.
2376 */
2377 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, &rect, surf, NULL, &rect, D3DX_FILTER_NONE, 0);
2378 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
2379
2380 get_surface_readback(device, newsurf, D3DFMT_A8R8G8B8, &surface_rb);
2381 check_readback_pixel_4bpp(&surface_rb, 0, 0, pixdata_a8r8g8b8[0], TRUE);
2382 check_readback_pixel_4bpp(&surface_rb, 1, 0, pixdata_a8r8g8b8[1], TRUE);
2383 check_readback_pixel_4bpp(&surface_rb, 0, 1, pixdata_a8r8g8b8[2], TRUE);
2384 check_readback_pixel_4bpp(&surface_rb, 1, 1, pixdata_a8r8g8b8[3], TRUE);
2385 release_surface_readback(&surface_rb);
2386
2387 /* Contents of the multisampled surface are preserved. */
2389 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
2390
2391 get_surface_readback(device, newsurf, D3DFMT_A8R8G8B8, &surface_rb);
2392 check_readback_pixel_4bpp(&surface_rb, 0, 0, pixdata_a8r8g8b8[0], TRUE);
2393 check_readback_pixel_4bpp(&surface_rb, 1, 0, pixdata_a8r8g8b8[1], TRUE);
2394 check_readback_pixel_4bpp(&surface_rb, 0, 1, pixdata_a8r8g8b8[2], TRUE);
2395 check_readback_pixel_4bpp(&surface_rb, 1, 1, pixdata_a8r8g8b8[3], TRUE);
2396 release_surface_readback(&surface_rb);
2397
2399 }
2400 else
2401 {
2402 skip("Failed to create multisampled render target.\n");
2403 }
2404
2406 ok(hr == D3D_OK, "IDirect3DDevice9_GetRenderTarget returned %#lx, expected %#lx.\n", hr, D3D_OK);
2407
2409 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#lx, expected %#lx.\n", hr, D3D_OK);
2411 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#lx, expected %#lx.\n", hr, D3D_OK);
2412 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0xff000000);
2413 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#lx, expected %#lx.\n", hr, D3D_OK);
2415 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#lx, expected %#lx.\n", hr, D3D_OK);
2417 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#lx, expected %#lx.\n", hr, D3D_OK);
2418
2419 /* rects */
2420 SetRect(&rect, 2, 2, 1, 1);
2422 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#lx, expected %#lx.\n", hr, D3DERR_INVALIDCALL);
2423 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, &rect, D3DX_DEFAULT, 0);
2424 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#lx, expected %#lx.\n", hr, D3DERR_INVALIDCALL);
2426 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#lx, expected %#lx.\n", hr, D3DERR_INVALIDCALL);
2427 hr = D3DXLoadSurfaceFromSurface(surf, NULL, &rect, newsurf, NULL, NULL, D3DX_DEFAULT, 0);
2428 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#lx, expected %#lx.\n", hr, D3DERR_INVALIDCALL);
2430 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#lx, expected %#lx.\n", hr, D3DERR_INVALIDCALL);
2431 SetRect(&rect, 1, 1, 1, 1);
2433 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#lx, expected %#lx.\n", hr, D3D_OK);
2435 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#lx, expected %#lx.\n", hr, D3D_OK);
2436 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, &rect, D3DX_DEFAULT, 0);
2437 ok(hr == E_FAIL, "D3DXLoadSurfaceFromSurface returned %#lx, expected %#lx.\n", hr, E_FAIL);
2438 hr = D3DXLoadSurfaceFromSurface(surf, NULL, &rect, newsurf, NULL, NULL, D3DX_DEFAULT, 0);
2439 ok(hr == E_FAIL, "D3DXLoadSurfaceFromSurface returned %#lx, expected %#lx.\n", hr, E_FAIL);
2440 if (0)
2441 {
2442 /* Somehow it crashes with a STATUS_INTEGER_DIVIDE_BY_ZERO exception
2443 * on Windows. */
2445 ok(hr == E_FAIL, "D3DXLoadSurfaceFromSurface returned %#lx, expected %#lx.\n", hr, E_FAIL);
2446 }
2447 SetRect(&rect, 1, 1, 2, 2);
2448 SetRect(&destrect, 1, 1, 2, 2);
2449 hr = D3DXLoadSurfaceFromSurface(surf, NULL, &rect, newsurf, NULL, &destrect, D3DX_FILTER_NONE, 0);
2450 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#lx, expected %#lx.\n", hr, D3D_OK);
2452 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#lx, expected %#lx.\n", hr, D3D_OK);
2453 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, &destrect, D3DX_FILTER_NONE, 0);
2454 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#lx, expected %#lx.\n", hr, D3D_OK);
2455
2456 for (i = 0; i < ARRAY_SIZE(test_filter_values); ++i)
2457 {
2458 winetest_push_context("Filter %d (%#x)", i, test_filter_values[i].filter);
2459
2461 ok(hr == test_filter_values[i].expected_hr, "Unexpected hr %#lx.\n", hr);
2462
2464 }
2465
2467
2468 check_release((IUnknown*)surf, 0);
2469
2470 SetRect(&rect, 1, 1, 2, 2);
2472 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2473 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8,
2475 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2477 check_pixel_4bpp(&lockrect, 0, 0, 0x8dc32bf6);
2479
2480 /*
2481 * Test negative offsets in the source rectangle. Causes an access
2482 * violation when run on 64-bit Windows.
2483 */
2484 if (sizeof(void *) != 8)
2485 {
2486 SetRect(&rect, 0, -1, 1, 0);
2487 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, &pixdata_a8b8g8r8[2],
2489 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2491 check_pixel_4bpp(&lockrect, 0, 0, pixdata_a8b8g8r8[0]);
2493 }
2494 else
2495 skip("Skipping test for negative source rectangle values on 64-bit.\n");
2496
2497 check_release((IUnknown *)surf, 0);
2498
2499 /* test color conversion */
2500 SetRect(&rect, 0, 0, 2, 2);
2501 /* A8R8G8B8 */
2503 if(FAILED(hr)) skip("Failed to create a surface (%#lx)\n", hr);
2504 else {
2506
2507 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2,
2509 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
2511 check_pixel_4bpp(&lockrect, 0, 0, 0x57dbffff);
2512 check_pixel_4bpp(&lockrect, 1, 0, 0x98ffff00);
2513 check_pixel_4bpp(&lockrect, 0, 1, 0xacdbff55);
2514 check_pixel_4bpp(&lockrect, 1, 1, 0xc8929255);
2516
2517 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5,
2519 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
2521 check_pixel_4bpp(&lockrect, 0, 0, 0x008cadad);
2522 check_pixel_4bpp(&lockrect, 1, 0, 0xff317342);
2523 check_pixel_4bpp(&lockrect, 0, 1, 0x0008ad10);
2524 check_pixel_4bpp(&lockrect, 1, 1, 0xff29088c);
2526
2527 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5,
2529 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
2531 check_pixel_4bpp(&lockrect, 0, 0, 0xff9cdfb5);
2532 check_pixel_4bpp(&lockrect, 1, 0, 0xff63b26b);
2533 check_pixel_4bpp(&lockrect, 0, 1, 0xff085d73);
2534 check_pixel_4bpp(&lockrect, 1, 1, 0xff425d73);
2536
2537 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16,
2539 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
2541 todo_wine {
2542 check_pixel_4bpp(&lockrect, 0, 0, 0xff3f08ff);
2543 }
2544 check_pixel_4bpp(&lockrect, 1, 0, 0xff44dcff);
2545 check_pixel_4bpp(&lockrect, 0, 1, 0xff97e4ff);
2546 check_pixel_4bpp(&lockrect, 1, 1, 0xfffe9aff);
2548
2549 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8,
2551 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2553 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2554 check_pixel_4bpp(&lockrect, 0, 0, 0xc3f04c39);
2555 check_pixel_4bpp(&lockrect, 1, 0, 0x2392e85a);
2556 check_pixel_4bpp(&lockrect, 0, 1, 0x09fd97b1);
2557 check_pixel_4bpp(&lockrect, 1, 1, 0x8df62bc3);
2559
2560 SetRect(&rect, 0, 0, 1, 1);
2561 SetRect(&destrect, 1, 1, 2, 2);
2562 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata_a8b8g8r8,
2564 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2566 check_pixel_4bpp(&lockrect, 0, 0, 0xc3f04c39);
2567 check_pixel_4bpp(&lockrect, 1, 0, 0x2392e85a);
2568 check_pixel_4bpp(&lockrect, 0, 1, 0x09fd97b1);
2569 check_pixel_4bpp(&lockrect, 1, 1, 0xc3f04c39);
2571
2572 SetRect(&rect, 0, 0, 2, 2);
2573
2574 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10,
2576 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2578 check_pixel_4bpp(&lockrect, 0, 0, 0x555c95bf);
2579 check_pixel_4bpp(&lockrect, 1, 0, 0x556d663f);
2580 check_pixel_4bpp(&lockrect, 0, 1, 0xaac385ad);
2581 todo_wine {
2582 check_pixel_4bpp(&lockrect, 1, 1, 0xfffcc575);
2583 }
2585
2586 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
2588 ok(SUCCEEDED(hr), "Failed to load surface, hr %#lx.\n", hr);
2590 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
2591 check_pixel_4bpp(&lockrect, 0, 0, 0xff000000);
2592 check_pixel_4bpp(&lockrect, 1, 0, 0x00ffffff);
2593 check_pixel_4bpp(&lockrect, 0, 1, 0xff303030);
2594 check_pixel_4bpp(&lockrect, 1, 1, 0x7f7f7f7f);
2596 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
2597
2598 /* From a signed normalized format to an unsigned normalized format. */
2599 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_q8w8v8u8, D3DFMT_Q8W8V8U8, 8, NULL, &rect,
2600 D3DX_FILTER_NONE, 0);
2601 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
2602
2604 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
2605 check_pixel_4bpp(&lockrect, 0, 0, 0xb08090a0);
2606 check_pixel_4bpp(&lockrect, 1, 0, 0xffc0d0e0);
2607 check_pixel_4bpp(&lockrect, 0, 1, 0x2f00001f);
2608 check_pixel_4bpp(&lockrect, 1, 1, 0x7e3f4f5f);
2610 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
2611
2612 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a32b32g32r32f, D3DFMT_A32B32G32R32F, 32, NULL, &rect,
2613 D3DX_FILTER_NONE, 0);
2614 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
2616 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
2617 check_pixel_4bpp(&lockrect, 0, 0, 0xff001aff);
2618 check_pixel_4bpp(&lockrect, 1, 0, 0xffffffff);
2619 check_pixel_4bpp(&lockrect, 0, 1, 0x000000ff);
2620 check_pixel_4bpp(&lockrect, 1, 1, 0x00000000);
2622 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
2623
2624 /* Test D3DXLoadSurfaceFromMemory with indexed color image */
2625 if (0)
2626 {
2627 /* Crashes on Nvidia Win10. */
2628 palette.peRed = bmp_1bpp[56];
2629 palette.peGreen = bmp_1bpp[55];
2630 palette.peBlue = bmp_1bpp[54];
2631 palette.peFlags = bmp_1bpp[57]; /* peFlags is the alpha component in DX8 and higher */
2633 D3DFMT_P8, 1, (const PALETTEENTRY *)&palette, &rect, D3DX_FILTER_NONE, 0);
2634 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
2636 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx\n", hr);
2637 ok(*(DWORD*)lockrect.pBits == 0x80f3f2f1,
2638 "Pixel color mismatch: got %#lx, expected 0x80f3f2f1\n", *(DWORD*)lockrect.pBits);
2640 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx\n", hr);
2641 }
2642
2643 /* Test D3DXLoadSurfaceFromFileInMemory with indexed color image (alpha is not taken into account for bmp file) */
2645 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
2647 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx\n", hr);
2648 ok(*(DWORD*)lockrect.pBits == 0xfff3f2f1, "Pixel color mismatch: got %#lx, expected 0xfff3f2f1\n", *(DWORD*)lockrect.pBits);
2650 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx\n", hr);
2651
2652 SetRect(&rect, 0, 0, 2, 2);
2653 for (i = 0; i < ARRAY_SIZE(test_filter_values); ++i)
2654 {
2655 winetest_push_context("Filter %d (%#x)", i, test_filter_values[i].filter);
2656
2659 ok(hr == test_filter_values[i].expected_hr, "Unexpected hr %#lx.\n", hr);
2660
2661 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8, 8, NULL, &rect,
2663 ok(hr == test_filter_values[i].expected_hr, "Unexpected hr %#lx.\n", hr);
2664
2666 }
2667
2668 /* Test D3DXLoadSurfaceFromFileInMemory with indexed pixel format DDS files. */
2670 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
2672 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
2673 check_pixel_4bpp(&lockrect, 0, 0, 0xffec2700);
2674 check_pixel_4bpp(&lockrect, 1, 0, 0xffec2700);
2675 check_pixel_4bpp(&lockrect, 0, 1, 0xffec2700);
2676 check_pixel_4bpp(&lockrect, 1, 1, 0xffec2700);
2678 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
2679
2681 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
2683 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
2684 check_pixel_4bpp(&lockrect, 0, 0, 0xf0000000);
2685 check_pixel_4bpp(&lockrect, 1, 0, 0xe0004000);
2686 check_pixel_4bpp(&lockrect, 0, 1, 0xb0400000);
2687 check_pixel_4bpp(&lockrect, 1, 1, 0xa0404000);
2689 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
2690
2691 check_release((IUnknown*)surf, 0);
2692 }
2693
2694 /* A1R5G5B5 */
2696 if(FAILED(hr)) skip("Failed to create a surface (%#lx)\n", hr);
2697 else {
2698 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2,
2700 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
2702 check_pixel_2bpp(&lockrect, 0, 0, 0x6fff);
2703 check_pixel_2bpp(&lockrect, 1, 0, 0xffe0);
2704 check_pixel_2bpp(&lockrect, 0, 1, 0xefea);
2705 check_pixel_2bpp(&lockrect, 1, 1, 0xca4a);
2707
2708 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5,
2710 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
2712 check_pixel_2bpp(&lockrect, 0, 0, 0x46b5);
2713 check_pixel_2bpp(&lockrect, 1, 0, 0x99c8);
2714 check_pixel_2bpp(&lockrect, 0, 1, 0x06a2);
2715 check_pixel_2bpp(&lockrect, 1, 1, 0x9431);
2717
2718 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5,
2720 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
2722 check_pixel_2bpp(&lockrect, 0, 0, 0xcf76);
2723 check_pixel_2bpp(&lockrect, 1, 0, 0xb2cd);
2724 check_pixel_2bpp(&lockrect, 0, 1, 0x856e);
2725 check_pixel_2bpp(&lockrect, 1, 1, 0xa16e);
2727
2728 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16,
2730 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
2732 todo_wine {
2733 check_pixel_2bpp(&lockrect, 0, 0, 0xa03f);
2734 }
2735 check_pixel_2bpp(&lockrect, 1, 0, 0xa37f);
2736 check_pixel_2bpp(&lockrect, 0, 1, 0xcb9f);
2737 check_pixel_2bpp(&lockrect, 1, 1, 0xfe7f);
2739
2740 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8,
2742 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
2744 todo_wine {
2745 check_pixel_2bpp(&lockrect, 0, 0, 0xf527);
2746 check_pixel_2bpp(&lockrect, 1, 0, 0x4b8b);
2747 }
2748 check_pixel_2bpp(&lockrect, 0, 1, 0x7e56);
2749 check_pixel_2bpp(&lockrect, 1, 1, 0xf8b8);
2751
2752 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10,
2754 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
2756 check_pixel_2bpp(&lockrect, 0, 0, 0x2e57);
2757 todo_wine {
2758 check_pixel_2bpp(&lockrect, 1, 0, 0x3588);
2759 }
2760 check_pixel_2bpp(&lockrect, 0, 1, 0xe215);
2761 check_pixel_2bpp(&lockrect, 1, 1, 0xff0e);
2763
2764 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
2766 ok(SUCCEEDED(hr), "Failed to load surface, hr %#lx.\n", hr);
2768 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
2769 check_pixel_2bpp(&lockrect, 0, 0, 0x8000);
2770 check_pixel_2bpp(&lockrect, 1, 0, 0x7fff);
2771 check_pixel_2bpp(&lockrect, 0, 1, 0x98c6);
2772 check_pixel_2bpp(&lockrect, 1, 1, 0x3def);
2774 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
2775
2776 check_release((IUnknown*)surf, 0);
2777 }
2778
2779 /* A8L8 */
2781 if (FAILED(hr))
2782 skip("Failed to create A8L8 texture, hr %#lx.\n", hr);
2783 else
2784 {
2785 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &surf);
2786 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#lx.\n", hr);
2787
2788 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2,
2790 ok(SUCCEEDED(hr), "Failed to load surface, hr %#lx.\n", hr);
2792 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
2793 check_pixel_2bpp(&lockrect, 0, 0, 0x57f7);
2794 check_pixel_2bpp(&lockrect, 1, 0, 0x98ed);
2795 check_pixel_2bpp(&lockrect, 0, 1, 0xaceb);
2796 check_pixel_2bpp(&lockrect, 1, 1, 0xc88d);
2798 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
2799
2800 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5,
2802 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
2804 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
2805 check_pixel_2bpp(&lockrect, 0, 0, 0x00a6);
2806 check_pixel_2bpp(&lockrect, 1, 0, 0xff62);
2807 check_pixel_2bpp(&lockrect, 0, 1, 0x007f);
2808 check_pixel_2bpp(&lockrect, 1, 1, 0xff19);
2810 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
2811
2812 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5,
2814 ok(SUCCEEDED(hr), "Failed to load surface, hr %#lx.\n", hr);
2816 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
2817 check_pixel_2bpp(&lockrect, 0, 0, 0xffce);
2818 check_pixel_2bpp(&lockrect, 1, 0, 0xff9c);
2819 check_pixel_2bpp(&lockrect, 0, 1, 0xff4d);
2820 check_pixel_2bpp(&lockrect, 1, 1, 0xff59);
2822 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
2823
2824 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16,
2826 ok(SUCCEEDED(hr), "Failed to load surface, hr %#lx.\n", hr);
2828 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
2829 check_pixel_2bpp(&lockrect, 0, 0, 0xff25);
2830 check_pixel_2bpp(&lockrect, 1, 0, 0xffbe);
2831 check_pixel_2bpp(&lockrect, 0, 1, 0xffd6);
2832 check_pixel_2bpp(&lockrect, 1, 1, 0xffb6);
2834 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
2835
2836 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8,
2838 ok(SUCCEEDED(hr), "Failed to load surface, hr %#lx.\n", hr);
2840 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
2841 check_pixel_2bpp(&lockrect, 0, 0, 0xc36d);
2842 check_pixel_2bpp(&lockrect, 1, 0, 0x23cb);
2843 check_pixel_2bpp(&lockrect, 0, 1, 0x09af);
2844 check_pixel_2bpp(&lockrect, 1, 1, 0x8d61);
2846 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
2847
2848 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10,
2850 ok(SUCCEEDED(hr), "Failed to load surface, hr %#lx.\n", hr);
2852 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
2853 check_pixel_2bpp(&lockrect, 0, 0, 0x558c);
2854 check_pixel_2bpp(&lockrect, 1, 0, 0x5565);
2855 check_pixel_2bpp(&lockrect, 0, 1, 0xaa95);
2856 check_pixel_2bpp(&lockrect, 1, 1, 0xffcb);
2858 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
2859
2860 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
2862 ok(SUCCEEDED(hr), "Failed to load surface, hr %#lx.\n", hr);
2864 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#lx.\n", hr);
2865 check_pixel_2bpp(&lockrect, 0, 0, 0xff00);
2866 check_pixel_2bpp(&lockrect, 1, 0, 0x00ff);
2867 check_pixel_2bpp(&lockrect, 0, 1, 0xff30);
2868 check_pixel_2bpp(&lockrect, 1, 1, 0x7f7f);
2870 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#lx.\n", hr);
2871
2872 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_q8w8v8u8, D3DFMT_Q8W8V8U8, 8, NULL, &rect,
2873 D3DX_FILTER_NONE, 0);
2874 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
2875
2877 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
2878 check_pixel_2bpp(&lockrect, 0, 0, 0xb08d);
2879 check_pixel_2bpp(&lockrect, 1, 0, 0xffce);
2880 check_pixel_2bpp(&lockrect, 0, 1, 0x2f02);
2881 check_pixel_2bpp(&lockrect, 1, 1, 0x7e4d);
2883 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
2884
2885 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a32b32g32r32f, D3DFMT_A32B32G32R32F, 32, NULL, &rect,
2886 D3DX_FILTER_NONE, 0);
2887 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
2889 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
2890 todo_wine check_pixel_2bpp(&lockrect, 0, 0, 0xff25);
2891 check_pixel_2bpp(&lockrect, 1, 0, 0xffff);
2892 todo_wine check_pixel_2bpp(&lockrect, 0, 1, 0x0012);
2893 check_pixel_2bpp(&lockrect, 1, 1, 0x0000);
2895 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
2896
2897 check_release((IUnknown*)surf, 1);
2898 check_release((IUnknown*)tex, 0);
2899 }
2900
2901 /* DXT1, DXT2, DXT3, DXT4, DXT5 */
2903 if (FAILED(hr))
2904 skip("Failed to create A8R8G8B8 surface, hr %#lx.\n", hr);
2905 else
2906 {
2908 ok(SUCCEEDED(hr), "Failed to load surface, hr %#lx.\n", hr);
2909
2911 if (FAILED(hr))
2912 skip("Failed to create DXT2 texture, hr %#lx.\n", hr);
2913 else
2914 {
2915 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
2916 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#lx.\n", hr);
2918 ok(SUCCEEDED(hr), "Failed to convert pixels to DXT2 format.\n");
2919 check_release((IUnknown*)newsurf, 1);
2920 check_release((IUnknown*)tex, 0);
2921 }
2922
2924 if (FAILED(hr))
2925 skip("Failed to create DXT3 texture, hr %#lx.\n", hr);
2926 else
2927 {
2928 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
2929 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#lx.\n", hr);
2931 ok(SUCCEEDED(hr), "Failed to convert pixels to DXT3 format.\n");
2932 check_release((IUnknown*)newsurf, 1);
2933 check_release((IUnknown*)tex, 0);
2934 }
2935
2937 if (FAILED(hr))
2938 skip("Failed to create DXT4 texture, hr %#lx.\n", hr);
2939 else
2940 {
2941 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
2942 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#lx.\n", hr);
2944 ok(SUCCEEDED(hr), "Failed to convert pixels to DXT4 format.\n");
2945 check_release((IUnknown*)newsurf, 1);
2946 check_release((IUnknown*)tex, 0);
2947 }
2948
2950 if (FAILED(hr))
2951 skip("Failed to create DXT5 texture, hr %#lx.\n", hr);
2952 else
2953 {
2954 struct surface_readback surface_rb;
2955
2956 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
2957 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#lx.\n", hr);
2959 ok(SUCCEEDED(hr), "Failed to convert pixels to DXT5 format.\n");
2960
2961 SetRect(&rect, 0, 0, 4, 2);
2962 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, &rect, surf, NULL, &rect, D3DX_FILTER_NONE, 0);
2963 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2964 hr = D3DXLoadSurfaceFromMemory(newsurf, NULL, &rect, &dds_dxt5[128],
2966 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2967 check_release((IUnknown *)newsurf, 1);
2968 check_release((IUnknown *)tex, 0);
2969
2970 /* Test updating subarea of compressed texture. */
2972 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2973 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
2974 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2975 SetRect(&destrect, 0, 0, 4, 8);
2976 SetRect(&rect, 0, 0, 4, 8);
2977 memset(buffer, 0x40, sizeof(buffer));
2978 hr = D3DXLoadSurfaceFromMemory(newsurf, NULL, &destrect, buffer,
2980 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2981
2982 hr = IDirect3DSurface9_LockRect(newsurf, &lockrect, &destrect, D3DLOCK_READONLY);
2983 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2984 /* 2 identical 16 bytes DXT5 blocks. The exact values in blocks may differ from Windows due to
2985 * different compression algorithms. */
2986 ok(!memcmp(lockrect.pBits, (char *)lockrect.pBits + lockrect.Pitch, 16), "data mismatch.\n");
2988 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2989
2990 check_release((IUnknown *)newsurf, 1);
2991 check_release((IUnknown *)tex, 0);
2992
2993 /* Test a rect larger than but not an integer multiple of the block size. */
2995 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2996 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
2997 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
2998 SetRect(&rect, 0, 0, 4, 6);
2999 hr = D3DXLoadSurfaceFromMemory(newsurf, NULL, &rect, &dds_dxt5[112],
3001 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3002
3003 check_release((IUnknown *)newsurf, 1);
3004 check_release((IUnknown *)tex, 0);
3005
3006 /* More misalignment tests. */
3008 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3009 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
3010 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3011
3012 SetRect(&rect, 2, 2, 6, 6);
3014 D3DFMT_DXT5, 16 * 2, NULL, &rect, D3DX_FILTER_POINT, 0);
3015 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3016
3018 D3DFMT_DXT5, 16 * 2, NULL, NULL, D3DX_FILTER_POINT, 0);
3019 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#lx.\n", hr);
3020
3022 D3DFMT_DXT5, 16 * 2, NULL, &rect, D3DX_FILTER_POINT, 0);
3023 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3024
3025 check_release((IUnknown *)newsurf, 1);
3026 check_release((IUnknown *)tex, 0);
3027
3028 /* Misalignment tests but check the resulting image. */
3030 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3031 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
3032 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3033
3034 SetRect(&rect, 0, 0, 8, 8);
3036 D3DFMT_DXT5, 16 * 2, NULL, &rect, D3DX_FILTER_NONE, 0);
3037 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3038
3039 get_surface_decompressed_readback(device, newsurf, &surface_rb);
3040
3041 check_readback_pixel_4bpp(&surface_rb, 0, 0, 0xff0000ff, FALSE); /* Blue block, top left. */
3042 check_readback_pixel_4bpp(&surface_rb, 3, 3, 0xff0000ff, FALSE); /* Blue block, bottom right. */
3043 check_readback_pixel_4bpp(&surface_rb, 7, 0, 0xff00ff00, FALSE); /* Green block, top right. */
3044 check_readback_pixel_4bpp(&surface_rb, 4, 3, 0xff00ff00, FALSE); /* Green block, bottom left. */
3045 check_readback_pixel_4bpp(&surface_rb, 3, 4, 0xffff0000, FALSE); /* Red block, top right. */
3046 check_readback_pixel_4bpp(&surface_rb, 0, 7, 0xffff0000, FALSE); /* Red block, bottom left. */
3047 check_readback_pixel_4bpp(&surface_rb, 4, 4, 0xff000000, FALSE); /* Black block, top left. */
3048 check_readback_pixel_4bpp(&surface_rb, 7, 7, 0xff000000, FALSE); /* Black block, bottom right. */
3049
3050 release_surface_readback(&surface_rb);
3051
3052 /*
3053 * Load our surface into a destination rectangle that overlaps
3054 * multiple blocks. Original data in the blocks should be
3055 * preserved.
3056 */
3057 SetRect(&rect, 4, 4, 8, 8);
3058 SetRect(&destrect, 2, 2, 6, 6);
3059 hr = D3DXLoadSurfaceFromMemory(newsurf, NULL, &destrect, dxt5_8_8,
3060 D3DFMT_DXT5, 16 * 2, NULL, &rect, D3DX_FILTER_NONE, 0);
3061 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3062
3063 get_surface_decompressed_readback(device, newsurf, &surface_rb);
3064
3065 check_readback_pixel_4bpp(&surface_rb, 0, 0, 0xff0000ff, FALSE); /* Blue block, top left. */
3066 check_readback_pixel_4bpp(&surface_rb, 3, 3, 0xff000000, FALSE); /* Blue block, bottom right. */
3067 check_readback_pixel_4bpp(&surface_rb, 7, 0, 0xff00ff00, FALSE); /* Green block, top right. */
3068 check_readback_pixel_4bpp(&surface_rb, 4, 3, 0xff000000, FALSE); /* Green block, bottom left. */
3069 check_readback_pixel_4bpp(&surface_rb, 3, 4, 0xff000000, FALSE); /* Red block, top right. */
3070 check_readback_pixel_4bpp(&surface_rb, 0, 7, 0xffff0000, FALSE); /* Red block, bottom left. */
3071 check_readback_pixel_4bpp(&surface_rb, 4, 4, 0xff000000, FALSE); /* Black block, top left. */
3072 check_readback_pixel_4bpp(&surface_rb, 7, 7, 0xff000000, FALSE); /* Black block, bottom right. */
3073
3074 release_surface_readback(&surface_rb);
3075
3076 /*
3077 * Our source and destination rectangles start on aligned
3078 * boundaries, but the size is not the entire block.
3079 */
3080 SetRect(&rect, 4, 0, 6, 2);
3081 SetRect(&destrect, 4, 0, 6, 2);
3082 hr = D3DXLoadSurfaceFromMemory(newsurf, NULL, &destrect, dxt5_8_8,
3083 D3DFMT_DXT5, 16 * 2, NULL, &rect, D3DX_FILTER_NONE, 0);
3084 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3085
3086 get_surface_decompressed_readback(device, newsurf, &surface_rb);
3087
3088 check_readback_pixel_4bpp(&surface_rb, 4, 0, 0xff00ff00, FALSE); /* Green block, top left. */
3089 /*
3090 * Bottom left of green block, should still be black from prior
3091 * operation.
3092 */
3093 check_readback_pixel_4bpp(&surface_rb, 4, 3, 0xff000000, FALSE);
3094
3095 release_surface_readback(&surface_rb);
3096
3097 check_release((IUnknown *)newsurf, 1);
3098 check_release((IUnknown *)tex, 0);
3099 }
3100
3102 if (FAILED(hr))
3103 skip("Failed to create DXT1 texture, hr %#lx.\n", hr);
3104 else
3105 {
3106 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
3107 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#lx.\n", hr);
3109 ok(SUCCEEDED(hr), "Failed to convert pixels to DXT1 format.\n");
3110
3112 ok(SUCCEEDED(hr), "Failed to convert pixels from DXT1 format.\n");
3113
3114 check_release((IUnknown*)newsurf, 1);
3115 check_release((IUnknown*)tex, 0);
3116 }
3117
3118 check_release((IUnknown*)surf, 0);
3119 }
3120
3122 if (FAILED(hr))
3123 skip("Failed to create a D3DFMT_A32B32G32R32F surface, hr %#lx.\n", hr);
3124 else
3125 {
3126 /* Direct copy. */
3127 SetRect(&rect, 0, 0, 2, 2);
3128 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a32b32g32r32f, D3DFMT_A32B32G32R32F, 32, NULL, &rect,
3129 D3DX_FILTER_NONE, 0);
3130 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3131
3133 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
3134 check_pixel_float4(&lockrect, 0, 0, pixdata_a32b32g32r32f[0], pixdata_a32b32g32r32f[1],
3135 pixdata_a32b32g32r32f[2], pixdata_a32b32g32r32f[3], 0, FALSE);
3136 check_pixel_float4(&lockrect, 1, 0, pixdata_a32b32g32r32f[4], pixdata_a32b32g32r32f[5],
3137 pixdata_a32b32g32r32f[6], pixdata_a32b32g32r32f[7], 0, FALSE);
3138 check_pixel_float4(&lockrect, 0, 1, pixdata_a32b32g32r32f[8], pixdata_a32b32g32r32f[9],
3139 pixdata_a32b32g32r32f[10], pixdata_a32b32g32r32f[11], 0, FALSE);
3140 check_pixel_float4(&lockrect, 1, 1, pixdata_a32b32g32r32f[12], pixdata_a32b32g32r32f[13],
3141 pixdata_a32b32g32r32f[14], pixdata_a32b32g32r32f[15], 0, FALSE);
3143 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
3144
3145 /* Signed normalized value to full range float. */
3146 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_q8w8v8u8, D3DFMT_Q8W8V8U8, 8, NULL, &rect,
3147 D3DX_FILTER_NONE, 0);
3148 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3149
3151 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
3152 check_pixel_float4(&lockrect, 0, 0, 0.00000000e+000f, 1.25984251e-001f, 2.51968503e-001f, 3.77952754e-001f, 0, FALSE);
3153 check_pixel_float4(&lockrect, 1, 0, 5.03937006e-001f, 6.29921257e-001f, 7.55905509e-001f, 1.00000000e+000f, 0, FALSE);
3154 check_pixel_float4(&lockrect, 0, 1, -1.00000000e+000f, -1.00000000e+000f, -7.55905509e-001f, -6.29921257e-001f, 0, FALSE);
3155 check_pixel_float4(&lockrect, 1, 1, -5.03937006e-001f, -3.77952754e-001f, -2.51968503e-001f, -7.87401572e-003f, 0, FALSE);
3157 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
3158
3159 /* Unsigned normalized value to full range float. */
3160 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8_2, D3DFMT_A8B8G8R8, 8, NULL, &rect,
3161 D3DX_FILTER_NONE, 0);
3162 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3163
3165 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
3166 check_pixel_float4(&lockrect, 0, 0, 0.00000000e+000f, 6.27451017e-002f, 1.25490203e-001f, 1.88235313e-001f, 1, FALSE);
3167 check_pixel_float4(&lockrect, 1, 0, 2.50980407e-001f, 3.13725501e-001f, 3.76470625e-001f, 4.39215720e-001f, 1, FALSE);
3168 check_pixel_float4(&lockrect, 0, 1, 5.01960814e-001f, 5.64705908e-001f, 6.27451003e-001f, 6.90196097e-001f, 0, FALSE);
3169 check_pixel_float4(&lockrect, 1, 1, 7.52941251e-001f, 8.15686345e-001f, 8.78431439e-001f, 1.00000000e+000f, 1, FALSE);
3171 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
3172
3173 /* V8U8 snorm. */
3174 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_v8u8, D3DFMT_V8U8, 4, NULL, &rect,
3175 D3DX_FILTER_NONE, 0);
3176 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3177
3179 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
3180 check_pixel_float4(&lockrect, 0, 0, 0.00000000e+000f, 3.77952754e-001f, 1.0f, 1.0f, 0, FALSE);
3181 check_pixel_float4(&lockrect, 1, 0, 0.503937f, 1.0f, 1.0f, 1.0f, 0, FALSE);
3182 check_pixel_float4(&lockrect, 0, 1, -1.0f, -1.0f, 1.0f, 1.0f, 0, FALSE);
3183 check_pixel_float4(&lockrect, 1, 1, -5.03937006e-001f, -7.87401572e-003f, 1.0f, 1.0f, 0, FALSE);
3185 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
3186
3187 /* A2W10V10U10 unorm/snorm. */
3188 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2w10v10u10, D3DFMT_A2W10V10U10, 8, NULL, &rect,
3189 D3DX_FILTER_NONE, 0);
3190 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3191
3193 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
3194 check_pixel_float4(&lockrect, 0, 0, 0.0f, 1.81996077e-001f, 3.63992155e-001f, 0.0f, 1, FALSE);
3195 check_pixel_float4(&lockrect, 1, 0, 5.45988262e-001f, 7.27984309e-001f, 1.0f, 3.33333343e-001f, 1, FALSE);
3196 check_pixel_float4(&lockrect, 0, 1, -1.0f, -1.0f, -5.47945201e-001f, 6.66666687e-001f, 0, FALSE);
3197 check_pixel_float4(&lockrect, 1, 1, -3.65949124e-001f, -1.83953032e-001f, -1.95694715e-003f, 1.0f, 0, FALSE);
3199 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
3200
3201 /* X8L8V8U8 unorm/snorm. */
3202 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_x8l8v8u8, D3DFMT_X8L8V8U8, 8, NULL, &rect,
3203 D3DX_FILTER_NONE, 0);
3204 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3205
3206 /* The luma value goes into the alpha channel. */
3208 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
3209 check_pixel_float4(&lockrect, 0, 0, 0.0, 3.77952754e-001f, 1.0f, 0.0f, 0, FALSE);
3210 check_pixel_float4(&lockrect, 1, 0, 5.03937006e-001f, 1.0f, 1.0f, 3.33333343e-001, 0, FALSE);
3211 check_pixel_float4(&lockrect, 0, 1, -1.0f, -1.0f, 1.0f, 6.66666687e-001, 0, FALSE);
3212 check_pixel_float4(&lockrect, 1, 1, -5.03937006e-001f, -7.87401572e-003f, 1.0f, 1.0f, 0, FALSE);
3214 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
3215
3216 check_release((IUnknown*)surf, 0);
3217 }
3218
3220 if (FAILED(hr))
3221 skip("Failed to create D3DFMT_Q8W8V8U8 texture, hr %#lx.\n", hr);
3222 else
3223 {
3224 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &surf);
3225 ok(hr == D3D_OK, "Failed to get the surface, hr %#lx.\n", hr);
3226
3227 /* Snorm to snorm, direct copy. */
3228 SetRect(&rect, 0, 0, 2, 2);
3229 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_q8w8v8u8, D3DFMT_Q8W8V8U8, 8, NULL, &rect,
3230 D3DX_FILTER_NONE, 0);
3231 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
3233 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
3234 check_pixel_4bpp(&lockrect, 0, 0, pixdata_q8w8v8u8[0]);
3235 check_pixel_4bpp(&lockrect, 1, 0, pixdata_q8w8v8u8[1]);
3236 check_pixel_4bpp(&lockrect, 0, 1, pixdata_q8w8v8u8[2]);
3237 check_pixel_4bpp(&lockrect, 1, 1, pixdata_q8w8v8u8[3]);
3239 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
3240
3241 /* Unorm to snorm. */
3242 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8,
3244 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3245
3247 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
3248 check_pixel_4bpp(&lockrect, 0, 0, 0x43bbce70);
3249 check_pixel_4bpp(&lockrect, 1, 0, 0xa5dc6812);
3250 check_pixel_4bpp(&lockrect, 0, 1, 0x8b31177d);
3251 check_pixel_4bpp(&lockrect, 1, 1, 0x0d43ad76);
3253 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
3254
3255 /* Full range float to snorm. */
3256 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a32b32g32r32f, D3DFMT_A32B32G32R32F, 32, NULL, &rect,
3257 D3DX_FILTER_NONE, 0);
3258 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
3259
3261 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
3262 check_pixel_4bpp(&lockrect, 0, 0, 0x7f7f0d00);
3263 check_pixel_4bpp(&lockrect, 1, 0, 0x7f7f7f7f);
3264 check_pixel_4bpp(&lockrect, 0, 1, 0x827fe8f4);
3265 check_pixel_4bpp(&lockrect, 1, 1, 0x82828282);
3267 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
3268
3269 /* Unorm alpha and unorm luma to snorm. */
3270 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8, D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0);
3271 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
3272
3274 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
3275 check_pixel_4bpp(&lockrect, 0, 0, 0x7f828282);
3276 check_pixel_4bpp(&lockrect, 1, 0, 0x827f7f7f);
3277 check_pixel_4bpp(&lockrect, 0, 1, 0x7fb2b2b2);
3278 check_pixel_4bpp(&lockrect, 1, 1, 0x00000000);
3280 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
3281
3282 check_release((IUnknown*)surf, 1);
3283 check_release((IUnknown*)tex, 0);
3284 }
3285
3287 if (FAILED(hr))
3288 skip("Failed to create D3DFMT_X8L8V8U8 texture, hr %#lx.\n", hr);
3289 else
3290 {
3291 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &surf);
3292 ok(hr == D3D_OK, "Failed to get the surface, hr %#lx.\n", hr);
3293
3294 SetRect(&rect, 0, 0, 2, 2);
3295 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8_2, D3DFMT_A8B8G8R8, 8, NULL, &rect,
3296 D3DX_FILTER_NONE, 0);
3297 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
3298
3299 /*
3300 * The L8 channel here doesn't do RGB->Luma conversion, it just
3301 * copies the alpha channel directly as UNORM. V8 and U8 are snorm,
3302 * pulled from r/g respectively. The X8 (b) channel is set to 0.
3303 */
3305 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
3306 check_pixel_4bpp(&lockrect, 0, 0, 0x00309282);
3307 check_pixel_4bpp(&lockrect, 1, 0, 0x0070d2c2);
3308 check_pixel_4bpp(&lockrect, 0, 1, 0x00b01000);
3309 check_pixel_4bpp(&lockrect, 1, 1, 0x00ff5040);
3311 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
3312
3313 /*
3314 * Q8 will get converted to unorm range, v8u8, despite being in the
3315 * same range, will not be directly copied. 0x80/0x81 are clamped to
3316 * 0x82, and 0xd0/0xc0 end up as 0xd1/0xc1.
3317 */
3318 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_q8w8v8u8, D3DFMT_Q8W8V8U8, 8, NULL, &rect,
3319 D3DX_FILTER_NONE, 0);
3320 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
3321
3323 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
3324 check_pixel_4bpp(&lockrect, 0, 0, 0x00b01000);
3325 check_pixel_4bpp(&lockrect, 1, 0, 0x00ff5040);
3326 check_pixel_4bpp(&lockrect, 0, 1, 0x002f8282);
3327 check_pixel_4bpp(&lockrect, 1, 1, 0x007ed1c1);
3329 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
3330
3331 check_release((IUnknown*)surf, 1);
3332 check_release((IUnknown*)tex, 0);
3333 }
3334
3336 if (FAILED(hr))
3337 skip("Failed to create D3DFMT_V8U8 texture, hr %#lx.\n", hr);
3338 else
3339 {
3340 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &surf);
3341 ok(hr == D3D_OK, "Failed to get the surface, hr %#lx.\n", hr);
3342
3343 /* R and G channels converted to SNORM range. */
3344 SetRect(&rect, 0, 0, 2, 2);
3345 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8_2, D3DFMT_A8B8G8R8, 8, NULL, &rect,
3346 D3DX_FILTER_NONE, 0);
3347 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
3348
3350 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
3351 check_pixel_2bpp(&lockrect, 0, 0, 0x9282);
3352 check_pixel_2bpp(&lockrect, 1, 0, 0xd2c2);
3353 check_pixel_2bpp(&lockrect, 0, 1, 0x1000);
3354 check_pixel_2bpp(&lockrect, 1, 1, 0x5040);
3356 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
3357
3358 /*
3359 * Pull the V8U8 channels. Even though they're the same range, they're
3360 * not directly copied over. 0x80/0x81 are clamped to 0x82, and
3361 * 0xd0/0xc0 end up as 0xd1/0xc1.
3362 */
3363 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_q8w8v8u8, D3DFMT_Q8W8V8U8, 8, NULL, &rect,
3364 D3DX_FILTER_NONE, 0);
3365 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
3366
3368 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
3369 check_pixel_2bpp(&lockrect, 0, 0, 0x1000);
3370 check_pixel_2bpp(&lockrect, 1, 0, 0x5040);
3371 /*
3372 * Wine does direct copies from the source pixels here, but if we
3373 * force conversion to float on the source and then convert back to
3374 * snorm we'd match these values.
3375 */
3376 todo_wine check_pixel_2bpp(&lockrect, 0, 1, 0x8282);
3377 todo_wine check_pixel_2bpp(&lockrect, 1, 1, 0xd1c1);
3379 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
3380
3381 check_release((IUnknown*)surf, 1);
3382 check_release((IUnknown*)tex, 0);
3383 }
3384
3386 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
3387
3390 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
3391
3393 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
3394
3395 check_pixel_8bpp(&lockrect, 0, 0, 0xffff202010100000);
3396 check_pixel_8bpp(&lockrect, 1, 0, 0xffff505040403030);
3397 check_pixel_8bpp(&lockrect, 0, 1, 0xffff808070706060);
3398 check_pixel_8bpp(&lockrect, 1, 1, 0xffffb0b0a0a09090);
3399
3401 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
3402
3405 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
3406
3408 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
3409
3410 check_pixel_8bpp(&lockrect, 0, 0, 0x3030202010100000);
3411 check_pixel_8bpp(&lockrect, 1, 0, 0x7070606050504040);
3412 check_pixel_8bpp(&lockrect, 0, 1, 0xb0b0a0a090908080);
3413 check_pixel_8bpp(&lockrect, 1, 1, 0xf0f0e0e0d0d0c0c0);
3414
3416 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
3417 check_release((IUnknown *)surf, 0);
3418
3422
3423 /* cleanup */
3424 if(testdummy_ok) DeleteFileA("testdummy.bmp");
3425 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
3426}
#define broken(x)
Definition: atltest.h:178
#define ARRAY_SIZE(A)
Definition: main.h:20
RECT rect
Definition: combotst.c:67
@ D3DMULTISAMPLE_NONE
Definition: d3d8types.h:672
@ D3DMULTISAMPLE_2_SAMPLES
Definition: d3d8types.h:673
@ D3DFMT_UNKNOWN
Definition: d3d8types.h:601
@ D3DPOOL_SCRATCH
Definition: d3d8types.h:712
@ D3DPOOL_DEFAULT
Definition: d3d8types.h:709
@ D3DPOOL_MANAGED
Definition: d3d8types.h:710
#define IDirect3DTexture9_GetSurfaceLevel(p, a, b)
Definition: d3d9.h:861
#define IDirect3DDevice9_CreateTexture(p, a, b, c, d, e, f, g, h)
Definition: d3d9.h:1358
#define IDirect3DTexture9_Release(p)
Definition: d3d9.h:842
#define IDirect3DDevice9_CreateRenderTarget(p, a, b, c, d, e, f, g, h)
Definition: d3d9.h:1363
#define IDirect3DDevice9_GetRenderTarget(p, a, b)
Definition: d3d9.h:1373
static const uint8_t pixdata[]
static const uint8_t dds_a8p8[]
static const uint8_t dxt5_8_8[]
static const struct @1911 test_filter_values[]
static const uint8_t dds_dxt5_8_8[]
static const uint8_t dds_dxt5[]
#define E_FAIL
Definition: ddrawi.h:102
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:2702
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: surface.c:1745
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: surface.c:1798
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:1700
#define NAN
Definition: math.h:273
#define INFINITY
Definition: math.h:272
unsigned short uint16_t
Definition: stdint.h:35
#define D3DX_DEFAULT
Definition: d3dx9.h:24
#define D3DX_FILTER_MIRROR
Definition: d3dx9tex.h:35
#define D3DX_FILTER_LINEAR
Definition: d3dx9tex.h:29
#define D3DX_FILTER_TRIANGLE
Definition: d3dx9tex.h:30
#define D3DX_FILTER_POINT
Definition: d3dx9tex.h:28
DWORD IDirect3DSurface9
Definition: dxva2api.idl:23
GLuint buffer
Definition: glext.h:5915
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
void __cdecl void __cdecl void __cdecl void __cdecl void __cdecl void winetest_pop_context(void)
void __cdecl void __cdecl void __cdecl void __cdecl void __cdecl winetest_push_context(const char *fmt,...) __WINE_PRINTF_ATTR(1
Definition: test.h:539
static void test_load_surface_from_tga(IDirect3DDevice9 *device)
Definition: surface.c:1935
static void test_format_conversion(IDirect3DDevice9 *device)
Definition: surface.c:1317
#define check_readback_pixel_4bpp(rb, x, y, color, todo)
Definition: surface.c:1111
#define check_pixel_2bpp(lockrect, x, y, color)
Definition: surface.c:1074
#define check_pixel_float4(lockrect, x, y, fx, fy, fz, fw, ulps, todo)
Definition: surface.c:1095
#define check_pixel_8bpp(lockrect, x, y, color)
Definition: surface.c:1088
static void release_surface_readback(struct surface_readback *rb)
Definition: surface.c:77
#define check_pixel_4bpp(lockrect, x, y, color)
Definition: surface.c:1081
static void test_dxt_premultiplied_alpha(IDirect3DDevice9 *device)
Definition: surface.c:1396
static void get_surface_decompressed_readback(IDirect3DDevice9 *device, IDirect3DSurface9 *compressed_surface, struct surface_readback *rb)
Definition: surface.c:128
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
Definition: dcommon.idl:28
Definition: filter.c:165

Referenced by START_TEST().

◆ test_D3DXSaveSurfaceToFile()

static void test_D3DXSaveSurfaceToFile ( IDirect3DDevice9 *  device)
static

Definition at line 3963 of file surface.c.

3964{
3965 static const BYTE pixels[] =
3966 {0xff, 0x00, 0x00, 0x00, 0xff, 0x00,
3967 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,};
3968 DWORD pitch = sizeof(pixels) / 2;
3969 IDirect3DSurface9 *surface;
3970 D3DXIMAGE_INFO image_info;
3971 D3DLOCKED_RECT lock_rect;
3972 HRESULT hr;
3973 RECT rect;
3974
3976 if (FAILED(hr))
3977 {
3978 skip("Couldn't create surface.\n");
3979 return;
3980 }
3981
3982 SetRect(&rect, 0, 0, 2, 2);
3984 pitch, NULL, &rect, D3DX_FILTER_NONE, 0);
3985 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3986
3987 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, NULL);
3988 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3989
3990 hr = D3DXLoadSurfaceFromFileA(surface, NULL, NULL, "saved_surface.bmp",
3991 NULL, D3DX_FILTER_NONE, 0, &image_info);
3992 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3993
3994 ok(image_info.Width == 2, "Wrong width %u.\n", image_info.Width);
3995 ok(image_info.Height == 2, "Wrong height %u.\n", image_info.Height);
3996 ok(image_info.Format == D3DFMT_R8G8B8, "Wrong format %#x.\n", image_info.Format);
3997 ok(image_info.ImageFileFormat == D3DXIFF_BMP, "Wrong file format %u.\n", image_info.ImageFileFormat);
3998
3999 hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
4000 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4001
4002 ok(!memcmp(lock_rect.pBits, pixels, pitch),
4003 "Pixel data mismatch in the first row.\n");
4004 ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch),
4005 "Pixel data mismatch in the second row.\n");
4006
4008
4009 SetRect(&rect, 0, 1, 2, 2);
4010 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
4011 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4012 SetRect(&rect, 0, 0, 2, 1);
4013 hr = D3DXLoadSurfaceFromFileA(surface, NULL, &rect, "saved_surface.bmp", NULL,
4014 D3DX_FILTER_NONE, 0, &image_info);
4015 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4016
4017 hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
4018 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4019 ok(!memcmp(lock_rect.pBits, pixels + pitch, pitch),
4020 "Pixel data mismatch in the first row.\n");
4021 ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch),
4022 "Pixel data mismatch in the second row.\n");
4024
4025 SetRect(&rect, 0, 0, 2, 2);
4027 pitch, NULL, &rect, D3DX_FILTER_NONE, 0);
4028 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4029
4031 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#lx.\n", hr);
4032
4033 /* PPM and TGA are supported, even though MSDN claims they aren't */
4034 todo_wine
4035 {
4036 hr = D3DXSaveSurfaceToFileA("saved_surface.ppm", D3DXIFF_PPM, surface, NULL, NULL);
4037 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4038 hr = D3DXSaveSurfaceToFileA("saved_surface.tga", D3DXIFF_TGA, surface, NULL, NULL);
4039 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4040 }
4041
4042 hr = D3DXSaveSurfaceToFileA("saved_surface.dds", D3DXIFF_DDS, surface, NULL, NULL);
4043 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4044
4045 hr = D3DXLoadSurfaceFromFileA(surface, NULL, NULL, "saved_surface.dds",
4046 NULL, D3DX_FILTER_NONE, 0, &image_info);
4047 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4048
4049 ok(image_info.Width == 2, "Wrong width %u.\n", image_info.Width);
4050 ok(image_info.Format == D3DFMT_R8G8B8, "Wrong format %#x.\n", image_info.Format);
4051 ok(image_info.ImageFileFormat == D3DXIFF_DDS, "Wrong file format %u.\n", image_info.ImageFileFormat);
4052
4053 hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
4054 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
4055 ok(!memcmp(lock_rect.pBits, pixels, pitch),
4056 "Pixel data mismatch in the first row.\n");
4057 ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch),
4058 "Pixel data mismatch in the second row.\n");
4060
4061 hr = D3DXSaveSurfaceToFileA("saved_surface", D3DXIFF_PFM + 1, surface, NULL, NULL);
4062 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#lx.\n", hr);
4063
4064 SetRect(&rect, 0, 0, 4, 4);
4065 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
4066 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#lx.\n", hr);
4067 SetRect(&rect, 2, 0, 1, 4);
4068 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
4069 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#lx.\n", hr);
4070 SetRect(&rect, 0, 2, 4, 1);
4071 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
4072 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#lx.\n", hr);
4073 SetRect(&rect, -1, -1, 2, 2);
4074 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
4075 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#lx.\n", hr);
4077 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
4078 /* fails when debug version of d3d9 is used */
4079 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "Got unexpected hr %#lx.\n", hr);
4080
4081 DeleteFileA("saved_surface.bmp");
4082 DeleteFileA("saved_surface.ppm");
4083 DeleteFileA("saved_surface.tga");
4084 DeleteFileA("saved_surface.dds");
4085
4087}
HRESULT WINAPI D3DXSaveSurfaceToFileA(const char *dst_filename, D3DXIMAGE_FILEFORMAT file_format, IDirect3DSurface9 *src_surface, const PALETTEENTRY *src_palette, const RECT *src_rect)
Definition: surface.c:2899
@ D3DXIFF_BMP
Definition: dx8vb.idl:62
@ D3DXIFF_PPM
Definition: dx8vb.idl:67
@ D3DXIFF_PFM
Definition: d3dx9tex.h:72
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: gl.h:1546
BOOL WINAPI SetRectEmpty(_Out_ LPRECT)
D3DXIMAGE_FILEFORMAT ImageFileFormat
Definition: d3dx9tex.h:84
D3DFORMAT Format
Definition: d3dx9tex.h:82

Referenced by START_TEST().

◆ test_D3DXSaveSurfaceToFileInMemory()

static void test_D3DXSaveSurfaceToFileInMemory ( IDirect3DDevice9 *  device)
static

Definition at line 3829 of file surface.c.

3830{
3831 static const struct dds_pixel_format d3dfmt_a8r8g8b8_pf = { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32,
3832 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 };
3833 static const uint32_t tmp_pixdata_4_4[] = { 0xff000000, 0xff000000, 0xff000000, 0xff000000,
3834 0x00ff0040, 0x00ff0040, 0x00ff0040, 0x00ff0040,
3835 0x0000ff80, 0x0000ff80, 0x0000ff80, 0x0000ff80,
3836 0x000000c0, 0x000000c0, 0x000000c0, 0x000000c0 };
3837 static const struct
3838 {
3839 DWORD usage;
3840 D3DPOOL pool;
3841 }
3842 test_access_types[] =
3843 {
3844 {0, D3DPOOL_MANAGED},
3845 {0, D3DPOOL_DEFAULT},
3847 };
3848
3849 struct
3850 {
3851 DWORD magic;
3852 struct dds_header header;
3853 BYTE *data;
3854 } *dds;
3855 IDirect3DSurface9 *surface;
3856 IDirect3DTexture9 *texture;
3857 unsigned int i, x, y;
3859 HRESULT hr;
3860 RECT rect;
3861
3863 if (FAILED(hr)) {
3864 skip("Couldn't create surface\n");
3865 return;
3866 }
3867
3868 SetRect(&rect, 0, 0, 4, 4);
3869 hr = D3DXLoadSurfaceFromMemory(surface, NULL, NULL, tmp_pixdata_4_4, D3DFMT_A8R8G8B8, 16, NULL, &rect, D3DX_FILTER_NONE, 0);
3870 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3871
3874 /* fails with the debug version of d3d9 */
3875 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXSaveSurfaceToFileInMemory returned %#lx, expected %#lx\n", hr, D3D_OK);
3876 if (SUCCEEDED(hr)) {
3878 ok(size > 0, "ID3DXBuffer_GetBufferSize returned %lu, expected > 0\n", size);
3880 }
3881
3884 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3885
3887 check_dds_header(&dds->header, DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT, 0, 0, 0, 0, 0,
3888 &d3dfmt_a8r8g8b8_pf, DDSCAPS_TEXTURE | DDSCAPS_ALPHA, 0, FALSE);
3890
3891 /* Test rectangle argument for D3DXIFF_DDS. */
3892 SetRect(&rect, 0, 0, 0, 2);
3894 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3895
3897 check_dds_header(&dds->header, DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT, 2, 0, 0, 0, 0,
3898 &d3dfmt_a8r8g8b8_pf, DDSCAPS_TEXTURE | DDSCAPS_ALPHA, 0, FALSE);
3900
3901 SetRect(&rect, 0, 0, 2, 0);
3903 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3904
3906 check_dds_header(&dds->header, DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT, 0, 2, 0, 0, 0,
3907 &d3dfmt_a8r8g8b8_pf, DDSCAPS_TEXTURE | DDSCAPS_ALPHA, 0, FALSE);
3909
3910 SetRect(&rect, 2, 2, 4, 4);
3912 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3913
3915 check_dds_header(&dds->header, DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT, 2, 2, 0, 0, 0,
3916 &d3dfmt_a8r8g8b8_pf, DDSCAPS_TEXTURE | DDSCAPS_ALPHA, 0, FALSE);
3917 for (y = 0; y < 2; ++y)
3918 {
3919 for (x = 0; x < 2; ++x)
3920 {
3921 const uint32_t expected_pixel = tmp_pixdata_4_4[((2 + y) * 4) + (x + 2)];
3922 const uint32_t saved_pixel = ((uint32_t *)&dds->data)[(y * 2) + x];
3923
3924 ok(expected_pixel == saved_pixel, "Unexpected pixel value %#x.\n", saved_pixel);
3925 }
3926 }
3928
3930 ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
3931
3933 check_dds_header(&dds->header, DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT, 4, 4, 0, 0, 0,
3934 &d3dfmt_a8r8g8b8_pf, DDSCAPS_TEXTURE | DDSCAPS_ALPHA, 0, FALSE);
3936
3938
3939 for (i = 0; i < ARRAY_SIZE(test_access_types); ++i)
3940 {
3941 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 0, test_access_types[i].usage,
3942 D3DFMT_A8R8G8B8, test_access_types[i].pool, &texture, NULL);
3943 ok(hr == D3D_OK, "Unexpected hr %#lx, i %u.\n", hr, i);
3944
3946 ok(hr == D3D_OK, "Unexpected hr %#lx, i %u.\n", hr, i);
3947
3949 ok(hr == D3D_OK, "Unexpected hr %#lx, i %u.\n", hr, i);
3951
3953 ok(hr == D3D_OK, "Unexpected hr %#lx, i %u.\n", hr, i);
3955
3958 }
3959
3961}
enum _D3DPOOL D3DPOOL
#define D3DUSAGE_RENDERTARGET
Definition: d3d8types.h:91
struct ID3DXBuffer ID3DXBuffer
Definition: d3dx8core.h:51
HRESULT WINAPI D3DXSaveSurfaceToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE_FILEFORMAT file_format, IDirect3DSurface9 *src_surface, const PALETTEENTRY *src_palette, const RECT *src_rect)
Definition: surface.c:2949
#define DDSCAPS_ALPHA
Definition: surface.c:95
#define ID3DXBuffer_GetBufferSize(p)
Definition: d3dx9core.h:86
#define ID3DXBuffer_GetBufferPointer(p)
Definition: d3dx9core.h:85
#define ID3DXBuffer_Release(p)
Definition: d3dx9core.h:83
GLenum GLuint texture
Definition: glext.h:6295
GLsizeiptr const GLvoid GLenum usage
Definition: glext.h:5919
static void test_save_surface_to_dds(IDirect3DDevice9 *device)
Definition: surface.c:3506
#define check_dds_header(header, flags, height, width, pitch, depth, mip_levels, pixel_format, caps, caps2, wine_todo)
Definition: surface.c:3463

Referenced by START_TEST().

◆ test_dds_header_handling()

static void test_dds_header_handling ( void  )
static

Definition at line 284 of file surface.c.

285{
286 int i;
287 HRESULT hr;
289 struct
290 {
291 DWORD magic;
292 struct dds_header header;
293 BYTE data[4096 * 1024];
294 } *dds;
295
296 static const struct
297 {
299 DWORD flags;
300 DWORD width;
302 DWORD pitch;
303 DWORD miplevels;
304 DWORD pixel_data_size;
305 struct
306 {
307 HRESULT hr;
308 UINT miplevels;
309 BOOL todo;
310 }
311 expected;
312 } tests[] = {
313 /* pitch is ignored */
314 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, 0, 4, 4, 0, 0,
315 63 /* pixel data size */, { D3DXERR_INVALIDDATA, 0 } },
316 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDSD_PITCH, 4, 4, 0 /* pitch */, 0,
317 64, { D3D_OK, 1 } },
318 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDSD_PITCH, 4, 4, 1 /* pitch */, 0,
319 64, { D3D_OK, 1 } },
320 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDSD_PITCH, 4, 4, 2 /* pitch */, 0,
321 64, { D3D_OK, 1 } },
322 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDSD_PITCH, 4, 4, 3 /* pitch */, 0,
323 64, { D3D_OK, 1 } },
324 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDSD_PITCH, 4, 4, 4 /* pitch */, 0,
325 64, { D3D_OK, 1 } },
326 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDSD_PITCH, 4, 4, 16 /* pitch */, 0,
327 64, { D3D_OK, 1 } },
328 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDSD_PITCH, 4, 4, 1024 /* pitch */, 0,
329 64, { D3D_OK, 1 } },
330 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDSD_PITCH, 4, 4, -1 /* pitch */, 0,
331 64, { D3D_OK, 1 } },
332 /* linear size is ignored */
333 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, 0, 4, 4, 0, 0,
334 7 /* pixel data size */, { D3DXERR_INVALIDDATA, 1 } },
335 /* 10. */
336 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDSD_LINEARSIZE, 4, 4, 0 /* linear size */, 0,
337 8, { D3D_OK, 1 } },
338 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDSD_LINEARSIZE, 4, 4, 1 /* linear size */, 0,
339 8, { D3D_OK, 1 } },
340 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDSD_LINEARSIZE, 4, 4, 2 /* linear size */, 0,
341 8, { D3D_OK, 1 } },
342 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDSD_LINEARSIZE, 4, 4, 9 /* linear size */, 0,
343 8, { D3D_OK, 1 } },
344 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDSD_LINEARSIZE, 4, 4, 16 /* linear size */, 0,
345 8, { D3D_OK, 1 } },
346 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDSD_LINEARSIZE, 4, 4, -1 /* linear size */, 0,
347 8, { D3D_OK, 1 } },
348 /* integer overflows */
349 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000000, 0x80000000 /* 0x80000000 * 0x80000000 * 4 = 0 */, 0, 0,
350 64, { D3D_OK, 1, .todo = TRUE } },
351 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x8000100, 0x800100 /* 0x8000100 * 0x800100 * 4 = 262144 */, 0, 0,
352 64, { D3DXERR_INVALIDDATA, 0 } },
353 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0, 0,
354 4, { D3D_OK, 1 } },
355 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0, 0,
356 3 /* pixel data size */, { D3DXERR_INVALIDDATA, 0 } },
357 /* 20. File size is validated. */
358 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 64, 0, 0, 49151, { D3DXERR_INVALIDDATA, 0 } },
359 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 64, 0, 0, 49152, { D3D_OK, 1 } },
360 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDSD_MIPMAPCOUNT, 256, 64, 0, 4, 65279, { D3DXERR_INVALIDDATA, 0 } },
361 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDSD_MIPMAPCOUNT, 256, 64, 0, 4, 65280, { D3D_OK, 4 } },
362 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDSD_MIPMAPCOUNT, 256, 64, 0, 9, 65540, { D3DXERR_INVALIDDATA, 0 } },
363 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDSD_MIPMAPCOUNT, 256, 64, 0, 9, 65541, { D3D_OK, 9 } },
364 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 0, 196607, { D3DXERR_INVALIDDATA, 0 } },
365 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 0, 196608, { D3D_OK, 1 } },
366 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 0, 196609, { D3D_OK, 1 } },
367 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 1, 196607, { D3DXERR_INVALIDDATA, 0 } },
368 /* 30. */
369 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 1, 196608, { D3D_OK, 1 } },
370 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 0, 196607, { D3DXERR_INVALIDDATA, 0 } },
371 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 0, 196608, { D3D_OK, 1 } },
372 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 0, 400000, { D3D_OK, 1 } },
373 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 9, 262142, { D3DXERR_INVALIDDATA, 0 } },
374 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 9, 262143, { D3D_OK, 9 } },
375 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 10, 262145, { D3DXERR_INVALIDDATA, 0 } },
376 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 10, 262146, { D3D_OK, 10 } },
377 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 20, 262175, { D3DXERR_INVALIDDATA, 0 } },
378 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 20, 262176, { D3D_OK, 20 } },
379 /* 40. */
380 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, 0, 256, 256, 0, 0, 32767, { D3DXERR_INVALIDDATA, 0 } },
381 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, 0, 256, 256, 0, 0, 32768, { D3D_OK, 1 } },
382 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 0, 32767, { D3DXERR_INVALIDDATA, 0 } },
383 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 0, 32768, { D3D_OK, 1 } },
384 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 9, 43703, { D3DXERR_INVALIDDATA, 0 } },
385 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 9, 43704, { D3D_OK, 9 } },
386 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 20, 43791, { D3DXERR_INVALIDDATA, 0 } },
387 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 20, 43792, { D3D_OK, 20 } },
388 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, 0, 256, 256, 0, 0, 65535, { D3DXERR_INVALIDDATA, 0 } },
389 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, 0, 256, 256, 0, 0, 65536, { D3D_OK, 1 } },
390 /* 50. */
391 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 0, 65535, { D3DXERR_INVALIDDATA, 0 } },
392 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 0, 65536, { D3D_OK, 1 } },
393 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 9, 87407, { D3DXERR_INVALIDDATA, 0 } },
394 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 9, 87408, { D3D_OK, 9 } },
395 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 20, 87583, { D3DXERR_INVALIDDATA, 0 } },
396 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDSD_MIPMAPCOUNT, 256, 256, 0, 20, 87584, { D3D_OK, 20 } },
397 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDSD_MIPMAPCOUNT, 256, 64, 0, 4, 21759, { D3DXERR_INVALIDDATA, 0 } },
398 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDSD_MIPMAPCOUNT, 256, 64, 0, 4, 21760, { D3D_OK, 4 } },
399 /* DDSD_MIPMAPCOUNT is ignored */
400 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 0, 262146, { D3D_OK, 1 } },
401 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 2, 262146, { D3D_OK, 2 } },
402 /* 60. */
403 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 9, 262146, { D3D_OK, 9 } },
404 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 10, 262146, { D3D_OK, 10 } },
405 /* Packed formats. */
406 { { 32, DDS_PF_FOURCC, D3DFMT_R8G8_B8G8, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (4 * 3 * 2), { D3D_OK, 1 } },
407 { { 32, DDS_PF_FOURCC, D3DFMT_G8R8_G8B8, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (4 * 3 * 2), { D3D_OK, 1 } },
408 { { 32, DDS_PF_FOURCC, D3DFMT_UYVY, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (4 * 3 * 2), { D3D_OK, 1 } },
409 { { 32, DDS_PF_FOURCC, D3DFMT_YUY2, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (4 * 3 * 2), { D3D_OK, 1 } },
410 /* Uneven height/width is supported, but pixel size must align. */
411 { { 32, DDS_PF_FOURCC, D3DFMT_R8G8_B8G8, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (3 * 3 * 2), { D3DXERR_INVALIDDATA, 0 } },
412 { { 32, DDS_PF_FOURCC, D3DFMT_G8R8_G8B8, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (3 * 3 * 2), { D3DXERR_INVALIDDATA, 0 } },
413 /* 70. */
414 { { 32, DDS_PF_FOURCC, D3DFMT_R8G8_B8G8, 0, 0, 0, 0, 0 }, 0, 4, 3, 4, 1, (4 * 3 * 2), { D3D_OK, 1 } },
415 { { 32, DDS_PF_FOURCC, D3DFMT_G8R8_G8B8, 0, 0, 0, 0, 0 }, 0, 4, 3, 4, 1, (4 * 3 * 2), { D3D_OK, 1 } },
416 { { 32, DDS_PF_FOURCC, D3DFMT_UYVY, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (3 * 3 * 2), { D3DXERR_INVALIDDATA, 0 } },
417 { { 32, DDS_PF_FOURCC, D3DFMT_YUY2, 0, 0, 0, 0, 0 }, 0, 3, 3, 0, 0, (3 * 3 * 2), { D3DXERR_INVALIDDATA, 0 } },
418 { { 32, DDS_PF_FOURCC, D3DFMT_UYVY, 0, 0, 0, 0, 0 }, 0, 4, 3, 4, 1, (4 * 3 * 2), { D3D_OK, 1 } },
419 { { 32, DDS_PF_FOURCC, D3DFMT_YUY2, 0, 0, 0, 0, 0 }, 0, 4, 3, 4, 1, (4 * 3 * 2), { D3D_OK, 1 } },
420 };
421 static const struct
422 {
427 uint32_t row_pitch;
428 uint32_t mip_levels;
429 uint32_t caps;
430 uint32_t caps2;
431 struct
432 {
433 HRESULT hr;
437 uint32_t mip_levels;
438 D3DRESOURCETYPE resource_type;
439 }
440 expected;
441 uint32_t pixel_data_size;
442 BOOL todo_hr;
443 BOOL todo_info;
444 } info_tests[] = {
445 /* Depth value set to 4, but no caps bits are set. Depth is ignored. */
446 { (DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT), 4, 4, 4, (4 * 4), 3, 0, 0,
447 { D3D_OK, 4, 4, 1, 3, D3DRTYPE_TEXTURE, }, 292 },
448 /* The volume texture caps2 field is ignored. */
449 { (DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT), 4, 4, 4, (4 * 4), 3,
451 { D3D_OK, 4, 4, 1, 3, D3DRTYPE_TEXTURE, }, 292 },
452 /*
453 * The DDSD_DEPTH flag is the only thing checked to determine if a DDS
454 * file represents a volume texture.
455 */
456 { (DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_DEPTH), 4, 4, 4, (4 * 4), 3,
457 0, 0,
458 { D3D_OK, 4, 4, 4, 3, D3DRTYPE_VOLUMETEXTURE, }, 292 },
459 /* Even if the depth field is set to 0, it's still a volume texture. */
460 { (DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_DEPTH), 4, 4, 0, (4 * 4), 3,
461 0, 0,
462 { D3D_OK, 4, 4, 1, 3, D3DRTYPE_VOLUMETEXTURE, }, 292 },
463 /* The DDSD_DEPTH flag overrides cubemap caps. */
464 { (DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_DEPTH), 4, 4, 4, (4 * 4), 3,
466 { D3D_OK, 4, 4, 4, 3, D3DRTYPE_VOLUMETEXTURE, }, (292 * 6) },
467 /* Cubemap where width field does not equal height. */
468 { (DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT), 4, 5, 1, (4 * 4), 1,
470 { D3D_OK, 4, 5, 1, 1, D3DRTYPE_CUBETEXTURE, }, (80 * 6) },
471 /* Partial cubemaps are not supported. */
472 { (DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT), 4, 4, 1, (4 * 4), 1,
474 { D3DXERR_INVALIDDATA, }, (64 * 6) },
475 };
476
477 dds = calloc(1, sizeof(*dds));
478 if (!dds)
479 {
480 skip("Failed to allocate memory.\n");
481 return;
482 }
483
484 for (i = 0; i < ARRAY_SIZE(tests); i++)
485 {
486 DWORD file_size = sizeof(dds->magic) + sizeof(dds->header) + tests[i].pixel_data_size;
487 assert(file_size <= sizeof(*dds));
488
489 winetest_push_context("Test %u", i);
490 dds->magic = MAKEFOURCC('D','D','S',' ');
491 fill_dds_header(&dds->header);
492 dds->header.flags |= tests[i].flags;
493 dds->header.width = tests[i].width;
494 dds->header.height = tests[i].height;
495 dds->header.pitch_or_linear_size = tests[i].pitch;
496 dds->header.miplevels = tests[i].miplevels;
497 dds->header.pixel_format = tests[i].pixel_format;
498
500 todo_wine_if(tests[i].expected.todo) ok(hr == tests[i].expected.hr, "Unexpected hr %#lx, expected %#lx.\n",
501 hr, tests[i].expected.hr);
502 if (SUCCEEDED(hr))
503 {
504 ok(info.MipLevels == tests[i].expected.miplevels, "Unexpected MipLevels %u, expected %u.\n",
505 info.MipLevels, tests[i].expected.miplevels);
506 }
508 }
509
510 for (i = 0; i < ARRAY_SIZE(info_tests); i++)
511 {
512 uint32_t file_size = sizeof(dds->magic) + sizeof(dds->header) + info_tests[i].pixel_data_size;
513 assert(file_size <= sizeof(*dds));
514
515 winetest_push_context("Test %u", i);
516 dds->magic = MAKEFOURCC('D','D','S',' ');
517 fill_dds_header(&dds->header);
518 dds->header.flags = info_tests[i].flags;
519 dds->header.width = info_tests[i].width;
520 dds->header.height = info_tests[i].height;
521 dds->header.depth = info_tests[i].depth;
522 dds->header.pitch_or_linear_size = info_tests[i].row_pitch;
523 dds->header.miplevels = info_tests[i].mip_levels;
524 dds->header.caps = info_tests[i].caps;
525 dds->header.caps2 = info_tests[i].caps2;
526
527 memset(&info, 0, sizeof(info));
529 todo_wine_if(info_tests[i].todo_hr) ok(hr == info_tests[i].expected.hr, "Unexpected hr %#lx.\n", hr);
530 if (SUCCEEDED(info_tests[i].expected.hr))
531 {
532 check_image_info(&info, info_tests[i].expected.width, info_tests[i].expected.height,
533 info_tests[i].expected.depth, info_tests[i].expected.mip_levels, D3DFMT_X8R8G8B8,
534 info_tests[i].expected.resource_type, D3DXIFF_DDS, info_tests[i].todo_info);
535 }
537 }
538
539 free(dds);
540}
enum _D3DRESOURCETYPE D3DRESOURCETYPE
#define free
Definition: debug_ros.c:5
#define DDSCAPS2_CUBEMAP
Definition: ddsformat.c:64
#define DDSCAPS2_VOLUME
Definition: ddsformat.c:65
unsigned int UINT
Definition: sysinfo.c:13
static struct test_info tests[]
static unsigned int file_size
Definition: regtests2xml.c:47
#define calloc
Definition: rosglue.h:14
#define DDSCAPS2_CUBEMAP_ALLFACES
Definition: ddraw.h:299
#define DDSD_PITCH
Definition: ddraw.h:213
#define DDSD_MIPMAPCOUNT
Definition: ddraw.h:223
#define DDSCAPS2_CUBEMAP_POSITIVEX
Definition: ddraw.h:293
#define DDSD_LINEARSIZE
Definition: ddraw.h:225
#define DDSD_DEPTH
Definition: ddraw.h:229
#define DDSCAPS_COMPLEX
Definition: ddraw.h:254

Referenced by test_D3DXGetImageInfo().

◆ test_dxt_premultiplied_alpha()

static void test_dxt_premultiplied_alpha ( IDirect3DDevice9 *  device)
static

Definition at line 1396 of file surface.c.

1397{
1398 static const uint32_t dxt_pma_decompressed_expected[] =
1399 {
1400 0x00000000, 0x22ffffff, 0x44ffffff, 0x66ffffff, 0x88f7f3f7, 0xaac5c2c5, 0xcca5a2a5, 0xff848284,
1401 0x00000000, 0x22ffffff, 0x44ffffff, 0x66ffffff, 0x88f7f3f7, 0xaac5c2c5, 0xcca5a2a5, 0xff848284,
1402 };
1403 static const uint32_t dxt_decompressed_expected[] =
1404 {
1405 0x00848284, 0x22848284, 0x44848284, 0x66848284, 0x88848284, 0xaa848284, 0xcc848284, 0xff848284,
1406 0x00848284, 0x22848284, 0x44848284, 0x66848284, 0x88848284, 0xaa848284, 0xcc848284, 0xff848284,
1407 };
1408 static const uint8_t dxt3_block[] =
1409 {
1410 0x20,0x64,0xa8,0xfc,0x20,0x64,0xa8,0xfc,0x10,0x84,0x10,0x84,0x00,0x00,0x00,0x00,
1411 };
1412 static const uint8_t dxt5_block[] =
1413 {
1414 0x22,0xcc,0x86,0xc6,0xe6,0x86,0xc6,0xe6,0x10,0x84,0x10,0x84,0x00,0x00,0x00,0x00,
1415 };
1416 static const uint32_t test_compress_pixels[] =
1417 {
1418 0xffffffff, 0x00ffffff, 0xffffffff, 0x00ffffff, 0xffffffff, 0x00ffffff, 0xffffffff, 0x00ffffff,
1419 0xffffffff, 0x00ffffff, 0xffffffff, 0x00ffffff, 0xffffffff, 0x00ffffff, 0xffffffff, 0x00ffffff,
1420 };
1421 static const struct test
1422 {
1423 D3DFORMAT pma_fmt;
1424 D3DFORMAT nonpma_fmt;
1425 const uint8_t *dxt_block;
1426 const char *name;
1427 } tests[] =
1428 {
1429 { D3DFMT_DXT2, D3DFMT_DXT3, dxt3_block, "DXT2 / DXT3" },
1430 { D3DFMT_DXT4, D3DFMT_DXT5, dxt5_block, "DXT4 / DXT5" },
1431 };
1432 static const RECT src_rect = { 0, 0, 4, 4 };
1433 IDirect3DSurface9 *decomp_surf;
1434 D3DLOCKED_RECT lock_rect;
1435 uint32_t i, x, y;
1436 HRESULT hr;
1437
1439 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
1440 for (i = 0; i < ARRAY_SIZE(tests); ++i)
1441 {
1442 struct surface_readback surface_rb;
1443 IDirect3DSurface9 *pma_surf, *surf;
1444 IDirect3DTexture9 *pma_tex, *tex;
1445
1446 winetest_push_context("Test %s", tests[i].name);
1447 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, tests[i].pma_fmt, D3DPOOL_SYSTEMMEM, &pma_tex, NULL);
1448 if (FAILED(hr))
1449 {
1450 skip("Failed to create texture for format %#x, hr %#lx.\n", tests[i].pma_fmt, hr);
1452 continue;
1453 }
1454
1455 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, tests[i].nonpma_fmt, D3DPOOL_SYSTEMMEM, &tex, NULL);
1456 if (FAILED(hr))
1457 {
1458 skip("Failed to create texture for format %#x, hr %#lx.\n", tests[i].nonpma_fmt, hr);
1461 continue;
1462 }
1463
1464 hr = IDirect3DTexture9_GetSurfaceLevel(pma_tex, 0, &pma_surf);
1465 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
1466
1467 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &surf);
1468 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
1469
1470 /* Compress and load the same image onto each DXT surface. */
1471 hr = D3DXLoadSurfaceFromMemory(pma_surf, NULL, NULL, test_compress_pixels, D3DFMT_A8B8G8R8, 16, NULL, &src_rect, D3DX_FILTER_NONE, 0);
1472 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
1473
1474 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, test_compress_pixels, D3DFMT_A8B8G8R8, 16, NULL, &src_rect, D3DX_FILTER_NONE, 0);
1475 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
1476
1477 /*
1478 * For DXT2/DXT4, the source image has all of its color channels
1479 * premultiplied by the alpha value prior to compression. If the
1480 * alpha channel's value is 0, then the color channel values are
1481 * lost.
1482 */
1483 get_surface_decompressed_readback(device, pma_surf, &surface_rb);
1484 for (y = 0; y < 4; ++y)
1485 {
1486 for (x = 0; x < 4; ++x)
1487 {
1488 const uint32_t expected_pixel = !(x & 0x01) ? 0xffffffff : 0x00000000;
1489
1490 check_readback_pixel_4bpp(&surface_rb, x, y, expected_pixel, !expected_pixel);
1491 }
1492 }
1493 release_surface_readback(&surface_rb);
1494
1495 /* For DXT3/DXT5, no premultiplication by the alpha channel value is done. */
1496 get_surface_decompressed_readback(device, surf, &surface_rb);
1497 for (y = 0; y < 4; ++y)
1498 {
1499 for (x = 0; x < 4; ++x)
1500 check_readback_pixel_4bpp(&surface_rb, x, y, test_compress_pixels[(y * 4) + x], FALSE);
1501 }
1502 release_surface_readback(&surface_rb);
1503
1504 /*
1505 * Load our test DXT block with the premultiplied alpha DXT format.
1506 * The block is decompressed, and then the premultiplied alpha
1507 * operation is undone prior to being copied to the destination
1508 * surface.
1509 */
1510 hr = D3DXLoadSurfaceFromMemory(decomp_surf, NULL, NULL, tests[i].dxt_block, tests[i].pma_fmt, 16, NULL, &src_rect, D3DX_FILTER_NONE, 0);
1511 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
1512 IDirect3DSurface9_LockRect(decomp_surf, &lock_rect, NULL, D3DLOCK_READONLY);
1513 for (y = 0; y < 4; ++y)
1514 {
1515 for (x = 0; x < 4; ++x)
1516 {
1517 const uint32_t expected_pixel = dxt_pma_decompressed_expected[(y * 4) + x];
1518 const BOOL todo = ((expected_pixel >> 24) & 0xff) != 0xff;
1519
1520 todo_wine_if(todo) check_pixel_4bpp(&lock_rect, x, y, expected_pixel);
1521 }
1522 }
1523 IDirect3DSurface9_UnlockRect(decomp_surf);
1524
1525 /*
1526 * Load our test DXT block as a non-premultiplied alpha DXT format.
1527 * The block is decompressed, and the data is copied over directly.
1528 */
1529 hr = D3DXLoadSurfaceFromMemory(decomp_surf, NULL, NULL, tests[i].dxt_block, tests[i].nonpma_fmt, 16, NULL, &src_rect, D3DX_FILTER_NONE, 0);
1530 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
1531 IDirect3DSurface9_LockRect(decomp_surf, &lock_rect, NULL, D3DLOCK_READONLY);
1532 for (y = 0; y < 4; ++y)
1533 {
1534 for (x = 0; x < 4; ++x)
1535 check_pixel_4bpp(&lock_rect, x, y, dxt_decompressed_expected[(y * 4) + x]);
1536 }
1537 IDirect3DSurface9_UnlockRect(decomp_surf);
1538
1539 IDirect3DSurface9_Release(pma_surf);
1544 }
1545 IDirect3DSurface9_Release(decomp_surf);
1546}
enum _D3DFORMAT D3DFORMAT
#define test
Definition: rosglue.h:37
Definition: name.c:39

Referenced by test_D3DXLoadSurface().

◆ test_format_conversion()

static void test_format_conversion ( IDirect3DDevice9 *  device)
static

Definition at line 1317 of file surface.c.

1318{
1319 struct
1320 {
1321 D3DFORMAT src_format;
1322 const PALETTEENTRY *src_palette;
1323 const RECT src_rect;
1324 const void *src_data;
1325
1327 const void *expected_dst_data;
1328 BOOL todo;
1329 } tests[] = {
1337 };
1338 uint32_t i;
1339
1340 for (i = 0; i < ARRAY_SIZE(tests); ++i)
1341 {
1342 IDirect3DTexture9 *tex;
1343 HRESULT hr;
1344
1345 winetest_push_context("Test %u", i);
1346 hr = IDirect3DDevice9_CreateTexture(device, tests[i].src_rect.right, tests[i].src_rect.bottom, 1, 0,
1347 tests[i].dst_format, D3DPOOL_MANAGED, &tex, NULL);
1348 if (SUCCEEDED(hr))
1349 {
1350 const uint32_t src_pitch = get_bpp_for_d3dformat(tests[i].src_format) * tests[i].src_rect.right;
1351 const uint32_t dst_pitch = get_bpp_for_d3dformat(tests[i].dst_format) * tests[i].src_rect.right;
1352 IDirect3DSurface9 *surf;
1353
1354 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &surf);
1355 ok(hr == D3D_OK, "Failed to get the surface, hr %#lx.\n", hr);
1356
1357 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, tests[i].src_data, tests[i].src_format,
1358 src_pitch, tests[i].src_palette, &tests[i].src_rect, D3DX_FILTER_NONE, 0);
1359 todo_wine_if(tests[i].todo) ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
1360 if (SUCCEEDED(hr))
1361 {
1362 const uint32_t dst_fmt_bpp = get_bpp_for_d3dformat(tests[i].dst_format);
1363 D3DLOCKED_RECT lock_rect;
1364 uint32_t x, y;
1365
1367 for (y = 0; y < tests[i].src_rect.bottom; ++y)
1368 {
1369 const uint8_t *dst_expected_row = ((uint8_t *)tests[i].expected_dst_data) + (dst_pitch * y);
1370 const uint8_t *dst_row = ((uint8_t *)lock_rect.pBits) + (lock_rect.Pitch * y);
1371
1372 for (x = 0; x < tests[i].src_rect.right; ++x)
1373 {
1374 const uint8_t *dst_expected_pixel = dst_expected_row + (dst_fmt_bpp * x);
1375 const uint8_t *dst_pixel = dst_row + (dst_fmt_bpp * x);
1376 BOOL pixel_match = !memcmp(dst_pixel, dst_expected_pixel, dst_fmt_bpp);
1377
1378 todo_wine_if(tests[i].todo) ok(pixel_match, "Pixel mismatch at (%u,%u).\n", x, y);
1379 }
1380 }
1381
1383 }
1384
1385 check_release((IUnknown *)surf, 1);
1386 check_release((IUnknown *)tex, 0);
1387 }
1388 else
1389 {
1390 skip("Failed to create texture for format %d, hr %#lx.\n", tests[i].dst_format, hr);
1391 }
1393 }
1394}
static const uint8_t a8p8_2_2_expected[]
Definition: surface.c:1276
static const uint8_t v16u16_2_2_expected2[]
Definition: surface.c:1212
static const uint8_t v16u16_2_2_expected[]
Definition: surface.c:1207
static const uint8_t a16b16g16r16_2_2_expected[]
Definition: surface.c:1239
static const uint8_t v8u8_2_2_expected[]
Definition: surface.c:1225
static const uint8_t q16w16v16u16_2_2_expected[]
Definition: surface.c:1253
static const uint8_t p8_2_2[]
Definition: surface.c:1261
static const uint8_t p8_2_2_expected[]
Definition: surface.c:1266
static const uint16_t v16u16_2_2[]
Definition: surface.c:1202
static const uint8_t a8p8_2_2[]
Definition: surface.c:1271
static const uint16_t a16b16g16r16_2_2[]
Definition: surface.c:1233
static const uint16_t q16w16v16u16_2_2[]
Definition: surface.c:1247
static const PALETTEENTRY test_palette[256]
Definition: surface.c:1119
static const uint8_t v8u8_2_2[]
Definition: surface.c:1220
static const char * dst_format
Definition: dib.c:1339

Referenced by test_D3DXLoadSurface().

◆ test_load_surface_from_tga()

static void test_load_surface_from_tga ( IDirect3DDevice9 *  device)
static

Definition at line 1935 of file surface.c.

1936{
1937 static const struct
1938 {
1939 struct tga_header header;
1940 const uint8_t *color_map;
1941 uint32_t color_map_size;
1942 const uint8_t *pixels;
1943 uint32_t pixels_size;
1944
1945 const uint8_t *expected;
1946 } tga_tests[] =
1947 {
1948 { { 0, COLORMAP_TYPE_ONE, IMAGETYPE_COLORMAPPED, 0, 256, 15, 0, 0, 4, 4, 8, 0 },
1952 },
1953 { { 0, COLORMAP_TYPE_ONE, IMAGETYPE_COLORMAPPED | IMAGETYPE_RLE, 0, 256, 15, 0, 0, 4, 4, 8, 0 },
1957 },
1958 { { 0, COLORMAP_TYPE_ONE, IMAGETYPE_COLORMAPPED, 0, 256, 16, 0, 0, 4, 4, 8, 0 },
1962 },
1963 { { 0, COLORMAP_TYPE_ONE, IMAGETYPE_COLORMAPPED, 0, 256, 24, 0, 0, 4, 4, 8, 0 },
1967 },
1968 { { 0, COLORMAP_TYPE_ONE, IMAGETYPE_COLORMAPPED, 0, 256, 32, 0, 0, 4, 4, 8, 0 },
1972 },
1973 { { 0, COLORMAP_TYPE_ONE, IMAGETYPE_COLORMAPPED, 0, 128, 32, 0, 0, 4, 4, 8, 0 },
1977 },
1978 { { 0, COLORMAP_TYPE_NONE, IMAGETYPE_TRUECOLOR, 0, 0, 0, 0, 0, 4, 4, 15, 0 },
1979 NULL, 0,
1982 },
1983 { { 0, COLORMAP_TYPE_NONE, IMAGETYPE_TRUECOLOR | IMAGETYPE_RLE, 0, 0, 0, 0, 0, 4, 4, 15, 0 },
1984 NULL, 0,
1987 },
1988 { { 0, COLORMAP_TYPE_NONE, IMAGETYPE_TRUECOLOR, 0, 0, 0, 0, 0, 4, 4, 16, 0 },
1989 NULL, 0,
1992 },
1993 { { 0, COLORMAP_TYPE_NONE, IMAGETYPE_TRUECOLOR | IMAGETYPE_RLE, 0, 0, 0, 0, 0, 4, 4, 16, 0 },
1994 NULL, 0,
1997 },
1998 { { 0, COLORMAP_TYPE_NONE, IMAGETYPE_TRUECOLOR, 0, 0, 0, 0, 0, 4, 4, 24, 0 },
1999 NULL, 0,
2002 },
2003 { { 0, COLORMAP_TYPE_NONE, IMAGETYPE_TRUECOLOR | IMAGETYPE_RLE, 0, 0, 0, 0, 0, 4, 4, 24, 0 },
2004 NULL, 0,
2007 },
2008 { { 0, COLORMAP_TYPE_NONE, IMAGETYPE_TRUECOLOR, 0, 0, 0, 0, 0, 4, 4, 32, 0 },
2009 NULL, 0,
2012 },
2013 { { 0, COLORMAP_TYPE_NONE, IMAGETYPE_TRUECOLOR | IMAGETYPE_RLE, 0, 0, 0, 0, 0, 4, 4, 32, 0 },
2014 NULL, 0,
2017 },
2018 { { 0, COLORMAP_TYPE_NONE, IMAGETYPE_GRAYSCALE, 0, 0, 0, 0, 0, 4, 4, 8, 0 },
2019 NULL, 0,
2022 },
2023 { { 0, COLORMAP_TYPE_NONE, IMAGETYPE_GRAYSCALE | IMAGETYPE_RLE, 0, 0, 0, 0, 0, 4, 4, 8, 0 },
2024 NULL, 0,
2027 },
2028 };
2029 static const uint8_t rle_test_bits[] = { 15, 16, 24, 32 };
2030 struct
2031 {
2032 struct tga_header header;
2033 uint8_t data[4096 * 1024];
2034 } *tga;
2035 IDirect3DSurface9 *surface;
2036 unsigned int i;
2037 HRESULT hr;
2038
2039 if (!(tga = calloc(1, sizeof(*tga))))
2040 {
2041 skip("Failed to allocate memory.\n");
2042 return;
2043 }
2044
2045 for (i = 0; i < ARRAY_SIZE(tga_tests); ++i)
2046 {
2047 const uint32_t file_size = sizeof(tga->header) + tga_tests[i].color_map_size + tga_tests[i].pixels_size;
2048 D3DFORMAT surface_fmt;
2050
2051 winetest_push_context("Test %u", i);
2052
2053 tga->header = tga_tests[i].header;
2054 if (tga_tests[i].color_map)
2055 memcpy(tga->data, tga_tests[i].color_map, tga_tests[i].color_map_size);
2056 memcpy(tga->data + tga_tests[i].color_map_size, tga_tests[i].pixels, tga_tests[i].pixels_size);
2057
2059 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
2060 surface_fmt = (info.Format == D3DFMT_P8) ? D3DFMT_A8B8G8R8 : info.Format;
2061
2063 &surface, NULL);
2064 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
2065
2066 /*
2067 * Unlike D3DXGetImageInfo*() which only validates header size, the
2068 * size of the image data is also validated when loading into a surface.
2069 */
2071 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
2072
2074 ok(hr == D3DXERR_INVALIDDATA, "Unexpected hr %#lx.\n", hr);
2075
2076 /* Read as default, bottom to top, left to right. */
2078 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
2079 check_tga_surface_load(surface, tga_tests[i].expected, FALSE, TRUE);
2080
2081 /* Read as top to bottom, left to right. */
2082 tga->header.image_descriptor = IMAGE_TOPTOBOTTOM;
2084 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
2085 check_tga_surface_load(surface, tga_tests[i].expected, FALSE, FALSE);
2086
2087 /* Read as bottom to top, right to left. */
2088 tga->header.image_descriptor = IMAGE_RIGHTTOLEFT;
2090 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
2091 check_tga_surface_load(surface, tga_tests[i].expected, TRUE, TRUE);
2092
2093 /* Read as top to bottom, right to left. */
2094 tga->header.image_descriptor = IMAGE_TOPTOBOTTOM | IMAGE_RIGHTTOLEFT;
2096 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
2097 check_tga_surface_load(surface, tga_tests[i].expected, TRUE, FALSE);
2098
2099 check_release((IUnknown *)surface, 0);
2101 }
2102
2103 /*
2104 * Test RLE behavior. RLE packets cannot cross row boundaries.
2105 */
2106 for (i = 0; i < ARRAY_SIZE(rle_test_bits); ++i)
2107 {
2108 const struct tga_header rle_hdr = { 0, COLORMAP_TYPE_NONE, IMAGETYPE_TRUECOLOR | IMAGETYPE_RLE, 0, 0, 0, 0, 0,
2109 4, 2, rle_test_bits[i], IMAGE_TOPTOBOTTOM };
2110 const uint32_t packet_size = ((rle_test_bits[i] + 7) / 8) + 1;
2111 uint32_t file_size = sizeof(tga->header);
2112 D3DFORMAT surface_fmt;
2114
2115 winetest_push_context("Test %u", i);
2116
2117 memset(tga->data, 0, sizeof(tga->data));
2118 tga->header = rle_hdr;
2119
2121 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
2122 surface_fmt = info.Format;
2123
2125 &surface, NULL);
2126 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
2127
2128 /*
2129 * This packet encodes 8 pixels, but the image has a width of 4. This
2130 * should fail.
2131 */
2132 tga->data[0] = 0x87;
2133 file_size += packet_size;
2135 ok(hr == D3DXERR_INVALIDDATA, "Unexpected hr %#lx.\n", hr);
2136
2137 /* Two packets, each containing 4 pixels. This succeeds. */
2138 tga->data[0] = 0x83;
2139 tga->data[packet_size] = 0x83;
2140 file_size += packet_size;
2141
2143 ok(hr == D3D_OK, "Unexpected hr %#lx.\n", hr);
2144
2145 /* Second packet with only 2 pixels, doesn't finish the final row. */
2146 tga->data[packet_size] = 0x82;
2148 ok(hr == D3DXERR_INVALIDDATA, "Unexpected hr %#lx.\n", hr);
2149
2150 check_release((IUnknown *)surface, 0);
2152 }
2153
2154 free(tga);
2155}
#define IMAGETYPE_COLORMAPPED
Definition: surface.c:1088
#define IMAGE_RIGHTTOLEFT
Definition: surface.c:1094
#define IMAGE_TOPTOBOTTOM
Definition: surface.c:1095
#define IMAGETYPE_GRAYSCALE
Definition: surface.c:1090
#define IMAGETYPE_RLE
Definition: surface.c:1092
#define IMAGETYPE_TRUECOLOR
Definition: surface.c:1089
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static const uint8_t test_tga_color_map_15bpp_rle_expected[]
Definition: surface.c:1828
static const uint8_t test_tga_color_map_32bpp_expected[]
Definition: surface.c:1852
static const uint8_t test_tga_color_map_index_4_4[]
Definition: surface.c:1740
static const uint8_t test_tga_grayscale_8bpp_4_4_rle[]
Definition: surface.c:1813
static const uint8_t test_tga_true_color_24bpp_4_4[]
Definition: surface.c:1776
static const uint8_t test_tga_true_color_16bpp_rle_expected[]
Definition: surface.c:1874
static const uint8_t test_tga_grayscale_8bpp_rle_expected[]
Definition: surface.c:1895
static const uint8_t test_tga_true_color_16bpp_4_4_rle[]
Definition: surface.c:1769
static const uint8_t test_tga_color_map_16bpp[]
Definition: surface.c:1584
#define COLORMAP_TYPE_NONE
Definition: surface.c:542
static const uint8_t test_tga_color_map_half_32bpp_expected[]
Definition: surface.c:1860
static const uint8_t test_tga_color_map_15bpp_expected[]
Definition: surface.c:1820
static const uint8_t test_tga_true_color_24bpp_rle_expected[]
Definition: surface.c:1880
static const uint8_t test_tga_true_color_32bpp_rle_expected[]
Definition: surface.c:1887
static const uint8_t test_tga_color_map_32bpp[]
Definition: surface.c:1672
static const uint8_t test_tga_color_map_24bpp[]
Definition: surface.c:1620
static const uint8_t test_tga_true_color_15bpp_4_4_rle[]
Definition: surface.c:1756
static const uint8_t test_tga_color_map_24bpp_expected[]
Definition: surface.c:1844
static const uint8_t test_tga_true_color_32bpp_4_4[]
Definition: surface.c:1791
#define COLORMAP_TYPE_ONE
Definition: surface.c:543
static const uint8_t test_tga_true_color_24bpp_4_4_rle[]
Definition: surface.c:1783
static const uint8_t test_tga_color_map_index_4_4_rle[]
Definition: surface.c:1745
static const uint8_t test_tga_grayscale_8bpp_4_4[]
Definition: surface.c:1808
static const uint8_t test_tga_true_color_15bpp_rle_expected[]
Definition: surface.c:1868
static const uint8_t test_tga_true_color_16bpp_4_4[]
Definition: surface.c:1763
static const uint8_t test_tga_color_map_15bpp[]
Definition: surface.c:1548
static const uint8_t test_tga_color_map_16bpp_expected[]
Definition: surface.c:1836
#define check_tga_surface_load(surface, expected, right_to_left, bottom_to_top)
Definition: surface.c:1900
static const uint8_t test_tga_true_color_32bpp_4_4_rle[]
Definition: surface.c:1799
static const uint8_t test_tga_true_color_15bpp_4_4[]
Definition: surface.c:1750

Referenced by test_D3DXLoadSurface().

◆ test_save_surface_to_dds()

static void test_save_surface_to_dds ( IDirect3DDevice9 *  device)
static

Definition at line 3506 of file surface.c.

3507{
3508 struct expected
3509 {
3510 HRESULT hr;
3515 uint32_t pitch;
3517 uint32_t mip_levels;
3518 uint32_t caps;
3519 uint32_t caps2;
3521 };
3522 static const struct
3523 {
3527 const PALETTEENTRY *palette;
3528 struct expected expected_vals;
3529 BOOL todo_hr;
3530 BOOL todo_expected;
3531 } dds_tests[] =
3532 {
3533 { D3DFMT_P8, 4, 4, test_palette,
3534 { D3D_OK, { 32, DDS_PF_INDEXED, 0, 8, 0, 0, 0, 0 },
3537 }
3538 },
3539 { D3DFMT_A8P8, 4, 4, test_palette,
3540 { D3D_OK, { 32, DDS_PF_INDEXED | DDS_PF_ALPHA, 0, 16, 0, 0, 0, 0xff00 },
3541 DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT, 4, 4, 0, 0, 0,
3543 PALETTED_DDS_FILE_HEADER_SIZE + (4 * 2 * 4)
3544 }
3545 },
3546 /* If a palette isn't provided, d3dx converts to D3DFMT_A8R8G8B8. */
3547 { D3DFMT_P8, 4, 4, NULL,
3548 { D3D_OK, { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 },
3550 DDS_FILE_HEADER_SIZE + (4 * 4 * 4)
3551 }, .todo_hr = TRUE
3552 },
3553 { D3DFMT_A8P8, 4, 4, NULL,
3554 { D3D_OK, { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 },
3556 DDS_FILE_HEADER_SIZE + (4 * 4 * 4)
3557 }, .todo_hr = TRUE
3558 },
3559 { D3DFMT_V8U8, 4, 4, NULL,
3560 { D3D_OK, { 32, DDS_PF_BUMPDUDV, 0, 16, 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000 },
3562 DDS_FILE_HEADER_SIZE + (4 * 2 * 4)
3563 }
3564 },
3565 { D3DFMT_V16U16, 4, 4, NULL,
3566 { D3D_OK, { 32, DDS_PF_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000 },
3568 DDS_FILE_HEADER_SIZE + (4 * 4 * 4)
3569 }
3570 },
3571 { D3DFMT_Q8W8V8U8, 4, 4, NULL,
3572 { D3D_OK, { 32, DDS_PF_BUMPDUDV, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 },
3574 DDS_FILE_HEADER_SIZE + (4 * 4 * 4)
3575 }
3576 },
3577 { D3DFMT_A2W10V10U10, 4, 4, NULL,
3578 { D3D_OK, { 32, DDS_PF_BUMPDUDV | DDS_PF_ALPHA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000 },
3580 DDS_FILE_HEADER_SIZE + (4 * 4 * 4)
3581 }
3582 },
3583 { D3DFMT_X8L8V8U8, 4, 4, NULL,
3584 { D3D_OK, { 32, DDS_PF_BUMPLUMINANCE, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000 },
3586 DDS_FILE_HEADER_SIZE + (4 * 4 * 4)
3587 }
3588 },
3589 { D3DFMT_R5G6B5, 4, 4, NULL,
3590 { D3D_OK, { 32, DDS_PF_RGB, 0, 16, 0xf800, 0x07e0, 0x001f, 0 },
3592 DDS_FILE_HEADER_SIZE + (4 * 2 * 4)
3593 }
3594 },
3595 /* 10. */
3596 { D3DFMT_A1R5G5B5, 4, 4, NULL,
3597 { D3D_OK, { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x8000 },
3599 DDS_FILE_HEADER_SIZE + (4 * 2 * 4)
3600 }
3601 },
3602 { D3DFMT_A4R4G4B4, 4, 4, NULL,
3603 { D3D_OK, { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x0f00, 0x00f0, 0x000f, 0xf000 },
3605 DDS_FILE_HEADER_SIZE + (4 * 2 * 4)
3606 }
3607 },
3608 { D3DFMT_R3G3B2, 4, 4, NULL,
3609 { D3D_OK, { 32, DDS_PF_RGB, 0, 8, 0xe0, 0x1c, 0x03, 0 },
3611 DDS_FILE_HEADER_SIZE + (4 * 4)
3612 }
3613 },
3614 { D3DFMT_A8R3G3B2, 4, 4, NULL,
3615 { D3D_OK, { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x00e0, 0x001c, 0x0003, 0xff00 },
3617 DDS_FILE_HEADER_SIZE + (4 * 2 * 4)
3618 }
3619 },
3620 { D3DFMT_X4R4G4B4, 4, 4, NULL,
3621 { D3D_OK, { 32, DDS_PF_RGB, 0, 16, 0xf00, 0x0f0, 0x00f, 0 },
3623 DDS_FILE_HEADER_SIZE + (4 * 2 * 4)
3624 }
3625 },
3626 { D3DFMT_A2B10G10R10, 4, 4, NULL,
3627 { D3D_OK, { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000 },
3629 DDS_FILE_HEADER_SIZE + (4 * 4 * 4)
3630 }
3631 },
3632 { D3DFMT_A2R10G10B10, 4, 4, NULL,
3633 { D3D_OK, { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000 },
3635 DDS_FILE_HEADER_SIZE + (4 * 4 * 4)
3636 }
3637 },
3638 { D3DFMT_A8R8G8B8, 4, 4, NULL,
3639 { D3D_OK, { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 },
3641 DDS_FILE_HEADER_SIZE + (4 * 4 * 4)
3642 }
3643 },
3644 { D3DFMT_A8B8G8R8, 4, 4, NULL,
3645 { D3D_OK, { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 },
3647 DDS_FILE_HEADER_SIZE + (4 * 4 * 4)
3648 }
3649 },
3650 { D3DFMT_X8R8G8B8, 4, 4, NULL,
3651 { D3D_OK, { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 },
3653 DDS_FILE_HEADER_SIZE + (4 * 4 * 4)
3654 }
3655 },
3656 /* 20. */
3657 { D3DFMT_X8B8G8R8, 4, 4, NULL,
3658 { D3D_OK, { 32, DDS_PF_RGB, 0, 32, 0x0000ff, 0x00ff00, 0xff0000, 0 },
3660 DDS_FILE_HEADER_SIZE + (4 * 4 * 4)
3661 }
3662 },
3663 { D3DFMT_R8G8B8, 4, 4, NULL,
3664 { D3D_OK, { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0 },
3666 DDS_FILE_HEADER_SIZE + (4 * 3 * 4)
3667 }
3668 },
3669 { D3DFMT_G16R16, 4, 4, NULL,
3670 { D3D_OK, { 32, DDS_PF_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0, 0 },
3672 DDS_FILE_HEADER_SIZE + (4 * 4 * 4)
3673 }
3674 },
3675 { D3DFMT_A8, 4, 4, NULL,
3676 { D3D_OK, { 32, DDS_PF_ALPHA_ONLY, 0, 8, 0, 0, 0, 0xff },
3678 DDS_FILE_HEADER_SIZE + (4 * 4)
3679 }
3680 },
3681 { D3DFMT_DXT1, 4, 4, NULL,
3682 { D3D_OK, { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 },
3685 }
3686 },
3687 { D3DFMT_DXT2, 4, 4, NULL,
3688 { D3D_OK, { 32, DDS_PF_FOURCC, D3DFMT_DXT2, 0, 0, 0, 0, 0 },
3691 }
3692 },
3693 { D3DFMT_DXT3, 4, 4, NULL,
3694 { D3D_OK, { 32, DDS_PF_FOURCC, D3DFMT_DXT3, 0, 0, 0, 0, 0 },
3697 }
3698 },
3699 { D3DFMT_DXT4, 4, 4, NULL,
3700 { D3D_OK, { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 },
3703 }
3704 },
3705 { D3DFMT_DXT5, 4, 4, NULL,
3706 { D3D_OK, { 32, DDS_PF_FOURCC, D3DFMT_DXT5, 0, 0, 0, 0, 0 },
3709 }
3710 },
3711 { D3DFMT_A16B16G16R16, 4, 4, NULL,
3712 { D3D_OK, { 32, DDS_PF_FOURCC, D3DFMT_A16B16G16R16, 0, 0, 0, 0, 0 },
3714 DDS_FILE_HEADER_SIZE + (4 * 8 * 4)
3715 }
3716 },
3717 /* 30. */
3718 { D3DFMT_Q16W16V16U16, 4, 4, NULL,
3719 { D3D_OK, { 32, DDS_PF_FOURCC, D3DFMT_Q16W16V16U16, 0, 0, 0, 0, 0 },
3721 DDS_FILE_HEADER_SIZE + (4 * 8 * 4)
3722 }
3723 },
3724 { D3DFMT_R16F, 4, 4, NULL,
3725 { D3D_OK, { 32, DDS_PF_FOURCC, D3DFMT_R16F, 0, 0, 0, 0, 0 },
3727 DDS_FILE_HEADER_SIZE + (4 * 2 * 4)
3728 }
3729 },
3730 { D3DFMT_G16R16F, 4, 4, NULL,
3731 { D3D_OK, { 32, DDS_PF_FOURCC, D3DFMT_G16R16F, 0, 0, 0, 0, 0 },
3733 DDS_FILE_HEADER_SIZE + (4 * 4 * 4)
3734 }
3735 },
3736 { D3DFMT_A16B16G16R16F, 4, 4, NULL,
3737 { D3D_OK, { 32, DDS_PF_FOURCC, D3DFMT_A16B16G16R16F, 0, 0, 0, 0, 0 },
3739 DDS_FILE_HEADER_SIZE + (4 * 8 * 4)
3740 }
3741 },
3742 { D3DFMT_R32F, 4, 4, NULL,
3743 { D3D_OK, { 32, DDS_PF_FOURCC, D3DFMT_R32F, 0, 0, 0, 0, 0 },
3745 DDS_FILE_HEADER_SIZE + (4 * 4 * 4)
3746 }
3747 },
3748 { D3DFMT_G32R32F, 4, 4, NULL,
3749 { D3D_OK, { 32, DDS_PF_FOURCC, D3DFMT_G32R32F, 0, 0, 0, 0, 0 },
3751 DDS_FILE_HEADER_SIZE + (4 * 8 * 4)
3752 }
3753 },
3754 { D3DFMT_A32B32G32R32F, 4, 4, NULL,
3755 { D3D_OK, { 32, DDS_PF_FOURCC, D3DFMT_A32B32G32R32F, 0, 0, 0, 0, 0 },
3757 DDS_FILE_HEADER_SIZE + (4 * 16 * 4)
3758 }
3759 },
3760 { D3DFMT_G8R8_G8B8, 4, 4, NULL,
3761 { D3D_OK, { 32, DDS_PF_FOURCC, D3DFMT_G8R8_G8B8, 0, 0, 0, 0, 0 },
3763 DDS_FILE_HEADER_SIZE + (4 * 2 * 4)
3764 }
3765 },
3766 { D3DFMT_R8G8_B8G8, 4, 4, NULL,
3767 { D3D_OK, { 32, DDS_PF_FOURCC, D3DFMT_R8G8_B8G8, 0, 0, 0, 0, 0 },
3769 DDS_FILE_HEADER_SIZE + (4 * 2 * 4)
3770 }
3771 },
3772 { D3DFMT_UYVY, 4, 4, NULL,
3773 { D3D_OK, { 32, DDS_PF_FOURCC, D3DFMT_UYVY, 0, 0, 0, 0, 0 },
3775 DDS_FILE_HEADER_SIZE + (4 * 2 * 4)
3776 }
3777 },
3778 /* 40. */
3779 { D3DFMT_YUY2, 4, 4, NULL,
3780 { D3D_OK, { 32, DDS_PF_FOURCC, D3DFMT_YUY2, 0, 0, 0, 0, 0 },
3782 DDS_FILE_HEADER_SIZE + (4 * 2 * 4)
3783 }
3784 },
3785 };
3786 struct
3787 {
3788 DWORD magic;
3789 struct dds_header header;
3790 BYTE *data;
3791 } *dds;
3792 IDirect3DSurface9 *surface;
3794 unsigned int i;
3795 HRESULT hr;
3796
3797 for (i = 0; i < ARRAY_SIZE(dds_tests); ++i)
3798 {
3799 const struct expected *expected = &dds_tests[i].expected_vals;
3800
3801 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, dds_tests[i].width, dds_tests[i].height, dds_tests[i].format,
3802 D3DPOOL_SCRATCH, &surface, NULL);
3803 if (FAILED(hr))
3804 {
3805 skip("Couldn't create surface for format %#x.\n", dds_tests[i].format);
3806 continue;
3807 }
3808
3809 winetest_push_context("Test %u", i);
3810 hr = D3DXSaveSurfaceToFileInMemory(&buffer, D3DXIFF_DDS, surface, dds_tests[i].palette, NULL);
3811 todo_wine_if(dds_tests[i].todo_hr) ok(hr == expected->hr, "Unexpected hr %#lx.\n", hr);
3812 if (SUCCEEDED(hr))
3813 {
3814 ok(ID3DXBuffer_GetBufferSize(buffer) == expected->buffer_size, "Unexpected buffer size %lu.\n",
3816
3818 check_dds_header(&dds->header, expected->flags, expected->height, expected->width, expected->pitch,
3819 expected->depth, expected->mip_levels, &expected->pixel_format, expected->caps, expected->caps2,
3820 dds_tests[i].todo_expected);
3822 }
3823
3826 }
3827}
#define DDSCAPS_PALETTE
Definition: surface.c:97
#define PALETTED_DDS_FILE_HEADER_SIZE
Definition: surface.c:3505
#define DDS_FILE_HEADER_SIZE
Definition: surface.c:3504
wchar_t const *const size_t const buffer_size
Definition: stat.cpp:95

Referenced by test_D3DXSaveSurfaceToFileInMemory().

◆ test_tga_header_handling()

static void test_tga_header_handling ( void  )
static

Definition at line 600 of file surface.c.

601{
602 static const struct
603 {
604 struct tga_header header;
605 struct
606 {
607 HRESULT hr;
611 } expected;
612 uint32_t extra_header_size;
613 } info_tests[] =
614 {
615 /* 15 bpp true color. */
616 { { 0, COLORMAP_TYPE_NONE, IMAGETYPE_TRUECOLOR, 0, 0, 0, 0, 0, 4, 4, 15, 0 },
617 { D3D_OK, 4, 4, D3DFMT_X1R5G5B5 }
618 },
619 /* 16 bpp true color. */
620 { { 0, COLORMAP_TYPE_NONE, IMAGETYPE_TRUECOLOR, 0, 0, 0, 0, 0, 4, 4, 16, 0 },
621 { D3D_OK, 4, 4, D3DFMT_A1R5G5B5 }
622 },
623 /* 24 bpp true color. */
624 { { 0, COLORMAP_TYPE_NONE, IMAGETYPE_TRUECOLOR, 0, 0, 0, 0, 0, 4, 4, 24, 0 },
625 { D3D_OK, 4, 4, D3DFMT_R8G8B8 }
626 },
627 /* 32 bpp true color. */
628 { { 0, COLORMAP_TYPE_NONE, IMAGETYPE_TRUECOLOR, 0, 0, 0, 0, 0, 4, 4, 32, 0 },
629 { D3D_OK, 4, 4, D3DFMT_A8R8G8B8 }
630 },
631 /* 8 bit paletted, 15 bpp palette. */
632 { { 0, COLORMAP_TYPE_ONE, IMAGETYPE_COLORMAPPED, 0, 256, 15, 0, 0, 4, 4, 8, 0 },
633 { D3D_OK, 4, 4, D3DFMT_P8 }, (256 * 2)
634 },
635 /* 8 bit paletted, 16 bpp palette. */
636 { { 0, COLORMAP_TYPE_ONE, IMAGETYPE_COLORMAPPED, 0, 256, 16, 0, 0, 4, 4, 8, 0 },
637 { D3D_OK, 4, 4, D3DFMT_P8 }, (256 * 2)
638 },
639 /* 8 bit paletted, 24 bpp palette. */
640 { { 0, COLORMAP_TYPE_ONE, IMAGETYPE_COLORMAPPED, 0, 256, 24, 0, 0, 4, 4, 8, 0 },
641 { D3D_OK, 4, 4, D3DFMT_P8 }, (256 * 3)
642 },
643 /* 8 bit paletted, 32 bpp palette. */
644 { { 0, COLORMAP_TYPE_ONE, IMAGETYPE_COLORMAPPED, 0, 256, 32, 0, 0, 4, 4, 8, 0 },
645 { D3D_OK, 4, 4, D3DFMT_P8 }, (256 * 4)
646 },
647 /* Grayscale, 8bpp. */
648 { { 0, COLORMAP_TYPE_NONE, IMAGETYPE_GRAYSCALE, 0, 0, 0, 0, 0, 4, 4, 8, 0 },
649 { D3D_OK, 4, 4, D3DFMT_L8 }
650 },
651 /* No 16-bit grayscale. */
652 { { 0, COLORMAP_TYPE_NONE, IMAGETYPE_GRAYSCALE, 0, 0, 0, 0, 0, 4, 4, 16, 0 },
654 },
655 };
656 struct
657 {
658 struct tga_header header;
659 uint8_t data[4096 * 1024];
660 } *tga;
661 struct tga_footer tmp_footer;
662 uint32_t i;
663
664 tga = calloc(1, sizeof(*tga));
665 if (!tga)
666 {
667 skip("Failed to allocate memory.\n");
668 return;
669 }
670
671 for (i = 0; i < ARRAY_SIZE(info_tests); i++)
672 {
673 uint32_t file_size = sizeof(tga->header) + info_tests[i].extra_header_size;
674 assert(file_size <= sizeof(*tga));
675
676 winetest_push_context("Test %u", i);
677
678 tga->header = info_tests[i].header;
679 check_tga_image_info(tga, file_size, info_tests[i].expected.width, info_tests[i].expected.height,
680 info_tests[i].expected.format, info_tests[i].expected.hr);
681
682 /* X/Y origin fields are ignored. */
683 tga->header.xorigin = tga->header.width + 1;
684 tga->header.yorigin = tga->header.height + 1;
685 check_tga_image_info(tga, file_size, info_tests[i].expected.width, info_tests[i].expected.height,
686 info_tests[i].expected.format, info_tests[i].expected.hr);
687
688 /* Image descriptor field is ignored. */
689 tga->header.image_descriptor = 0xcf;
690 check_tga_image_info(tga, file_size, info_tests[i].expected.width, info_tests[i].expected.height,
691 info_tests[i].expected.format, info_tests[i].expected.hr);
692
693 if (FAILED(info_tests[i].expected.hr))
694 goto next;
695
696 /*
697 * Footer offsets do not seem to be validated. Possible that footer
698 * isn't even checked for.
699 */
700 tmp_footer = default_tga_footer;
701 tmp_footer.extension_area_offset = 65536;
702 memcpy(&tga->data[info_tests[i].extra_header_size], &tmp_footer, sizeof(tmp_footer));
703 check_tga_image_info(tga, file_size + sizeof(tmp_footer), info_tests[i].expected.width, info_tests[i].expected.height,
704 info_tests[i].expected.format, info_tests[i].expected.hr);
705
706 /* Check RLE type. */
707 tga->header.image_type |= IMAGETYPE_RLE;
708 check_tga_image_info(tga, file_size, info_tests[i].expected.width, info_tests[i].expected.height,
709 info_tests[i].expected.format, info_tests[i].expected.hr);
710 tga->header.image_type &= ~IMAGETYPE_RLE;
711
712 if (tga->header.image_type == IMAGETYPE_COLORMAPPED)
713 goto next;
714
715 /*
716 * Even if the image isn't color mapped, the color map fields are used
717 * to validate header size.
718 */
719 tga->header.color_map_length = 1;
720 check_tga_image_info(tga, file_size, info_tests[i].expected.width, info_tests[i].expected.height,
721 info_tests[i].expected.format, info_tests[i].expected.hr);
722
723 tga->header.color_map_entrysize = 8;
725
726 /* Add a byte to file size to account for color map. */
727 check_tga_image_info(tga, file_size + 1, info_tests[i].expected.width, info_tests[i].expected.height,
728 info_tests[i].expected.format, info_tests[i].expected.hr);
729
730 /* ID length field is also considered. */
731 tga->header.id_length = 1;
733
734 /* Add another byte to file size to account for id length. */
735 check_tga_image_info(tga, file_size + 2, info_tests[i].expected.width, info_tests[i].expected.height,
736 info_tests[i].expected.format, info_tests[i].expected.hr);
737
738 /*
739 * If the color map type field is set but the color map fields
740 * result in a color map size of 0, header is considered invalid.
741 * Also, the entrysize value is now validated, e.g it must be 15,
742 * 16, 24, or 32.
743 */
744 tga->header.id_length = tga->header.color_map_entrysize = tga->header.color_map_length = 0;
745 tga->header.color_map_type = COLORMAP_TYPE_ONE;
747
748 /* 8 isn't a valid entry size. */
749 tga->header.color_map_entrysize = 8;
750 tga->header.color_map_length = 1;
752
753 /* 16 is a valid entry size. */
754 tga->header.color_map_entrysize = 16;
755 check_tga_image_info(tga, file_size + 2, info_tests[i].expected.width, info_tests[i].expected.height,
756 info_tests[i].expected.format, info_tests[i].expected.hr);
757
758 /* First entry doesn't factor into validation. */
759 tga->header.color_map_firstentry = 512;
760 check_tga_image_info(tga, file_size + 2, info_tests[i].expected.width, info_tests[i].expected.height,
761 info_tests[i].expected.format, info_tests[i].expected.hr);
762next:
764 }
765
766 free(tga);
767}
static const struct tga_footer default_tga_footer
Definition: surface.c:578
#define check_tga_image_info(tga, tga_size, expected_width, expected_height, expected_format, expected_hr)
Definition: surface.c:583
static unsigned __int64 next
Definition: rand_nt.c:6

Referenced by test_D3DXGetImageInfo().

Variable Documentation

◆ a16b16g16r16_2_2

const uint16_t a16b16g16r16_2_2[]
static
Initial value:
=
{
0x0000,0x1000,0x2000,0x3000,0x4000,0x5000,0x6000,0x7000,
0x8000,0x9000,0xa000,0xb000,0xc000,0xd000,0xe000,0xffff,
}

Definition at line 1233 of file surface.c.

Referenced by test_format_conversion().

◆ a16b16g16r16_2_2_expected

const uint8_t a16b16g16r16_2_2_expected[]
static
Initial value:
=
{
0x00,0x00,0x00,0x00,0x80,0x00,0x80,0x3d,0x80,0x00,0x00,0x3e,0xc0,0x00,0x40,0x3e,
0x80,0x00,0x80,0x3e,0xa0,0x00,0xa0,0x3e,0xc0,0x00,0xc0,0x3e,0xe0,0x00,0xe0,0x3e,
0x80,0x00,0x00,0x3f,0x90,0x00,0x10,0x3f,0xa0,0x00,0x20,0x3f,0xb0,0x00,0x30,0x3f,
0xc0,0x00,0x40,0x3f,0xd0,0x00,0x50,0x3f,0xe0,0x00,0x60,0x3f,0x00,0x00,0x80,0x3f,
}

Definition at line 1239 of file surface.c.

Referenced by test_format_conversion().

◆ a8p8_2_2

const uint8_t a8p8_2_2[]
static
Initial value:
=
{
0x00,0x10,0x40,0x20,0x80,0x30,0xff,0x40
}

Definition at line 1271 of file surface.c.

Referenced by test_format_conversion().

◆ a8p8_2_2_expected

const uint8_t a8p8_2_2_expected[]
static
Initial value:
=
{
0x00,0x00,0x00,0x10,0x00,0x00,0x40,0x20,0x00,0x00,0x80,0x30,0xff,0xff,0xff,0x40,
}

Definition at line 1276 of file surface.c.

Referenced by test_format_conversion().

◆ default_tga_footer

const struct tga_footer default_tga_footer
static
Initial value:
= {
0, 0,
{ 'T', 'R', 'U', 'E', 'V', 'I', 'S', 'I', 'O', 'N', '-', 'X', 'F', 'I', 'L', 'E', '.', 0 }
}

Definition at line 578 of file surface.c.

Referenced by test_tga_header_handling().

◆ p8_2_2

const uint8_t p8_2_2[]
static
Initial value:
=
{
0x00,0x40,0x80,0xff,
}

Definition at line 1261 of file surface.c.

Referenced by test_format_conversion().

◆ p8_2_2_expected

const uint8_t p8_2_2_expected[]
static
Initial value:
=
{
0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x00,0x00,0x80,0x80,0xff,0xff,0xff,0xff,
}

Definition at line 1266 of file surface.c.

Referenced by test_format_conversion().

◆ q16w16v16u16_2_2

const uint16_t q16w16v16u16_2_2[]
static
Initial value:
=
{
0x0000,0x1000,0x2000,0x3000,0x4000,0x5000,0x6000,0x7fff,
0x8000,0x8001,0xa000,0xb000,0xc000,0xd000,0xe000,0xffff,
}

Definition at line 1247 of file surface.c.

Referenced by test_format_conversion().

◆ q16w16v16u16_2_2_expected

const uint8_t q16w16v16u16_2_2_expected[]
static
Initial value:
=
{
0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x3e,0x00,0x01,0x80,0x3e,0x80,0x01,0xc0,0x3e,
0x00,0x01,0x00,0x3f,0x40,0x01,0x20,0x3f,0x80,0x01,0x40,0x3f,0x00,0x00,0x80,0x3f,
0x00,0x00,0x80,0xbf,0x00,0x00,0x80,0xbf,0x80,0x01,0x40,0xbf,0x40,0x01,0x20,0xbf,
0x00,0x01,0x00,0xbf,0x80,0x01,0xc0,0xbe,0x00,0x01,0x80,0xbe,0x00,0x01,0x00,0xb8,
}

Definition at line 1253 of file surface.c.

Referenced by test_format_conversion().

◆ test_palette

const PALETTEENTRY test_palette[256] ( void  )
static

Definition at line 1119 of file surface.c.

Referenced by test_format_conversion(), and test_save_surface_to_dds().

◆ test_tga_color_map_15bpp

const uint8_t test_tga_color_map_15bpp[]
static

Definition at line 1548 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_color_map_15bpp_expected

const uint8_t test_tga_color_map_15bpp_expected[]
static
Initial value:
=
{
0x00,0x00,0x00,0xff,0x00,0x42,0x00,0xff,0x00,0x84,0x00,0xff,0x00,0xc6,0x00,0xff,
0x42,0x00,0x00,0xff,0x42,0x42,0x00,0xff,0x42,0x84,0x00,0xff,0x42,0xc6,0x00,0xff,
0x84,0x00,0x00,0xff,0x84,0x42,0x00,0xff,0x84,0x84,0x00,0xff,0x84,0xc6,0x00,0xff,
0xc6,0x00,0x00,0xff,0xc6,0x42,0x00,0xff,0xc6,0x84,0x00,0xff,0xff,0xff,0xff,0xff,
}

Definition at line 1820 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_color_map_15bpp_rle_expected

const uint8_t test_tga_color_map_15bpp_rle_expected[]
static
Initial value:
=
{
0x00,0x42,0x00,0xff,0x00,0x42,0x00,0xff,0x00,0x42,0x00,0xff,0x00,0x42,0x00,0xff,
0x00,0x84,0x00,0xff,0x00,0x84,0x00,0xff,0x00,0x84,0x00,0xff,0x00,0x84,0x00,0xff,
0x84,0x00,0x00,0xff,0x84,0x42,0x00,0xff,0x84,0x84,0x00,0xff,0x84,0xc6,0x00,0xff,
0xc6,0x00,0x00,0xff,0xc6,0x42,0x00,0xff,0xc6,0x84,0x00,0xff,0xff,0xff,0xff,0xff,
}

Definition at line 1828 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_color_map_16bpp

const uint8_t test_tga_color_map_16bpp[]
static

Definition at line 1584 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_color_map_16bpp_expected

const uint8_t test_tga_color_map_16bpp_expected[]
static
Initial value:
=
{
0x00,0x00,0x00,0x00,0x00,0x42,0x00,0x00,0x00,0x84,0x00,0x00,0x00,0xc6,0x00,0x00,
0x42,0x00,0x00,0x00,0x42,0x42,0x00,0x00,0x42,0x84,0x00,0x00,0x42,0xc6,0x00,0x00,
0x84,0x00,0x00,0xff,0x84,0x42,0x00,0xff,0x84,0x84,0x00,0xff,0x84,0xc6,0x00,0xff,
0xc6,0x00,0x00,0xff,0xc6,0x42,0x00,0xff,0xc6,0x84,0x00,0xff,0xff,0xff,0xff,0xff,
}

Definition at line 1836 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_color_map_24bpp

const uint8_t test_tga_color_map_24bpp[]
static

Definition at line 1620 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_color_map_24bpp_expected

const uint8_t test_tga_color_map_24bpp_expected[]
static
Initial value:
=
{
0x00,0x00,0x00,0xff,0x00,0x40,0x00,0xff,0x00,0x80,0x00,0xff,0x00,0xc0,0x00,0xff,
0x40,0x00,0x00,0xff,0x40,0x40,0x00,0xff,0x40,0x80,0x00,0xff,0x40,0xc0,0x00,0xff,
0x80,0x00,0x00,0xff,0x80,0x40,0x00,0xff,0x80,0x80,0x00,0xff,0x80,0xc0,0x00,0xff,
0xc0,0x00,0x00,0xff,0xc0,0x40,0x00,0xff,0xc0,0x80,0x00,0xff,0xff,0xff,0xff,0xff,
}

Definition at line 1844 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_color_map_32bpp

const uint8_t test_tga_color_map_32bpp[]
static

Definition at line 1672 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_color_map_32bpp_expected

const uint8_t test_tga_color_map_32bpp_expected[]
static
Initial value:
=
{
0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x10,0x00,0x80,0x00,0x20,0x00,0xc0,0x00,0x30,
0x40,0x00,0x00,0x40,0x40,0x40,0x00,0x50,0x40,0x80,0x00,0x60,0x40,0xc0,0x00,0x70,
0x80,0x00,0x00,0x80,0x80,0x40,0x00,0x90,0x80,0x80,0x00,0xa0,0x80,0xc0,0x00,0xb0,
0xc0,0x00,0x00,0xc0,0xc0,0x40,0x00,0xd0,0xc0,0x80,0x00,0xe0,0xff,0xff,0xff,0xff,
}

Definition at line 1852 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_color_map_half_32bpp_expected

const uint8_t test_tga_color_map_half_32bpp_expected[]
static
Initial value:
=
{
0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x10,0x00,0x80,0x00,0x20,0x00,0xc0,0x00,0x30,
0x40,0x00,0x00,0x40,0x40,0x40,0x00,0x50,0x40,0x80,0x00,0x60,0x40,0xc0,0x00,0x70,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
}

Definition at line 1860 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_color_map_index_4_4

const uint8_t test_tga_color_map_index_4_4[]
static
Initial value:
=
{
0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80,0x90,0xa0,0xb0,0xc0,0xd0,0xe0,0xff,
}

Definition at line 1740 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_color_map_index_4_4_rle

const uint8_t test_tga_color_map_index_4_4_rle[]
static
Initial value:
=
{
0x83,0x10,0x83,0x20,0x03,0x80,0x90,0xa0,0xb0,0x03,0xc0,0xd0,0xe0,0xff,
}

Definition at line 1745 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_grayscale_8bpp_4_4

const uint8_t test_tga_grayscale_8bpp_4_4[]
static
Initial value:
=
{
0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80,0x90,0xa0,0xb0,0xc0,0xd0,0xe0,0xf0,
}

Definition at line 1808 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_grayscale_8bpp_4_4_rle

const uint8_t test_tga_grayscale_8bpp_4_4_rle[]
static
Initial value:
=
{
0x03,0x00,0x10,0x20,0x30,0x82,0x40,0x00,0x70,0x03,0x80,0x90,0xa0,0xb0,0x03,0xc0,
0xd0,0xe0,0xf0,
}

Definition at line 1813 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_grayscale_8bpp_rle_expected

const uint8_t test_tga_grayscale_8bpp_rle_expected[]
static
Initial value:
=
{
0x00,0x10,0x20,0x30,0x40,0x40,0x40,0x70,0x80,0x90,0xa0,0xb0,0xc0,0xd0,0xe0,0xf0,
}

Definition at line 1895 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_true_color_15bpp_4_4

const uint8_t test_tga_true_color_15bpp_4_4[]
static
Initial value:
=
{
0x00,0x04,0x42,0x0c,0x84,0x14,0xc6,0x1c,0x08,0x25,0x4a,0x2d,0x8c,0x35,0xce,0x3d,
0x10,0x46,0x52,0x4e,0x94,0x56,0xd6,0x5e,0x18,0x67,0x5a,0x6f,0x9c,0x77,0xde,0x7f,
}

Definition at line 1750 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_true_color_15bpp_4_4_rle

const uint8_t test_tga_true_color_15bpp_4_4_rle[]
static
Initial value:
=
{
0x03,0x00,0x04,0x42,0x0c,0x84,0x14,0xc6,0x1c,0x81,0x08,0x25,0x00,0x8c,0x35,0x00,
0xce,0x3d,0x03,0x10,0x46,0x52,0x4e,0x94,0x56,0xd6,0x5e,0x03,0x18,0x67,0x5a,0x6f,
0x9c,0x77,0xde,0x7f,
}

Definition at line 1756 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_true_color_15bpp_rle_expected

const uint8_t test_tga_true_color_15bpp_rle_expected[]
static
Initial value:
=
{
0x00,0x04,0x42,0x0c,0x84,0x14,0xc6,0x1c,0x08,0x25,0x08,0x25,0x8c,0x35,0xce,0x3d,
0x10,0x46,0x52,0x4e,0x94,0x56,0xd6,0x5e,0x18,0x67,0x5a,0x6f,0x9c,0x77,0xde,0x7f,
}

Definition at line 1868 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_true_color_16bpp_4_4

const uint8_t test_tga_true_color_16bpp_4_4[]
static
Initial value:
=
{
0x00,0x04,0x42,0x0c,0x84,0x14,0xc6,0x1c,0x08,0x25,0x4a,0x2d,0x8c,0x35,0xce,0x3d,
0x10,0xc6,0x52,0xce,0x94,0xd6,0xd6,0xde,0x18,0xe7,0x5a,0xef,0x9c,0xf7,0xde,0xff,
}

Definition at line 1763 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_true_color_16bpp_4_4_rle

const uint8_t test_tga_true_color_16bpp_4_4_rle[]
static
Initial value:
=
{
0x03,0x00,0x04,0x42,0x0c,0x84,0x14,0xc6,0x1c,0x81,0x08,0x25,0x00,0x8c,0x35,0x00,
0xce,0x3d,0x03,0x10,0xc6,0x52,0xce,0x94,0xd6,0xd6,0xde,0x03,0x18,0xe7,0x5a,0xef,
0x9c,0xf7,0xde,0xff,
}

Definition at line 1769 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_true_color_16bpp_rle_expected

const uint8_t test_tga_true_color_16bpp_rle_expected[]
static
Initial value:
=
{
0x00,0x04,0x42,0x0c,0x84,0x14,0xc6,0x1c,0x08,0x25,0x08,0x25,0x8c,0x35,0xce,0x3d,
0x10,0xc6,0x52,0xce,0x94,0xd6,0xd6,0xde,0x18,0xe7,0x5a,0xef,0x9c,0xf7,0xde,0xff,
}

Definition at line 1874 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_true_color_24bpp_4_4

const uint8_t test_tga_true_color_24bpp_4_4[]
static
Initial value:
=
{
0x00,0x04,0x08,0x10,0x14,0x18,0x20,0x24,0x28,0x30,0x34,0x38,0x40,0x44,0x48,0x50,
0x54,0x58,0x60,0x64,0x68,0x70,0x74,0x78,0x80,0x84,0x88,0x90,0x94,0x98,0xa0,0xa4,
0xa8,0xb0,0xb4,0xb8,0xc0,0xc4,0xc8,0xd0,0xd4,0xd8,0xe0,0xe4,0xe8,0xf0,0xf4,0xf8,
}

Definition at line 1776 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_true_color_24bpp_4_4_rle

const uint8_t test_tga_true_color_24bpp_4_4_rle[]
static
Initial value:
=
{
0x03,0x00,0x04,0x08,0x10,0x14,0x18,0x20,0x24,0x28,0x30,0x34,0x38,0x81,0x40,0x44,
0x48,0x00,0x60,0x64,0x68,0x00,0x70,0x74,0x78,0x03,0x80,0x84,0x88,0x90,0x94,0x98,
0xa0,0xa4,0xa8,0xb0,0xb4,0xb8,0x03,0xc0,0xc4,0xc8,0xd0,0xd4,0xd8,0xe0,0xe4,0xe8,
0xf0,0xf4,0xf8,
}

Definition at line 1783 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_true_color_24bpp_rle_expected

const uint8_t test_tga_true_color_24bpp_rle_expected[]
static
Initial value:
=
{
0x00,0x04,0x08,0x10,0x14,0x18,0x20,0x24,0x28,0x30,0x34,0x38,0x40,0x44,0x48,0x40,
0x44,0x48,0x60,0x64,0x68,0x70,0x74,0x78,0x80,0x84,0x88,0x90,0x94,0x98,0xa0,0xa4,
0xa8,0xb0,0xb4,0xb8,0xc0,0xc4,0xc8,0xd0,0xd4,0xd8,0xe0,0xe4,0xe8,0xf0,0xf4,0xf8,
}

Definition at line 1880 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_true_color_32bpp_4_4

const uint8_t test_tga_true_color_32bpp_4_4[]
static
Initial value:
=
{
0x08,0x04,0x00,0x0c,0x18,0x14,0x10,0x1c,0x28,0x24,0x20,0x2c,0x38,0x34,0x30,0x3c,
0x48,0x44,0x40,0x4c,0x58,0x54,0x50,0x5c,0x68,0x64,0x60,0x6c,0x78,0x74,0x70,0x7c,
0x88,0x84,0x80,0x8c,0x98,0x94,0x90,0x9c,0xa8,0xa4,0xa0,0xac,0xb8,0xb4,0xb0,0xbc,
0xc8,0xc4,0xc0,0xcc,0xd8,0xd4,0xd0,0xdc,0xe8,0xe4,0xe0,0xec,0xf8,0xf4,0xf0,0xfc,
}

Definition at line 1791 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_true_color_32bpp_4_4_rle

const uint8_t test_tga_true_color_32bpp_4_4_rle[]
static
Initial value:
=
{
0x03,0x08,0x04,0x00,0x0c,0x18,0x14,0x10,0x1c,0x28,0x24,0x20,0x2c,0x38,0x34,0x30,
0x3c,0x81,0x48,0x44,0x40,0x4c,0x00,0x68,0x64,0x60,0x6c,0x00,0x78,0x74,0x70,0x7c,
0x03,0x88,0x84,0x80,0x8c,0x98,0x94,0x90,0x9c,0xa8,0xa4,0xa0,0xac,0xb8,0xb4,0xb0,
0xbc,0x03,0xc8,0xc4,0xc0,0xcc,0xd8,0xd4,0xd0,0xdc,0xe8,0xe4,0xe0,0xec,0xf8,0xf4,
0xf0,0xfc,
}

Definition at line 1799 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ test_tga_true_color_32bpp_rle_expected

const uint8_t test_tga_true_color_32bpp_rle_expected[]
static
Initial value:
=
{
0x08,0x04,0x00,0x0c,0x18,0x14,0x10,0x1c,0x28,0x24,0x20,0x2c,0x38,0x34,0x30,0x3c,
0x48,0x44,0x40,0x4c,0x48,0x44,0x40,0x4c,0x68,0x64,0x60,0x6c,0x78,0x74,0x70,0x7c,
0x88,0x84,0x80,0x8c,0x98,0x94,0x90,0x9c,0xa8,0xa4,0xa0,0xac,0xb8,0xb4,0xb0,0xbc,
0xc8,0xc4,0xc0,0xcc,0xd8,0xd4,0xd0,0xdc,0xe8,0xe4,0xe0,0xec,0xf8,0xf4,0xf0,0xfc,
}

Definition at line 1887 of file surface.c.

Referenced by test_load_surface_from_tga().

◆ v16u16_2_2

const uint16_t v16u16_2_2[]
static
Initial value:
=
{
0x0000, 0x3000, 0x4000, 0x7fff, 0x8000, 0x8001, 0xc000, 0xffff,
}

Definition at line 1202 of file surface.c.

Referenced by test_format_conversion().

◆ v16u16_2_2_expected

const uint8_t v16u16_2_2_expected[]
static
Initial value:
=
{
0x00,0x80,0x00,0xb0,0x00,0xc0,0xff,0xff,0x00,0x00,0x00,0x00,0xff,0x3f,0xff,0x7f,
}

Definition at line 1207 of file surface.c.

Referenced by test_format_conversion().

◆ v16u16_2_2_expected2

const uint8_t v16u16_2_2_expected2[]
static
Initial value:
=
{
0x00,0x00,0x00,0x00,0x80,0x01,0xc0,0x3e,0x00,0x00,0x80,0x3f,0x00,0x00,0x80,0x3f,
0x00,0x01,0x00,0x3f,0x00,0x00,0x80,0x3f,0x00,0x00,0x80,0x3f,0x00,0x00,0x80,0x3f,
0x00,0x00,0x80,0xbf,0x00,0x00,0x80,0xbf,0x00,0x00,0x80,0x3f,0x00,0x00,0x80,0x3f,
0x00,0x01,0x00,0xbf,0x00,0x01,0x00,0xb8,0x00,0x00,0x80,0x3f,0x00,0x00,0x80,0x3f,
}

Definition at line 1212 of file surface.c.

Referenced by test_format_conversion().

◆ v8u8_2_2

const uint8_t v8u8_2_2[]
static
Initial value:
=
{
0x00,0x30,0x40,0x7f,0x80,0x81,0xc0,0xff,
}

Definition at line 1220 of file surface.c.

Referenced by test_format_conversion().

◆ v8u8_2_2_expected

const uint8_t v8u8_2_2_expected[]
static
Initial value:
=
{
0x00,0x00,0x00,0x00,0x06,0x83,0xc1,0x3e,0x00,0x00,0x80,0x3f,0x00,0x00,0x80,0x3f,
0x04,0x02,0x01,0x3f,0x00,0x00,0x80,0x3f,0x00,0x00,0x80,0x3f,0x00,0x00,0x80,0x3f,
0x00,0x00,0x80,0xbf,0x00,0x00,0x80,0xbf,0x00,0x00,0x80,0x3f,0x00,0x00,0x80,0x3f,
0x04,0x02,0x01,0xbf,0x04,0x02,0x01,0xbc,0x00,0x00,0x80,0x3f,0x00,0x00,0x80,0x3f,
}

Definition at line 1225 of file surface.c.

Referenced by test_format_conversion().