windowscodecs: Implement DdsFrameEncode_SetPixelFormat.
[wine.git] / dlls / windowscodecs / tests / ddsformat.c
blob06cd062e9622417c823250ddae7dfde5343c863f
1 /*
2 * Copyright 2020 Ziqing Hui
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "wincodec.h"
25 #include "wine/test.h"
27 #define GET_RGB565_R(color) ((BYTE)(((color) >> 11) & 0x1F))
28 #define GET_RGB565_G(color) ((BYTE)(((color) >> 5) & 0x3F))
29 #define GET_RGB565_B(color) ((BYTE)(((color) >> 0) & 0x1F))
30 #define MAKE_RGB565(r, g, b) ((WORD)(((BYTE)(r) << 11) | ((BYTE)(g) << 5) | (BYTE)(b)))
31 #define MAKE_ARGB(a, r, g, b) (((DWORD)(a) << 24) | ((DWORD)(r) << 16) | ((DWORD)(g) << 8) | (DWORD)(b))
33 #define BLOCK_WIDTH 4
34 #define BLOCK_HEIGHT 4
36 /* 1x1 uncompressed(Alpha) DDS image */
37 static BYTE test_dds_alpha[] = {
38 'D', 'D', 'S', ' ', 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00,
39 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
40 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
41 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
43 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
45 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
46 0xFF
49 /* 1x1 uncompressed(Luminance) DDS image */
50 static BYTE test_dds_luminance[] = {
51 'D', 'D', 'S', ' ', 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00,
52 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
53 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
54 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
55 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
56 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00,
57 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
58 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59 0x82
62 /* 4x4 uncompressed(16bpp RGB565) DDS image */
63 static BYTE test_dds_rgb565[] = {
64 'D', 'D', 'S', ' ', 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00,
65 0x04, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
66 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
67 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
68 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
69 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00,
70 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
71 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
72 0xF5, 0xA7, 0x08, 0x69, 0x4C, 0x7B, 0x08, 0x69, 0xF5, 0xA7, 0xF5, 0xA7, 0xF5, 0xA7, 0x4C, 0x7B,
73 0x4C, 0x7B, 0x4C, 0x7B, 0x4C, 0x7B, 0xB1, 0x95, 0x4C, 0x7B, 0x08, 0x69, 0x08, 0x69, 0x4C, 0x7B
76 /* 1x1 uncompressed(24bpp RGB) DDS image */
77 static BYTE test_dds_24bpp[] = {
78 'D', 'D', 'S', ' ', 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00,
79 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
80 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
81 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
82 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
83 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00,
84 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
85 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
86 0x70, 0x81, 0x83
89 /* 1x1 uncompressed(32bpp XRGB) DDS image */
90 static BYTE test_dds_32bpp_xrgb[] = {
91 'D', 'D', 'S', ' ', 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00,
92 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
93 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
94 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
95 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
96 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00,
97 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
98 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
99 0x70, 0x81, 0x83, 0x00
102 /* 1x1 uncompressed(32bpp ARGB) DDS image */
103 static BYTE test_dds_32bpp_argb[] = {
104 'D', 'D', 'S', ' ', 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00,
105 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
106 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
107 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
108 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
109 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00,
110 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x10, 0x00, 0x00,
111 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
112 0x70, 0x81, 0x83, 0xFF
115 /* 1x1 uncompressed(64bpp ABGR) DDS image */
116 static BYTE test_dds_64bpp[] = {
117 'D', 'D', 'S', ' ', 0x7C, 0x00, 0x00, 0x00, 0x0F, 0x10, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00,
118 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
119 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
120 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
121 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
122 0x04, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
123 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
124 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
125 0x83, 0x83, 0x81, 0x81, 0x70, 0x70, 0xFF, 0xFF
128 /* 1x1 uncompressed(96bpp ABGR float) DDS image */
129 static BYTE test_dds_96bpp[] = {
130 'D', 'D', 'S', ' ', 0x7C, 0x00, 0x00, 0x00, 0x0F, 0x10, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00,
131 0x01, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
132 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
133 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
134 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
135 0x04, 0x00, 0x00, 0x00, 'D', 'X', '1', '0', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
136 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
137 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
138 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
139 0x00, 0x00, 0x00, 0x00, 0x84, 0x83, 0x03, 0x3F, 0x82, 0x81, 0x01, 0x3F, 0xE2, 0xE0, 0xE0, 0x3E
142 /* 1x1 uncompressed(128bpp ABGR float) DDS image */
143 static BYTE test_dds_128bpp[] = {
144 'D', 'D', 'S', ' ', 0x7C, 0x00, 0x00, 0x00, 0x0F, 0x10, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00,
145 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
146 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
147 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
148 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
149 0x04, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
150 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
151 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
152 0x84, 0x83, 0x03, 0x3F, 0x82, 0x81, 0x01, 0x3F, 0xE2, 0xE0, 0xE0, 0x3E, 0x00, 0x00, 0x80, 0x3F
155 /* 4x4 compressed(DXT1) cube map, mipMapCount = 3 */
156 static BYTE test_dds_cube[] = {
157 'D', 'D', 'S', ' ', 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x0A, 0x00, 0x04, 0x00, 0x00, 0x00,
158 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
159 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
160 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
161 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
162 0x04, 0x00, 0x00, 0x00, 'D', 'X', 'T', '1', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
163 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x40, 0x00,
164 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
165 0xF5, 0xA7, 0x08, 0x69, 0x74, 0xC0, 0xBF, 0xD7, 0x32, 0x96, 0x0B, 0x7B, 0xCC, 0x55, 0xCC, 0x55,
166 0x0E, 0x84, 0x0E, 0x84, 0x00, 0x00, 0x00, 0x00, 0xF5, 0xA7, 0x08, 0x69, 0x74, 0xC0, 0xBF, 0xD7,
167 0x32, 0x96, 0x0B, 0x7B, 0xCC, 0x55, 0xCC, 0x55, 0x0E, 0x84, 0x0E, 0x84, 0x00, 0x00, 0x00, 0x00,
168 0xF5, 0xA7, 0x08, 0x69, 0x74, 0xC0, 0xBF, 0xD7, 0x32, 0x96, 0x0B, 0x7B, 0xCC, 0x55, 0xCC, 0x55,
169 0x0E, 0x84, 0x0E, 0x84, 0x00, 0x00, 0x00, 0x00, 0xF5, 0xA7, 0x08, 0x69, 0x74, 0xC0, 0xBF, 0xD7,
170 0x32, 0x96, 0x0B, 0x7B, 0xCC, 0x55, 0xCC, 0x55, 0x0E, 0x84, 0x0E, 0x84, 0x00, 0x00, 0x00, 0x00,
171 0xF5, 0xA7, 0x08, 0x69, 0x74, 0xC0, 0xBF, 0xD7, 0x32, 0x96, 0x0B, 0x7B, 0xCC, 0x55, 0xCC, 0x55,
172 0x0E, 0x84, 0x0E, 0x84, 0x00, 0x00, 0x00, 0x00, 0xF5, 0xA7, 0x08, 0x69, 0x74, 0xC0, 0xBF, 0xD7,
173 0x32, 0x96, 0x0B, 0x7B, 0xCC, 0x55, 0xCC, 0x55, 0x0E, 0x84, 0x0E, 0x84, 0x00, 0x00, 0x00, 0x00
176 /* 4x4 compressed(DXT1) cube map with extended header, mipMapCount=3 */
177 static BYTE test_dds_cube_dx10[] = {
178 'D', 'D', 'S', ' ', 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x0A, 0x00, 0x04, 0x00, 0x00, 0x00,
179 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
181 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
182 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
183 0x04, 0x00, 0x00, 0x00, 'D', 'X', '1', '0', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
184 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x40, 0x00,
185 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
186 0x47, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
187 0x03, 0x00, 0x00, 0x00, 0xF5, 0xA7, 0x08, 0x69, 0x74, 0xC0, 0xBF, 0xD7, 0x32, 0x96, 0x0B, 0x7B,
188 0xCC, 0x55, 0xCC, 0x55, 0x0E, 0x84, 0x0E, 0x84, 0x00, 0x00, 0x00, 0x00, 0xF5, 0xA7, 0x08, 0x69,
189 0x74, 0xC0, 0xBF, 0xD7, 0x32, 0x96, 0x0B, 0x7B, 0xCC, 0x55, 0xCC, 0x55, 0x0E, 0x84, 0x0E, 0x84,
190 0x00, 0x00, 0x00, 0x00, 0xF5, 0xA7, 0x08, 0x69, 0x74, 0xC0, 0xBF, 0xD7, 0x32, 0x96, 0x0B, 0x7B,
191 0xCC, 0x55, 0xCC, 0x55, 0x0E, 0x84, 0x0E, 0x84, 0x00, 0x00, 0x00, 0x00, 0xF5, 0xA7, 0x08, 0x69,
192 0x74, 0xC0, 0xBF, 0xD7, 0x32, 0x96, 0x0B, 0x7B, 0xCC, 0x55, 0xCC, 0x55, 0x0E, 0x84, 0x0E, 0x84,
193 0x00, 0x00, 0x00, 0x00, 0xF5, 0xA7, 0x08, 0x69, 0x74, 0xC0, 0xBF, 0xD7, 0x32, 0x96, 0x0B, 0x7B,
194 0xCC, 0x55, 0xCC, 0x55, 0x0E, 0x84, 0x0E, 0x84, 0x00, 0x00, 0x00, 0x00, 0xF5, 0xA7, 0x08, 0x69,
195 0x74, 0xC0, 0xBF, 0xD7, 0x32, 0x96, 0x0B, 0x7B, 0xCC, 0x55, 0xCC, 0x55, 0x0E, 0x84, 0x0E, 0x84,
196 0x00, 0x00, 0x00, 0x00
199 /* 4x4 compressed(DXT1) DDS image with mip maps, mipMapCount=3 */
200 static BYTE test_dds_mipmaps[] = {
201 'D', 'D', 'S', ' ', 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x0A, 0x00, 0x04, 0x00, 0x00, 0x00,
202 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
203 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
204 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
205 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
206 0x04, 0x00, 0x00, 0x00, 'D', 'X', 'T', '1', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
207 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x40, 0x00,
208 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
209 0xF5, 0xA7, 0x08, 0x69, 0x74, 0xC0, 0xBF, 0xD7, 0xB1, 0x95, 0x6D, 0x7B, 0xFC, 0x55, 0x5D, 0x5D,
210 0x2E, 0x8C, 0x4E, 0x7C, 0xAA, 0xAB, 0xAB, 0xAB
213 /* 4x4 compressed(DXT1) volume texture, depth=4, mipMapCount=3 */
214 static BYTE test_dds_volume[] = {
215 'D', 'D', 'S', ' ', 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x8A, 0x00, 0x04, 0x00, 0x00, 0x00,
216 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
217 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
220 0x04, 0x00, 0x00, 0x00, 'D', 'X', 'T', '1', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
221 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x40, 0x00,
222 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
223 0xD5, 0xA7, 0x2C, 0x7B, 0xE0, 0x00, 0x55, 0x55, 0xD5, 0xA7, 0x49, 0x69, 0x57, 0x00, 0xFF, 0x55,
224 0xD5, 0xA7, 0x48, 0x69, 0xFD, 0x80, 0xFF, 0x55, 0x30, 0x8D, 0x89, 0x71, 0x55, 0xA8, 0x00, 0xFF,
225 0x32, 0x96, 0x6D, 0x83, 0xA8, 0x55, 0x5D, 0x5D, 0x0E, 0x84, 0x6D, 0x7B, 0xA8, 0xA9, 0xAD, 0xAD,
226 0x2E, 0x8C, 0x2E, 0x7C, 0xAA, 0xAB, 0xAB, 0xAB
229 /* 4x4 compressed(DXT1) texture array, arraySize=3, mipMapCount=3 */
230 static BYTE test_dds_array[] = {
231 'D', 'D', 'S', ' ', 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x0A, 0x00, 0x04, 0x00, 0x00, 0x00,
232 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
233 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
235 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
236 0x04, 0x00, 0x00, 0x00, 'D', 'X', '1', '0', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x40, 0x00,
238 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
239 0x47, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
240 0x00, 0x00, 0x00, 0x00, 0xF5, 0xA7, 0x08, 0x69, 0x74, 0xC0, 0xBF, 0xD7, 0x32, 0x96, 0x0B, 0x7B,
241 0xCC, 0x55, 0xCC, 0x55, 0x0E, 0x84, 0x0E, 0x84, 0x00, 0x00, 0x00, 0x00, 0xF5, 0xA7, 0x08, 0x69,
242 0x74, 0xC0, 0xBF, 0xD7, 0x32, 0x96, 0x0B, 0x7B, 0xCC, 0x55, 0xCC, 0x55, 0x0E, 0x84, 0x0E, 0x84,
243 0x00, 0x00, 0x00, 0x00, 0xF5, 0xA7, 0x08, 0x69, 0x74, 0xC0, 0xBF, 0xD7, 0x32, 0x96, 0x0B, 0x7B,
244 0xCC, 0x55, 0xCC, 0x55, 0x0E, 0x84, 0x0E, 0x84, 0x00, 0x00, 0x00, 0x00
247 /* 4x4 compressed(DXT1c) DDS image */
248 static BYTE test_dds_dxt1c[] = {
249 'D', 'D', 'S', ' ', 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00,
250 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
252 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
253 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
254 0x04, 0x00, 0x00, 0x00, 'D', 'X', 'T', '1', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
255 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
257 0x9A, 0xE6, 0x2B, 0x39, 0x37, 0xB7, 0x7F, 0x7F
260 /* 4x4 compressed(DXT1a) DDS image */
261 static BYTE test_dds_dxt1a[] = {
262 'D', 'D', 'S', ' ', 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00,
263 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
264 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
265 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
266 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
267 0x04, 0x00, 0x00, 0x00, 'D', 'X', 'T', '1', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
270 0x2A, 0x31, 0xF5, 0xBC, 0xE3, 0x6E, 0x2A, 0x3A
273 /* 4x4 compressed(DXT2) DDS image, mipMapCount=3 */
274 static BYTE test_dds_dxt2[] = {
275 'D', 'D', 'S', ' ', 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00,
276 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
277 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
278 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
279 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
280 0x04, 0x00, 0x00, 0x00, 'D', 'X', 'T', '2', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
281 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x40, 0x00,
282 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
283 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xDE, 0xC4, 0x10, 0x2F, 0xBF, 0xFF, 0x7B,
284 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x57, 0x53, 0x00, 0x00, 0x52, 0x52, 0x55, 0x55,
285 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCE, 0x59, 0x00, 0x00, 0x54, 0x55, 0x55, 0x55
288 /* 1x3 compressed(DXT3) DDS image, mipMapCount=2 */
289 static BYTE test_dds_dxt3[] = {
290 'D', 'D', 'S', ' ', 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x0A, 0x00, 0x03, 0x00, 0x00, 0x00,
291 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
293 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
294 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
295 0x04, 0x00, 0x00, 0x00, 'D', 'X', 'T', '3', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
296 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x40, 0x00,
297 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
298 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0C, 0x92, 0x38, 0x84, 0x00, 0xFF, 0x55, 0xFF,
299 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x53, 0x8B, 0x53, 0x8B, 0x00, 0x00, 0x00, 0x00
302 /* 4x4 compressed(DXT4) DDS image, mipMapCount=3 */
303 static BYTE test_dds_dxt4[] = {
304 'D', 'D', 'S', ' ', 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00,
305 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
306 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
308 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
309 0x04, 0x00, 0x00, 0x00, 'D', 'X', 'T', '4', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
310 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x40, 0x00,
311 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
312 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFD, 0xDE, 0xC4, 0x10, 0x2F, 0xBF, 0xFF, 0x7B,
313 0xFF, 0x00, 0x40, 0x02, 0x24, 0x49, 0x92, 0x24, 0x57, 0x53, 0x00, 0x00, 0x52, 0x52, 0x55, 0x55,
314 0xFF, 0x00, 0x48, 0x92, 0x24, 0x49, 0x92, 0x24, 0xCE, 0x59, 0x00, 0x00, 0x54, 0x55, 0x55, 0x55
317 /* 6x6 compressed(DXT5) image, mipMapCount=3 */
318 static BYTE test_dds_dxt5[] = {
319 'D', 'D', 'S', ' ', 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x0A, 0x00, 0x06, 0x00, 0x00, 0x00,
320 0x06, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
321 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
322 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
323 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
324 0x04, 0x00, 0x00, 0x00, 0x44, 0x58, 0x54, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
325 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x40, 0x00,
326 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
327 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x73, 0x8E, 0x51, 0x97, 0x97, 0xBF, 0xAF,
328 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9D, 0xC6, 0xCF, 0x52, 0x22, 0x22, 0xBB, 0x55,
329 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0xA2, 0xB8, 0x5B, 0xF8, 0xF8, 0xF8, 0xF8,
330 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x3A, 0x05, 0x19, 0xCC, 0x66, 0xCC, 0x66,
331 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x9D, 0x0A, 0x39, 0xCF, 0xEF, 0x9B, 0xEF,
332 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x6A, 0xF0, 0x6A, 0x00, 0x00, 0x00, 0x00
335 /* 12x12 compressed(DXT3) texture array, arraySize=2, mipMapCount=4 */
336 static BYTE test_dds_12x12[] = {
337 'D', 'D', 'S', ' ', 0x7C, 0x00, 0x00, 0x00, 0x07, 0x10, 0x0A, 0x00, 0x0C, 0x00, 0x00, 0x00,
338 0x0C, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
339 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
340 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
341 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
342 0x04, 0x00, 0x00, 0x00, 'D', 'X', '1', '0', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
343 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x40, 0x00,
344 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
345 0x4A, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
346 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xB5, 0xA7, 0xAD, 0x83,
347 0x60, 0x60, 0xE0, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x12, 0x96, 0x6B, 0x72,
348 0xD5, 0xD5, 0xAF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x30, 0x8D, 0x89, 0x69,
349 0x57, 0x5F, 0x5E, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xB4, 0xA7, 0xAD, 0x83,
350 0x00, 0xAA, 0xFF, 0x55, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF3, 0x9E, 0x6D, 0x83,
351 0x00, 0x00, 0xAA, 0x55, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x12, 0x96, 0xCD, 0x83,
352 0x5C, 0xF8, 0xAA, 0xAF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xEC, 0x7A, 0xC9, 0x71,
353 0x80, 0x60, 0x60, 0x60, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0x72, 0xA8, 0x68,
354 0x28, 0xBE, 0xD7, 0xD7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAF, 0x8C, 0xEA, 0x71,
355 0x0B, 0xAB, 0xAD, 0xBD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x54, 0x9F, 0xCC, 0x7A,
356 0x5C, 0xA8, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x50, 0x8D, 0x49, 0x69,
357 0x77, 0xEE, 0x88, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0C, 0x7B, 0x08, 0x69,
358 0xF8, 0x58, 0xF8, 0x58, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4E, 0x84, 0x6B, 0x72,
359 0x33, 0x99, 0x33, 0x99, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x14, 0x9F, 0x0A, 0x72,
360 0xDC, 0xAA, 0x75, 0xAA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0E, 0x84, 0x0E, 0x84,
361 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xB5, 0xA7, 0xAD, 0x83,
362 0x60, 0x60, 0xE0, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x12, 0x96, 0x6B, 0x72,
363 0xD5, 0xD5, 0xAF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x30, 0x8D, 0x89, 0x69,
364 0x57, 0x5F, 0x5E, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xB4, 0xA7, 0xAD, 0x83,
365 0x00, 0xAA, 0xFF, 0x55, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF3, 0x9E, 0x6D, 0x83,
366 0x00, 0x00, 0xAA, 0x55, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x12, 0x96, 0xCD, 0x83,
367 0x5C, 0xF8, 0xAA, 0xAF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xEC, 0x7A, 0xC9, 0x71,
368 0x80, 0x60, 0x60, 0x60, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0x72, 0xA8, 0x68,
369 0x28, 0xBE, 0xD7, 0xD7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAF, 0x8C, 0xEA, 0x71,
370 0x0B, 0xAB, 0xAD, 0xBD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x54, 0x9F, 0xCC, 0x7A,
371 0x5C, 0xA8, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x50, 0x8D, 0x49, 0x69,
372 0x77, 0xEE, 0x88, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0C, 0x7B, 0x08, 0x69,
373 0xF8, 0x58, 0xF8, 0x58, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x4E, 0x84, 0x6B, 0x72,
374 0x33, 0x99, 0x33, 0x99, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x14, 0x9F, 0x0A, 0x72,
375 0xDC, 0xAA, 0x75, 0xAA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0E, 0x84, 0x0E, 0x84,
376 0x00, 0x00, 0x00, 0x00
379 static BYTE test_dds_bad_magic[sizeof(test_dds_dxt1c)];
380 static BYTE test_dds_bad_header[sizeof(test_dds_dxt1c)];
381 static BYTE test_byte[1] = { 0 };
382 static BYTE test_word[2] = { 0 };
383 static BYTE test_dword[4] = { 0 };
384 static BYTE test_qword_a[8] = { 0 };
385 static BYTE test_qword_b[8] = "DDS ";
387 static struct test_data {
388 BYTE *data;
389 UINT size;
390 HRESULT init_hr;
391 UINT expected_frame_count;
392 UINT expected_bytes_per_block;
393 UINT pixel_format_bpp;
394 const GUID *expected_pixel_format;
395 WICDdsParameters expected_parameters;
396 BOOL wine_init;
397 } test_data[] = {
398 { test_dds_alpha, sizeof(test_dds_alpha), WINCODEC_ERR_BADHEADER, 1, 1, 8, &GUID_WICPixelFormat8bppAlpha,
399 { 1, 1, 1, 1, 1, DXGI_FORMAT_A8_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown }, TRUE },
400 { test_dds_luminance, sizeof(test_dds_luminance), WINCODEC_ERR_BADHEADER, 1, 1, 8, &GUID_WICPixelFormat8bppGray,
401 { 1, 1, 1, 1, 1, DXGI_FORMAT_R8_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown }, TRUE },
402 { test_dds_rgb565, sizeof(test_dds_rgb565), WINCODEC_ERR_BADHEADER, 1, 2, 16, &GUID_WICPixelFormat16bppBGR565,
403 { 4, 4, 1, 1, 1, DXGI_FORMAT_B5G6R5_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown }, TRUE },
404 { test_dds_24bpp, sizeof(test_dds_24bpp), WINCODEC_ERR_BADHEADER, 1, 3, 24, &GUID_WICPixelFormat24bppBGR,
405 { 1, 1, 1, 1, 1, DXGI_FORMAT_UNKNOWN, WICDdsTexture2D, WICDdsAlphaModeUnknown }, TRUE },
406 { test_dds_32bpp_xrgb, sizeof(test_dds_32bpp_xrgb), WINCODEC_ERR_BADHEADER, 1, 4, 32, &GUID_WICPixelFormat32bppBGR,
407 { 1, 1, 1, 1, 1, DXGI_FORMAT_B8G8R8X8_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown }, TRUE },
408 { test_dds_32bpp_argb, sizeof(test_dds_32bpp_argb), WINCODEC_ERR_BADHEADER, 1, 4, 32, &GUID_WICPixelFormat32bppBGRA,
409 { 1, 1, 1, 1, 1, DXGI_FORMAT_B8G8R8A8_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown }, TRUE },
410 { test_dds_64bpp, sizeof(test_dds_64bpp), WINCODEC_ERR_BADHEADER, 1, 8, 64, &GUID_WICPixelFormat64bppRGBA,
411 { 1, 1, 1, 1, 1, DXGI_FORMAT_R16G16B16A16_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown }, TRUE },
412 { test_dds_96bpp, sizeof(test_dds_96bpp), WINCODEC_ERR_BADHEADER, 1, 12, 96, &GUID_WICPixelFormat96bppRGBFloat,
413 { 1, 1, 1, 1, 1, DXGI_FORMAT_R32G32B32_FLOAT, WICDdsTexture2D, WICDdsAlphaModeUnknown }, TRUE },
414 { test_dds_128bpp, sizeof(test_dds_128bpp), WINCODEC_ERR_BADHEADER, 1, 16, 128, &GUID_WICPixelFormat128bppRGBAFloat,
415 { 1, 1, 1, 1, 1, DXGI_FORMAT_R32G32B32A32_FLOAT, WICDdsTexture2D, WICDdsAlphaModeUnknown }, TRUE },
416 { test_dds_cube, sizeof(test_dds_cube), WINCODEC_ERR_BADHEADER, 18, 8, 32, &GUID_WICPixelFormat32bppPBGRA,
417 { 4, 4, 1, 3, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTextureCube, WICDdsAlphaModePremultiplied }, TRUE },
418 { test_dds_cube_dx10, sizeof(test_dds_cube_dx10), WINCODEC_ERR_BADHEADER, 18, 8, 32, &GUID_WICPixelFormat32bppBGRA,
419 { 4, 4, 1, 3, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTextureCube, WICDdsAlphaModeUnknown }, TRUE },
420 { test_dds_mipmaps, sizeof(test_dds_mipmaps), S_OK, 3, 8, 32, &GUID_WICPixelFormat32bppPBGRA,
421 { 4, 4, 1, 3, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTexture2D, WICDdsAlphaModePremultiplied } },
422 { test_dds_volume, sizeof(test_dds_volume), S_OK, 7, 8, 32, &GUID_WICPixelFormat32bppPBGRA,
423 { 4, 4, 4, 3, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTexture3D, WICDdsAlphaModePremultiplied } },
424 { test_dds_array, sizeof(test_dds_array), S_OK, 9, 8, 32, &GUID_WICPixelFormat32bppBGRA,
425 { 4, 4, 1, 3, 3, DXGI_FORMAT_BC1_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown } },
426 { test_dds_dxt1c, sizeof(test_dds_dxt1c), S_OK, 1, 8, 32, &GUID_WICPixelFormat32bppPBGRA,
427 { 4, 4, 1, 1, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTexture2D, WICDdsAlphaModePremultiplied } },
428 { test_dds_dxt1a, sizeof(test_dds_dxt1a), S_OK, 1, 8, 32, &GUID_WICPixelFormat32bppPBGRA,
429 { 4, 4, 1, 1, 1, DXGI_FORMAT_BC1_UNORM, WICDdsTexture2D, WICDdsAlphaModePremultiplied } },
430 { test_dds_dxt2, sizeof(test_dds_dxt2), S_OK, 3, 16, 32, &GUID_WICPixelFormat32bppPBGRA,
431 { 4, 4, 1, 3, 1, DXGI_FORMAT_BC2_UNORM, WICDdsTexture2D, WICDdsAlphaModePremultiplied } },
432 { test_dds_dxt3, sizeof(test_dds_dxt3), S_OK, 2, 16, 32, &GUID_WICPixelFormat32bppBGRA,
433 { 1, 3, 1, 2, 1, DXGI_FORMAT_BC2_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown } },
434 { test_dds_dxt4, sizeof(test_dds_dxt4), S_OK, 3, 16, 32, &GUID_WICPixelFormat32bppPBGRA,
435 { 4, 4, 1, 3, 1, DXGI_FORMAT_BC3_UNORM, WICDdsTexture2D, WICDdsAlphaModePremultiplied } },
436 { test_dds_dxt5, sizeof(test_dds_dxt5), S_OK, 3, 16, 32, &GUID_WICPixelFormat32bppBGRA,
437 { 6, 6, 1, 3, 1, DXGI_FORMAT_BC3_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown } },
438 { test_dds_12x12, sizeof(test_dds_12x12), S_OK, 8, 16, 32, &GUID_WICPixelFormat32bppBGRA,
439 { 12, 12, 1, 4, 2, DXGI_FORMAT_BC2_UNORM, WICDdsTexture2D, WICDdsAlphaModeUnknown } },
440 { test_dds_bad_magic, sizeof(test_dds_bad_magic), WINCODEC_ERR_UNKNOWNIMAGEFORMAT },
441 { test_dds_bad_header, sizeof(test_dds_bad_header), WINCODEC_ERR_BADHEADER },
442 { test_byte, sizeof(test_byte), WINCODEC_ERR_STREAMREAD },
443 { test_word, sizeof(test_word), WINCODEC_ERR_STREAMREAD },
444 { test_dword, sizeof(test_dword), WINCODEC_ERR_UNKNOWNIMAGEFORMAT },
445 { test_qword_a, sizeof(test_qword_a), WINCODEC_ERR_UNKNOWNIMAGEFORMAT },
446 { test_qword_b, sizeof(test_qword_b), WINCODEC_ERR_STREAMREAD },
449 static DXGI_FORMAT compressed_formats[] = {
450 DXGI_FORMAT_BC1_TYPELESS, DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC1_UNORM_SRGB,
451 DXGI_FORMAT_BC2_TYPELESS, DXGI_FORMAT_BC2_UNORM, DXGI_FORMAT_BC2_UNORM_SRGB,
452 DXGI_FORMAT_BC3_TYPELESS, DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_BC3_UNORM_SRGB,
453 DXGI_FORMAT_BC4_TYPELESS, DXGI_FORMAT_BC4_UNORM, DXGI_FORMAT_BC4_SNORM,
454 DXGI_FORMAT_BC5_TYPELESS, DXGI_FORMAT_BC5_UNORM, DXGI_FORMAT_BC5_SNORM,
455 DXGI_FORMAT_BC6H_TYPELESS, DXGI_FORMAT_BC6H_UF16, DXGI_FORMAT_BC6H_SF16,
456 DXGI_FORMAT_BC7_TYPELESS, DXGI_FORMAT_BC7_UNORM, DXGI_FORMAT_BC7_UNORM_SRGB
459 static IWICImagingFactory *factory = NULL;
461 static IWICStream *create_stream(const void *image_data, UINT image_size)
463 HRESULT hr;
464 IWICStream *stream = NULL;
466 hr = IWICImagingFactory_CreateStream(factory, &stream);
467 ok(hr == S_OK, "CreateStream failed, hr %#x\n", hr);
468 if (hr != S_OK) goto fail;
470 hr = IWICStream_InitializeFromMemory(stream, (BYTE *)image_data, image_size);
471 ok(hr == S_OK, "InitializeFromMemory failed, hr %#x\n", hr);
472 if (hr != S_OK) goto fail;
474 return stream;
476 fail:
477 if (stream) IWICStream_Release(stream);
478 return NULL;
481 static IWICBitmapDecoder *create_decoder(void)
483 HRESULT hr;
484 IWICBitmapDecoder *decoder = NULL;
485 GUID guidresult;
487 hr = CoCreateInstance(&CLSID_WICDdsDecoder, NULL, CLSCTX_INPROC_SERVER,
488 &IID_IWICBitmapDecoder, (void **)&decoder);
489 if (hr != S_OK) {
490 win_skip("Dds decoder is not supported\n");
491 return NULL;
494 memset(&guidresult, 0, sizeof(guidresult));
495 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
496 ok(hr == S_OK, "GetContainerFormat failed, hr %#x\n", hr);
497 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatDds),
498 "Got unexpected container format %s\n", debugstr_guid(&guidresult));
500 return decoder;
503 static IWICBitmapEncoder *create_encoder(void)
505 IWICBitmapEncoder *encoder = NULL;
506 GUID guidresult;
507 HRESULT hr;
509 hr = CoCreateInstance(&CLSID_WICDdsEncoder, NULL, CLSCTX_INPROC_SERVER,
510 &IID_IWICBitmapEncoder, (void **)&encoder);
511 if (hr != S_OK)
513 win_skip("DDS encoder is not supported\n");
514 return NULL;
517 memset(&guidresult, 0, sizeof(guidresult));
519 hr = IWICBitmapEncoder_GetContainerFormat(encoder, &guidresult);
520 ok(hr == S_OK, "GetContainerFormat failed, hr %#x\n", hr);
522 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatDds),
523 "Got unexpected container format %s\n", debugstr_guid(&guidresult));
525 return encoder;
528 static HRESULT init_decoder(IWICBitmapDecoder *decoder, IWICStream *stream, HRESULT expected, int index, BOOL wine_init)
530 HRESULT hr;
531 IWICWineDecoder *wine_decoder;
533 hr = IWICBitmapDecoder_Initialize(decoder, (IStream*)stream, WICDecodeMetadataCacheOnDemand);
534 ok(hr == expected, "Test %u: Expected hr %#x, got %#x\n", index, expected, hr);
536 if (hr != S_OK && wine_init) {
537 hr = IWICBitmapDecoder_QueryInterface(decoder, &IID_IWICWineDecoder, (void **)&wine_decoder);
538 ok(hr == S_OK || broken(hr != S_OK), "Test %u: QueryInterface failed, hr %#x\n", index, hr);
540 if (hr == S_OK) {
541 hr = IWICWineDecoder_Initialize(wine_decoder, (IStream*)stream, WICDecodeMetadataCacheOnDemand);
542 ok(hr == S_OK, "Test %u: Initialize failed, hr %#x\n", index, hr);
546 return hr;
549 static void release_encoder(IWICBitmapEncoder *encoder, IWICDdsEncoder *dds_encoder, IWICStream *stream)
551 if (dds_encoder) IWICDdsEncoder_Release(dds_encoder);
552 if (stream) IWICStream_Release(stream);
553 if (encoder) IWICBitmapEncoder_Release(encoder);
556 static HRESULT create_and_init_encoder(BYTE *image_buffer, UINT buffer_size, WICDdsParameters *params,
557 IWICBitmapEncoder **encoder, IWICDdsEncoder **dds_encoder, IWICStream **stream)
559 IWICDdsEncoder *dds = NULL;
560 HRESULT hr;
562 *encoder = create_encoder();
563 if (!*encoder) goto fail;
565 *stream = create_stream(image_buffer, buffer_size);
566 if (!*stream) goto fail;
568 hr = IWICBitmapEncoder_Initialize(*encoder, (IStream *)*stream, WICBitmapEncoderNoCache);
569 ok(hr == S_OK, "Initialize failed, hr %#x\n", hr);
570 if (hr != S_OK) goto fail;
572 hr = IWICBitmapEncoder_QueryInterface(*encoder, &IID_IWICDdsEncoder, (void **)&dds);
573 ok(hr == S_OK, "QueryInterface failed, hr %#x\n", hr);
574 if (hr != S_OK) goto fail;
576 if (params)
578 hr = IWICDdsEncoder_SetParameters(dds, params);
579 ok(hr == S_OK, "SetParameters failed, hr %#x\n", hr);
580 if (hr != S_OK) goto fail;
583 if (dds_encoder)
585 *dds_encoder = dds;
587 else
589 IWICDdsEncoder_Release(dds);
590 dds = NULL;
593 return S_OK;
595 fail:
596 release_encoder(*encoder, dds, *stream);
597 return E_FAIL;
600 static BOOL is_compressed(DXGI_FORMAT format)
602 UINT i;
603 for (i = 0; i < ARRAY_SIZE(compressed_formats); i++)
605 if (format == compressed_formats[i]) return TRUE;
607 return FALSE;
610 static BOOL has_extended_header(const BYTE *data)
612 return data[84] == 'D' && data[85] == 'X' && data[86] == '1' && data[87] == '0';
615 static DWORD rgb565_to_argb(WORD color, BYTE alpha)
617 return MAKE_ARGB(alpha, (GET_RGB565_R(color) * 0xFF + 0x0F) / 0x1F,
618 (GET_RGB565_G(color) * 0xFF + 0x1F) / 0x3F,
619 (GET_RGB565_B(color) * 0xFF + 0x0F) / 0x1F);
622 static void decode_block(const BYTE *block_data, UINT block_count, DXGI_FORMAT format,
623 UINT width, UINT height, DWORD *buffer)
625 const BYTE *block, *color_indices, *alpha_indices, *alpha_table;
626 int i, j, x, y, block_x, block_y, color_index, alpha_index;
627 int block_size, color_offset, color_indices_offset;
628 WORD color[4], color_value = 0;
629 BYTE alpha[8], alpha_value = 0;
631 if (format == DXGI_FORMAT_BC1_UNORM) {
632 block_size = 8;
633 color_offset = 0;
634 color_indices_offset = 4;
635 } else {
636 block_size = 16;
637 color_offset = 8;
638 color_indices_offset = 12;
640 block_x = 0;
641 block_y = 0;
643 for (i = 0; i < block_count; i++)
645 block = block_data + i * block_size;
647 color[0] = *((WORD *)(block + color_offset));
648 color[1] = *((WORD *)(block + color_offset + 2));
649 color[2] = MAKE_RGB565(((GET_RGB565_R(color[0]) * 2 + GET_RGB565_R(color[1]) + 1) / 3),
650 ((GET_RGB565_G(color[0]) * 2 + GET_RGB565_G(color[1]) + 1) / 3),
651 ((GET_RGB565_B(color[0]) * 2 + GET_RGB565_B(color[1]) + 1) / 3));
652 color[3] = MAKE_RGB565(((GET_RGB565_R(color[0]) + GET_RGB565_R(color[1]) * 2 + 1) / 3),
653 ((GET_RGB565_G(color[0]) + GET_RGB565_G(color[1]) * 2 + 1) / 3),
654 ((GET_RGB565_B(color[0]) + GET_RGB565_B(color[1]) * 2 + 1) / 3));
656 switch (format)
658 case DXGI_FORMAT_BC1_UNORM:
659 if (color[0] <= color[1]) {
660 color[2] = MAKE_RGB565(((GET_RGB565_R(color[0]) + GET_RGB565_R(color[1]) + 1) / 2),
661 ((GET_RGB565_G(color[0]) + GET_RGB565_G(color[1]) + 1) / 2),
662 ((GET_RGB565_B(color[0]) + GET_RGB565_B(color[1]) + 1) / 2));
663 color[3] = 0;
665 break;
666 case DXGI_FORMAT_BC2_UNORM:
667 alpha_table = block;
668 break;
669 case DXGI_FORMAT_BC3_UNORM:
670 alpha[0] = *block;
671 alpha[1] = *(block + 1);
672 if (alpha[0] > alpha[1]) {
673 for (j = 2; j < 8; j++)
675 alpha[j] = (BYTE)((alpha[0] * (8 - j) + alpha[1] * (j - 1) + 3) / 7);
677 } else {
678 for (j = 2; j < 6; j++)
680 alpha[j] = (BYTE)((alpha[0] * (6 - j) + alpha[1] * (j - 1) + 2) / 5);
682 alpha[6] = 0;
683 alpha[7] = 0xFF;
685 alpha_indices = block + 2;
686 break;
687 default:
688 break;
691 color_indices = block + color_indices_offset;
692 for (j = 0; j < 16; j++)
694 x = block_x + j % 4;
695 y = block_y + j / 4;
696 if (x >= width || y >= height) continue;
698 color_index = (color_indices[j / 4] >> ((j % 4) * 2)) & 0x3;
699 color_value = color[color_index];
701 switch (format)
703 case DXGI_FORMAT_BC1_UNORM:
704 if ((color[0] <= color[1]) && !color_value) {
705 color_value = 0;
706 alpha_value = 0;
707 } else {
708 alpha_value = 0xFF;
710 break;
711 case DXGI_FORMAT_BC2_UNORM:
712 alpha_value = (alpha_table[j / 2] >> (j % 2) * 4) & 0xF;
713 alpha_value = (BYTE)((alpha_value * 0xFF + 0x7)/ 0xF);
714 break;
715 case DXGI_FORMAT_BC3_UNORM:
716 alpha_index = (*((DWORD *)(alpha_indices + (j / 8) * 3)) >> ((j % 8) * 3)) & 0x7;
717 alpha_value = alpha[alpha_index];
718 break;
719 default:
720 break;
722 buffer[x + y * width] = rgb565_to_argb(color_value, alpha_value);
725 block_x += BLOCK_WIDTH;
726 if (block_x >= width) {
727 block_x = 0;
728 block_y += BLOCK_HEIGHT;
733 static BOOL color_match(DWORD color_a, DWORD color_b)
735 static const int tolerance = 8;
737 const int da = abs((int)((color_a & 0xFF000000) >> 24) - (int)((color_b & 0xFF000000) >> 24));
738 const int dr = abs((int)((color_a & 0x00FF0000) >> 16) - (int)((color_b & 0x00FF0000) >> 16));
739 const int dg = abs((int)((color_a & 0x0000FF00) >> 8) - (int)((color_b & 0x0000FF00) >> 8));
740 const int db = abs((int)((color_a & 0x000000FF) >> 0) - (int)((color_b & 0x000000FF) >> 0));
742 return (da <= tolerance && dr <= tolerance && dg <= tolerance && db <= tolerance);
745 static BOOL color_buffer_match(DWORD *color_buffer_a, DWORD *color_buffer_b, UINT color_count)
747 UINT i;
749 for (i = 0; i < color_count; i++)
751 if (!color_match(color_buffer_a[i], color_buffer_b[i])) return FALSE;
754 return TRUE;
757 static void copy_pixels(void *src_buffer, UINT src_stride, void *dst_buffer, UINT dst_stride, UINT size)
759 char *src = src_buffer, *dst = dst_buffer;
760 UINT i;
762 for (i = 0; i < size; i++)
764 *dst = src[i];
765 if (i % src_stride == src_stride - 1) dst += dst_stride - src_stride;
766 dst ++;
770 static void test_dds_decoder_initialize(void)
772 int i;
774 memcpy(test_dds_bad_magic, test_dds_dxt1c, sizeof(test_dds_dxt1c));
775 memcpy(test_dds_bad_header, test_dds_dxt1c, sizeof(test_dds_dxt1c));
776 test_dds_bad_magic[0] = 0;
777 test_dds_bad_header[4] = 0;
779 for (i = 0; i < ARRAY_SIZE(test_data); i++)
781 IWICStream *stream = NULL;
782 IWICBitmapDecoder *decoder = NULL;
784 stream = create_stream(test_data[i].data, test_data[i].size);
785 if (!stream) goto next;
787 decoder = create_decoder();
788 if (!decoder) goto next;
790 init_decoder(decoder, stream, test_data[i].init_hr, i, test_data[i].wine_init);
792 next:
793 if (decoder) IWICBitmapDecoder_Release(decoder);
794 if (stream) IWICStream_Release(stream);
798 static void test_dds_decoder_global_properties(IWICBitmapDecoder *decoder)
800 HRESULT hr;
801 IWICPalette *palette = NULL;
802 IWICMetadataQueryReader *metadata_reader = NULL;
803 IWICBitmapSource *preview = NULL, *thumnail = NULL;
804 IWICColorContext *color_context = NULL;
805 UINT count;
807 hr = IWICImagingFactory_CreatePalette(factory, &palette);
808 ok(hr == S_OK, "CreatePalette failed, hr %#x\n", hr);
809 if (hr == S_OK) {
810 hr = IWICBitmapDecoder_CopyPalette(decoder, palette);
811 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "CopyPalette got unexpected hr %#x\n", hr);
812 hr = IWICBitmapDecoder_CopyPalette(decoder, NULL);
813 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE, "CopyPalette got unexpected hr %#x\n", hr);
816 hr = IWICBitmapDecoder_GetMetadataQueryReader(decoder, &metadata_reader);
817 todo_wine ok (hr == S_OK, "GetMetadataQueryReader got unexpected hr %#x\n", hr);
818 hr = IWICBitmapDecoder_GetMetadataQueryReader(decoder, NULL);
819 ok(hr == E_INVALIDARG, "GetMetadataQueryReader got unexpected hr %#x\n", hr);
821 hr = IWICBitmapDecoder_GetPreview(decoder, &preview);
822 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "GetPreview got unexpected hr %#x\n", hr);
823 hr = IWICBitmapDecoder_GetPreview(decoder, NULL);
824 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "GetPreview got unexpected hr %#x\n", hr);
826 hr = IWICBitmapDecoder_GetColorContexts(decoder, 1, &color_context, &count);
827 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "GetColorContexts got unexpected hr %#x\n", hr);
828 hr = IWICBitmapDecoder_GetColorContexts(decoder, 1, NULL, NULL);
829 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "GetColorContexts got unexpected hr %#x\n", hr);
831 hr = IWICBitmapDecoder_GetThumbnail(decoder, &thumnail);
832 ok(hr == WINCODEC_ERR_CODECNOTHUMBNAIL, "GetThumbnail got unexpected hr %#x\n", hr);
833 hr = IWICBitmapDecoder_GetThumbnail(decoder, NULL);
834 ok(hr == WINCODEC_ERR_CODECNOTHUMBNAIL, "GetThumbnail got unexpected hr %#x\n", hr);
836 if (palette) IWICPalette_Release(palette);
837 if (metadata_reader) IWICMetadataQueryReader_Release(metadata_reader);
838 if (preview) IWICBitmapSource_Release(preview);
839 if (color_context) IWICColorContext_Release(color_context);
840 if (thumnail) IWICBitmapSource_Release(thumnail);
843 static void test_dds_decoder_image_parameters(void)
845 int i;
846 HRESULT hr;
847 WICDdsParameters parameters;
849 for (i = 0; i < ARRAY_SIZE(test_data); i++)
851 UINT frame_count;
852 IWICStream *stream = NULL;
853 IWICBitmapDecoder *decoder = NULL;
854 IWICDdsDecoder *dds_decoder = NULL;
856 stream = create_stream(test_data[i].data, test_data[i].size);
857 if (!stream) goto next;
859 decoder = create_decoder();
860 if (!decoder) goto next;
862 hr = IWICBitmapDecoder_QueryInterface(decoder, &IID_IWICDdsDecoder, (void **)&dds_decoder);
863 ok(hr == S_OK, "QueryInterface failed, hr %#x\n", hr);
864 if (hr != S_OK) goto next;
866 hr = IWICBitmapDecoder_GetFrameCount(decoder, &frame_count);
867 ok(hr == WINCODEC_ERR_WRONGSTATE, "Test %u: GetFrameCount got unexpected hr %#x\n", i, hr);
868 hr = IWICBitmapDecoder_GetFrameCount(decoder, NULL);
869 ok(hr == E_INVALIDARG, "Test %u: GetFrameCount got unexpected hr %#x\n", i, hr);
871 hr = IWICDdsDecoder_GetParameters(dds_decoder, &parameters);
872 ok(hr == WINCODEC_ERR_WRONGSTATE, "Test %u: GetParameters got unexpected hr %#x\n", i, hr);
873 hr = IWICDdsDecoder_GetParameters(dds_decoder, NULL);
874 ok(hr == E_INVALIDARG, "Test %u: GetParameters got unexpected hr %#x\n", i, hr);
876 if (test_data[i].init_hr != S_OK && !test_data[i].wine_init) continue;
878 hr = init_decoder(decoder, stream, test_data[i].init_hr, i, test_data[i].wine_init);
879 if (hr != S_OK) {
880 if (test_data[i].expected_parameters.Dimension == WICDdsTextureCube) {
881 win_skip("Test %u: Cube map is not supported\n", i);
882 } else {
883 win_skip("Test %u: Uncompressed DDS image is not supported\n", i);
885 goto next;
888 hr = IWICBitmapDecoder_GetFrameCount(decoder, &frame_count);
889 ok(hr == S_OK, "Test %u: GetFrameCount failed, hr %#x\n", i, hr);
890 if (hr == S_OK) {
891 ok(frame_count == test_data[i].expected_frame_count, "Test %u: Expected frame count %u, got %u\n",
892 i, test_data[i].expected_frame_count, frame_count);
894 hr = IWICBitmapDecoder_GetFrameCount(decoder, NULL);
895 ok(hr == E_INVALIDARG, "Test %u: GetParameters got unexpected hr %#x\n", i, hr);
897 hr = IWICDdsDecoder_GetParameters(dds_decoder, &parameters);
898 ok(hr == S_OK, "Test %u: GetParameters failed, hr %#x\n", i, hr);
899 if (hr == S_OK) {
900 ok(parameters.Width == test_data[i].expected_parameters.Width,
901 "Test %u: Expected Width %u, got %u\n", i, test_data[i].expected_parameters.Width, parameters.Width);
902 ok(parameters.Height == test_data[i].expected_parameters.Height,
903 "Test %u: Expected Height %u, got %u\n", i, test_data[i].expected_parameters.Height, parameters.Height);
904 ok(parameters.Depth == test_data[i].expected_parameters.Depth,
905 "Test %u: Expected Depth %u, got %u\n", i, test_data[i].expected_parameters.Depth, parameters.Depth);
906 ok(parameters.MipLevels == test_data[i].expected_parameters.MipLevels,
907 "Test %u: Expected MipLevels %u, got %u\n", i, test_data[i].expected_parameters.MipLevels, parameters.MipLevels);
908 ok(parameters.ArraySize == test_data[i].expected_parameters.ArraySize,
909 "Test %u: Expected ArraySize %u, got %u\n", i, test_data[i].expected_parameters.ArraySize, parameters.ArraySize);
910 ok(parameters.DxgiFormat == test_data[i].expected_parameters.DxgiFormat,
911 "Test %u: Expected DxgiFormat %#x, got %#x\n", i, test_data[i].expected_parameters.DxgiFormat, parameters.DxgiFormat);
912 ok(parameters.Dimension == test_data[i].expected_parameters.Dimension,
913 "Test %u: Expected Dimension %#x, got %#x\n", i, test_data[i].expected_parameters.Dimension, parameters.Dimension);
914 ok(parameters.AlphaMode == test_data[i].expected_parameters.AlphaMode,
915 "Test %u: Expected AlphaMode %#x, got %#x\n", i, test_data[i].expected_parameters.AlphaMode, parameters.AlphaMode);
917 hr = IWICDdsDecoder_GetParameters(dds_decoder, NULL);
918 ok(hr == E_INVALIDARG, "Test %u: GetParameters got unexpected hr %#x\n", i, hr);
920 next:
921 if (decoder) IWICBitmapDecoder_Release(decoder);
922 if (stream) IWICStream_Release(stream);
923 if (dds_decoder) IWICDdsDecoder_Release(dds_decoder);
928 static void test_dds_decoder_frame_properties(IWICBitmapFrameDecode *frame_decode, IWICDdsFrameDecode *dds_frame,
929 UINT frame_count, WICDdsParameters *params, int i, int frame_index)
931 HRESULT hr;
932 UINT width, height ,expected_width, expected_height, slice_index, depth;
933 UINT width_in_blocks, height_in_blocks, expected_width_in_blocks, expected_height_in_blocks;
934 UINT expected_block_width, expected_block_height;
935 WICDdsFormatInfo format_info;
936 GUID pixel_format;
938 /* frame size tests */
940 hr = IWICBitmapFrameDecode_GetSize(frame_decode, NULL, NULL);
941 ok(hr == E_INVALIDARG, "Test %u, frame %u: GetSize got unexpected hr %#x\n", i, frame_index, hr);
942 hr = IWICBitmapFrameDecode_GetSize(frame_decode, NULL, &height);
943 ok(hr == E_INVALIDARG, "Test %u, frame %u: GetSize got unexpected hr %#x\n", i, frame_index, hr);
944 hr = IWICBitmapFrameDecode_GetSize(frame_decode, &width, NULL);
945 ok(hr == E_INVALIDARG, "Test %u, frame %u: GetSize got unexpected hr %#x\n", i, frame_index, hr);
946 hr = IWICBitmapFrameDecode_GetSize(frame_decode, &width, &height);
947 ok(hr == S_OK, "Test %u, frame %u: GetSize failed, hr %#x\n", i, frame_index, hr);
948 if (hr != S_OK) return;
950 depth = params->Depth;
951 expected_width = params->Width;
952 expected_height = params->Height;
953 slice_index = frame_index % (frame_count / params->ArraySize);
954 while (slice_index >= depth)
956 if (expected_width > 1) expected_width /= 2;
957 if (expected_height > 1) expected_height /= 2;
958 slice_index -= depth;
959 if (depth > 1) depth /= 2;
961 ok(width == expected_width, "Test %u, frame %u: Expected width %u, got %u\n", i, expected_width, frame_index, width);
962 ok(height == expected_height, "Test %u, frame %u: Expected height %u, got %u\n", i, expected_height, frame_index, height);
964 /* frame format information tests */
966 if (is_compressed(test_data[i].expected_parameters.DxgiFormat)) {
967 expected_block_width = BLOCK_WIDTH;
968 expected_block_height = BLOCK_HEIGHT;
969 } else {
970 expected_block_width = 1;
971 expected_block_height = 1;
974 hr = IWICDdsFrameDecode_GetFormatInfo(dds_frame, NULL);
975 ok(hr == E_INVALIDARG, "Test %u, frame %u: GetFormatInfo got unexpected hr %#x\n", i, frame_index, hr);
976 hr = IWICDdsFrameDecode_GetFormatInfo(dds_frame, &format_info);
977 ok(hr == S_OK, "Test %u, frame %u: GetFormatInfo failed, hr %#x\n", i, frame_index, hr);
978 if (hr != S_OK) return;
980 ok(format_info.DxgiFormat == test_data[i].expected_parameters.DxgiFormat,
981 "Test %u, frame %u: Expected DXGI format %#x, got %#x\n",
982 i, frame_index, test_data[i].expected_parameters.DxgiFormat, format_info.DxgiFormat);
983 ok(format_info.BytesPerBlock == test_data[i].expected_bytes_per_block,
984 "Test %u, frame %u: Expected bytes per block %u, got %u\n",
985 i, frame_index, test_data[i].expected_bytes_per_block, format_info.BytesPerBlock);
986 ok(format_info.BlockWidth == expected_block_width,
987 "Test %u, frame %u: Expected block width %u, got %u\n",
988 i, frame_index, expected_block_width, format_info.BlockWidth);
989 ok(format_info.BlockHeight == expected_block_height,
990 "Test %u, frame %u: Expected block height %u, got %u\n",
991 i, frame_index, expected_block_height, format_info.BlockHeight);
994 /* size in blocks tests */
996 hr = IWICDdsFrameDecode_GetSizeInBlocks(dds_frame, NULL, NULL);
997 ok(hr == E_INVALIDARG, "Test %u, frame %u: GetSizeInBlocks got unexpected hr %#x\n", i, frame_index, hr);
998 hr = IWICDdsFrameDecode_GetSizeInBlocks(dds_frame, NULL, &height_in_blocks);
999 ok(hr == E_INVALIDARG, "Test %u, frame %u: GetSizeInBlocks got unexpected hr %#x\n", i, frame_index, hr);
1000 hr = IWICDdsFrameDecode_GetSizeInBlocks(dds_frame, &width_in_blocks, NULL);
1001 ok(hr == E_INVALIDARG, "Test %u, frame %u: GetSizeInBlocks got unexpected hr %#x\n", i, frame_index, hr);
1002 hr = IWICDdsFrameDecode_GetSizeInBlocks(dds_frame, &width_in_blocks, &height_in_blocks);
1003 ok(hr == S_OK, "Test %u, frame %u: GetSizeInBlocks failed, hr %#x\n", i, frame_index, hr);
1004 if (hr != S_OK) return;
1006 expected_width_in_blocks = (expected_width + expected_block_width - 1) / expected_block_width;
1007 expected_height_in_blocks = (expected_height + expected_block_height - 1) / expected_block_height;
1008 ok(width_in_blocks == expected_width_in_blocks,
1009 "Test %u, frame %u: Expected width in blocks %u, got %u\n", i, frame_index, expected_width_in_blocks, width_in_blocks);
1010 ok(height_in_blocks == expected_height_in_blocks,
1011 "Test %u, frame %u: Expected height in blocks %u, got %u\n", i, frame_index, expected_height_in_blocks, height_in_blocks);
1013 /* pixel format tests */
1015 hr = IWICBitmapFrameDecode_GetPixelFormat(frame_decode, NULL);
1016 ok(hr == E_INVALIDARG, "Test %u, frame %u: GetPixelFormat got unexpected hr %#x\n", i, frame_index, hr);
1017 hr = IWICBitmapFrameDecode_GetPixelFormat(frame_decode, &pixel_format);
1018 ok(hr == S_OK, "Test %u, frame %u: GetPixelFormat failed, hr %#x\n", i, frame_index, hr);
1019 if (hr != S_OK) return;
1020 ok(IsEqualGUID(&pixel_format, test_data[i].expected_pixel_format),
1021 "Test %u, frame %u: Expected pixel format %s, got %s\n",
1022 i, frame_index, debugstr_guid(test_data[i].expected_pixel_format), debugstr_guid(&pixel_format));
1025 static void test_dds_decoder_frame_data(IWICBitmapFrameDecode* frame, IWICDdsFrameDecode *dds_frame, UINT frame_count,
1026 WICDdsParameters *params, int i, int frame_index)
1028 HRESULT hr;
1029 GUID pixel_format;
1030 WICDdsFormatInfo format_info;
1031 WICRect rect = { 0, 0, 1, 1 }, rect_test_a = { 0, 0, 0, 0 }, rect_test_b = { 0, 0, 0xdeadbeaf, 0xdeadbeaf };
1032 WICRect rect_test_c = { -0xdeadbeaf, -0xdeadbeaf, 1, 1 }, rect_test_d = { 0xdeadbeaf, 0xdeadbeaf, 1, 1 };
1033 BYTE buffer[2048], pixels[2048];
1034 UINT stride, frame_stride, frame_size, frame_width, frame_height, width_in_blocks, height_in_blocks, bpp;
1035 UINT width, height, depth, array_index;
1036 UINT block_offset;
1037 int slice_index;
1039 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &pixel_format);
1040 ok(hr == S_OK, "Test %u, frame %u: GetPixelFormat failed, hr %#x\n", i, frame_index, hr);
1041 if (hr != S_OK) return;
1042 hr = IWICBitmapFrameDecode_GetSize(frame, &frame_width, &frame_height);
1043 ok(hr == S_OK, "Test %u, frame %u: GetSize failed, hr %#x\n", i, frame_index, hr);
1044 if (hr != S_OK) return;
1045 hr = IWICDdsFrameDecode_GetFormatInfo(dds_frame, &format_info);
1046 ok(hr == S_OK, "Test %u, frame %u: GetFormatInfo failed, hr %#x\n", i, frame_index, hr);
1047 if (hr != S_OK) return;
1048 hr = IWICDdsFrameDecode_GetSizeInBlocks(dds_frame, &width_in_blocks, &height_in_blocks);
1049 ok(hr == S_OK, "Test %u, frame %u: GetSizeInBlocks failed, hr %#x\n", i, frame_index, hr);
1050 if (hr != S_OK) return;
1051 stride = rect.Width * format_info.BytesPerBlock;
1052 frame_stride = width_in_blocks * format_info.BytesPerBlock;
1053 frame_size = frame_stride * height_in_blocks;
1055 /* CopyBlocks tests */
1057 hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, NULL, 0, 0, NULL);
1058 ok(hr == E_INVALIDARG, "Test %u, frame %u: CopyBlocks got unexpected hr %#x\n", i, frame_index, hr);
1060 hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, &rect_test_a, stride, sizeof(buffer), buffer);
1061 ok(hr == E_INVALIDARG, "Test %u, frame %u: CopyBlocks got unexpected hr %#x\n", i, frame_index, hr);
1062 hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, &rect_test_b, stride, sizeof(buffer), buffer);
1063 ok(hr == E_INVALIDARG, "Test %u, frame %u: CopyBlocks got unexpected hr %#x\n", i, frame_index, hr);
1064 hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, &rect_test_c, stride, sizeof(buffer), buffer);
1065 ok(hr == E_INVALIDARG, "Test %u, frame %u: CopyBlocks got unexpected hr %#x\n", i, frame_index, hr);
1066 hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, &rect_test_d, stride, sizeof(buffer), buffer);
1067 ok(hr == E_INVALIDARG, "Test %u, frame %u: CopyBlocks got unexpected hr %#x\n", i, frame_index, hr);
1069 hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, NULL, frame_stride - 1, sizeof(buffer), buffer);
1070 ok(hr == E_INVALIDARG, "Test %u, frame %u: CopyBlocks got unexpected hr %#x\n", i, frame_index, hr);
1071 hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, NULL, frame_stride * 2, sizeof(buffer), buffer);
1072 ok(hr == S_OK, "Test %u, frame %u: CopyBlocks got unexpected hr %#x\n", i, frame_index, hr);
1073 hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, NULL, frame_stride, sizeof(buffer), buffer);
1074 ok(hr == S_OK, "Test %u, frame %u: CopyBlocks got unexpected hr %#x\n", i, frame_index, hr);
1075 hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, NULL, frame_stride, frame_stride * height_in_blocks - 1, buffer);
1076 ok(hr == E_INVALIDARG, "Test %u, frame %u: CopyBlocks got unexpected hr %#x\n", i, frame_index, hr);
1077 hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, NULL, frame_stride, frame_stride * height_in_blocks, buffer);
1078 ok(hr == S_OK, "Test %u, frame %u: CopyBlocks got unexpected hr %#x\n", i, frame_index, hr);
1080 hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, &rect, 0, sizeof(buffer), buffer);
1081 ok(hr == E_INVALIDARG, "Test %u, frame %u: CopyBlocks got unexpected hr %#x\n", i, frame_index, hr);
1082 hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, &rect, stride - 1, sizeof(buffer), buffer);
1083 ok(hr == E_INVALIDARG, "Test %u, frame %u: CopyBlocks got unexpected hr %#x\n", i, frame_index, hr);
1084 hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, &rect, stride * 2, sizeof(buffer), buffer);
1085 ok(hr == S_OK, "Test %u, frame %u: CopyBlocks got unexpected hr %#x\n", i, frame_index, hr);
1087 hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, &rect, stride, 0, buffer);
1088 ok(hr == E_INVALIDARG, "Test %u, frame %u: CopyBlocks got unexpected hr %#x\n", i, frame_index, hr);
1089 hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, &rect, stride, 1, buffer);
1090 ok(hr == E_INVALIDARG || (hr == S_OK && test_data[i].expected_bytes_per_block == 1),
1091 "Test %u, frame %u: CopyBlocks got unexpected hr %#x\n", i, frame_index, hr);
1092 hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, &rect, stride, stride * rect.Height - 1, buffer);
1093 ok(hr == E_INVALIDARG, "Test %u, frame %u: CopyBlocks got unexpected hr %#x\n", i, frame_index, hr);
1094 hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, &rect, stride, stride * rect.Height, buffer);
1095 ok(hr == S_OK, "Test %u, frame %u: CopyBlocks got unexpected hr %#x\n", i, frame_index, hr);
1097 hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, &rect, stride, sizeof(buffer), NULL);
1098 ok(hr == E_INVALIDARG, "Test %u, frame %u: CopyBlocks got unexpected hr %#x\n", i, frame_index, hr);
1100 block_offset = 128; /* DDS magic and header */
1101 if (has_extended_header(test_data[i].data)) block_offset += 20; /* DDS extended header */
1102 width = params->Width;
1103 height = params->Height;
1104 depth = params->Depth;
1105 slice_index = frame_index % (frame_count / params->ArraySize);
1106 array_index = frame_index / (frame_count / params->ArraySize);
1107 block_offset += (test_data[i].size - block_offset) / params->ArraySize * array_index;
1108 while (slice_index >= 0)
1110 width_in_blocks = (width + format_info.BlockWidth - 1) / format_info.BlockWidth;
1111 height_in_blocks = (width + format_info.BlockWidth - 1) / format_info.BlockWidth;
1112 block_offset += (slice_index >= depth) ?
1113 (width_in_blocks * height_in_blocks * format_info.BytesPerBlock * depth) :
1114 (width_in_blocks * height_in_blocks * format_info.BytesPerBlock * slice_index);
1115 if (width > 1) width /= 2;
1116 if (height > 1) height /= 2;
1117 slice_index -= depth;
1118 if (depth > 1) depth /= 2;
1121 memset(buffer, 0, sizeof(buffer));
1122 hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, &rect, stride, sizeof(buffer), buffer);
1123 ok(hr == S_OK, "Test %u, frame %u: CopyBlocks failed, hr %#x\n", i, frame_index, hr);
1124 if (hr != S_OK) return;
1125 ok(!memcmp(test_data[i].data + block_offset, buffer, format_info.BytesPerBlock),
1126 "Test %u, frame %u: Block data mismatch\n", i, frame_index);
1128 memset(buffer, 0, sizeof(buffer));
1129 hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, NULL, frame_stride, sizeof(buffer), buffer);
1130 ok(hr == S_OK, "Test %u, frame %u: CopyBlocks failed, hr %#x\n", i, frame_index, hr);
1131 if (hr != S_OK) return;
1132 ok(!memcmp(test_data[i].data + block_offset, buffer, frame_size),
1133 "Test %u, frame %u: Block data mismatch\n", i, frame_index);
1135 memset(buffer, 0, sizeof(buffer));
1136 memset(pixels, 0, sizeof(pixels));
1137 copy_pixels(test_data[i].data + block_offset, frame_stride, pixels, frame_stride * 2, frame_size);
1138 hr = IWICDdsFrameDecode_CopyBlocks(dds_frame, NULL, frame_stride * 2, sizeof(buffer), buffer);
1139 ok(hr == S_OK, "Test %u, frame %u: CopyBlocks failed, hr %#x\n", i, frame_index, hr);
1140 if (hr != S_OK) return;
1141 ok(!memcmp(pixels, buffer, frame_size),
1142 "Test %u, frame %u: Block data mismatch\n", i, frame_index);
1144 /* CopyPixels tests */
1146 bpp = test_data[i].pixel_format_bpp;
1147 stride = rect.Width * bpp / 8;
1148 frame_stride = frame_width * bpp / 8;
1149 frame_size = frame_stride * frame_height;
1151 hr = IWICBitmapFrameDecode_CopyPixels(frame, NULL, 0, 0, NULL);
1152 ok(hr == E_INVALIDARG, "Test %u, frame %u: CopyPixels got unexpected hr %#x\n", i, frame_index, hr);
1154 hr = IWICBitmapFrameDecode_CopyPixels(frame, &rect_test_a, stride, sizeof(buffer), buffer);
1155 ok(hr == E_INVALIDARG, "Test %u, frame %u: CopyPixels got unexpected hr %#x\n", i, frame_index, hr);
1156 hr = IWICBitmapFrameDecode_CopyPixels(frame, &rect_test_b, stride, sizeof(buffer), buffer);
1157 ok(hr == E_INVALIDARG, "Test %u, frame %u: CopyPixels got unexpected hr %#x\n", i, frame_index, hr);
1158 hr = IWICBitmapFrameDecode_CopyPixels(frame, &rect_test_c, stride, sizeof(buffer), buffer);
1159 ok(hr == E_INVALIDARG, "Test %u, frame %u: CopyPixels got unexpected hr %#x\n", i, frame_index, hr);
1160 hr = IWICBitmapFrameDecode_CopyPixels(frame, &rect_test_d, stride, sizeof(buffer), buffer);
1161 ok(hr == E_INVALIDARG, "Test %u, frame %u: CopyPixels got unexpected hr %#x\n", i, frame_index, hr);
1163 hr = IWICBitmapFrameDecode_CopyPixels(frame, NULL, frame_stride - 1, sizeof(buffer), buffer);
1164 ok(hr == E_INVALIDARG, "Test %u, frame %u: CopyPixels got unexpected hr %#x\n", i, frame_index, hr);
1165 hr = IWICBitmapFrameDecode_CopyPixels(frame, NULL, frame_stride * 2, sizeof(buffer), buffer);
1166 ok(hr == S_OK, "Test %u, frame %u: CopyPixels got unexpected hr %#x\n", i, frame_index, hr);
1167 hr = IWICBitmapFrameDecode_CopyPixels(frame, NULL, frame_stride, sizeof(buffer), buffer);
1168 ok(hr == S_OK, "Test %u, frame %u: CopyPixels got unexpected hr %#x\n", i, frame_index, hr);
1169 hr = IWICBitmapFrameDecode_CopyPixels(frame, NULL, frame_stride, frame_stride * frame_height - 1, buffer);
1170 ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "Test %u, frame %u: CopyPixels got unexpected hr %#x\n", i, frame_index, hr);
1171 hr = IWICBitmapFrameDecode_CopyPixels(frame, NULL, frame_stride, frame_stride * frame_height, buffer);
1172 ok(hr == S_OK, "Test %u, frame %u: CopyPixels got unexpected hr %#x\n", i, frame_index, hr);
1174 hr = IWICBitmapFrameDecode_CopyPixels(frame, &rect, 0, sizeof(buffer), buffer);
1175 ok(hr == E_INVALIDARG, "Test %u, frame %u: CopyPixels got unexpected hr %#x\n", i, frame_index, hr);
1176 hr = IWICBitmapFrameDecode_CopyPixels(frame, &rect, stride - 1, sizeof(buffer), buffer);
1177 ok(hr == E_INVALIDARG, "Test %u, frame %u: CopyPixels got unexpected hr %#x\n", i, frame_index, hr);
1178 hr = IWICBitmapFrameDecode_CopyPixels(frame, &rect, stride * 2, sizeof(buffer), buffer);
1179 ok(hr == S_OK, "Test %u, frame %u: CopyPixels got unexpected hr %#x\n", i, frame_index, hr);
1181 hr = IWICBitmapFrameDecode_CopyPixels(frame, &rect, stride, 0, buffer);
1182 ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "Test %u, frame %u: CopyPixels got unexpected hr %#x\n", i, frame_index, hr);
1183 hr = IWICBitmapFrameDecode_CopyPixels(frame, &rect, stride, 1, buffer);
1184 ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER || (hr == S_OK && test_data[i].expected_bytes_per_block == 1),
1185 "Test %u, frame %u: CopyPixels got unexpected hr %#x\n", i, frame_index, hr);
1186 hr = IWICBitmapFrameDecode_CopyPixels(frame, &rect, stride, stride * rect.Height - 1, buffer);
1187 ok(hr == WINCODEC_ERR_INSUFFICIENTBUFFER, "Test %u, frame %u: CopyPixels got unexpected hr %#x\n", i, frame_index, hr);
1188 hr = IWICBitmapFrameDecode_CopyPixels(frame, &rect, stride, stride * rect.Height, buffer);
1189 ok(hr == S_OK, "Test %u, frame %u: CopyPixels got unexpected hr %#x\n", i, frame_index, hr);
1191 hr = IWICBitmapFrameDecode_CopyPixels(frame, &rect, stride, sizeof(buffer), NULL);
1192 ok(hr == E_INVALIDARG, "Test %u, frame %u: CopyBlocks got unexpected hr %#x\n", i, frame_index, hr);
1194 memset(buffer, 0, sizeof(pixels));
1195 if (is_compressed(format_info.DxgiFormat)) {
1196 decode_block(test_data[i].data + block_offset, width_in_blocks * height_in_blocks,
1197 format_info.DxgiFormat, frame_width, frame_height, (DWORD *)pixels);
1198 } else {
1199 memcpy(pixels, test_data[i].data + block_offset, frame_size);
1202 memset(buffer, 0, sizeof(buffer));
1203 hr = IWICBitmapFrameDecode_CopyPixels(frame, &rect, stride, sizeof(buffer), buffer);
1204 ok(hr == S_OK, "Test %u, frame %u: CopyPixels failed, hr %#x\n", i, frame_index, hr);
1205 if (hr == S_OK) {
1206 if (is_compressed(format_info.DxgiFormat)) {
1207 ok(color_buffer_match((DWORD *)pixels, (DWORD *)buffer, 1),
1208 "Test %u, frame %u: Pixels mismatch\n", i, frame_index);
1209 } else {
1210 ok(!memcmp(pixels, buffer, bpp / 8),
1211 "Test %u, frame %u: Pixels mismatch\n", i, frame_index);
1215 memset(buffer, 0, sizeof(buffer));
1216 hr = IWICBitmapFrameDecode_CopyPixels(frame, NULL, frame_stride, sizeof(buffer), buffer);
1217 ok(hr == S_OK, "Test %u, frame %u: CopyPixels failed, hr %#x\n", i, frame_index, hr);
1218 if (hr == S_OK) {
1219 if (is_compressed(format_info.DxgiFormat)) {
1220 ok(color_buffer_match((DWORD *)pixels, (DWORD *)buffer, frame_size / (bpp / 8)),
1221 "Test %u, frame %u: Pixels mismatch\n", i, frame_index);
1222 } else {
1223 ok(!memcmp(pixels, buffer, frame_size),
1224 "Test %u, frame %u: Pixels mismatch\n", i, frame_index);
1229 static void test_dds_decoder_frame(IWICBitmapDecoder *decoder, int i)
1231 HRESULT hr;
1232 IWICDdsDecoder *dds_decoder = NULL;
1233 UINT frame_count, j;
1234 WICDdsParameters params;
1236 hr = IWICBitmapDecoder_GetFrameCount(decoder, &frame_count);
1237 ok(hr == S_OK, "Test %u: GetFrameCount failed, hr %#x\n", i, hr);
1238 if (hr != S_OK) return;
1239 hr = IWICBitmapDecoder_QueryInterface(decoder, &IID_IWICDdsDecoder, (void **)&dds_decoder);
1240 ok(hr == S_OK, "Test %u: QueryInterface failed, hr %#x\n", i, hr);
1241 if (hr != S_OK) goto end;
1242 hr = IWICDdsDecoder_GetParameters(dds_decoder, &params);
1243 ok(hr == S_OK, "Test %u: GetParameters failed, hr %#x\n", i, hr);
1244 if (hr != S_OK) goto end;
1246 if (test_data[i].expected_parameters.Dimension == WICDdsTextureCube) params.ArraySize *= 6;
1248 for (j = 0; j < frame_count; j++)
1250 IWICBitmapFrameDecode *frame_decode = NULL;
1251 IWICDdsFrameDecode *dds_frame = NULL;
1253 hr = IWICBitmapDecoder_GetFrame(decoder, j, &frame_decode);
1254 ok(hr == S_OK, "Test %u, frame %u: GetFrame failed, hr %#x\n", i, j, hr);
1255 if (hr != S_OK) goto next;
1256 hr = IWICBitmapFrameDecode_QueryInterface(frame_decode, &IID_IWICDdsFrameDecode, (void **)&dds_frame);
1257 ok(hr == S_OK, "Test %u, frame %u: QueryInterface failed, hr %#x\n", i, j, hr);
1258 if (hr != S_OK) goto next;
1260 test_dds_decoder_frame_properties(frame_decode, dds_frame, frame_count, &params, i, j);
1261 test_dds_decoder_frame_data(frame_decode, dds_frame, frame_count, &params, i, j);
1263 next:
1264 if (frame_decode) IWICBitmapFrameDecode_Release(frame_decode);
1265 if (dds_frame) IWICDdsFrameDecode_Release(dds_frame);
1268 end:
1269 if (dds_decoder) IWICDdsDecoder_Release(dds_decoder);
1272 static void test_dds_decoder(void)
1274 int i;
1275 HRESULT hr;
1277 test_dds_decoder_initialize();
1278 test_dds_decoder_image_parameters();
1280 for (i = 0; i < ARRAY_SIZE(test_data); i++)
1282 IWICStream *stream = NULL;
1283 IWICBitmapDecoder *decoder = NULL;
1285 if (test_data[i].init_hr != S_OK && !test_data[i].wine_init) continue;
1287 stream = create_stream(test_data[i].data, test_data[i].size);
1288 if (!stream) goto next;
1289 decoder = create_decoder();
1290 if (!decoder) goto next;
1291 hr = init_decoder(decoder, stream, test_data[i].init_hr, i, test_data[i].wine_init);
1292 if (hr != S_OK) {
1293 if (test_data[i].expected_parameters.Dimension == WICDdsTextureCube) {
1294 win_skip("Test %u: Cube map is not supported\n", i);
1295 } else {
1296 win_skip("Test %u: Uncompressed DDS image is not supported\n", i);
1298 goto next;
1301 test_dds_decoder_global_properties(decoder);
1302 test_dds_decoder_frame(decoder, i);
1304 next:
1305 if (decoder) IWICBitmapDecoder_Release(decoder);
1306 if (stream) IWICStream_Release(stream);
1310 static void test_dds_encoder_initialize(void)
1312 IWICBitmapEncoder *encoder = NULL;
1313 IWICStream *stream = NULL;
1314 BYTE buffer[1];
1315 HRESULT hr;
1317 encoder = create_encoder();
1318 if (!encoder) goto end;
1320 stream = create_stream(buffer, sizeof(buffer));
1321 if (!stream) goto end;
1323 /* initialize with invalid cache option */
1325 hr = IWICBitmapEncoder_Initialize(encoder, (IStream *)stream, 0xdeadbeef);
1326 todo_wine
1327 ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "Initialize got unexpected hr %#x\n", hr);
1329 hr = IWICBitmapEncoder_Initialize(encoder, (IStream *)stream, WICBitmapEncoderNoCache);
1330 todo_wine
1331 ok(hr == E_INVALIDARG, "Initialize got unexpected hr %#x\n", hr);
1333 IWICBitmapEncoder_Release(encoder);
1335 /* initialize with null stream */
1337 encoder = create_encoder();
1338 if (!encoder) goto end;
1340 hr = IWICBitmapEncoder_Initialize(encoder, NULL, WICBitmapEncoderNoCache);
1341 ok(hr == E_INVALIDARG, "Initialize got unexpected hr %#x\n", hr);
1343 hr = IWICBitmapEncoder_Initialize(encoder, (IStream *)stream, WICBitmapEncoderNoCache);
1344 ok(hr == S_OK, "Initialize failed, hr %#x\n", hr);
1346 IWICBitmapEncoder_Release(encoder);
1348 /* regularly initialize */
1350 encoder = create_encoder();
1351 if (!encoder) goto end;
1353 hr = IWICBitmapEncoder_Initialize(encoder, (IStream *)stream, WICBitmapEncoderNoCache);
1354 ok(hr == S_OK, "Initialize failed, hr %#x\n", hr);
1356 hr = IWICBitmapEncoder_Initialize(encoder, (IStream *)stream, WICBitmapEncoderNoCache);
1357 ok(hr == WINCODEC_ERR_WRONGSTATE, "Initialize got unexpected hr %#x\n", hr);
1359 end:
1360 if (stream) IWICStream_Release(stream);
1361 if (encoder) IWICBitmapEncoder_Release(encoder);
1364 static void test_dds_encoder_params(void)
1366 WICDdsParameters params, params_set = { 4, 4, 4, 3, 1, DXGI_FORMAT_BC1_UNORM,
1367 WICDdsTexture3D, WICDdsAlphaModePremultiplied };
1368 IWICDdsEncoder *dds_encoder = NULL;
1369 IWICBitmapEncoder *encoder = NULL;
1370 IWICStream *stream = NULL;
1371 BYTE buffer[1024];
1372 HRESULT hr;
1373 UINT i;
1375 hr = create_and_init_encoder(buffer, sizeof(buffer), NULL, &encoder, &dds_encoder, &stream);
1376 if (hr != S_OK) goto end;
1378 hr = IWICDdsEncoder_GetParameters(dds_encoder, NULL);
1379 ok(hr == E_INVALIDARG, "GetParameters got unexpected hr %#x\n", hr);
1381 hr = IWICDdsEncoder_GetParameters(dds_encoder, &params);
1382 ok(hr == S_OK, "GetParameters failed, hr %#x\n", hr);
1383 if (hr != S_OK) goto end;
1385 /* default DDS parameters for encoder */
1386 ok(params.Width == 1, "Got unexpected Width %u\n", params.Width);
1387 ok(params.Height == 1, "Got unexpected Height %u\n", params.Height);
1388 ok(params.Depth == 1, "Got unexpected Depth %u\n", params.Depth);
1389 ok(params.MipLevels == 1, "Got unexpected MipLevels %u\n", params.MipLevels);
1390 ok(params.ArraySize == 1, "Got unexpected ArraySize %u\n", params.ArraySize);
1391 ok(params.DxgiFormat == DXGI_FORMAT_BC3_UNORM, "Got unexpected DxgiFormat %#x\n", params.DxgiFormat);
1392 ok(params.Dimension == WICDdsTexture2D, "Got unexpected Dimension %#x\n", params.Dimension);
1393 ok(params.AlphaMode == WICDdsAlphaModeUnknown, "Got unexpected AlphaMode %#x\n", params.AlphaMode);
1395 hr = IWICDdsEncoder_SetParameters(dds_encoder, NULL);
1396 ok(hr == E_INVALIDARG, "SetParameters got unexpected hr %#x\n", hr);
1398 hr = IWICDdsEncoder_SetParameters(dds_encoder, &params_set);
1399 ok(hr == S_OK, "SetParameters failed, hr %#x\n", hr);
1400 if (hr != S_OK) goto end;
1402 IWICDdsEncoder_GetParameters(dds_encoder, &params);
1404 ok(params.Width == params_set.Width,
1405 "Expected Width %u, got %u\n", params_set.Width, params.Width);
1406 ok(params.Height == params_set.Height,
1407 "Expected Height %u, got %u\n", params_set.Height, params.Height);
1408 ok(params.Depth == params_set.Depth,
1409 "Expected Depth %u, got %u\n", params_set.Depth, params.Depth);
1410 ok(params.MipLevels == params_set.MipLevels,
1411 "Expected MipLevels %u, got %u\n", params_set.MipLevels, params.MipLevels);
1412 ok(params.ArraySize == params_set.ArraySize,
1413 "Expected ArraySize %u, got %u\n", params_set.ArraySize, params.ArraySize);
1414 ok(params.DxgiFormat == params_set.DxgiFormat,
1415 "Expected DxgiFormat %u, got %#x\n", params_set.DxgiFormat, params.DxgiFormat);
1416 ok(params.Dimension == params_set.Dimension,
1417 "Expected Dimension %u, got %#x\n", params_set.Dimension, params.Dimension);
1418 ok(params.AlphaMode == params_set.AlphaMode,
1419 "Expected AlphaMode %u, got %#x\n", params_set.AlphaMode, params.AlphaMode);
1421 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
1423 hr = IWICDdsEncoder_SetParameters(dds_encoder, &test_data[i].expected_parameters);
1424 todo_wine_if(test_data[i].init_hr != S_OK)
1425 ok((hr == S_OK && test_data[i].init_hr == S_OK) || hr == WINCODEC_ERR_BADHEADER,
1426 "Test %u: SetParameters got unexpected hr %#x\n", i, hr);
1429 end:
1430 release_encoder(encoder, dds_encoder, stream);
1433 static void test_dds_encoder_create_frame(void)
1435 WICDdsParameters params = { 4, 4, 1, 3, 1, DXGI_FORMAT_BC1_UNORM,
1436 WICDdsTexture2D, WICDdsAlphaModePremultiplied };
1437 IWICBitmapFrameEncode *frame0 = NULL, *frame1 = NULL;
1438 UINT array_index, mip_level, slice_index;
1439 IWICDdsEncoder *dds_encoder = NULL;
1440 IWICBitmapEncoder *encoder = NULL;
1441 IWICStream *stream = NULL;
1442 BYTE buffer[1024];
1443 HRESULT hr;
1445 hr = create_and_init_encoder(buffer, sizeof(buffer), &params, &encoder, &dds_encoder, &stream);
1446 if (hr != S_OK) goto end;
1448 hr = IWICBitmapEncoder_CreateNewFrame(encoder, &frame0, NULL);
1449 ok(hr == S_OK, "CreateNewFrame failed, hr %#x\n", hr);
1450 hr = IWICBitmapEncoder_CreateNewFrame(encoder, &frame1, NULL);
1451 ok(hr == WINCODEC_ERR_WRONGSTATE, "CreateNewFrame got unexpected hr %#x\n", hr);
1453 IWICBitmapFrameEncode_Release(frame0);
1454 hr = IWICBitmapEncoder_CreateNewFrame(encoder, &frame1, NULL);
1455 ok(hr == WINCODEC_ERR_WRONGSTATE, "CreateNewFrame got unexpected hr %#x\n", hr);
1457 release_encoder(encoder, dds_encoder, stream);
1459 create_and_init_encoder(buffer, sizeof(buffer), &params, &encoder, &dds_encoder, &stream);
1460 hr = IWICDdsEncoder_CreateNewFrame(dds_encoder, &frame0, &array_index, &mip_level, &slice_index);
1461 ok(hr == S_OK, "CreateNewFrame failed, hr %#x\n", hr);
1462 IWICBitmapFrameEncode_Release(frame0);
1463 release_encoder(encoder, dds_encoder, stream);
1465 create_and_init_encoder(buffer, sizeof(buffer), &params, &encoder, &dds_encoder, &stream);
1466 hr = IWICDdsEncoder_CreateNewFrame(dds_encoder, &frame0, NULL, NULL, NULL);
1467 ok(hr == S_OK, "CreateNewFrame failed, hr %#x\n", hr);
1468 IWICBitmapFrameEncode_Release(frame0);
1470 end:
1471 release_encoder(encoder, dds_encoder, stream);
1474 static void test_dds_encoder_pixel_format(void)
1476 DXGI_FORMAT image_formats[] = { DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC2_UNORM, DXGI_FORMAT_BC3_UNORM };
1477 const WICPixelFormatGUID *test_formats[] =
1479 &GUID_WICPixelFormat8bppIndexed,
1480 &GUID_WICPixelFormatBlackWhite,
1481 &GUID_WICPixelFormat16bppGray,
1482 &GUID_WICPixelFormat8bppAlpha,
1483 &GUID_WICPixelFormat16bppBGR555,
1484 &GUID_WICPixelFormat16bppBGR565,
1485 &GUID_WICPixelFormat24bppBGR,
1486 &GUID_WICPixelFormat32bppBGR,
1487 &GUID_WICPixelFormat32bppBGRA,
1488 &GUID_WICPixelFormat32bppPBGRA,
1489 &GUID_WICPixelFormat32bppRGB,
1490 &GUID_WICPixelFormat32bppRGBA,
1491 &GUID_WICPixelFormat32bppPRGBA,
1492 &GUID_WICPixelFormat48bppRGB,
1493 &GUID_WICPixelFormat64bppRGB,
1494 &GUID_WICPixelFormat64bppRGBA
1496 IWICBitmapFrameEncode *frame = NULL;
1497 IWICDdsEncoder *dds_encoder = NULL;
1498 IWICBitmapEncoder *encoder = NULL;
1499 IWICStream *stream = NULL;
1500 WICPixelFormatGUID format;
1501 WICDdsParameters params;
1502 BYTE buffer[1];
1503 HRESULT hr;
1504 UINT i, j;
1506 for (i = 0; i < ARRAY_SIZE(image_formats); ++i)
1508 hr = create_and_init_encoder(buffer, sizeof(buffer), NULL, &encoder, &dds_encoder, &stream);
1509 if (hr != S_OK)
1511 release_encoder(encoder, dds_encoder, stream);
1512 return;
1515 IWICDdsEncoder_GetParameters(dds_encoder, &params);
1516 params.DxgiFormat = image_formats[i];
1517 IWICDdsEncoder_SetParameters(dds_encoder, &params);
1519 IWICBitmapEncoder_CreateNewFrame(encoder, &frame, NULL);
1521 hr = IWICBitmapFrameEncode_SetPixelFormat(frame, &format);
1522 ok(hr == WINCODEC_ERR_NOTINITIALIZED, "SetPixelFormat got unexpected hr %#x\n", hr);
1524 IWICBitmapFrameEncode_Initialize(frame, NULL);
1526 for (j = 0; j < ARRAY_SIZE(test_formats); ++j)
1528 format = *(test_formats[j]);
1529 hr = IWICBitmapFrameEncode_SetPixelFormat(frame, &format);
1530 ok(hr == S_OK, "Test %u: SetPixelFormat failed, hr %#x\n", j, hr);
1531 ok(IsEqualGUID(&format, &GUID_WICPixelFormat32bppBGRA),
1532 "Test %u: Got unexpected GUID %s\n", j, debugstr_guid(&format));
1535 IWICBitmapFrameEncode_Release(frame);
1536 release_encoder(encoder, dds_encoder, stream);
1540 static void test_dds_encoder(void)
1542 test_dds_encoder_initialize();
1543 test_dds_encoder_params();
1544 test_dds_encoder_create_frame();
1545 test_dds_encoder_pixel_format();
1548 START_TEST(ddsformat)
1550 HRESULT hr;
1551 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
1553 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
1554 &IID_IWICImagingFactory, (void **)&factory);
1555 ok(hr == S_OK, "CoCreateInstance failed, hr %#x\n", hr);
1556 if (hr != S_OK) goto end;
1558 test_dds_decoder();
1559 test_dds_encoder();
1561 end:
1562 if (factory) IWICImagingFactory_Release(factory);
1563 CoUninitialize();