ReactOS 0.4.16-dev-401-g45b008d
surface.c
Go to the documentation of this file.
1/*
2 * Tests for the D3DX9 surface functions
3 *
4 * Copyright 2009 Tony Wasserka
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#define COBJMACROS
22#include <assert.h>
23#include "wine/test.h"
24#include "d3dx9tex.h"
25#include "resources.h"
26
27#define check_release(obj, exp) _check_release(__LINE__, obj, exp)
28static inline void _check_release(unsigned int line, IUnknown *obj, int exp)
29{
30 int ref = IUnknown_Release(obj);
31 ok_(__FILE__, line)(ref == exp, "Invalid refcount. Expected %d, got %d\n", exp, ref);
32}
33
34/* 1x1 bmp (1 bpp) */
35static const unsigned char bmp_1bpp[] = {
360x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
370x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
380x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
390x00,0x00,0x02,0x00,0x00,0x00,0xf1,0xf2,0xf3,0x80,0xf4,0xf5,0xf6,0x81,0x00,0x00,
400x00,0x00
41};
42
43/* 1x1 bmp (2 bpp) */
44static const unsigned char bmp_2bpp[] = {
450x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
460x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x02,0x00,0x00,0x00,
470x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
480x00,0x00,0x02,0x00,0x00,0x00,0xf1,0xf2,0xf3,0x80,0xf4,0xf5,0xf6,0x81,0x00,0x00,
490x00,0x00
50};
51
52/* 1x1 bmp (4 bpp) */
53static const unsigned char bmp_4bpp[] = {
540x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
550x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x04,0x00,0x00,0x00,
560x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
570x00,0x00,0x02,0x00,0x00,0x00,0xf1,0xf2,0xf3,0x80,0xf4,0xf5,0xf6,0x81,0x00,0x00,
580x00,0x00
59};
60
61/* 1x1 bmp (8 bpp) */
62static const unsigned char bmp_8bpp[] = {
630x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
640x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x08,0x00,0x00,0x00,
650x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
660x00,0x00,0x02,0x00,0x00,0x00,0xf1,0xf2,0xf3,0x80,0xf4,0xf5,0xf6,0x81,0x00,0x00,
670x00,0x00
68};
69
70/* 2x2 bmp (32 bpp XRGB) */
71static const unsigned char bmp_32bpp_xrgb[] =
72{
73 0x42,0x4d,0x46,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00,0x28,0x00,
74 0x00,0x00,0x02,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x01,0x00,0x20,0x00,0x00,0x00,
75 0x00,0x00,0x10,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x00,0x00,
76 0x00,0x00,0x00,0x00,0x00,0x00,0xa0,0xb0,0xc0,0x00,0xa1,0xb1,0xc1,0x00,0xa2,0xb2,
77 0xc2,0x00,0xa3,0xb3,0xc3,0x00
78};
79
80/* 2x2 bmp (32 bpp ARGB) */
81static const unsigned char bmp_32bpp_argb[] =
82{
83 0x42,0x4d,0x46,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00,0x28,0x00,
84 0x00,0x00,0x02,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x01,0x00,0x20,0x00,0x00,0x00,
85 0x00,0x00,0x10,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x00,0x00,
86 0x00,0x00,0x00,0x00,0x00,0x00,0xa0,0xb0,0xc0,0x00,0xa1,0xb1,0xc1,0x00,0xa2,0xb2,
87 0xc2,0x00,0xa3,0xb3,0xc3,0x01
88};
89
90static const unsigned char png_grayscale[] =
91{
92 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49,
93 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00,
94 0x00, 0x00, 0x00, 0x3a, 0x7e, 0x9b, 0x55, 0x00, 0x00, 0x00, 0x0a, 0x49, 0x44,
95 0x41, 0x54, 0x08, 0xd7, 0x63, 0xf8, 0x0f, 0x00, 0x01, 0x01, 0x01, 0x00, 0x1b,
96 0xb6, 0xee, 0x56, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42,
97 0x60, 0x82
98};
99
100/* 2x2 A8R8G8B8 pixel data */
101static const unsigned char pixdata[] = {
1020xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
103};
104
105/* invalid image file */
106static const unsigned char noimage[4] = {
1070x11,0x22,0x33,0x44
108};
109
110/* 16x4 8-bit dds */
111static const unsigned char dds_8bit[] =
112{
113 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x0f,0x10,0x00,0x00,0x04,0x00,0x00,0x00,
114 0x10,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
115 0x47,0x49,0x4d,0x50,0x2d,0x44,0x44,0x53,0x5a,0x09,0x03,0x00,0x00,0x00,0x00,0x00,
116 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
117 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
118 0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
119 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,
120 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
121 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
122 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
123 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
124 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
125 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
126 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
127 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
128 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
129 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
130 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
131 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
132 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
133 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
134 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
135 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
136 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
137 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
138 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
139 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
140 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
141 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
142 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
143 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
144 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
145 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,
146 0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0xec,0x27,0x00,0xff,0x8c,0xcd,0x12,0xff,
147 0x78,0x01,0x14,0xff,0x50,0xcd,0x12,0xff,0x00,0x3d,0x8c,0xff,0x02,0x00,0x00,0xff,
148 0x47,0x00,0x00,0xff,0xda,0x07,0x02,0xff,0x50,0xce,0x12,0xff,0xea,0x11,0x01,0xff,
149 0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x08,0x3d,0x8c,0xff,0x08,0x01,0x00,0xff,
150 0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x60,0xcc,0x12,0xff,
151 0xa1,0xb2,0xd4,0xff,0xda,0x07,0x02,0xff,0x47,0x00,0x00,0xff,0x00,0x00,0x00,0xff,
152 0x50,0xce,0x12,0xff,0x00,0x00,0x14,0xff,0xa8,0xcc,0x12,0xff,0x3c,0xb2,0xd4,0xff,
153 0xda,0x07,0x02,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x01,0xff,
154 0x21,0x00,0x00,0xff,0xd8,0xcb,0x12,0xff,0x54,0xcd,0x12,0xff,0x8b,0x4f,0xd5,0xff,
155 0x00,0x04,0xda,0xff,0x00,0x00,0x00,0xff,0x3d,0x04,0x91,0xff,0x70,0xce,0x18,0xff,
156 0xb4,0xcc,0x12,0xff,0x6b,0x4e,0xd5,0xff,0xb0,0xcc,0x12,0xff,0x00,0x00,0x00,0xff,
157 0xc8,0x05,0x91,0xff,0x98,0xc7,0xcc,0xff,0x7c,0xcd,0x12,0xff,0x51,0x05,0x91,0xff,
158 0x48,0x07,0x14,0xff,0x6d,0x05,0x91,0xff,0x00,0x07,0xda,0xff,0xa0,0xc7,0xcc,0xff,
159 0x00,0x07,0xda,0xff,0x3a,0x77,0xd5,0xff,0xda,0x07,0x02,0xff,0x7c,0x94,0xd4,0xff,
160 0xe0,0xce,0xd6,0xff,0x0a,0x80,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,
161 0x78,0x9a,0xab,0xff,0xde,0x08,0x18,0xff,0xda,0x07,0x02,0xff,0x30,0x00,0x00,0xff,
162 0x00,0x00,0x00,0xff,0x50,0xce,0x12,0xff,0x8c,0xcd,0x12,0xff,0xd0,0xb7,0xd8,0xff,
163 0x00,0x00,0x00,0xff,0x60,0x32,0xd9,0xff,0x30,0xc1,0x1a,0xff,0xa8,0xcd,0x12,0xff,
164 0xa4,0xcd,0x12,0xff,0xc0,0x1d,0x4b,0xff,0x46,0x71,0x0e,0xff,0xc0,0x1d,0x4b,0xff,
165 0x09,0x87,0xd4,0xff,0x00,0x00,0x00,0xff,0xf6,0x22,0x00,0xff,0x64,0xcd,0x12,0xff,
166 0x00,0x00,0x00,0xff,0xca,0x1d,0x4b,0xff,0x09,0x87,0xd4,0xff,0xaa,0x02,0x05,0xff,
167 0x82,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0xc0,0x1d,0x4b,0xff,
168 0xcd,0xab,0xba,0xff,0x00,0x00,0x00,0xff,0xa4,0xcd,0x12,0xff,0xc0,0x1d,0x4b,0xff,
169 0xd4,0xcd,0x12,0xff,0xa6,0x4c,0xd5,0xff,0x00,0xf0,0xfd,0xff,0xd4,0xcd,0x12,0xff,
170 0xf4,0x4c,0xd5,0xff,0x90,0xcd,0x12,0xff,0xc2,0x4c,0xd5,0xff,0x82,0x00,0x00,0xff,
171 0xaa,0x02,0x05,0xff,0x88,0xd4,0xba,0xff,0x14,0x00,0x00,0xff,0x01,0x00,0x00,0xff,
172 0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x10,0x00,0x00,0xff,0x00,0x00,0x00,0xff,
173 0x0c,0x08,0x13,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,
174 0xd0,0xcd,0x12,0xff,0xc6,0x84,0xf1,0xff,0x7c,0x84,0xf1,0xff,0x20,0x20,0xf5,0xff,
175 0x00,0x00,0x0a,0xff,0xf0,0xb0,0x94,0xff,0x64,0x6c,0xf1,0xff,0x85,0x6c,0xf1,0xff,
176 0x8b,0x4f,0xd5,0xff,0x00,0x04,0xda,0xff,0x88,0xd4,0xba,0xff,0x82,0x00,0x00,0xff,
177 0x39,0xde,0xd4,0xff,0x10,0x50,0xd5,0xff,0xaa,0x02,0x05,0xff,0x00,0x00,0x00,0xff,
178 0x4f,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x5c,0xce,0x12,0xff,0x00,0x00,0x00,0xff,
179 0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x5c,0xce,0x12,0xff,
180 0xaa,0x02,0x05,0xff,0x4c,0xce,0x12,0xff,0x39,0xe6,0xd4,0xff,0x00,0x00,0x00,0xff,
181 0x82,0x00,0x00,0xff,0x00,0x00,0x00,0xff,0x5b,0xe6,0xd4,0xff,0x00,0x00,0x00,0xff,
182 0x00,0x00,0x00,0xff,0x68,0x50,0xcd,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0xff,
183 0x00,0x00,0x00,0xff,0x10,0x00,0x00,0xff,0xe3,0xea,0x90,0xff,0x5c,0xce,0x12,0xff,
184 0x18,0x00,0x00,0xff,0x88,0xd4,0xba,0xff,0x82,0x00,0x00,0xff,0x00,0x00,0x00,0xff,
185 0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
186 0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
187 0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
188 0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01
189};
190
191/* 2x2 24-bit dds, 2 mipmaps */
192static const unsigned char dds_24bit[] = {
1930x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x0a,0x00,0x02,0x00,0x00,0x00,
1940x02,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
1950x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1960x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1970x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
1980x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0xff,0x00,
1990x00,0xff,0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
2000x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2010xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
202};
203
204/* 2x2 16-bit dds, no mipmaps */
205static const unsigned char dds_16bit[] = {
2060x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x02,0x00,0x00,0x00,
2070x02,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2080x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2090x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2100x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
2110x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,
2120xe0,0x03,0x00,0x00,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,
2130x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2140xff,0x7f,0xff,0x7f,0xff,0x7f,0xff,0x7f
215};
216
217/* 4x4 cube map dds */
218static const unsigned char dds_cube_map[] = {
2190x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x04,0x00,0x00,0x00,
2200x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2210x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2220x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2230x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
2240x04,0x00,0x00,0x00,0x44,0x58,0x54,0x35,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2250x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x00,0x00,
2260x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2270xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
2280xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
2290xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
2300xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
2310xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
2320xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50
233};
234
235/* 4x4x2 volume map dds, 2 mipmaps */
236static const unsigned char dds_volume_map[] = {
2370x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x8a,0x00,0x04,0x00,0x00,0x00,
2380x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
2390x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2400x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2410x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
2420x04,0x00,0x00,0x00,0x44,0x58,0x54,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2430x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
2440x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2450xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
2460xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
2470xff,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x2f,0x7e,0xcf,0x79,0x01,0x54,0x5c,0x5c,
2480x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x84,0xef,0x7b,0xaa,0xab,0xab,0xab
249};
250
251/* 4x2 dxt5 */
252static const BYTE dds_dxt5[] =
253{
254 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x02,0x00,0x00,0x00,
255 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
256 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
257 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
258 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
259 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x35,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
260 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x00,0x00,
261 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
262 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
263};
264
265/* 8x8 dxt5 */
266static const BYTE dds_dxt5_8_8[] =
267{
268 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x08,0x00,0x00,0x00,
269 0x08,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
270 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
271 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
272 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
273 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x35,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
274 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x00,0x00,
275 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
276 0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x00,0xe0,0x07,0x05,0x05,0x50,0x50,
277 0x3f,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0xff,0x07,0x05,0x05,0x50,0x50,
278 0x7f,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xf8,0xe0,0xff,0x05,0x05,0x50,0x50,
279 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x00,0x00,0x05,0x05,0x50,0x50,
280};
281
282static HRESULT create_file(const char *filename, const unsigned char *data, const unsigned int size)
283{
285 HANDLE hfile;
286
289
290 if(WriteFile(hfile, data, size, &received, NULL))
291 {
292 CloseHandle(hfile);
293 return D3D_OK;
294 }
295
296 CloseHandle(hfile);
297 return D3DERR_INVALIDCALL;
298}
299
300/* dds_header.flags */
301#define DDS_CAPS 0x00000001
302#define DDS_HEIGHT 0x00000002
303#define DDS_WIDTH 0x00000004
304#define DDS_PITCH 0x00000008
305#define DDS_PIXELFORMAT 0x00001000
306#define DDS_MIPMAPCOUNT 0x00020000
307#define DDS_LINEARSIZE 0x00080000
308
309/* dds_header.caps */
310#define DDSCAPS_ALPHA 0x00000002
311#define DDS_CAPS_TEXTURE 0x00001000
312
313/* dds_pixel_format.flags */
314#define DDS_PF_ALPHA 0x00000001
315#define DDS_PF_ALPHA_ONLY 0x00000002
316#define DDS_PF_FOURCC 0x00000004
317#define DDS_PF_RGB 0x00000040
318#define DDS_PF_LUMINANCE 0x00020000
319#define DDS_PF_BUMPLUMINANCE 0x00040000
320#define DDS_PF_BUMPDUDV 0x00080000
321
322struct dds_pixel_format
323{
324 DWORD size;
325 DWORD flags;
327 DWORD bpp;
328 DWORD rmask;
329 DWORD gmask;
330 DWORD bmask;
331 DWORD amask;
332};
333
334struct dds_header
335{
336 DWORD size;
337 DWORD flags;
339 DWORD width;
341 DWORD depth;
343 DWORD reserved[11];
345 DWORD caps;
346 DWORD caps2;
347 DWORD caps3;
348 DWORD caps4;
350};
351
352/* fills dds_header with reasonable default values */
354{
355 memset(header, 0, sizeof(*header));
356
357 header->size = sizeof(*header);
359 header->height = 4;
360 header->width = 4;
361 header->pixel_format.size = sizeof(header->pixel_format);
362 /* X8R8G8B8 */
363 header->pixel_format.flags = DDS_PF_RGB;
364 header->pixel_format.fourcc = 0;
365 header->pixel_format.bpp = 32;
366 header->pixel_format.rmask = 0xff0000;
367 header->pixel_format.gmask = 0x00ff00;
368 header->pixel_format.bmask = 0x0000ff;
369 header->pixel_format.amask = 0;
370 header->caps = DDS_CAPS_TEXTURE;
371}
372
373#define check_dds_pixel_format(flags, fourcc, bpp, rmask, gmask, bmask, amask, format) \
374 check_dds_pixel_format_(__LINE__, flags, fourcc, bpp, rmask, gmask, bmask, amask, format)
375static void check_dds_pixel_format_(unsigned int line,
378 D3DFORMAT expected_format)
379{
380 HRESULT hr;
382 struct
383 {
384 DWORD magic;
385 struct dds_header header;
386 BYTE data[256];
387 } dds;
388
389 dds.magic = MAKEFOURCC('D','D','S',' ');
390 fill_dds_header(&dds.header);
391 dds.header.pixel_format.flags = flags;
392 dds.header.pixel_format.fourcc = fourcc;
393 dds.header.pixel_format.bpp = bpp;
394 dds.header.pixel_format.rmask = rmask;
395 dds.header.pixel_format.gmask = gmask;
396 dds.header.pixel_format.bmask = bmask;
397 dds.header.pixel_format.amask = amask;
398 memset(dds.data, 0, sizeof(dds.data));
399
400 hr = D3DXGetImageInfoFromFileInMemory(&dds, sizeof(dds), &info);
401 ok_(__FILE__, line)(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x for pixel format %#x, expected %#x\n",
402 hr, expected_format, D3D_OK);
403 if (SUCCEEDED(hr))
404 {
405 ok_(__FILE__, line)(info.Format == expected_format, "D3DXGetImageInfoFromFileInMemory returned format %#x, expected %#x\n",
406 info.Format, expected_format);
407 }
408}
409
411{
412 int i;
413 HRESULT hr;
415 struct
416 {
417 DWORD magic;
418 struct dds_header header;
419 BYTE data[4096 * 1024];
420 } *dds;
421
422 struct
423 {
425 DWORD flags;
426 DWORD width;
428 DWORD pitch;
429 DWORD miplevels;
430 DWORD pixel_data_size;
431 struct
432 {
433 HRESULT hr;
434 UINT miplevels;
435 }
436 expected;
437 } tests[] = {
438 /* pitch is ignored */
439 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, 0, 4, 4, 0, 0,
440 63 /* pixel data size */, { D3DXERR_INVALIDDATA, 0 } },
441 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 0 /* pitch */, 0,
442 64, { D3D_OK, 1 } },
443 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 1 /* pitch */, 0,
444 64, { D3D_OK, 1 } },
445 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 2 /* pitch */, 0,
446 64, { D3D_OK, 1 } },
447 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 3 /* pitch */, 0,
448 64, { D3D_OK, 1 } },
449 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 4 /* pitch */, 0,
450 64, { D3D_OK, 1 } },
451 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 16 /* pitch */, 0,
452 64, { D3D_OK, 1 } },
453 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, 1024 /* pitch */, 0,
454 64, { D3D_OK, 1 } },
455 { { 32, DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 }, DDS_PITCH, 4, 4, -1 /* pitch */, 0,
456 64, { D3D_OK, 1 } },
457 /* linear size is ignored */
458 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, 0, 4, 4, 0, 0,
459 7 /* pixel data size */, { D3DXERR_INVALIDDATA, 1 } },
460 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 0 /* linear size */, 0,
461 8, { D3D_OK, 1 } },
462 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 1 /* linear size */, 0,
463 8, { D3D_OK, 1 } },
464 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 2 /* linear size */, 0,
465 8, { D3D_OK, 1 } },
466 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 9 /* linear size */, 0,
467 8, { D3D_OK, 1 } },
468 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, 16 /* linear size */, 0,
469 8, { D3D_OK, 1 } },
470 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_LINEARSIZE, 4, 4, -1 /* linear size */, 0,
471 8, { D3D_OK, 1 } },
472 /* integer overflows */
473 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000000, 0x80000000 /* 0x80000000 * 0x80000000 * 4 = 0 */, 0, 0,
474 64, { D3D_OK, 1 } },
475 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x8000100, 0x800100 /* 0x8000100 * 0x800100 * 4 = 262144 */, 0, 0,
476 64, { D3DXERR_INVALIDDATA, 0 } },
477 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0, 0,
478 4, { D3D_OK, 1 } },
479 { { 32, DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0 }, 0, 0x80000001, 0x80000001 /* 0x80000001 * 0x80000001 * 4 = 4 */, 0, 0,
480 3 /* pixel data size */, { D3DXERR_INVALIDDATA, 0 } },
481 /* file size is validated */
482 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 64, 0, 0, 49151, { D3DXERR_INVALIDDATA, 0 } },
483 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 64, 0, 0, 49152, { D3D_OK, 1 } },
484 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 64, 0, 4, 65279, { D3DXERR_INVALIDDATA, 0 } },
485 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 64, 0, 4, 65280, { D3D_OK, 4 } },
486 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 64, 0, 9, 65540, { D3DXERR_INVALIDDATA, 0 } },
487 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 64, 0, 9, 65541, { D3D_OK, 9 } },
488 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 0, 196607, { D3DXERR_INVALIDDATA, 0 } },
489 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 0, 196608, { D3D_OK, 1 } },
490 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 0, 196609, { D3D_OK, 1 } },
491 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 1, 196607, { D3DXERR_INVALIDDATA, 0 } },
492 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 1, 196608, { D3D_OK, 1 } },
493 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 0, 196607, { D3DXERR_INVALIDDATA, 0 } },
494 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 0, 196608, { D3D_OK, 1 } },
495 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 0, 400000, { D3D_OK, 1 } },
496 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 9, 262142, { D3DXERR_INVALIDDATA, 0 } },
497 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 9, 262143, { D3D_OK, 9 } },
498 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 10, 262145, { D3DXERR_INVALIDDATA, 0 } },
499 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 10, 262146, { D3D_OK, 10 } },
500 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 20, 262175, { D3DXERR_INVALIDDATA, 0 } },
501 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, DDS_MIPMAPCOUNT, 256, 256, 0, 20, 262176, { D3D_OK, 20 } },
502 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, 0, 256, 256, 0, 0, 32767, { D3DXERR_INVALIDDATA, 0 } },
503 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, 0, 256, 256, 0, 0, 32768, { D3D_OK, 1 } },
504 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 0, 32767, { D3DXERR_INVALIDDATA, 0 } },
505 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 0, 32768, { D3D_OK, 1 } },
506 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 9, 43703, { D3DXERR_INVALIDDATA, 0 } },
507 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 9, 43704, { D3D_OK, 9 } },
508 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 20, 43791, { D3DXERR_INVALIDDATA, 0 } },
509 { { 32, DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 20, 43792, { D3D_OK, 20 } },
510 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, 0, 256, 256, 0, 0, 65535, { D3DXERR_INVALIDDATA, 0 } },
511 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, 0, 256, 256, 0, 0, 65536, { D3D_OK, 1 } },
512 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 0, 65535, { D3DXERR_INVALIDDATA, 0 } },
513 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 0, 65536, { D3D_OK, 1 } },
514 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 9, 87407, { D3DXERR_INVALIDDATA, 0 } },
515 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 9, 87408, { D3D_OK, 9 } },
516 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 20, 87583, { D3DXERR_INVALIDDATA, 0 } },
517 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 256, 0, 20, 87584, { D3D_OK, 20 } },
518 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 64, 0, 4, 21759, { D3DXERR_INVALIDDATA, 0 } },
519 { { 32, DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0 }, DDS_MIPMAPCOUNT, 256, 64, 0, 4, 21760, { D3D_OK, 4 } },
520 /* DDS_MIPMAPCOUNT is ignored */
521 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 0, 262146, { D3D_OK, 1 } },
522 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 2, 262146, { D3D_OK, 2 } },
523 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 9, 262146, { D3D_OK, 9 } },
524 { { 32, DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000 }, 0, 256, 256, 0, 10, 262146, { D3D_OK, 10 } },
525 };
526
527 dds = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*dds));
528 if (!dds)
529 {
530 skip("Failed to allocate memory.\n");
531 return;
532 }
533
534 for (i = 0; i < ARRAY_SIZE(tests); i++)
535 {
536 DWORD file_size = sizeof(dds->magic) + sizeof(dds->header) + tests[i].pixel_data_size;
537 assert(file_size <= sizeof(*dds));
538
539 dds->magic = MAKEFOURCC('D','D','S',' ');
540 fill_dds_header(&dds->header);
541 dds->header.flags |= tests[i].flags;
542 dds->header.width = tests[i].width;
543 dds->header.height = tests[i].height;
544 dds->header.pitch_or_linear_size = tests[i].pitch;
545 dds->header.miplevels = tests[i].miplevels;
546 dds->header.pixel_format = tests[i].pixel_format;
547
549 ok(hr == tests[i].expected.hr, "%d: D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n",
550 i, hr, tests[i].expected.hr);
551 if (SUCCEEDED(hr))
552 {
553 ok(info.MipLevels == tests[i].expected.miplevels, "%d: Got MipLevels %u, expected %u\n",
554 i, info.MipLevels, tests[i].expected.miplevels);
555 }
556 }
557
558 HeapFree(GetProcessHeap(), 0, dds);
559}
560
561static void test_D3DXGetImageInfo(void)
562{
563 HRESULT hr;
565 BOOL testdummy_ok, testbitmap_ok;
566
567 hr = create_file("testdummy.bmp", noimage, sizeof(noimage)); /* invalid image */
568 testdummy_ok = SUCCEEDED(hr);
569
570 hr = create_file("testbitmap.bmp", bmp_1bpp, sizeof(bmp_1bpp)); /* valid image */
571 testbitmap_ok = SUCCEEDED(hr);
572
573 /* D3DXGetImageInfoFromFile */
574 if(testbitmap_ok) {
575 hr = D3DXGetImageInfoFromFileA("testbitmap.bmp", &info);
576 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
577
578 hr = D3DXGetImageInfoFromFileA("testbitmap.bmp", NULL); /* valid image, second parameter is NULL */
579 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
580 } else skip("Couldn't create \"testbitmap.bmp\"\n");
581
582 if(testdummy_ok) {
583 hr = D3DXGetImageInfoFromFileA("testdummy.bmp", NULL); /* invalid image, second parameter is NULL */
584 ok(hr == D3D_OK, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3D_OK);
585
586 hr = D3DXGetImageInfoFromFileA("testdummy.bmp", &info);
587 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
588 } else skip("Couldn't create \"testdummy.bmp\"\n");
589
590 hr = D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", &info);
591 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
592
593 hr = D3DXGetImageInfoFromFileA("filedoesnotexist.bmp", NULL);
594 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
595
597 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
598
600 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
601
603 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
604
605
606 /* D3DXGetImageInfoFromResource */
608 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
609
611 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
612
614 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
615
617 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
618
620 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
621
622 hr = D3DXGetImageInfoFromResourceA(NULL, "resourcedoesnotexist", &info);
623 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
624
625 hr = D3DXGetImageInfoFromResourceA(NULL, "resourcedoesnotexist", NULL);
626 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
627
629 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
630
631
632 /* D3DXGetImageInfoFromFileInMemory */
634 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
635
636 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp, sizeof(bmp_1bpp)+5, &info); /* too large size */
637 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
638
640 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
641
643 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK);
644
646 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
647
648 todo_wine {
650 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
651 }
652
654 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
655
657 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
658
660 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
661
663 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
664
666 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
667
669 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
670
672 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
673
675 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
676
678 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
679
680 /* test BMP support */
682 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
683 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
684 ok(info.Format == D3DFMT_P8, "Got format %u, expected %u\n", info.Format, D3DFMT_P8);
686 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
688 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
689 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
690 ok(info.Format == D3DFMT_P8, "Got format %u, expected %u\n", info.Format, D3DFMT_P8);
692 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
693 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
694 ok(info.Format == D3DFMT_P8, "Got format %u, expected %u\n", info.Format, D3DFMT_P8);
695
697 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
698 ok(info.Format == D3DFMT_X8R8G8B8, "Got unexpected format %u.\n", info.Format);
700 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
701 ok(info.Format == D3DFMT_A8R8G8B8, "Got unexpected format %u.\n", info.Format);
702
703 /* Grayscale PNG */
705 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
706 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
707 ok(info.Format == D3DFMT_L8, "Got format %u, expected %u\n", info.Format, D3DFMT_L8);
708
709 /* test DDS support */
711 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
712 if (hr == D3D_OK) {
713 ok(info.Width == 2, "Got width %u, expected 2\n", info.Width);
714 ok(info.Height == 2, "Got height %u, expected 2\n", info.Height);
715 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
716 ok(info.MipLevels == 2, "Got miplevels %u, expected 2\n", info.MipLevels);
717 ok(info.Format == D3DFMT_R8G8B8, "Got format %#x, expected %#x\n", info.Format, D3DFMT_R8G8B8);
718 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
719 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
720 } else skip("Couldn't get image info from 24-bit DDS file in memory\n");
721
723 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
724 if (hr == D3D_OK) {
725 ok(info.Width == 2, "Got width %u, expected 2\n", info.Width);
726 ok(info.Height == 2, "Got height %u, expected 2\n", info.Height);
727 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
728 ok(info.MipLevels == 1, "Got miplevels %u, expected 1\n", info.MipLevels);
729 ok(info.Format == D3DFMT_X1R5G5B5, "Got format %#x, expected %#x\n", info.Format, D3DFMT_X1R5G5B5);
730 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
731 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
732 } else skip("Couldn't get image info from 16-bit DDS file in memory\n");
733
734 memset(&info, 0, sizeof(info));
736 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x\n", hr);
737 ok(info.Width == 16, "Got width %u.\n", info.Width);
738 ok(info.Height == 4, "Got height %u.\n", info.Height);
739 ok(info.Depth == 1, "Got depth %u.\n", info.Depth);
740 ok(info.MipLevels == 1, "Got miplevels %u.\n", info.MipLevels);
741 ok(info.Format == D3DFMT_P8, "Got format %#x.\n", info.Format);
742 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x.\n", info.ResourceType);
743 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x.\n", info.ImageFileFormat);
744
746 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
747 if (hr == D3D_OK) {
748 ok(info.Width == 4, "Got width %u, expected 4\n", info.Width);
749 ok(info.Height == 4, "Got height %u, expected 4\n", info.Height);
750 ok(info.Depth == 1, "Got depth %u, expected 1\n", info.Depth);
751 ok(info.MipLevels == 1, "Got miplevels %u, expected 1\n", info.MipLevels);
752 ok(info.Format == D3DFMT_DXT5, "Got format %#x, expected %#x\n", info.Format, D3DFMT_DXT5);
753 ok(info.ResourceType == D3DRTYPE_CUBETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_CUBETEXTURE);
754 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
755 } else skip("Couldn't get image info from cube map in memory\n");
756
758 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
759 if (hr == D3D_OK) {
760 ok(info.Width == 4, "Got width %u, expected 4\n", info.Width);
761 ok(info.Height == 4, "Got height %u, expected 4\n", info.Height);
762 ok(info.Depth == 2, "Got depth %u, expected 2\n", info.Depth);
763 ok(info.MipLevels == 3, "Got miplevels %u, expected 3\n", info.MipLevels);
764 ok(info.Format == D3DFMT_DXT3, "Got format %#x, expected %#x\n", info.Format, D3DFMT_DXT3);
765 ok(info.ResourceType == D3DRTYPE_VOLUMETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_VOLUMETEXTURE);
766 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got image file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
767 } else skip("Couldn't get image info from volume map in memory\n");
768
778 check_dds_pixel_format(DDS_PF_RGB, 0, 16, 0xf800, 0x07e0, 0x001f, 0, D3DFMT_R5G6B5);
779 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x7c00, 0x03e0, 0x001f, 0x8000, D3DFMT_A1R5G5B5);
780 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x0f00, 0x00f0, 0x000f, 0xf000, D3DFMT_A4R4G4B4);
781 check_dds_pixel_format(DDS_PF_RGB, 0, 8, 0xe0, 0x1c, 0x03, 0, D3DFMT_R3G3B2);
783 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 16, 0x00e0, 0x001c, 0x0003, 0xff00, D3DFMT_A8R3G3B2);
784 check_dds_pixel_format(DDS_PF_RGB, 0, 16, 0xf00, 0x0f0, 0x00f, 0, D3DFMT_X4R4G4B4);
785 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000, D3DFMT_A2B10G10R10);
786 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000, D3DFMT_A2R10G10B10);
787 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, D3DFMT_A8R8G8B8);
788 check_dds_pixel_format(DDS_PF_RGB | DDS_PF_ALPHA, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000, D3DFMT_A8B8G8R8);
789 check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0xff0000, 0x00ff00, 0x0000ff, 0, D3DFMT_X8R8G8B8);
790 check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0x0000ff, 0x00ff00, 0xff0000, 0, D3DFMT_X8B8G8R8);
791 check_dds_pixel_format(DDS_PF_RGB, 0, 24, 0xff0000, 0x00ff00, 0x0000ff, 0, D3DFMT_R8G8B8);
792 check_dds_pixel_format(DDS_PF_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_G16R16);
794 check_dds_pixel_format(DDS_PF_LUMINANCE, 0, 16, 0xffff, 0, 0, 0, D3DFMT_L16);
795 check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 16, 0x00ff, 0, 0, 0xff00, D3DFMT_A8L8);
797 check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0, 0, D3DFMT_V8U8);
798 check_dds_pixel_format(DDS_PF_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0, 0, D3DFMT_V16U16);
799 check_dds_pixel_format(DDS_PF_BUMPLUMINANCE, 0, 32, 0x0000ff, 0x00ff00, 0xff0000, 0, D3DFMT_X8L8V8U8);
800
802
804 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
805
807 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
808
810 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
811
813 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
814
815
816 /* cleanup */
817 if(testdummy_ok) DeleteFileA("testdummy.bmp");
818 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
819}
820
821#define check_pixel_2bpp(lockrect, x, y, color) _check_pixel_2bpp(__LINE__, lockrect, x, y, color)
822static inline void _check_pixel_2bpp(unsigned int line, const D3DLOCKED_RECT *lockrect, int x, int y, WORD expected_color)
823{
824 WORD color = ((WORD*)lockrect->pBits)[x + y * lockrect->Pitch / 2];
825 ok_(__FILE__, line)(color == expected_color, "Got color 0x%04x, expected 0x%04x\n", color, expected_color);
826}
827
828#define check_pixel_4bpp(lockrect, x, y, color) _check_pixel_4bpp(__LINE__, lockrect, x, y, color)
829static inline void _check_pixel_4bpp(unsigned int line, const D3DLOCKED_RECT *lockrect, int x, int y, DWORD expected_color)
830{
831 DWORD color = ((DWORD*)lockrect->pBits)[x + y * lockrect->Pitch / 4];
832 ok_(__FILE__, line)(color == expected_color, "Got color 0x%08x, expected 0x%08x\n", color, expected_color);
833}
834
835static void test_D3DXLoadSurface(IDirect3DDevice9 *device)
836{
837 HRESULT hr;
838 BOOL testdummy_ok, testbitmap_ok;
839 IDirect3DTexture9 *tex;
840 IDirect3DSurface9 *surf, *newsurf;
841 RECT rect, destrect;
842 D3DLOCKED_RECT lockrect;
843 static const WORD pixdata_a8r3g3b2[] = { 0x57df, 0x98fc, 0xacdd, 0xc891 };
844 static const WORD pixdata_a1r5g5b5[] = { 0x46b5, 0x99c8, 0x06a2, 0x9431 };
845 static const WORD pixdata_r5g6b5[] = { 0x9ef6, 0x658d, 0x0aee, 0x42ee };
846 static const WORD pixdata_a8l8[] = { 0xff00, 0x00ff, 0xff30, 0x7f7f };
847 static const DWORD pixdata_g16r16[] = { 0x07d23fbe, 0xdc7f44a4, 0xe4d8976b, 0x9a84fe89 };
848 static const DWORD pixdata_a8b8g8r8[] = { 0xc3394cf0, 0x235ae892, 0x09b197fd, 0x8dc32bf6 };
849 static const DWORD pixdata_a2r10g10b10[] = { 0x57395aff, 0x5b7668fd, 0xb0d856b5, 0xff2c61d6 };
850
851 hr = create_file("testdummy.bmp", noimage, sizeof(noimage)); /* invalid image */
852 testdummy_ok = SUCCEEDED(hr);
853
854 hr = create_file("testbitmap.bmp", bmp_1bpp, sizeof(bmp_1bpp)); /* valid image */
855 testbitmap_ok = SUCCEEDED(hr);
856
858 if(FAILED(hr)) {
859 skip("Failed to create a surface (%#x)\n", hr);
860 if(testdummy_ok) DeleteFileA("testdummy.bmp");
861 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
862 return;
863 }
864
865 /* D3DXLoadSurfaceFromFile */
866 if(testbitmap_ok) {
867 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "testbitmap.bmp", NULL, D3DX_DEFAULT, 0, NULL);
868 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3D_OK);
869
870 hr = D3DXLoadSurfaceFromFileA(NULL, NULL, NULL, "testbitmap.bmp", NULL, D3DX_DEFAULT, 0, NULL);
871 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
872 } else skip("Couldn't create \"testbitmap.bmp\"\n");
873
874 if(testdummy_ok) {
875 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "testdummy.bmp", NULL, D3DX_DEFAULT, 0, NULL);
876 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
877 } else skip("Couldn't create \"testdummy.bmp\"\n");
878
880 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
881
883 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
884
885
886 /* D3DXLoadSurfaceFromResource */
889 ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK);
890
893 ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK);
894
896 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
897
900 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
901
904 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
905
906
907 /* D3DXLoadSurfaceFromFileInMemory */
909 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
910
912 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
913
915 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
916
918 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
919
921 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
922
924 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
925
927 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
928
929
930 /* D3DXLoadSurfaceFromMemory */
931 SetRect(&rect, 0, 0, 2, 2);
932
934 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
935
937 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
938
940 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
941
943 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
944
946 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
947
949 ok(hr == E_FAIL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, E_FAIL);
950
951 SetRect(&destrect, -1, -1, 1, 1); /* destination rect is partially outside texture boundaries */
953 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
954
955 SetRect(&destrect, 255, 255, 257, 257); /* destination rect is partially outside texture boundaries */
957 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
958
959 SetRect(&destrect, 1, 1, 0, 0); /* left > right, top > bottom */
961 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
962
963 SetRect(&destrect, 1, 2, 1, 2); /* left = right, top = bottom */
965 /* fails when debug version of d3d9 is used */
966 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
967
968 SetRect(&destrect, 257, 257, 257, 257); /* left = right, top = bottom, but invalid values */
970 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
971
972
973 /* D3DXLoadSurfaceFromSurface */
975 if(SUCCEEDED(hr)) {
977 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
978
980 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
981
983 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
984
985 check_release((IUnknown*)newsurf, 0);
986 } else skip("Failed to create a second surface\n");
987
989 if (SUCCEEDED(hr))
990 {
991 IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
992
994 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK);
995
998 } else skip("Failed to create texture\n");
999
1000 /* non-lockable render target */
1002 ok(hr == D3D_OK, "Unexpected hr %#x.\n", hr);
1004 ok(hr == D3D_OK, "Unexpected hr %#x.\n", hr);
1006
1007 /* non-lockable multisampled render target */
1009 if (SUCCEEDED(hr))
1010 {
1012 ok(hr == D3D_OK, "Unexpected hr %#x.\n", hr);
1013
1015 }
1016 else
1017 {
1018 skip("Failed to create multisampled render target.\n");
1019 }
1020
1022 ok(hr == D3D_OK, "IDirect3DDevice9_GetRenderTarget returned %#x, expected %#x.\n", hr, D3D_OK);
1023
1025 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, D3D_OK);
1027 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, D3D_OK);
1028 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0xff000000);
1029 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, D3D_OK);
1031 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, D3D_OK);
1033 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, D3D_OK);
1034
1035 /* rects */
1036 SetRect(&rect, 2, 2, 1, 1);
1038 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
1039 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, &rect, D3DX_DEFAULT, 0);
1040 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
1042 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
1043 hr = D3DXLoadSurfaceFromSurface(surf, NULL, &rect, newsurf, NULL, NULL, D3DX_DEFAULT, 0);
1044 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
1046 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
1047 SetRect(&rect, 1, 1, 1, 1);
1049 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, D3D_OK);
1051 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, D3D_OK);
1052 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, &rect, D3DX_DEFAULT, 0);
1053 ok(hr == E_FAIL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, E_FAIL);
1054 hr = D3DXLoadSurfaceFromSurface(surf, NULL, &rect, newsurf, NULL, NULL, D3DX_DEFAULT, 0);
1055 ok(hr == E_FAIL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, E_FAIL);
1056 if (0)
1057 {
1058 /* Somehow it crashes with a STATUS_INTEGER_DIVIDE_BY_ZERO exception
1059 * on Windows. */
1061 ok(hr == E_FAIL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, E_FAIL);
1062 }
1063 SetRect(&rect, 1, 1, 2, 2);
1064 SetRect(&destrect, 1, 1, 2, 2);
1065 hr = D3DXLoadSurfaceFromSurface(surf, NULL, &rect, newsurf, NULL, &destrect, D3DX_FILTER_NONE, 0);
1066 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, D3D_OK);
1068 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, D3D_OK);
1069 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, &destrect, D3DX_FILTER_NONE, 0);
1070 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, D3D_OK);
1071
1073
1074 check_release((IUnknown*)surf, 0);
1075
1076 SetRect(&rect, 1, 1, 2, 2);
1078 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1079 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8,
1081 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1083 check_pixel_4bpp(&lockrect, 0, 0, 0x8dc32bf6);
1085 check_release((IUnknown *)surf, 0);
1086
1087 /* test color conversion */
1088 SetRect(&rect, 0, 0, 2, 2);
1089 /* A8R8G8B8 */
1091 if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr);
1092 else {
1094
1095 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2,
1097 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
1099 check_pixel_4bpp(&lockrect, 0, 0, 0x57dbffff);
1100 check_pixel_4bpp(&lockrect, 1, 0, 0x98ffff00);
1101 check_pixel_4bpp(&lockrect, 0, 1, 0xacdbff55);
1102 check_pixel_4bpp(&lockrect, 1, 1, 0xc8929255);
1104
1105 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5,
1107 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
1109 check_pixel_4bpp(&lockrect, 0, 0, 0x008cadad);
1110 check_pixel_4bpp(&lockrect, 1, 0, 0xff317342);
1111 check_pixel_4bpp(&lockrect, 0, 1, 0x0008ad10);
1112 check_pixel_4bpp(&lockrect, 1, 1, 0xff29088c);
1114
1115 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5,
1117 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
1119 check_pixel_4bpp(&lockrect, 0, 0, 0xff9cdfb5);
1120 check_pixel_4bpp(&lockrect, 1, 0, 0xff63b26b);
1121 check_pixel_4bpp(&lockrect, 0, 1, 0xff085d73);
1122 check_pixel_4bpp(&lockrect, 1, 1, 0xff425d73);
1124
1125 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16,
1127 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
1129 todo_wine {
1130 check_pixel_4bpp(&lockrect, 0, 0, 0xff3f08ff);
1131 }
1132 check_pixel_4bpp(&lockrect, 1, 0, 0xff44dcff);
1133 check_pixel_4bpp(&lockrect, 0, 1, 0xff97e4ff);
1134 check_pixel_4bpp(&lockrect, 1, 1, 0xfffe9aff);
1136
1137 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8,
1139 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1141 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1142 check_pixel_4bpp(&lockrect, 0, 0, 0xc3f04c39);
1143 check_pixel_4bpp(&lockrect, 1, 0, 0x2392e85a);
1144 check_pixel_4bpp(&lockrect, 0, 1, 0x09fd97b1);
1145 check_pixel_4bpp(&lockrect, 1, 1, 0x8df62bc3);
1147
1148 SetRect(&rect, 0, 0, 1, 1);
1149 SetRect(&destrect, 1, 1, 2, 2);
1150 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata_a8b8g8r8,
1152 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1154 check_pixel_4bpp(&lockrect, 0, 0, 0xc3f04c39);
1155 check_pixel_4bpp(&lockrect, 1, 0, 0x2392e85a);
1156 check_pixel_4bpp(&lockrect, 0, 1, 0x09fd97b1);
1157 check_pixel_4bpp(&lockrect, 1, 1, 0xc3f04c39);
1159
1160 SetRect(&rect, 0, 0, 2, 2);
1161
1162 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10,
1164 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1166 check_pixel_4bpp(&lockrect, 0, 0, 0x555c95bf);
1167 check_pixel_4bpp(&lockrect, 1, 0, 0x556d663f);
1168 check_pixel_4bpp(&lockrect, 0, 1, 0xaac385ad);
1169 todo_wine {
1170 check_pixel_4bpp(&lockrect, 1, 1, 0xfffcc575);
1171 }
1173
1174 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
1176 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1178 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
1179 check_pixel_4bpp(&lockrect, 0, 0, 0xff000000);
1180 check_pixel_4bpp(&lockrect, 1, 0, 0x00ffffff);
1181 check_pixel_4bpp(&lockrect, 0, 1, 0xff303030);
1182 check_pixel_4bpp(&lockrect, 1, 1, 0x7f7f7f7f);
1184 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1185
1186 /* Test D3DXLoadSurfaceFromMemory with indexed color image */
1187 if (0)
1188 {
1189 /* Crashes on Nvidia Win10. */
1190 palette.peRed = bmp_1bpp[56];
1191 palette.peGreen = bmp_1bpp[55];
1192 palette.peBlue = bmp_1bpp[54];
1193 palette.peFlags = bmp_1bpp[57]; /* peFlags is the alpha component in DX8 and higher */
1195 D3DFMT_P8, 1, (const PALETTEENTRY *)&palette, &rect, D3DX_FILTER_NONE, 0);
1196 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1198 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x\n", hr);
1199 ok(*(DWORD*)lockrect.pBits == 0x80f3f2f1,
1200 "Pixel color mismatch: got %#x, expected 0x80f3f2f1\n", *(DWORD*)lockrect.pBits);
1202 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x\n", hr);
1203 }
1204
1205 /* Test D3DXLoadSurfaceFromFileInMemory with indexed color image (alpha is not taken into account for bmp file) */
1207 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1209 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x\n", hr);
1210 ok(*(DWORD*)lockrect.pBits == 0xfff3f2f1, "Pixel color mismatch: got %#x, expected 0xfff3f2f1\n", *(DWORD*)lockrect.pBits);
1212 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x\n", hr);
1213
1214 check_release((IUnknown*)surf, 0);
1215 }
1216
1217 /* A1R5G5B5 */
1219 if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr);
1220 else {
1221 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2,
1223 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
1225 check_pixel_2bpp(&lockrect, 0, 0, 0x6fff);
1226 check_pixel_2bpp(&lockrect, 1, 0, 0xffe0);
1227 check_pixel_2bpp(&lockrect, 0, 1, 0xefea);
1228 check_pixel_2bpp(&lockrect, 1, 1, 0xca4a);
1230
1231 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5,
1233 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
1235 check_pixel_2bpp(&lockrect, 0, 0, 0x46b5);
1236 check_pixel_2bpp(&lockrect, 1, 0, 0x99c8);
1237 check_pixel_2bpp(&lockrect, 0, 1, 0x06a2);
1238 check_pixel_2bpp(&lockrect, 1, 1, 0x9431);
1240
1241 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5,
1243 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
1245 check_pixel_2bpp(&lockrect, 0, 0, 0xcf76);
1246 check_pixel_2bpp(&lockrect, 1, 0, 0xb2cd);
1247 check_pixel_2bpp(&lockrect, 0, 1, 0x856e);
1248 check_pixel_2bpp(&lockrect, 1, 1, 0xa16e);
1250
1251 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16,
1253 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
1255 todo_wine {
1256 check_pixel_2bpp(&lockrect, 0, 0, 0xa03f);
1257 }
1258 check_pixel_2bpp(&lockrect, 1, 0, 0xa37f);
1259 check_pixel_2bpp(&lockrect, 0, 1, 0xcb9f);
1260 check_pixel_2bpp(&lockrect, 1, 1, 0xfe7f);
1262
1263 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8,
1265 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
1267 todo_wine {
1268 check_pixel_2bpp(&lockrect, 0, 0, 0xf527);
1269 check_pixel_2bpp(&lockrect, 1, 0, 0x4b8b);
1270 }
1271 check_pixel_2bpp(&lockrect, 0, 1, 0x7e56);
1272 check_pixel_2bpp(&lockrect, 1, 1, 0xf8b8);
1274
1275 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10,
1277 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
1279 check_pixel_2bpp(&lockrect, 0, 0, 0x2e57);
1280 todo_wine {
1281 check_pixel_2bpp(&lockrect, 1, 0, 0x3588);
1282 }
1283 check_pixel_2bpp(&lockrect, 0, 1, 0xe215);
1284 check_pixel_2bpp(&lockrect, 1, 1, 0xff0e);
1286
1287 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
1289 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1291 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
1292 check_pixel_2bpp(&lockrect, 0, 0, 0x8000);
1293 check_pixel_2bpp(&lockrect, 1, 0, 0x7fff);
1294 check_pixel_2bpp(&lockrect, 0, 1, 0x98c6);
1295 check_pixel_2bpp(&lockrect, 1, 1, 0x3def);
1297 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1298
1299 check_release((IUnknown*)surf, 0);
1300 }
1301
1302 /* A8L8 */
1304 if (FAILED(hr))
1305 skip("Failed to create A8L8 texture, hr %#x.\n", hr);
1306 else
1307 {
1308 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &surf);
1309 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#x.\n", hr);
1310
1311 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2,
1313 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1315 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
1316 check_pixel_2bpp(&lockrect, 0, 0, 0x57f7);
1317 check_pixel_2bpp(&lockrect, 1, 0, 0x98ed);
1318 check_pixel_2bpp(&lockrect, 0, 1, 0xaceb);
1319 check_pixel_2bpp(&lockrect, 1, 1, 0xc88d);
1321 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1322
1323 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5,
1325 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
1327 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
1328 check_pixel_2bpp(&lockrect, 0, 0, 0x00a6);
1329 check_pixel_2bpp(&lockrect, 1, 0, 0xff62);
1330 check_pixel_2bpp(&lockrect, 0, 1, 0x007f);
1331 check_pixel_2bpp(&lockrect, 1, 1, 0xff19);
1333 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1334
1335 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5,
1337 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1339 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
1340 check_pixel_2bpp(&lockrect, 0, 0, 0xffce);
1341 check_pixel_2bpp(&lockrect, 1, 0, 0xff9c);
1342 check_pixel_2bpp(&lockrect, 0, 1, 0xff4d);
1343 check_pixel_2bpp(&lockrect, 1, 1, 0xff59);
1345 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1346
1347 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16,
1349 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1351 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
1352 check_pixel_2bpp(&lockrect, 0, 0, 0xff25);
1353 check_pixel_2bpp(&lockrect, 1, 0, 0xffbe);
1354 check_pixel_2bpp(&lockrect, 0, 1, 0xffd6);
1355 check_pixel_2bpp(&lockrect, 1, 1, 0xffb6);
1357 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1358
1359 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8,
1361 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1363 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
1364 check_pixel_2bpp(&lockrect, 0, 0, 0xc36d);
1365 check_pixel_2bpp(&lockrect, 1, 0, 0x23cb);
1366 check_pixel_2bpp(&lockrect, 0, 1, 0x09af);
1367 check_pixel_2bpp(&lockrect, 1, 1, 0x8d61);
1369 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1370
1371 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10,
1373 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1375 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
1376 check_pixel_2bpp(&lockrect, 0, 0, 0x558c);
1377 check_pixel_2bpp(&lockrect, 1, 0, 0x5565);
1378 check_pixel_2bpp(&lockrect, 0, 1, 0xaa95);
1379 check_pixel_2bpp(&lockrect, 1, 1, 0xffcb);
1381 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1382
1383 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8,
1385 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1387 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
1388 check_pixel_2bpp(&lockrect, 0, 0, 0xff00);
1389 check_pixel_2bpp(&lockrect, 1, 0, 0x00ff);
1390 check_pixel_2bpp(&lockrect, 0, 1, 0xff30);
1391 check_pixel_2bpp(&lockrect, 1, 1, 0x7f7f);
1393 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
1394
1395 check_release((IUnknown*)surf, 1);
1396 check_release((IUnknown*)tex, 0);
1397 }
1398
1399 /* DXT1, DXT2, DXT3, DXT4, DXT5 */
1401 if (FAILED(hr))
1402 skip("Failed to create A8R8G8B8 surface, hr %#x.\n", hr);
1403 else
1404 {
1406 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr);
1407
1409 if (FAILED(hr))
1410 skip("Failed to create DXT2 texture, hr %#x.\n", hr);
1411 else
1412 {
1413 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
1414 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#x.\n", hr);
1416 ok(SUCCEEDED(hr), "Failed to convert pixels to DXT2 format.\n");
1417 check_release((IUnknown*)newsurf, 1);
1418 check_release((IUnknown*)tex, 0);
1419 }
1420
1422 if (FAILED(hr))
1423 skip("Failed to create DXT3 texture, hr %#x.\n", hr);
1424 else
1425 {
1426 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
1427 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#x.\n", hr);
1429 ok(SUCCEEDED(hr), "Failed to convert pixels to DXT3 format.\n");
1430 check_release((IUnknown*)newsurf, 1);
1431 check_release((IUnknown*)tex, 0);
1432 }
1433
1435 if (FAILED(hr))
1436 skip("Failed to create DXT4 texture, hr %#x.\n", hr);
1437 else
1438 {
1439 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
1440 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#x.\n", hr);
1442 ok(SUCCEEDED(hr), "Failed to convert pixels to DXT4 format.\n");
1443 check_release((IUnknown*)newsurf, 1);
1444 check_release((IUnknown*)tex, 0);
1445 }
1446
1448 if (FAILED(hr))
1449 skip("Failed to create DXT5 texture, hr %#x.\n", hr);
1450 else
1451 {
1452 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
1453 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#x.\n", hr);
1455 ok(SUCCEEDED(hr), "Failed to convert pixels to DXT5 format.\n");
1456
1457 SetRect(&rect, 0, 0, 4, 2);
1458 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, &rect, surf, NULL, &rect, D3DX_FILTER_NONE, 0);
1459 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1460 hr = D3DXLoadSurfaceFromMemory(newsurf, NULL, &rect, &dds_dxt5[128],
1462 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1463 check_release((IUnknown *)newsurf, 1);
1464 check_release((IUnknown *)tex, 0);
1465
1466 /* Test a rect larger than but not an integer multiple of the block size. */
1468 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1469 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
1470 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1471 SetRect(&rect, 0, 0, 4, 6);
1472 hr = D3DXLoadSurfaceFromMemory(newsurf, NULL, &rect, &dds_dxt5[112],
1474 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1475
1476 check_release((IUnknown *)newsurf, 1);
1477 check_release((IUnknown *)tex, 0);
1478
1479 /* More misalignment tests. */
1481 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1482 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
1483 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1484
1485 SetRect(&rect, 2, 2, 6, 6);
1487 D3DFMT_DXT5, 16 * 2, NULL, &rect, D3DX_FILTER_POINT, 0);
1488 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1489
1491 D3DFMT_DXT5, 16 * 2, NULL, NULL, D3DX_FILTER_POINT, 0);
1492 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
1493
1495 D3DFMT_DXT5, 16 * 2, NULL, &rect, D3DX_FILTER_POINT, 0);
1496 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1497
1498 check_release((IUnknown *)newsurf, 1);
1499 check_release((IUnknown *)tex, 0);
1500 }
1501
1503 if (FAILED(hr))
1504 skip("Failed to create DXT1 texture, hr %#x.\n", hr);
1505 else
1506 {
1507 hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf);
1508 ok(SUCCEEDED(hr), "Failed to get the surface, hr %#x.\n", hr);
1510 ok(SUCCEEDED(hr), "Failed to convert pixels to DXT1 format.\n");
1511
1513 ok(SUCCEEDED(hr), "Failed to convert pixels from DXT1 format.\n");
1514
1515 check_release((IUnknown*)newsurf, 1);
1516 check_release((IUnknown*)tex, 0);
1517 }
1518
1519 check_release((IUnknown*)surf, 0);
1520 }
1521
1522 /* cleanup */
1523 if(testdummy_ok) DeleteFileA("testdummy.bmp");
1524 if(testbitmap_ok) DeleteFileA("testbitmap.bmp");
1525}
1526
1527static void test_D3DXSaveSurfaceToFileInMemory(IDirect3DDevice9 *device)
1528{
1529 static const struct
1530 {
1531 DWORD usage;
1532 D3DPOOL pool;
1533 }
1534 test_access_types[] =
1535 {
1536 {0, D3DPOOL_MANAGED},
1537 {0, D3DPOOL_DEFAULT},
1539 };
1540
1541 struct
1542 {
1543 DWORD magic;
1544 struct dds_header header;
1545 BYTE *data;
1546 } *dds;
1547 IDirect3DSurface9 *surface;
1548 IDirect3DTexture9 *texture;
1550 unsigned int i;
1551 HRESULT hr;
1552 RECT rect;
1553
1555 if (FAILED(hr)) {
1556 skip("Couldn't create surface\n");
1557 return;
1558 }
1559
1562 /* fails with the debug version of d3d9 */
1563 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXSaveSurfaceToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1564 if (SUCCEEDED(hr)) {
1566 ok(size > 0, "ID3DXBuffer_GetBufferSize returned %u, expected > 0\n", size);
1568 }
1569
1572 todo_wine ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1573 if (SUCCEEDED(hr))
1574 {
1576
1577 ok(dds->magic == MAKEFOURCC('D','D','S',' '), "Got unexpected DDS signature %#x.\n", dds->magic);
1578 ok(dds->header.size == sizeof(dds->header), "Got unexpected DDS size %u.\n", dds->header.size);
1579 ok(!dds->header.height, "Got unexpected height %u.\n", dds->header.height);
1580 ok(!dds->header.width, "Got unexpected width %u.\n", dds->header.width);
1581 ok(!dds->header.depth, "Got unexpected depth %u.\n", dds->header.depth);
1582 ok(!dds->header.miplevels, "Got unexpected miplevels %u.\n", dds->header.miplevels);
1583 ok(!dds->header.pitch_or_linear_size, "Got unexpected pitch_or_linear_size %u.\n", dds->header.pitch_or_linear_size);
1584 ok(dds->header.caps == (DDS_CAPS_TEXTURE | DDSCAPS_ALPHA), "Got unexpected caps %#x.\n", dds->header.caps);
1585 ok(dds->header.flags == (DDS_CAPS | DDS_HEIGHT | DDS_WIDTH | DDS_PIXELFORMAT),
1586 "Got unexpected flags %#x.\n", dds->header.flags);
1588 }
1589
1591 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1592
1594 ok(dds->magic == MAKEFOURCC('D','D','S',' '), "Got unexpected DDS signature %#x.\n", dds->magic);
1595 ok(dds->header.size == sizeof(dds->header), "Got unexpected DDS size %u.\n", dds->header.size);
1596 ok(dds->header.height == 4, "Got unexpected height %u.\n", dds->header.height);
1597 ok(dds->header.width == 4, "Got unexpected width %u.\n", dds->header.width);
1598 ok(!dds->header.depth, "Got unexpected depth %u.\n", dds->header.depth);
1599 ok(!dds->header.miplevels, "Got unexpected miplevels %u.\n", dds->header.miplevels);
1600 ok(!dds->header.pitch_or_linear_size, "Got unexpected pitch_or_linear_size %u.\n", dds->header.pitch_or_linear_size);
1601 todo_wine ok(dds->header.caps == (DDS_CAPS_TEXTURE | DDSCAPS_ALPHA), "Got unexpected caps %#x.\n", dds->header.caps);
1602 ok(dds->header.flags == (DDS_CAPS | DDS_HEIGHT | DDS_WIDTH | DDS_PIXELFORMAT),
1603 "Got unexpected flags %#x.\n", dds->header.flags);
1605
1607
1608 for (i = 0; i < ARRAY_SIZE(test_access_types); ++i)
1609 {
1610 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 0, test_access_types[i].usage,
1611 D3DFMT_A8R8G8B8, test_access_types[i].pool, &texture, NULL);
1612 ok(hr == D3D_OK, "Unexpected hr %#x, i %u.\n", hr, i);
1613
1615 ok(hr == D3D_OK, "Unexpected hr %#x, i %u.\n", hr, i);
1616
1618 ok(hr == D3D_OK, "Unexpected hr %#x, i %u.\n", hr, i);
1620
1622 ok(hr == D3D_OK, "Unexpected hr %#x, i %u.\n", hr, i);
1624
1627 }
1628}
1629
1630static void test_D3DXSaveSurfaceToFile(IDirect3DDevice9 *device)
1631{
1632 static const BYTE pixels[] =
1633 {0xff, 0x00, 0x00, 0x00, 0xff, 0x00,
1634 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,};
1635 DWORD pitch = sizeof(pixels) / 2;
1636 IDirect3DSurface9 *surface;
1637 D3DXIMAGE_INFO image_info;
1638 D3DLOCKED_RECT lock_rect;
1639 HRESULT hr;
1640 RECT rect;
1641
1643 if (FAILED(hr))
1644 {
1645 skip("Couldn't create surface.\n");
1646 return;
1647 }
1648
1649 SetRect(&rect, 0, 0, 2, 2);
1651 pitch, NULL, &rect, D3DX_FILTER_NONE, 0);
1652 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1653
1654 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, NULL);
1655 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1656
1657 hr = D3DXLoadSurfaceFromFileA(surface, NULL, NULL, "saved_surface.bmp",
1658 NULL, D3DX_FILTER_NONE, 0, &image_info);
1659 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1660
1661 ok(image_info.Width == 2, "Wrong width %u.\n", image_info.Width);
1662 ok(image_info.Height == 2, "Wrong height %u.\n", image_info.Height);
1663 ok(image_info.Format == D3DFMT_R8G8B8, "Wrong format %#x.\n", image_info.Format);
1664 ok(image_info.ImageFileFormat == D3DXIFF_BMP, "Wrong file format %u.\n", image_info.ImageFileFormat);
1665
1666 hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
1667 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1668
1669 ok(!memcmp(lock_rect.pBits, pixels, pitch),
1670 "Pixel data mismatch in the first row.\n");
1671 ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch),
1672 "Pixel data mismatch in the second row.\n");
1673
1675
1676 SetRect(&rect, 0, 1, 2, 2);
1677 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1678 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1679 SetRect(&rect, 0, 0, 2, 1);
1680 hr = D3DXLoadSurfaceFromFileA(surface, NULL, &rect, "saved_surface.bmp", NULL,
1681 D3DX_FILTER_NONE, 0, &image_info);
1682 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1683
1684 hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
1685 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1686 ok(!memcmp(lock_rect.pBits, pixels + pitch, pitch),
1687 "Pixel data mismatch in the first row.\n");
1688 ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch),
1689 "Pixel data mismatch in the second row.\n");
1691
1692 SetRect(&rect, 0, 0, 2, 2);
1694 pitch, NULL, &rect, D3DX_FILTER_NONE, 0);
1695 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1696
1698 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
1699
1700 /* PPM and TGA are supported, even though MSDN claims they aren't */
1701 todo_wine
1702 {
1703 hr = D3DXSaveSurfaceToFileA("saved_surface.ppm", D3DXIFF_PPM, surface, NULL, NULL);
1704 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1705 hr = D3DXSaveSurfaceToFileA("saved_surface.tga", D3DXIFF_TGA, surface, NULL, NULL);
1706 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1707 }
1708
1709 hr = D3DXSaveSurfaceToFileA("saved_surface.dds", D3DXIFF_DDS, surface, NULL, NULL);
1710 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1711
1712 hr = D3DXLoadSurfaceFromFileA(surface, NULL, NULL, "saved_surface.dds",
1713 NULL, D3DX_FILTER_NONE, 0, &image_info);
1714 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1715
1716 ok(image_info.Width == 2, "Wrong width %u.\n", image_info.Width);
1717 ok(image_info.Format == D3DFMT_R8G8B8, "Wrong format %#x.\n", image_info.Format);
1718 ok(image_info.ImageFileFormat == D3DXIFF_DDS, "Wrong file format %u.\n", image_info.ImageFileFormat);
1719
1720 hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
1721 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1722 ok(!memcmp(lock_rect.pBits, pixels, pitch),
1723 "Pixel data mismatch in the first row.\n");
1724 ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch),
1725 "Pixel data mismatch in the second row.\n");
1727
1728 hr = D3DXSaveSurfaceToFileA("saved_surface", D3DXIFF_PFM + 1, surface, NULL, NULL);
1729 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
1730
1731 SetRect(&rect, 0, 0, 4, 4);
1732 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1733 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
1734 SetRect(&rect, 2, 0, 1, 4);
1735 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1736 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
1737 SetRect(&rect, 0, 2, 4, 1);
1738 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1739 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
1740 SetRect(&rect, -1, -1, 2, 2);
1741 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1742 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
1744 hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
1745 /* fails when debug version of d3d9 is used */
1746 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "Got unexpected hr %#x.\n", hr);
1747
1748 DeleteFileA("saved_surface.bmp");
1749 DeleteFileA("saved_surface.ppm");
1750 DeleteFileA("saved_surface.tga");
1751 DeleteFileA("saved_surface.dds");
1752
1754}
1755
1757{
1758 HWND wnd;
1759 IDirect3D9 *d3d;
1760 IDirect3DDevice9 *device;
1762 HRESULT hr;
1763
1764 if (!(wnd = CreateWindowA("static", "d3dx9_test", WS_OVERLAPPEDWINDOW, 0, 0,
1765 640, 480, NULL, NULL, NULL, NULL)))
1766 {
1767 skip("Couldn't create application window\n");
1768 return;
1769 }
1771 if (!d3d) {
1772 skip("Couldn't create IDirect3D9 object\n");
1773 DestroyWindow(wnd);
1774 return;
1775 }
1776
1777 ZeroMemory(&d3dpp, sizeof(d3dpp));
1778 d3dpp.Windowed = TRUE;
1781 if(FAILED(hr)) {
1782 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1783 IDirect3D9_Release(d3d);
1784 DestroyWindow(wnd);
1785 return;
1786 }
1787
1792
1794 check_release((IUnknown*)d3d, 0);
1795 DestroyWindow(wnd);
1796}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define broken(x)
Definition: atltest.h:178
#define START_TEST(x)
Definition: atltest.h:75
#define ok_(x1, x2)
Definition: atltest.h:61
#define IDS_STRING
Definition: resource.h:17
#define ARRAY_SIZE(A)
Definition: main.h:20
#define D3DXERR_INVALIDDATA
Definition: compiler.c:30
@ D3DMULTISAMPLE_NONE
Definition: d3d8types.h:672
@ D3DMULTISAMPLE_2_SAMPLES
Definition: d3d8types.h:673
@ D3DFMT_DXT5
Definition: d3d8types.h:638
@ D3DFMT_A1R5G5B5
Definition: d3d8types.h:608
@ D3DFMT_UYVY
Definition: d3d8types.h:632
@ D3DFMT_YUY2
Definition: d3d8types.h:633
@ D3DFMT_X1R5G5B5
Definition: d3d8types.h:607
@ D3DFMT_DXT2
Definition: d3d8types.h:635
@ D3DFMT_R8G8B8
Definition: d3d8types.h:603
@ D3DFMT_R3G3B2
Definition: d3d8types.h:610
@ D3DFMT_A8L8
Definition: d3d8types.h:621
@ D3DFMT_V16U16
Definition: d3d8types.h:628
@ D3DFMT_A8R8G8B8
Definition: d3d8types.h:604
@ 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_V8U8
Definition: d3d8types.h:624
@ D3DFMT_DXT4
Definition: d3d8types.h:637
@ D3DFMT_A4R4G4B4
Definition: d3d8types.h:609
@ D3DFMT_P8
Definition: d3d8types.h:618
@ D3DFMT_UNKNOWN
Definition: d3d8types.h:601
@ D3DFMT_DXT3
Definition: d3d8types.h:636
@ D3DFMT_X8R8G8B8
Definition: d3d8types.h:605
@ D3DFMT_L8
Definition: d3d8types.h:620
@ D3DFMT_G16R16
Definition: d3d8types.h:615
@ D3DFMT_A4L4
Definition: d3d8types.h:622
@ D3DRTYPE_TEXTURE
Definition: d3d8types.h:812
@ D3DRTYPE_VOLUMETEXTURE
Definition: d3d8types.h:813
@ D3DRTYPE_CUBETEXTURE
Definition: d3d8types.h:814
enum _D3DPOOL D3DPOOL
@ D3DSWAPEFFECT_DISCARD
Definition: d3d8types.h:851
@ D3DDEVTYPE_HAL
Definition: d3d8types.h:576
#define D3DUSAGE_RENDERTARGET
Definition: d3d8types.h:91
@ D3DPOOL_SCRATCH
Definition: d3d8types.h:712
@ D3DPOOL_DEFAULT
Definition: d3d8types.h:709
@ D3DPOOL_SYSTEMMEM
Definition: d3d8types.h:711
@ D3DPOOL_MANAGED
Definition: d3d8types.h:710
enum _D3DFORMAT D3DFORMAT
#define D3DLOCK_READONLY
Definition: d3d8types.h:69
IDirect3D9 *WINAPI Direct3DCreate9(UINT SDKVersion)
Definition: d3d9.c:57
#define IDirect3DTexture9_GetSurfaceLevel(p, a, b)
Definition: d3d9.h:1033
#define IDirect3DSurface9_LockRect(p, a, b, c)
Definition: d3d9.h:635
#define IDirect3D9_CreateDevice(p, a, b, c, d, e, f)
Definition: d3d9.h:235
#define IDirect3DDevice9_CreateTexture(p, a, b, c, d, e, f, g, h)
Definition: d3d9.h:1530
#define IDirect3D9_Release(p)
Definition: d3d9.h:220
#define IDirect3DSurface9_UnlockRect(p)
Definition: d3d9.h:636
#define IDirect3DSurface9_Release(p)
Definition: d3d9.h:622
#define IDirect3DTexture9_Release(p)
Definition: d3d9.h:1014
#define IDirect3DDevice9_CreateRenderTarget(p, a, b, c, d, e, f, g, h)
Definition: d3d9.h:1535
#define IDirect3DDevice9_CreateOffscreenPlainSurface(p, a, b, c, d, e, f)
Definition: d3d9.h:1543
#define IDirect3DDevice9_GetRenderTarget(p, a, b)
Definition: d3d9.h:1545
@ D3DFMT_G8R8_G8B8
Definition: d3d9types.h:805
@ D3DFMT_R8G8_B8G8
Definition: d3d9types.h:806
@ D3DFMT_X8B8G8R8
Definition: d3d9types.h:777
@ D3DFMT_A2R10G10B10
Definition: d3d9types.h:779
@ D3DFMT_A8B8G8R8
Definition: d3d9types.h:776
@ D3DFMT_L16
Definition: d3d9types.h:815
#define D3D_OK
Definition: d3d.h:106
#define D3DERR_INVALIDCALL
struct ID3DXBuffer ID3DXBuffer
Definition: d3dx8core.h:51
#define D3DX_DEFAULT
Definition: d3dx9.h:24
#define ID3DXBuffer_GetBufferSize(p)
Definition: d3dx9core.h:86
#define ID3DXBuffer_GetBufferPointer(p)
Definition: d3dx9core.h:85
#define ID3DXBuffer_Release(p)
Definition: d3dx9core.h:83
#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
@ D3DXIFF_DDS
Definition: d3dx9tex.h:68
@ D3DXIFF_BMP
Definition: d3dx9tex.h:64
@ D3DXIFF_TGA
Definition: d3dx9tex.h:66
@ D3DXIFF_PFM
Definition: d3dx9tex.h:72
@ D3DXIFF_PPM
Definition: d3dx9tex.h:69
#define D3DX_FILTER_NONE
Definition: d3dx9tex.h:27
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
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:1963
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:1416
HRESULT WINAPI D3DXGetImageInfoFromFileInMemory(const void *data, UINT datasize, D3DXIMAGE_INFO *info)
Definition: surface.c:985
DWORD gmask
Definition: surface.c:187
#define DDS_CAPS
Definition: surface.c:84
#define DDS_HEIGHT
Definition: surface.c:85
HRESULT WINAPI D3DXGetImageInfoFromResourceA(HMODULE module, const char *resource, D3DXIMAGE_INFO *info)
Definition: surface.c:1184
DWORD amask
Definition: surface.c:189
#define DDS_PF_RGB
Definition: surface.c:116
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:2364
#define DDS_CAPS_TEXTURE
Definition: surface.c:95
#define DDS_PF_LUMINANCE
Definition: surface.c:118
HRESULT WINAPI D3DXSaveSurfaceToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE_FILEFORMAT file_format, IDirect3DSurface9 *src_surface, const PALETTEENTRY *src_palette, const RECT *src_rect)
Definition: surface.c:2414
HRESULT WINAPI D3DXGetImageInfoFromFileA(const char *file, D3DXIMAGE_INFO *info)
Definition: surface.c:1135
#define DDS_PF_BUMPLUMINANCE
Definition: surface.c:119
#define DDS_PF_BUMPDUDV
Definition: surface.c:120
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:1469
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:2233
DWORD rmask
Definition: surface.c:186
#define DDS_PF_ALPHA_ONLY
Definition: surface.c:113
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:1245
#define DDS_PIXELFORMAT
Definition: surface.c:88
#define DDS_WIDTH
Definition: surface.c:86
#define DDS_PF_FOURCC
Definition: surface.c:114
DWORD bpp
Definition: surface.c:185
#define DDS_PF_ALPHA
Definition: surface.c:112
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define HeapFree(x, y, z)
Definition: compat.h:735
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define assert(x)
Definition: debug.h:53
#define MAKEFOURCC(ch0, ch1, ch2, ch3)
Definition: dmdls.h:24
r received
Definition: btrfs.c:3005
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: gl.h:1546
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint texture
Definition: glext.h:6295
GLuint buffer
Definition: glext.h:5915
GLuint color
Definition: glext.h:6243
GLbitfield flags
Definition: glext.h:7161
GLsizeiptr const GLvoid GLenum usage
Definition: glext.h:5919
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
const char * filename
Definition: ioapi.h:137
static const int bmask[16]
Definition: jdhuff.c:579
#define CREATE_ALWAYS
Definition: disk.h:72
static struct test_info tests[]
BOOL expected
Definition: store.c:2063
#define IDB_BITMAP_1x1
Definition: resources.h:22
#define IDD_BITMAPDATA_1x1
Definition: resources.h:23
static const unsigned char pixdata[]
Definition: surface.c:101
static void test_D3DXSaveSurfaceToFileInMemory(IDirect3DDevice9 *device)
Definition: surface.c:1527
static void test_dds_header_handling(void)
Definition: surface.c:410
static const unsigned char dds_volume_map[]
Definition: surface.c:236
static const unsigned char dds_8bit[]
Definition: surface.c:111
static const BYTE dds_dxt5[]
Definition: surface.c:252
static const unsigned char dds_cube_map[]
Definition: surface.c:218
static const unsigned char dds_16bit[]
Definition: surface.c:205
static const unsigned char bmp_1bpp[]
Definition: surface.c:35
#define check_pixel_2bpp(lockrect, x, y, color)
Definition: surface.c:821
static const unsigned char bmp_32bpp_xrgb[]
Definition: surface.c:71
#define DDS_MIPMAPCOUNT
Definition: surface.c:306
static const unsigned char bmp_32bpp_argb[]
Definition: surface.c:81
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)
Definition: surface.c:375
#define DDS_PITCH
Definition: surface.c:304
static const unsigned char png_grayscale[]
Definition: surface.c:90
static void test_D3DXGetImageInfo(void)
Definition: surface.c:561
#define check_dds_pixel_format(flags, fourcc, bpp, rmask, gmask, bmask, amask, format)
Definition: surface.c:373
static void test_D3DXLoadSurface(IDirect3DDevice9 *device)
Definition: surface.c:835
static const BYTE dds_dxt5_8_8[]
Definition: surface.c:266
#define check_pixel_4bpp(lockrect, x, y, color)
Definition: surface.c:828
#define DDS_LINEARSIZE
Definition: surface.c:307
#define DDSCAPS_ALPHA
Definition: surface.c:310
static void _check_release(unsigned int line, IUnknown *obj, int exp)
Definition: surface.c:28
static const unsigned char bmp_8bpp[]
Definition: surface.c:62
static const unsigned char dds_24bit[]
Definition: surface.c:192
static const unsigned char bmp_2bpp[]
Definition: surface.c:44
static void test_D3DXSaveSurfaceToFile(IDirect3DDevice9 *device)
Definition: surface.c:1630
static void _check_pixel_4bpp(unsigned int line, const D3DLOCKED_RECT *lockrect, int x, int y, DWORD expected_color)
Definition: surface.c:829
static const unsigned char bmp_4bpp[]
Definition: surface.c:53
static void _check_pixel_2bpp(unsigned int line, const D3DLOCKED_RECT *lockrect, int x, int y, WORD expected_color)
Definition: surface.c:822
static const unsigned char noimage[4]
Definition: surface.c:106
static void fill_dds_header(struct dds_header *header)
Definition: surface.c:353
#define check_release(obj, exp)
Definition: surface.c:27
#define create_file(name, size)
Definition: asmcache.c:813
#define todo_wine
Definition: custom.c:89
static HPALETTE palette
Definition: clipboard.c:1345
DWORD exp
Definition: msg.c:16058
unsigned int UINT
Definition: ndis.h:50
#define GENERIC_WRITE
Definition: nt_native.h:90
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
static unsigned int file_size
Definition: regtests2xml.c:47
#define D3DADAPTER_DEFAULT
Definition: d3d8.h:57
#define D3D_SDK_VERSION
Definition: d3d8.h:56
#define D3DCREATE_SOFTWARE_VERTEXPROCESSING
Definition: d3d8.h:44
#define memset(x, y, z)
Definition: compat.h:39
HRESULT hr
Definition: shlfolder.c:183
& rect
Definition: startmenu.cpp:1413
D3DSWAPEFFECT SwapEffect
Definition: d3d8types.h:1128
D3DXIMAGE_FILEFORMAT ImageFileFormat
Definition: d3dx9tex.h:84
D3DFORMAT Format
Definition: d3dx9tex.h:82
DWORD caps3
Definition: surface.c:148
DWORD depth
Definition: surface.c:142
DWORD reserved[11]
Definition: surface.c:144
DWORD reserved2
Definition: surface.c:150
DWORD flags
Definition: surface.c:138
DWORD width
Definition: surface.c:140
DWORD caps2
Definition: surface.c:147
DWORD caps
Definition: surface.c:146
DWORD pitch_or_linear_size
Definition: surface.c:141
DWORD size
Definition: surface.c:137
DWORD miplevels
Definition: surface.c:143
DWORD height
Definition: surface.c:139
DWORD caps4
Definition: surface.c:149
Definition: devices.h:37
Definition: parser.c:49
Definition: send.c:48
#define ZeroMemory
Definition: winbase.h:1737
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4318
BOOL WINAPI SetRectEmpty(_Out_ LPRECT)
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581
BOOL WINAPI DestroyWindow(_In_ HWND)
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
unsigned char BYTE
Definition: xxhash.c:193