2 * Copyright 2012 Dmitry Timoshkov
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define WIN32_NO_STATUS
24 #define COM_NO_WINDOWS_H
32 #include <wine/test.h>
38 #define IFD_RATIONAL 5
40 #define IFD_UNDEFINED 7
43 #define IFD_SRATIONAL 10
62 static const struct tiff_1bpp_data
67 USHORT number_of_entries
;
68 struct IFD_entry entry
[13];
70 struct IFD_rational res
;
74 #ifdef WORDS_BIGENDIAN
80 FIELD_OFFSET(struct tiff_1bpp_data
, number_of_entries
),
83 { 0xff, IFD_SHORT
, 1, 0 }, /* SUBFILETYPE */
84 { 0x100, IFD_LONG
, 1, 1 }, /* IMAGEWIDTH */
85 { 0x101, IFD_LONG
, 1, 1 }, /* IMAGELENGTH */
86 { 0x102, IFD_SHORT
, 1, 1 }, /* BITSPERSAMPLE */
87 { 0x103, IFD_SHORT
, 1, 1 }, /* COMPRESSION: XP doesn't accept IFD_LONG here */
88 { 0x106, IFD_SHORT
, 1, 1 }, /* PHOTOMETRIC */
89 { 0x111, IFD_LONG
, 1, FIELD_OFFSET(struct tiff_1bpp_data
, pixel_data
) }, /* STRIPOFFSETS */
90 { 0x115, IFD_SHORT
, 1, 1 }, /* SAMPLESPERPIXEL */
91 { 0x116, IFD_LONG
, 1, 1 }, /* ROWSPERSTRIP */
92 { 0x117, IFD_LONG
, 1, 1 }, /* STRIPBYTECOUNT */
93 { 0x11a, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_1bpp_data
, res
) },
94 { 0x11b, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_1bpp_data
, res
) },
95 { 0x128, IFD_SHORT
, 1, 2 }, /* RESOLUTIONUNIT */
99 { 0x11, 0x22, 0x33, 0 }
102 static const struct tiff_8bpp_alpha
107 USHORT number_of_entries
;
108 struct IFD_entry entry
[15];
110 struct IFD_rational res
;
114 #ifdef WORDS_BIGENDIAN
120 FIELD_OFFSET(struct tiff_8bpp_alpha
, number_of_entries
),
123 { 0xff, IFD_SHORT
, 1, 0 }, /* SUBFILETYPE */
124 { 0x100, IFD_LONG
, 1, 2 }, /* IMAGEWIDTH */
125 { 0x101, IFD_LONG
, 1, 2 }, /* IMAGELENGTH */
126 { 0x102, IFD_SHORT
, 2, MAKELONG(8, 8) }, /* BITSPERSAMPLE */
127 { 0x103, IFD_SHORT
, 1, 1 }, /* COMPRESSION: XP doesn't accept IFD_LONG here */
128 { 0x106, IFD_SHORT
, 1, 1 }, /* PHOTOMETRIC */
129 { 0x111, IFD_LONG
, 1, FIELD_OFFSET(struct tiff_8bpp_alpha
, pixel_data
) }, /* STRIPOFFSETS */
130 { 0x115, IFD_SHORT
, 1, 2 }, /* SAMPLESPERPIXEL */
131 { 0x116, IFD_LONG
, 1, 2 }, /* ROWSPERSTRIP */
132 { 0x117, IFD_LONG
, 1, 8 }, /* STRIPBYTECOUNT */
133 { 0x11a, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_8bpp_alpha
, res
) },
134 { 0x11b, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_8bpp_alpha
, res
) },
135 { 0x11c, IFD_SHORT
, 1, 1 }, /* PLANARCONFIGURATION */
136 { 0x128, IFD_SHORT
, 1, 2 }, /* RESOLUTIONUNIT */
137 { 0x152, IFD_SHORT
, 1, 1 } /* EXTRASAMPLES: 1 - Associated alpha with pre-multiplied color */
141 { 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88 }
145 static IWICImagingFactory
*factory
;
147 static IStream
*create_stream(const void *data
, int data_size
)
154 hdata
= GlobalAlloc(GMEM_MOVEABLE
, data_size
);
155 ok(hdata
!= 0, "GlobalAlloc failed\n");
156 if (!hdata
) return NULL
;
158 locked_data
= GlobalLock(hdata
);
159 memcpy(locked_data
, data
, data_size
);
162 hr
= CreateStreamOnHGlobal(hdata
, TRUE
, &stream
);
163 ok(hr
== S_OK
, "CreateStreamOnHGlobal failed, hr=%x\n", hr
);
168 static IWICBitmapDecoder
*create_decoder(const void *image_data
, UINT image_size
)
172 IWICBitmapDecoder
*decoder
= NULL
;
175 stream
= create_stream(image_data
, image_size
);
177 hr
= IWICImagingFactory_CreateDecoderFromStream(factory
, stream
, NULL
, 0, &decoder
);
178 ok(hr
== S_OK
, "CreateDecoderFromStream error %#x\n", hr
);
180 hr
= IWICBitmapDecoder_GetContainerFormat(decoder
, &guid
);
181 ok(hr
== S_OK
, "GetContainerFormat error %#x\n", hr
);
182 ok(IsEqualGUID(&guid
, &GUID_ContainerFormatTiff
), "container format is not TIFF\n");
184 IStream_Release(stream
);
189 static void test_tiff_palette(void)
192 IWICBitmapDecoder
*decoder
;
193 IWICBitmapFrameDecode
*frame
;
194 IWICPalette
*palette
;
197 decoder
= create_decoder(&tiff_1bpp_data
, sizeof(tiff_1bpp_data
));
198 ok(decoder
!= 0, "Failed to load TIFF image data\n");
200 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
201 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
203 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &format
);
204 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
205 ok(IsEqualGUID(&format
, &GUID_WICPixelFormatBlackWhite
),
206 "got wrong format %s\n", wine_dbgstr_guid(&format
));
208 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
209 ok(hr
== S_OK
, "CreatePalette error %#x\n", hr
);
210 hr
= IWICBitmapFrameDecode_CopyPalette(frame
, palette
);
211 ok(hr
== WINCODEC_ERR_PALETTEUNAVAILABLE
,
212 "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %#x\n", hr
);
214 IWICPalette_Release(palette
);
215 IWICBitmapFrameDecode_Release(frame
);
216 IWICBitmapDecoder_Release(decoder
);
219 static void test_QueryCapability(void)
223 IWICBitmapDecoder
*decoder
;
224 IWICBitmapFrameDecode
*frame
;
225 static const DWORD exp_caps
= WICBitmapDecoderCapabilityCanDecodeAllImages
|
226 WICBitmapDecoderCapabilityCanDecodeSomeImages
|
227 WICBitmapDecoderCapabilityCanEnumerateMetadata
;
228 static const DWORD exp_caps_xp
= WICBitmapDecoderCapabilityCanDecodeAllImages
|
229 WICBitmapDecoderCapabilityCanDecodeSomeImages
;
232 ULARGE_INTEGER cur_pos
;
235 stream
= create_stream(&tiff_1bpp_data
, sizeof(tiff_1bpp_data
));
238 hr
= IWICImagingFactory_CreateDecoder(factory
, &GUID_ContainerFormatTiff
, NULL
, &decoder
);
239 ok(hr
== S_OK
, "CreateDecoder error %#x\n", hr
);
241 frame_count
= 0xdeadbeef;
242 hr
= IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
243 ok(hr
== S_OK
|| broken(hr
== E_POINTER
) /* XP */, "GetFrameCount error %#x\n", hr
);
244 ok(frame_count
== 0, "expected 0, got %u\n", frame_count
);
246 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
247 ok(hr
== WINCODEC_ERR_FRAMEMISSING
|| broken(hr
== E_POINTER
) /* XP */, "expected WINCODEC_ERR_FRAMEMISSING, got %#x\n", hr
);
250 hr
= IStream_Seek(stream
, pos
, SEEK_SET
, NULL
);
251 ok(hr
== S_OK
, "IStream_Seek error %#x\n", hr
);
253 capability
= 0xdeadbeef;
254 hr
= IWICBitmapDecoder_QueryCapability(decoder
, stream
, &capability
);
255 ok(hr
== S_OK
, "QueryCapability error %#x\n", hr
);
256 ok(capability
== exp_caps
|| capability
== exp_caps_xp
,
257 "expected %#x, got %#x\n", exp_caps
, capability
);
259 frame_count
= 0xdeadbeef;
260 hr
= IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
261 ok(hr
== S_OK
, "GetFrameCount error %#x\n", hr
);
262 ok(frame_count
== 1, "expected 1, got %u\n", frame_count
);
264 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
265 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
266 IWICBitmapFrameDecode_Release(frame
);
269 hr
= IStream_Seek(stream
, pos
, SEEK_CUR
, &cur_pos
);
270 ok(hr
== S_OK
, "IStream_Seek error %#x\n", hr
);
271 ok(cur_pos
.QuadPart
> 4 && cur_pos
.QuadPart
< sizeof(tiff_1bpp_data
),
272 "current stream pos is at %x/%x\n", cur_pos
.u
.LowPart
, cur_pos
.u
.HighPart
);
274 hr
= IWICBitmapDecoder_QueryCapability(decoder
, stream
, &capability
);
275 ok(hr
== WINCODEC_ERR_WRONGSTATE
, "expected WINCODEC_ERR_WRONGSTATE, got %#x\n", hr
);
277 hr
= IWICBitmapDecoder_Initialize(decoder
, stream
, WICDecodeMetadataCacheOnDemand
);
278 ok(hr
== WINCODEC_ERR_WRONGSTATE
, "expected WINCODEC_ERR_WRONGSTATE, got %#x\n", hr
);
280 IWICBitmapDecoder_Release(decoder
);
282 hr
= IWICImagingFactory_CreateDecoderFromStream(factory
, stream
, NULL
, 0, &decoder
);
284 ok(hr
== WINCODEC_ERR_COMPONENTNOTFOUND
, "expected WINCODEC_ERR_COMPONENTNOTFOUND, got %#x\n", hr
);
287 IWICBitmapDecoder_Release(decoder
);
290 hr
= IStream_Seek(stream
, pos
, SEEK_SET
, NULL
);
291 ok(hr
== S_OK
, "IStream_Seek error %#x\n", hr
);
293 hr
= IWICImagingFactory_CreateDecoderFromStream(factory
, stream
, NULL
, 0, &decoder
);
294 ok(hr
== S_OK
, "CreateDecoderFromStream error %#x\n", hr
);
296 frame_count
= 0xdeadbeef;
297 hr
= IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
298 ok(hr
== S_OK
, "GetFrameCount error %#x\n", hr
);
299 ok(frame_count
== 1, "expected 1, got %u\n", frame_count
);
301 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
302 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
303 IWICBitmapFrameDecode_Release(frame
);
305 hr
= IWICBitmapDecoder_Initialize(decoder
, stream
, WICDecodeMetadataCacheOnDemand
);
306 ok(hr
== WINCODEC_ERR_WRONGSTATE
, "expected WINCODEC_ERR_WRONGSTATE, got %#x\n", hr
);
308 hr
= IWICBitmapDecoder_QueryCapability(decoder
, stream
, &capability
);
309 ok(hr
== WINCODEC_ERR_WRONGSTATE
, "expected WINCODEC_ERR_WRONGSTATE, got %#x\n", hr
);
311 IWICBitmapDecoder_Release(decoder
);
312 IStream_Release(stream
);
315 static void test_tiff_8bpp_alpha(void)
318 IWICBitmapDecoder
*decoder
;
319 IWICBitmapFrameDecode
*frame
;
320 UINT frame_count
, width
, height
, i
;
322 IWICPalette
*palette
;
326 static const BYTE expected_data
[16] = { 0x11,0x11,0x11,0x22,0x33,0x33,0x33,0x44,
327 0x55,0x55,0x55,0x66,0x77,0x77,0x77,0x88 };
329 decoder
= create_decoder(&tiff_8bpp_alpha
, sizeof(tiff_8bpp_alpha
));
330 ok(decoder
!= 0, "Failed to load TIFF image data\n");
332 hr
= IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
333 ok(hr
== S_OK
, "GetFrameCount error %#x\n", hr
);
334 ok(frame_count
== 1, "expected 1, got %u\n", frame_count
);
336 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
337 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
339 hr
= IWICBitmapFrameDecode_GetSize(frame
, &width
, &height
);
340 ok(hr
== S_OK
, "GetSize error %#x\n", hr
);
341 ok(width
== 2, "expected 2, got %u\n", width
);
342 ok(height
== 2, "expected 2, got %u\n", height
);
344 hr
= IWICBitmapFrameDecode_GetResolution(frame
, &dpi_x
, &dpi_y
);
345 ok(hr
== S_OK
, "GetResolution error %#x\n", hr
);
346 ok(dpi_x
== 96.0, "expected 96.0, got %f\n", dpi_x
);
347 ok(dpi_y
== 96.0, "expected 96.0, got %f\n", dpi_y
);
349 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &format
);
350 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
351 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat32bppPBGRA
),
352 "got wrong format %s\n", wine_dbgstr_guid(&format
));
354 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
355 ok(hr
== S_OK
, "CreatePalette error %#x\n", hr
);
356 hr
= IWICBitmapFrameDecode_CopyPalette(frame
, palette
);
357 ok(hr
== WINCODEC_ERR_PALETTEUNAVAILABLE
,
358 "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %#x\n", hr
);
359 IWICPalette_Release(palette
);
365 hr
= IWICBitmapFrameDecode_CopyPixels(frame
, &rc
, 8, sizeof(data
), data
);
366 ok(hr
== S_OK
, "CopyPixels error %#x\n", hr
);
368 for (i
= 0; i
< sizeof(data
); i
++)
369 ok(data
[i
] == expected_data
[i
], "%u: expected %02x, got %02x\n", i
, expected_data
[i
], data
[i
]);
371 IWICBitmapFrameDecode_Release(frame
);
372 IWICBitmapDecoder_Release(decoder
);
375 START_TEST(tiffformat
)
379 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
381 hr
= CoCreateInstance(&CLSID_WICImagingFactory
, NULL
, CLSCTX_INPROC_SERVER
,
382 &IID_IWICImagingFactory
, (void **)&factory
);
383 ok(hr
== S_OK
, "CoCreateInstance error %#x\n", hr
);
384 if (FAILED(hr
)) return;
387 test_QueryCapability();
388 test_tiff_8bpp_alpha();
390 IWICImagingFactory_Release(factory
);