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) 28 static 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) */ 35 static const unsigned char bmp_1bpp[] = { 36 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00, 37 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00, 38 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00, 39 0x00,0x00,0x02,0x00,0x00,0x00,0xf1,0xf2,0xf3,0x80,0xf4,0xf5,0xf6,0x81,0x00,0x00, 40 0x00,0x00 41 }; 42 43 /* 1x1 bmp (2 bpp) */ 44 static const unsigned char bmp_2bpp[] = { 45 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00, 46 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x02,0x00,0x00,0x00, 47 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00, 48 0x00,0x00,0x02,0x00,0x00,0x00,0xf1,0xf2,0xf3,0x80,0xf4,0xf5,0xf6,0x81,0x00,0x00, 49 0x00,0x00 50 }; 51 52 /* 1x1 bmp (4 bpp) */ 53 static const unsigned char bmp_4bpp[] = { 54 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00, 55 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x04,0x00,0x00,0x00, 56 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00, 57 0x00,0x00,0x02,0x00,0x00,0x00,0xf1,0xf2,0xf3,0x80,0xf4,0xf5,0xf6,0x81,0x00,0x00, 58 0x00,0x00 59 }; 60 61 /* 1x1 bmp (8 bpp) */ 62 static const unsigned char bmp_8bpp[] = { 63 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00, 64 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x08,0x00,0x00,0x00, 65 0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00, 66 0x00,0x00,0x02,0x00,0x00,0x00,0xf1,0xf2,0xf3,0x80,0xf4,0xf5,0xf6,0x81,0x00,0x00, 67 0x00,0x00 68 }; 69 70 /* 2x2 bmp (32 bpp XRGB) */ 71 static 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) */ 81 static 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 90 static 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 */ 101 static const unsigned char pixdata[] = { 102 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff 103 }; 104 105 /* invalid image file */ 106 static const unsigned char noimage[4] = { 107 0x11,0x22,0x33,0x44 108 }; 109 110 /* 16x4 8-bit dds */ 111 static 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 */ 192 static const unsigned char dds_24bit[] = { 193 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x0a,0x00,0x02,0x00,0x00,0x00, 194 0x02,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00, 195 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 196 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 197 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00, 198 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0xff,0x00, 199 0x00,0xff,0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00, 200 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 201 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff 202 }; 203 204 /* 2x2 16-bit dds, no mipmaps */ 205 static const unsigned char dds_16bit[] = { 206 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x02,0x00,0x00,0x00, 207 0x02,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 208 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 209 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 210 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00, 211 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x7c,0x00,0x00, 212 0xe0,0x03,0x00,0x00,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00, 213 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 214 0xff,0x7f,0xff,0x7f,0xff,0x7f,0xff,0x7f 215 }; 216 217 /* 4x4 cube map dds */ 218 static const unsigned char dds_cube_map[] = { 219 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x04,0x00,0x00,0x00, 220 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 221 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 222 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 223 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00, 224 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x35,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 225 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x00,0x00, 226 0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 227 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50, 228 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50, 229 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50, 230 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50, 231 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50, 232 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50 233 }; 234 235 /* 4x4x2 volume map dds, 2 mipmaps */ 236 static const unsigned char dds_volume_map[] = { 237 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x8a,0x00,0x04,0x00,0x00,0x00, 238 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x00,0x00,0x00, 239 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 240 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 241 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00, 242 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 243 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00, 244 0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 245 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50, 246 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50, 247 0xff,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x2f,0x7e,0xcf,0x79,0x01,0x54,0x5c,0x5c, 248 0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x84,0xef,0x7b,0xaa,0xab,0xab,0xab 249 }; 250 251 /* 4x2 dxt5 */ 252 static 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 */ 266 static 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 282 static HRESULT create_file(const char *filename, const unsigned char *data, const unsigned int size) 283 { 284 DWORD received; 285 HANDLE hfile; 286 287 hfile = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); 288 if(hfile == INVALID_HANDLE_VALUE) return HRESULT_FROM_WIN32(GetLastError()); 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 322 struct dds_pixel_format 323 { 324 DWORD size; 325 DWORD flags; 326 DWORD fourcc; 327 DWORD bpp; 328 DWORD rmask; 329 DWORD gmask; 330 DWORD bmask; 331 DWORD amask; 332 }; 333 334 struct dds_header 335 { 336 DWORD size; 337 DWORD flags; 338 DWORD height; 339 DWORD width; 340 DWORD pitch_or_linear_size; 341 DWORD depth; 342 DWORD miplevels; 343 DWORD reserved[11]; 344 struct dds_pixel_format pixel_format; 345 DWORD caps; 346 DWORD caps2; 347 DWORD caps3; 348 DWORD caps4; 349 DWORD reserved2; 350 }; 351 352 /* fills dds_header with reasonable default values */ 353 static void fill_dds_header(struct dds_header *header) 354 { 355 memset(header, 0, sizeof(*header)); 356 357 header->size = sizeof(*header); 358 header->flags = DDS_CAPS | DDS_WIDTH | DDS_HEIGHT | DDS_PIXELFORMAT; 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) 375 static void check_dds_pixel_format_(unsigned int line, 376 DWORD flags, DWORD fourcc, DWORD bpp, 377 DWORD rmask, DWORD gmask, DWORD bmask, DWORD amask, 378 D3DFORMAT expected_format) 379 { 380 HRESULT hr; 381 D3DXIMAGE_INFO info; 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 410 static void test_dds_header_handling(void) 411 { 412 int i; 413 HRESULT hr; 414 D3DXIMAGE_INFO info; 415 struct 416 { 417 DWORD magic; 418 struct dds_header header; 419 BYTE data[4096 * 1024]; 420 } *dds; 421 422 struct 423 { 424 struct dds_pixel_format pixel_format; 425 DWORD flags; 426 DWORD width; 427 DWORD height; 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 548 hr = D3DXGetImageInfoFromFileInMemory(dds, file_size, &info); 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 561 static void test_D3DXGetImageInfo(void) 562 { 563 HRESULT hr; 564 D3DXIMAGE_INFO info; 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 596 hr = D3DXGetImageInfoFromFileA("", &info); 597 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA); 598 599 hr = D3DXGetImageInfoFromFileA(NULL, &info); 600 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); 601 602 hr = D3DXGetImageInfoFromFileA(NULL, NULL); 603 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); 604 605 606 /* D3DXGetImageInfoFromResource */ 607 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &info); /* RT_BITMAP */ 608 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK); 609 610 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), NULL); 611 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK); 612 613 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &info); /* RT_RCDATA */ 614 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK); 615 616 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDS_STRING), &info); 617 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA); 618 619 hr = D3DXGetImageInfoFromResourceA(NULL, MAKEINTRESOURCEA(IDS_STRING), NULL); 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 628 hr = D3DXGetImageInfoFromResourceA(NULL, NULL, NULL); 629 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA); 630 631 632 /* D3DXGetImageInfoFromFileInMemory */ 633 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp, sizeof(bmp_1bpp), &info); 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 639 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp, sizeof(bmp_1bpp), NULL); 640 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK); 641 642 hr = D3DXGetImageInfoFromFileInMemory(noimage, sizeof(noimage), NULL); 643 ok(hr == D3D_OK, "D3DXGetImageInfoFromResource returned %#x, expected %#x\n", hr, D3D_OK); 644 645 hr = D3DXGetImageInfoFromFileInMemory(noimage, sizeof(noimage), &info); 646 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA); 647 648 todo_wine { 649 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp, sizeof(bmp_1bpp)-1, &info); 650 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA); 651 } 652 653 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp+1, sizeof(bmp_1bpp)-1, &info); 654 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA); 655 656 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp, 0, &info); 657 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); 658 659 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp, 0, NULL); 660 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); 661 662 hr = D3DXGetImageInfoFromFileInMemory(noimage, 0, &info); 663 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); 664 665 hr = D3DXGetImageInfoFromFileInMemory(noimage, 0, NULL); 666 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); 667 668 hr = D3DXGetImageInfoFromFileInMemory(NULL, 0, &info); 669 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); 670 671 hr = D3DXGetImageInfoFromFileInMemory(NULL, 4, NULL); 672 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); 673 674 hr = D3DXGetImageInfoFromFileInMemory(NULL, 4, &info); 675 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); 676 677 hr = D3DXGetImageInfoFromFileInMemory(NULL, 0, NULL); 678 ok(hr == D3DERR_INVALIDCALL, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); 679 680 /* test BMP support */ 681 hr = D3DXGetImageInfoFromFileInMemory(bmp_1bpp, sizeof(bmp_1bpp), &info); 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); 685 hr = D3DXGetImageInfoFromFileInMemory(bmp_2bpp, sizeof(bmp_2bpp), &info); 686 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA); 687 hr = D3DXGetImageInfoFromFileInMemory(bmp_4bpp, sizeof(bmp_4bpp), &info); 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); 691 hr = D3DXGetImageInfoFromFileInMemory(bmp_8bpp, sizeof(bmp_8bpp), &info); 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 696 hr = D3DXGetImageInfoFromFileInMemory(bmp_32bpp_xrgb, sizeof(bmp_32bpp_xrgb), &info); 697 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); 698 ok(info.Format == D3DFMT_X8R8G8B8, "Got unexpected format %u.\n", info.Format); 699 hr = D3DXGetImageInfoFromFileInMemory(bmp_32bpp_argb, sizeof(bmp_32bpp_argb), &info); 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 */ 704 hr = D3DXGetImageInfoFromFileInMemory(png_grayscale, sizeof(png_grayscale), &info); 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 */ 710 hr = D3DXGetImageInfoFromFileInMemory(dds_24bit, sizeof(dds_24bit), &info); 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 722 hr = D3DXGetImageInfoFromFileInMemory(dds_16bit, sizeof(dds_16bit), &info); 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)); 735 hr = D3DXGetImageInfoFromFileInMemory(dds_8bit, sizeof(dds_8bit), &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 745 hr = D3DXGetImageInfoFromFileInMemory(dds_cube_map, sizeof(dds_cube_map), &info); 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 757 hr = D3DXGetImageInfoFromFileInMemory(dds_volume_map, sizeof(dds_volume_map), &info); 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 769 check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_DXT1, 0, 0, 0, 0, 0, D3DFMT_DXT1); 770 check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_DXT2, 0, 0, 0, 0, 0, D3DFMT_DXT2); 771 check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_DXT3, 0, 0, 0, 0, 0, D3DFMT_DXT3); 772 check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_DXT4, 0, 0, 0, 0, 0, D3DFMT_DXT4); 773 check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_DXT5, 0, 0, 0, 0, 0, D3DFMT_DXT5); 774 check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_R8G8_B8G8, 0, 0, 0, 0, 0, D3DFMT_R8G8_B8G8); 775 check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_G8R8_G8B8, 0, 0, 0, 0, 0, D3DFMT_G8R8_G8B8); 776 check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_UYVY, 0, 0, 0, 0, 0, D3DFMT_UYVY); 777 check_dds_pixel_format(DDS_PF_FOURCC, D3DFMT_YUY2, 0, 0, 0, 0, 0, D3DFMT_YUY2); 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); 782 check_dds_pixel_format(DDS_PF_ALPHA_ONLY, 0, 8, 0, 0, 0, 0xff, D3DFMT_A8); 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); 793 check_dds_pixel_format(DDS_PF_LUMINANCE, 0, 8, 0xff, 0, 0, 0, D3DFMT_L8); 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); 796 check_dds_pixel_format(DDS_PF_LUMINANCE | DDS_PF_ALPHA, 0, 8, 0x0f, 0, 0, 0xf0, D3DFMT_A4L4); 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 801 test_dds_header_handling(); 802 803 hr = D3DXGetImageInfoFromFileInMemory(dds_16bit, sizeof(dds_16bit) - 1, &info); 804 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA); 805 806 hr = D3DXGetImageInfoFromFileInMemory(dds_24bit, sizeof(dds_24bit) - 1, &info); 807 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA); 808 809 hr = D3DXGetImageInfoFromFileInMemory(dds_cube_map, sizeof(dds_cube_map) - 1, &info); 810 ok(hr == D3DXERR_INVALIDDATA, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA); 811 812 hr = D3DXGetImageInfoFromFileInMemory(dds_volume_map, sizeof(dds_volume_map) - 1, &info); 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) 822 static 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) 829 static 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 835 static 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 857 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf, NULL); 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 879 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0, NULL); 880 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); 881 882 hr = D3DXLoadSurfaceFromFileA(surf, NULL, NULL, "", NULL, D3DX_DEFAULT, 0, NULL); 883 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFile returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA); 884 885 886 /* D3DXLoadSurfaceFromResource */ 887 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, 888 MAKEINTRESOURCEA(IDB_BITMAP_1x1), NULL, D3DX_DEFAULT, 0, NULL); 889 ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK); 890 891 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, 892 MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), NULL, D3DX_DEFAULT, 0, NULL); 893 ok(hr == D3D_OK, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3D_OK); 894 895 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0, NULL); 896 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA); 897 898 hr = D3DXLoadSurfaceFromResourceA(NULL, NULL, NULL, NULL, 899 MAKEINTRESOURCEA(IDB_BITMAP_1x1), NULL, D3DX_DEFAULT, 0, NULL); 900 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); 901 902 hr = D3DXLoadSurfaceFromResourceA(surf, NULL, NULL, NULL, 903 MAKEINTRESOURCEA(IDS_STRING), NULL, D3DX_DEFAULT, 0, NULL); 904 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA); 905 906 907 /* D3DXLoadSurfaceFromFileInMemory */ 908 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp_1bpp, sizeof(bmp_1bpp), NULL, D3DX_DEFAULT, 0, NULL); 909 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK); 910 911 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, noimage, sizeof(noimage), NULL, D3DX_DEFAULT, 0, NULL); 912 ok(hr == D3DXERR_INVALIDDATA, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA); 913 914 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp_1bpp, 0, NULL, D3DX_DEFAULT, 0, NULL); 915 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); 916 917 hr = D3DXLoadSurfaceFromFileInMemory(NULL, NULL, NULL, bmp_1bpp, sizeof(bmp_1bpp), NULL, D3DX_DEFAULT, 0, NULL); 918 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); 919 920 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, NULL, 8, NULL, D3DX_DEFAULT, 0, NULL); 921 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); 922 923 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL); 924 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); 925 926 hr = D3DXLoadSurfaceFromFileInMemory(NULL, NULL, NULL, NULL, 0, NULL, D3DX_DEFAULT, 0, NULL); 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 933 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0); 934 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK); 935 936 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, 0, NULL, &rect, D3DX_FILTER_NONE, 0); 937 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK); 938 939 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, NULL, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0); 940 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); 941 942 hr = D3DXLoadSurfaceFromMemory(NULL, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0); 943 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); 944 945 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, NULL, D3DX_DEFAULT, 0); 946 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); 947 948 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata, D3DFMT_UNKNOWN, sizeof(pixdata), NULL, &rect, D3DX_DEFAULT, 0); 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 */ 952 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0); 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 */ 956 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0); 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 */ 960 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0); 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 */ 964 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0); 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 */ 969 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata, D3DFMT_A8R8G8B8, sizeof(pixdata), NULL, &rect, D3DX_FILTER_NONE, 0); 970 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); 971 972 973 /* D3DXLoadSurfaceFromSurface */ 974 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &newsurf, NULL); 975 if(SUCCEEDED(hr)) { 976 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0); 977 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK); 978 979 hr = D3DXLoadSurfaceFromSurface(NULL, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0); 980 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL); 981 982 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, 0); 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 988 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL); 989 if (SUCCEEDED(hr)) 990 { 991 IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf); 992 993 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_DEFAULT, 0); 994 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x\n", hr, D3D_OK); 995 996 IDirect3DSurface9_Release(newsurf); 997 IDirect3DTexture9_Release(tex); 998 } else skip("Failed to create texture\n"); 999 1000 /* non-lockable render target */ 1001 hr = IDirect3DDevice9_CreateRenderTarget(device, 256, 256, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, FALSE, &newsurf, NULL); 1002 ok(hr == D3D_OK, "Unexpected hr %#x.\n", hr); 1003 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0); 1004 ok(hr == D3D_OK, "Unexpected hr %#x.\n", hr); 1005 IDirect3DSurface9_Release(newsurf); 1006 1007 /* non-lockable multisampled render target */ 1008 hr = IDirect3DDevice9_CreateRenderTarget(device, 256, 256, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_2_SAMPLES, 0, FALSE, &newsurf, NULL); 1009 if (SUCCEEDED(hr)) 1010 { 1011 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0); 1012 ok(hr == D3D_OK, "Unexpected hr %#x.\n", hr); 1013 1014 IDirect3DSurface9_Release(newsurf); 1015 } 1016 else 1017 { 1018 skip("Failed to create multisampled render target.\n"); 1019 } 1020 1021 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &newsurf); 1022 ok(hr == D3D_OK, "IDirect3DDevice9_GetRenderTarget returned %#x, expected %#x.\n", hr, D3D_OK); 1023 1024 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0); 1025 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, D3D_OK); 1026 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0); 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); 1030 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_TRIANGLE | D3DX_FILTER_MIRROR, 0); 1031 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, D3D_OK); 1032 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_LINEAR, 0); 1033 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, D3D_OK); 1034 1035 /* rects */ 1036 SetRect(&rect, 2, 2, 1, 1); 1037 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, &rect, D3DX_FILTER_NONE, 0); 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); 1041 hr = D3DXLoadSurfaceFromSurface(surf, NULL, &rect, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0); 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); 1045 hr = D3DXLoadSurfaceFromSurface(surf, NULL, &rect, newsurf, NULL, NULL, D3DX_FILTER_POINT, 0); 1046 ok(hr == D3DERR_INVALIDCALL, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL); 1047 SetRect(&rect, 1, 1, 1, 1); 1048 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, &rect, D3DX_FILTER_NONE, 0); 1049 ok(hr == D3D_OK, "D3DXLoadSurfaceFromSurface returned %#x, expected %#x.\n", hr, D3D_OK); 1050 hr = D3DXLoadSurfaceFromSurface(surf, NULL, &rect, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0); 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. */ 1060 hr = D3DXLoadSurfaceFromSurface(surf, NULL, &rect, newsurf, NULL, NULL, D3DX_FILTER_POINT, 0); 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); 1067 hr = D3DXLoadSurfaceFromSurface(surf, NULL, &rect, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0); 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 1072 IDirect3DSurface9_Release(newsurf); 1073 1074 check_release((IUnknown*)surf, 0); 1075 1076 SetRect(&rect, 1, 1, 2, 2); 1077 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 1, 1, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf, NULL); 1078 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); 1079 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, 1080 D3DFMT_A8R8G8B8, 8, NULL, &rect, D3DX_FILTER_NONE, 0); 1081 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); 1082 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 1083 check_pixel_4bpp(&lockrect, 0, 0, 0x8dc32bf6); 1084 IDirect3DSurface9_UnlockRect(surf); 1085 check_release((IUnknown *)surf, 0); 1086 1087 /* test color conversion */ 1088 SetRect(&rect, 0, 0, 2, 2); 1089 /* A8R8G8B8 */ 1090 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surf, NULL); 1091 if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr); 1092 else { 1093 PALETTEENTRY palette; 1094 1095 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2, 1096 D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0); 1097 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK); 1098 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1103 IDirect3DSurface9_UnlockRect(surf); 1104 1105 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, 1106 D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0); 1107 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK); 1108 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1113 IDirect3DSurface9_UnlockRect(surf); 1114 1115 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, 1116 D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0); 1117 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK); 1118 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1123 IDirect3DSurface9_UnlockRect(surf); 1124 1125 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, 1126 D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0); 1127 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK); 1128 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1135 IDirect3DSurface9_UnlockRect(surf); 1136 1137 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, 1138 D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0); 1139 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); 1140 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1146 IDirect3DSurface9_UnlockRect(surf); 1147 1148 SetRect(&rect, 0, 0, 1, 1); 1149 SetRect(&destrect, 1, 1, 2, 2); 1150 hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata_a8b8g8r8, 1151 D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0); 1152 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); 1153 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1158 IDirect3DSurface9_UnlockRect(surf); 1159 1160 SetRect(&rect, 0, 0, 2, 2); 1161 1162 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, 1163 D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0); 1164 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); 1165 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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 } 1172 IDirect3DSurface9_UnlockRect(surf); 1173 1174 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8, 1175 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0); 1176 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr); 1177 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1183 hr = IDirect3DSurface9_UnlockRect(surf); 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 */ 1194 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, &bmp_1bpp[62], 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); 1197 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1201 hr = IDirect3DSurface9_UnlockRect(surf); 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) */ 1206 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, bmp_1bpp, sizeof(bmp_1bpp), NULL, D3DX_FILTER_NONE, 0, NULL); 1207 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK); 1208 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1211 hr = IDirect3DSurface9_UnlockRect(surf); 1212 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x\n", hr); 1213 1214 check_release((IUnknown*)surf, 0); 1215 } 1216 1217 /* A1R5G5B5 */ 1218 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_A1R5G5B5, D3DPOOL_DEFAULT, &surf, NULL); 1219 if(FAILED(hr)) skip("Failed to create a surface (%#x)\n", hr); 1220 else { 1221 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8r3g3b2, 1222 D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0); 1223 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK); 1224 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1229 IDirect3DSurface9_UnlockRect(surf); 1230 1231 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, 1232 D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0); 1233 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK); 1234 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1239 IDirect3DSurface9_UnlockRect(surf); 1240 1241 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, 1242 D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0); 1243 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK); 1244 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1249 IDirect3DSurface9_UnlockRect(surf); 1250 1251 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, 1252 D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0); 1253 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK); 1254 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1261 IDirect3DSurface9_UnlockRect(surf); 1262 1263 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, 1264 D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0); 1265 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK); 1266 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1273 IDirect3DSurface9_UnlockRect(surf); 1274 1275 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, 1276 D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0); 1277 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK); 1278 IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1285 IDirect3DSurface9_UnlockRect(surf); 1286 1287 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8, 1288 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0); 1289 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr); 1290 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1296 hr = IDirect3DSurface9_UnlockRect(surf); 1297 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr); 1298 1299 check_release((IUnknown*)surf, 0); 1300 } 1301 1302 /* A8L8 */ 1303 hr = IDirect3DDevice9_CreateTexture(device, 2, 2, 1, 0, D3DFMT_A8L8, D3DPOOL_MANAGED, &tex, NULL); 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, 1312 D3DFMT_A8R3G3B2, 4, NULL, &rect, D3DX_FILTER_NONE, 0); 1313 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr); 1314 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1320 hr = IDirect3DSurface9_UnlockRect(surf); 1321 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr); 1322 1323 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a1r5g5b5, 1324 D3DFMT_A1R5G5B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0); 1325 ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK); 1326 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1332 hr = IDirect3DSurface9_UnlockRect(surf); 1333 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr); 1334 1335 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_r5g6b5, 1336 D3DFMT_R5G6B5, 4, NULL, &rect, D3DX_FILTER_NONE, 0); 1337 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr); 1338 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1344 hr = IDirect3DSurface9_UnlockRect(surf); 1345 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr); 1346 1347 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_g16r16, 1348 D3DFMT_G16R16, 8, NULL, &rect, D3DX_FILTER_NONE, 0); 1349 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr); 1350 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1356 hr = IDirect3DSurface9_UnlockRect(surf); 1357 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr); 1358 1359 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, 1360 D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0); 1361 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr); 1362 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1368 hr = IDirect3DSurface9_UnlockRect(surf); 1369 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr); 1370 1371 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, 1372 D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0); 1373 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr); 1374 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1380 hr = IDirect3DSurface9_UnlockRect(surf); 1381 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr); 1382 1383 hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8l8, 1384 D3DFMT_A8L8, 4, NULL, &rect, D3DX_FILTER_NONE, 0); 1385 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr); 1386 hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY); 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); 1392 hr = IDirect3DSurface9_UnlockRect(surf); 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 */ 1400 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surf, NULL); 1401 if (FAILED(hr)) 1402 skip("Failed to create A8R8G8B8 surface, hr %#x.\n", hr); 1403 else 1404 { 1405 hr = D3DXLoadSurfaceFromFileInMemory(surf, NULL, NULL, dds_24bit, sizeof(dds_24bit), NULL, D3DX_FILTER_NONE, 0, NULL); 1406 ok(SUCCEEDED(hr), "Failed to load surface, hr %#x.\n", hr); 1407 1408 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_DXT2, D3DPOOL_SYSTEMMEM, &tex, NULL); 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); 1415 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0); 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 1421 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_DXT3, D3DPOOL_SYSTEMMEM, &tex, NULL); 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); 1428 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0); 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 1434 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_DXT4, D3DPOOL_SYSTEMMEM, &tex, NULL); 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); 1441 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0); 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 1447 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_DXT5, D3DPOOL_SYSTEMMEM, &tex, NULL); 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); 1454 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0); 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], 1461 D3DFMT_DXT5, 16, NULL, &rect, D3DX_FILTER_NONE, 0); 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. */ 1467 hr = IDirect3DDevice9_CreateTexture(device, 4, 8, 1, 0, D3DFMT_DXT5, D3DPOOL_SYSTEMMEM, &tex, NULL); 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], 1473 D3DFMT_DXT5, 16, NULL, &rect, D3DX_FILTER_POINT, 0); 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. */ 1480 hr = IDirect3DDevice9_CreateTexture(device, 8, 8, 1, 0, D3DFMT_DXT5, D3DPOOL_SYSTEMMEM, &tex, NULL); 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); 1486 hr = D3DXLoadSurfaceFromMemory(newsurf, NULL, NULL, &dds_dxt5_8_8[128], 1487 D3DFMT_DXT5, 16 * 2, NULL, &rect, D3DX_FILTER_POINT, 0); 1488 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); 1489 1490 hr = D3DXLoadSurfaceFromMemory(newsurf, NULL, &rect, &dds_dxt5_8_8[128], 1491 D3DFMT_DXT5, 16 * 2, NULL, NULL, D3DX_FILTER_POINT, 0); 1492 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr); 1493 1494 hr = D3DXLoadSurfaceFromMemory(newsurf, NULL, &rect, &dds_dxt5_8_8[128], 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 1502 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_DXT1, D3DPOOL_SYSTEMMEM, &tex, NULL); 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); 1509 hr = D3DXLoadSurfaceFromSurface(newsurf, NULL, NULL, surf, NULL, NULL, D3DX_FILTER_NONE, 0); 1510 ok(SUCCEEDED(hr), "Failed to convert pixels to DXT1 format.\n"); 1511 1512 hr = D3DXLoadSurfaceFromSurface(surf, NULL, NULL, newsurf, NULL, NULL, D3DX_FILTER_NONE, 0); 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 1527 static 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}, 1538 {D3DUSAGE_RENDERTARGET, 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; 1549 ID3DXBuffer *buffer; 1550 unsigned int i; 1551 HRESULT hr; 1552 RECT rect; 1553 1554 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &surface, NULL); 1555 if (FAILED(hr)) { 1556 skip("Couldn't create surface\n"); 1557 return; 1558 } 1559 1560 SetRectEmpty(&rect); 1561 hr = D3DXSaveSurfaceToFileInMemory(&buffer, D3DXIFF_BMP, surface, NULL, &rect); 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)) { 1565 DWORD size = ID3DXBuffer_GetBufferSize(buffer); 1566 ok(size > 0, "ID3DXBuffer_GetBufferSize returned %u, expected > 0\n", size); 1567 ID3DXBuffer_Release(buffer); 1568 } 1569 1570 SetRectEmpty(&rect); 1571 hr = D3DXSaveSurfaceToFileInMemory(&buffer, D3DXIFF_DDS, surface, NULL, &rect); 1572 todo_wine ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); 1573 if (SUCCEEDED(hr)) 1574 { 1575 dds = ID3DXBuffer_GetBufferPointer(buffer); 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); 1587 ID3DXBuffer_Release(buffer); 1588 } 1589 1590 hr = D3DXSaveSurfaceToFileInMemory(&buffer, D3DXIFF_DDS, surface, NULL, NULL); 1591 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); 1592 1593 dds = ID3DXBuffer_GetBufferPointer(buffer); 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); 1604 ID3DXBuffer_Release(buffer); 1605 1606 IDirect3DSurface9_Release(surface); 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 1614 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface); 1615 ok(hr == D3D_OK, "Unexpected hr %#x, i %u.\n", hr, i); 1616 1617 hr = D3DXSaveSurfaceToFileInMemory(&buffer, D3DXIFF_DDS, surface, NULL, NULL); 1618 ok(hr == D3D_OK, "Unexpected hr %#x, i %u.\n", hr, i); 1619 ID3DXBuffer_Release(buffer); 1620 1621 hr = D3DXSaveSurfaceToFileInMemory(&buffer, D3DXIFF_BMP, surface, NULL, NULL); 1622 ok(hr == D3D_OK, "Unexpected hr %#x, i %u.\n", hr, i); 1623 ID3DXBuffer_Release(buffer); 1624 1625 IDirect3DSurface9_Release(surface); 1626 IDirect3DTexture9_Release(texture); 1627 } 1628 } 1629 1630 static 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 1642 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_R8G8B8, D3DPOOL_SCRATCH, &surface, NULL); 1643 if (FAILED(hr)) 1644 { 1645 skip("Couldn't create surface.\n"); 1646 return; 1647 } 1648 1649 SetRect(&rect, 0, 0, 2, 2); 1650 hr = D3DXLoadSurfaceFromMemory(surface, NULL, NULL, pixels, D3DFMT_R8G8B8, 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 1674 IDirect3DSurface9_UnlockRect(surface); 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"); 1690 IDirect3DSurface9_UnlockRect(surface); 1691 1692 SetRect(&rect, 0, 0, 2, 2); 1693 hr = D3DXLoadSurfaceFromMemory(surface, NULL, NULL, pixels, D3DFMT_R8G8B8, 1694 pitch, NULL, &rect, D3DX_FILTER_NONE, 0); 1695 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); 1696 1697 hr = D3DXSaveSurfaceToFileA(NULL, D3DXIFF_BMP, surface, NULL, NULL); 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"); 1726 IDirect3DSurface9_UnlockRect(surface); 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); 1743 SetRectEmpty(&rect); 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 1753 IDirect3DSurface9_Release(surface); 1754 } 1755 1756 START_TEST(surface) 1757 { 1758 HWND wnd; 1759 IDirect3D9 *d3d; 1760 IDirect3DDevice9 *device; 1761 D3DPRESENT_PARAMETERS d3dpp; 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 } 1770 d3d = Direct3DCreate9(D3D_SDK_VERSION); 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; 1779 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; 1780 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device); 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 1788 test_D3DXGetImageInfo(); 1789 test_D3DXLoadSurface(device); 1790 test_D3DXSaveSurfaceToFileInMemory(device); 1791 test_D3DXSaveSurfaceToFile(device); 1792 1793 check_release((IUnknown*)device, 0); 1794 check_release((IUnknown*)d3d, 0); 1795 DestroyWindow(wnd); 1796 } 1797