2 * Copyright 2012,2016 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
27 #include "wine/test.h"
29 #define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
30 static void _expect_ref(IUnknown
* obj
, ULONG ref
, int line
)
34 rc
= IUnknown_Release(obj
);
35 ok_(__FILE__
,line
)(rc
== ref
, "expected refcount %d, got %d\n", ref
, rc
);
42 #define IFD_RATIONAL 5
44 #define IFD_UNDEFINED 7
47 #define IFD_SRATIONAL 10
66 static const struct tiff_1bpp_data
71 USHORT number_of_entries
;
72 struct IFD_entry entry
[13];
74 struct IFD_rational res
;
78 #ifdef WORDS_BIGENDIAN
84 FIELD_OFFSET(struct tiff_1bpp_data
, number_of_entries
),
87 { 0xff, IFD_SHORT
, 1, 0 }, /* SUBFILETYPE */
88 { 0x100, IFD_LONG
, 1, 1 }, /* IMAGEWIDTH */
89 { 0x101, IFD_LONG
, 1, 1 }, /* IMAGELENGTH */
90 { 0x102, IFD_SHORT
, 1, 1 }, /* BITSPERSAMPLE */
91 { 0x103, IFD_SHORT
, 1, 1 }, /* COMPRESSION: XP doesn't accept IFD_LONG here */
92 { 0x106, IFD_SHORT
, 1, 1 }, /* PHOTOMETRIC */
93 { 0x111, IFD_LONG
, 1, FIELD_OFFSET(struct tiff_1bpp_data
, pixel_data
) }, /* STRIPOFFSETS */
94 { 0x115, IFD_SHORT
, 1, 1 }, /* SAMPLESPERPIXEL */
95 { 0x116, IFD_LONG
, 1, 1 }, /* ROWSPERSTRIP */
96 { 0x117, IFD_LONG
, 1, 1 }, /* STRIPBYTECOUNT */
97 { 0x11a, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_1bpp_data
, res
) }, /* XRESOLUTION */
98 { 0x11b, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_1bpp_data
, res
) }, /* YRESOLUTION */
99 { 0x128, IFD_SHORT
, 1, 2 }, /* RESOLUTIONUNIT */
103 { 0x11, 0x22, 0x33, 0 }
106 static const struct tiff_8bpp_alpha
111 USHORT number_of_entries
;
112 struct IFD_entry entry
[15];
114 struct IFD_rational res
;
118 #ifdef WORDS_BIGENDIAN
124 FIELD_OFFSET(struct tiff_8bpp_alpha
, number_of_entries
),
127 { 0xff, IFD_SHORT
, 1, 0 }, /* SUBFILETYPE */
128 { 0x100, IFD_LONG
, 1, 2 }, /* IMAGEWIDTH */
129 { 0x101, IFD_LONG
, 1, 2 }, /* IMAGELENGTH */
130 { 0x102, IFD_SHORT
, 2, MAKELONG(8, 8) }, /* BITSPERSAMPLE */
131 { 0x103, IFD_SHORT
, 1, 1 }, /* COMPRESSION: XP doesn't accept IFD_LONG here */
132 { 0x106, IFD_SHORT
, 1, 1 }, /* PHOTOMETRIC */
133 { 0x111, IFD_LONG
, 1, FIELD_OFFSET(struct tiff_8bpp_alpha
, pixel_data
) }, /* STRIPOFFSETS */
134 { 0x115, IFD_SHORT
, 1, 2 }, /* SAMPLESPERPIXEL */
135 { 0x116, IFD_LONG
, 1, 2 }, /* ROWSPERSTRIP */
136 { 0x117, IFD_LONG
, 1, 8 }, /* STRIPBYTECOUNT */
137 { 0x11a, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_8bpp_alpha
, res
) }, /* XRESOLUTION */
138 { 0x11b, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_8bpp_alpha
, res
) }, /* YRESOLUTION */
139 { 0x11c, IFD_SHORT
, 1, 1 }, /* PLANARCONFIGURATION */
140 { 0x128, IFD_SHORT
, 1, 2 }, /* RESOLUTIONUNIT */
141 { 0x152, IFD_SHORT
, 1, 1 } /* EXTRASAMPLES: 1 - Associated alpha with pre-multiplied color */
145 { 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88 }
148 static const struct tiff_8bpp_data
153 USHORT number_of_entries
;
154 struct IFD_entry entry
[14];
156 struct IFD_rational res
;
157 short palette_data
[3][256];
161 #ifdef WORDS_BIGENDIAN
167 FIELD_OFFSET(struct tiff_8bpp_data
, number_of_entries
),
170 { 0xff, IFD_SHORT
, 1, 0 }, /* SUBFILETYPE */
171 { 0x100, IFD_LONG
, 1, 4 }, /* IMAGEWIDTH */
172 { 0x101, IFD_LONG
, 1, 1 }, /* IMAGELENGTH */
173 { 0x102, IFD_SHORT
, 1, 8 }, /* BITSPERSAMPLE: XP doesn't accept IFD_LONG here */
174 { 0x103, IFD_SHORT
, 1, 1 }, /* COMPRESSION: XP doesn't accept IFD_LONG here */
175 { 0x106, IFD_SHORT
, 1, 3 }, /* PHOTOMETRIC */
176 { 0x111, IFD_LONG
, 1, FIELD_OFFSET(struct tiff_8bpp_data
, pixel_data
) }, /* STRIPOFFSETS */
177 { 0x115, IFD_SHORT
, 1, 1 }, /* SAMPLESPERPIXEL */
178 { 0x116, IFD_LONG
, 1, 1 }, /* ROWSPERSTRIP */
179 { 0x117, IFD_LONG
, 1, 1 }, /* STRIPBYTECOUNT */
180 { 0x11a, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_8bpp_data
, res
) },
181 { 0x11b, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_8bpp_data
, res
) },
182 { 0x128, IFD_SHORT
, 1, 2 }, /* RESOLUTIONUNIT */
183 { 0x140, IFD_SHORT
, 256*3, FIELD_OFFSET(struct tiff_8bpp_data
, palette_data
) } /* COLORMAP */
191 static const struct tiff_resolution_test_data
193 struct IFD_rational resx
;
194 struct IFD_rational resy
;
195 LONG resolution_unit
;
196 double expected_dpi_x
;
197 double expected_dpi_y
;
198 /* if != 0: values for different behavior of some Windows versions */
201 } tiff_resolution_test_data
[] =
203 { { 100, 1 }, { 50, 1 }, 0, 100.0, 50.0, 0, 0 }, /* invalid resolution unit */
204 { { 50, 1 }, { 100, 1 }, 0, 50.0, 100.0, 0, 0 },
206 { { 100, 1 }, { 50, 1 }, 1, 100.0, 50.0, 0, 0 }, /* RESUNIT_NONE */
207 { { 50, 1 }, { 100, 1 }, 1, 50.0, 100.0, 0, 0 },
209 { { 49, 1 }, { 49, 1 }, 2, 49.0, 49.0, 0, 0 }, /* same resolution for both X and Y */
210 { { 33, 1 }, { 55, 1 }, 2, 33.0, 55.0, 0, 0 }, /* different resolutions for X and Y */
211 { { 50, 2 }, { 66, 3 }, 2, 25.0, 22.0, 0, 0 }, /* denominator != 1 */
213 { { 100, 1 }, { 200, 1 }, 3, 254.0, 508.0, 0, 0 }, /* unit = centimeters */
215 /* XP and Server 2003 do not discard both resolution values if only one of them is invalid */
216 { { 0, 1 }, { 29, 1 }, 2, 96.0, 96.0, 0, 29.0 }, /* resolution 0 */
217 { { 58, 1 }, { 29, 0 }, 2, 96.0, 96.0, 58.0, 0 }, /* denominator 0 (division by zero) */
219 /* XP and Server 2003 return 96 dots per centimeter (= 243.84 dpi) as fallback value */
220 { { 0, 1 }, { 100, 1 }, 3, 96.0, 96.0, 243.84, 254.0 }, /* resolution 0 and unit = centimeters */
221 { { 50, 1 }, { 72, 0 }, 3, 96.0, 96.0, 127.0, 243.84 } /* denominator 0 and unit = centimeters */
224 static struct tiff_resolution_image_data
229 USHORT number_of_entries
;
230 struct IFD_entry entry
[13];
232 struct IFD_rational resx
;
233 struct IFD_rational resy
;
235 } tiff_resolution_image_data
=
237 #ifdef WORDS_BIGENDIAN
243 FIELD_OFFSET(struct tiff_resolution_image_data
, number_of_entries
),
246 { 0xff, IFD_SHORT
, 1, 0 }, /* SUBFILETYPE */
247 { 0x100, IFD_LONG
, 1, 1 }, /* IMAGEWIDTH */
248 { 0x101, IFD_LONG
, 1, 1 }, /* IMAGELENGTH */
249 { 0x102, IFD_SHORT
, 1, 1 }, /* BITSPERSAMPLE */
250 { 0x103, IFD_SHORT
, 1, 1 }, /* COMPRESSION: XP doesn't accept IFD_LONG here */
251 { 0x106, IFD_SHORT
, 1, 1 }, /* PHOTOMETRIC */
252 { 0x111, IFD_LONG
, 1, FIELD_OFFSET(struct tiff_resolution_image_data
, pixel_data
) }, /* STRIPOFFSETS */
253 { 0x115, IFD_SHORT
, 1, 1 }, /* SAMPLESPERPIXEL */
254 { 0x116, IFD_LONG
, 1, 1 }, /* ROWSPERSTRIP */
255 { 0x117, IFD_LONG
, 1, 1 }, /* STRIPBYTECOUNT */
256 { 0x11a, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_resolution_image_data
, resx
) }, /* XRESOLUTION */
257 { 0x11b, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_resolution_image_data
, resy
) }, /* YRESOLUTION */
258 { 0x128, IFD_SHORT
, 1, 1 }, /* RESOLUTIONUNIT -- value will be filled with test data */
261 { 72, 1 }, /* value will be filled with test data */
262 { 72, 1 }, /* value will be filled with test data */
263 { 0x11, 0x22, 0x33, 0 }
266 static const struct tiff_24bpp_data
271 USHORT number_of_entries
;
272 struct IFD_entry entry
[13];
274 struct IFD_rational res
;
278 #ifdef WORDS_BIGENDIAN
284 FIELD_OFFSET(struct tiff_1bpp_data
, number_of_entries
),
287 { 0xff, IFD_SHORT
, 1, 0 }, /* SUBFILETYPE */
288 { 0x100, IFD_LONG
, 1, 1 }, /* IMAGEWIDTH */
289 { 0x101, IFD_LONG
, 1, 1 }, /* IMAGELENGTH */
290 { 0x102, IFD_SHORT
, 1, 8 }, /* BITSPERSAMPLE */
291 { 0x103, IFD_SHORT
, 1, 1 }, /* COMPRESSION: XP doesn't accept IFD_LONG here */
292 { 0x106, IFD_SHORT
, 1, 2 }, /* PHOTOMETRIC */
293 { 0x111, IFD_LONG
, 1, FIELD_OFFSET(struct tiff_24bpp_data
, pixel_data
) }, /* STRIPOFFSETS */
294 { 0x115, IFD_SHORT
, 1, 3 }, /* SAMPLESPERPIXEL */
295 { 0x116, IFD_LONG
, 1, 1 }, /* ROWSPERSTRIP */
296 { 0x117, IFD_LONG
, 1, 3 }, /* STRIPBYTECOUNT */
297 { 0x11a, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_24bpp_data
, res
) }, /* XRESOLUTION */
298 { 0x11b, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_24bpp_data
, res
) }, /* YRESOLUTION */
299 { 0x128, IFD_SHORT
, 1, 2 }, /* RESOLUTIONUNIT */
306 static const struct tiff_4bps_bgra
311 USHORT number_of_entries
;
312 struct IFD_entry entry
[14];
314 struct IFD_rational res
;
318 #ifdef WORDS_BIGENDIAN
324 FIELD_OFFSET(struct tiff_4bps_bgra
, number_of_entries
),
327 { 0xff, IFD_SHORT
, 1, 0 }, /* SUBFILETYPE */
328 { 0x100, IFD_LONG
, 1, 3 }, /* IMAGEWIDTH */
329 { 0x101, IFD_LONG
, 1, 2 }, /* IMAGELENGTH */
330 { 0x102, IFD_SHORT
, 1, 1 }, /* BITSPERSAMPLE */
331 { 0x103, IFD_SHORT
, 1, 1 }, /* COMPRESSION */
332 { 0x106, IFD_SHORT
, 1, 2 }, /* PHOTOMETRIC */
333 { 0x111, IFD_LONG
, 1, FIELD_OFFSET(struct tiff_4bps_bgra
, pixel_data
) }, /* STRIPOFFSETS */
334 { 0x115, IFD_SHORT
, 1, 4 }, /* SAMPLESPERPIXEL */
335 { 0x116, IFD_LONG
, 1, 2 }, /* ROWSPERSTRIP */
336 { 0x117, IFD_LONG
, 1, 4 }, /* STRIPBYTECOUNT */
337 { 0x11a, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_4bps_bgra
, res
) }, /* XRESOLUTION */
338 { 0x11b, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_4bps_bgra
, res
) }, /* YRESOLUTION */
339 { 0x11c, IFD_SHORT
, 1, 1 }, /* PLANARCONFIGURATION */
340 { 0x128, IFD_SHORT
, 1, 2 } /* RESOLUTIONUNIT */
344 { 0x12,0x30, 0x47,0xe0 }
348 static IWICImagingFactory
*factory
;
350 static IStream
*create_stream(const void *data
, int data_size
)
357 hdata
= GlobalAlloc(GMEM_MOVEABLE
, data_size
);
358 ok(hdata
!= 0, "GlobalAlloc failed\n");
359 if (!hdata
) return NULL
;
361 locked_data
= GlobalLock(hdata
);
362 memcpy(locked_data
, data
, data_size
);
365 hr
= CreateStreamOnHGlobal(hdata
, TRUE
, &stream
);
366 ok(hr
== S_OK
, "CreateStreamOnHGlobal failed, hr=%x\n", hr
);
371 static HRESULT
create_decoder(const void *image_data
, UINT image_size
, IWICBitmapDecoder
**decoder
)
382 hmem
= GlobalAlloc(0, image_size
);
383 data
= GlobalLock(hmem
);
384 memcpy(data
, image_data
, image_size
);
387 hr
= CreateStreamOnHGlobal(hmem
, TRUE
, &stream
);
388 ok(hr
== S_OK
, "CreateStreamOnHGlobal error %#x\n", hr
);
390 hr
= IWICImagingFactory_CreateDecoderFromStream(factory
, stream
, NULL
, 0, decoder
);
393 hr
= IWICBitmapDecoder_GetContainerFormat(*decoder
, &format
);
394 ok(hr
== S_OK
, "GetContainerFormat error %#x\n", hr
);
395 ok(IsEqualGUID(&format
, &GUID_ContainerFormatTiff
),
396 "wrong container format %s\n", wine_dbgstr_guid(&format
));
398 refcount
= IStream_Release(stream
);
399 ok(refcount
> 0, "expected stream refcount > 0\n");
405 static HRESULT
get_pixelformat_info(const GUID
*format
, UINT
*bpp
, UINT
*channels
, BOOL
*transparency
)
408 IWICComponentInfo
*info
;
409 IWICPixelFormatInfo2
*formatinfo
;
411 hr
= IWICImagingFactory_CreateComponentInfo(factory
, format
, &info
);
412 ok(hr
== S_OK
, "CreateComponentInfo(%s) error %#x\n", wine_dbgstr_guid(format
), hr
);
415 hr
= IWICComponentInfo_QueryInterface(info
, &IID_IWICPixelFormatInfo2
, (void **)&formatinfo
);
418 hr
= IWICPixelFormatInfo2_SupportsTransparency(formatinfo
, transparency
);
419 ok(hr
== S_OK
, "SupportsTransparency error %#x\n", hr
);
420 IWICPixelFormatInfo2_Release(formatinfo
);
422 hr
= IWICComponentInfo_QueryInterface(info
, &IID_IWICPixelFormatInfo
, (void **)&formatinfo
);
425 hr
= IWICPixelFormatInfo2_GetBitsPerPixel(formatinfo
, bpp
);
426 ok(hr
== S_OK
, "GetBitsPerPixel error %#x\n", hr
);
427 hr
= IWICPixelFormatInfo2_GetChannelCount(formatinfo
, channels
);
428 ok(hr
== S_OK
, "GetChannelCount error %#x\n", hr
);
429 IWICPixelFormatInfo2_Release(formatinfo
);
431 IWICComponentInfo_Release(info
);
436 static void dump_tiff(void *buf
)
439 struct tiff_1bpp_data
*tiff
;
440 struct IFD_entry
*tag
;
443 count
= *(short *)((char *)tiff
+ tiff
->dir_offset
);
444 tag
= (struct IFD_entry
*)((char *)tiff
+ tiff
->dir_offset
+ sizeof(short));
446 for (i
= 0; i
< count
; i
++)
448 printf("tag %u: id %04x, type %04x, count %u, value %d",
449 i
, tag
[i
].id
, tag
[i
].type
, tag
[i
].count
, tag
[i
].value
);
450 if (tag
[i
].id
== 0x102 && tag
[i
].count
> 2)
452 short *bps
= (short *)((char *)tiff
+ tag
[i
].value
);
453 printf(" (%d,%d,%d,%d)\n", bps
[0], bps
[1], bps
[2], bps
[3]);
460 static void test_tiff_1bpp_palette(void)
463 IWICBitmapDecoder
*decoder
;
464 IWICBitmapFrameDecode
*frame
;
465 IWICPalette
*palette
;
468 hr
= create_decoder(&tiff_1bpp_data
, sizeof(tiff_1bpp_data
), &decoder
);
469 ok(hr
== S_OK
, "Failed to load TIFF image data %#x\n", hr
);
470 if (hr
!= S_OK
) return;
472 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
473 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
475 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &format
);
476 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
477 ok(IsEqualGUID(&format
, &GUID_WICPixelFormatBlackWhite
),
478 "got wrong format %s\n", wine_dbgstr_guid(&format
));
480 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
481 ok(hr
== S_OK
, "CreatePalette error %#x\n", hr
);
482 hr
= IWICBitmapFrameDecode_CopyPalette(frame
, palette
);
483 ok(hr
== WINCODEC_ERR_PALETTEUNAVAILABLE
,
484 "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %#x\n", hr
);
486 IWICPalette_Release(palette
);
487 IWICBitmapFrameDecode_Release(frame
);
488 IWICBitmapDecoder_Release(decoder
);
491 static void test_QueryCapability(void)
495 IWICBitmapDecoder
*decoder
;
496 IWICBitmapFrameDecode
*frame
;
497 static const DWORD exp_caps
= WICBitmapDecoderCapabilityCanDecodeAllImages
|
498 WICBitmapDecoderCapabilityCanDecodeSomeImages
|
499 WICBitmapDecoderCapabilityCanEnumerateMetadata
;
500 static const DWORD exp_caps_xp
= WICBitmapDecoderCapabilityCanDecodeAllImages
|
501 WICBitmapDecoderCapabilityCanDecodeSomeImages
;
506 stream
= create_stream(&tiff_1bpp_data
, sizeof(tiff_1bpp_data
));
509 hr
= IWICImagingFactory_CreateDecoder(factory
, &GUID_ContainerFormatTiff
, NULL
, &decoder
);
510 ok(hr
== S_OK
, "CreateDecoder error %#x\n", hr
);
511 if (FAILED(hr
)) return;
513 frame_count
= 0xdeadbeef;
514 hr
= IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
515 ok(hr
== S_OK
|| broken(hr
== E_POINTER
) /* XP */, "GetFrameCount error %#x\n", hr
);
516 ok(frame_count
== 0, "expected 0, got %u\n", frame_count
);
518 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
519 ok(hr
== WINCODEC_ERR_FRAMEMISSING
|| broken(hr
== E_POINTER
) /* XP */, "expected WINCODEC_ERR_FRAMEMISSING, got %#x\n", hr
);
522 hr
= IStream_Seek(stream
, pos
, SEEK_SET
, NULL
);
523 ok(hr
== S_OK
, "IStream_Seek error %#x\n", hr
);
525 capability
= 0xdeadbeef;
526 hr
= IWICBitmapDecoder_QueryCapability(decoder
, stream
, &capability
);
527 ok(hr
== S_OK
, "QueryCapability error %#x\n", hr
);
528 ok(capability
== exp_caps
|| capability
== exp_caps_xp
,
529 "expected %#x, got %#x\n", exp_caps
, capability
);
531 frame_count
= 0xdeadbeef;
532 hr
= IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
533 ok(hr
== S_OK
, "GetFrameCount error %#x\n", hr
);
534 ok(frame_count
== 1, "expected 1, got %u\n", frame_count
);
536 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
537 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
538 IWICBitmapFrameDecode_Release(frame
);
541 hr
= IStream_Seek(stream
, pos
, SEEK_SET
, NULL
);
542 ok(hr
== S_OK
, "IStream_Seek error %#x\n", hr
);
544 hr
= IWICBitmapDecoder_QueryCapability(decoder
, stream
, &capability
);
545 ok(hr
== WINCODEC_ERR_WRONGSTATE
, "expected WINCODEC_ERR_WRONGSTATE, got %#x\n", hr
);
547 hr
= IWICBitmapDecoder_Initialize(decoder
, stream
, WICDecodeMetadataCacheOnDemand
);
548 ok(hr
== WINCODEC_ERR_WRONGSTATE
, "expected WINCODEC_ERR_WRONGSTATE, got %#x\n", hr
);
550 IWICBitmapDecoder_Release(decoder
);
552 /* CreateDecoderFromStream fails if seeked past the start */
553 hr
= IWICImagingFactory_CreateDecoderFromStream(factory
, stream
, NULL
, 0, &decoder
);
555 ok(hr
== WINCODEC_ERR_COMPONENTNOTFOUND
, "expected WINCODEC_ERR_COMPONENTNOTFOUND, got %#x\n", hr
);
558 IWICBitmapDecoder_Release(decoder
);
561 hr
= IStream_Seek(stream
, pos
, SEEK_SET
, NULL
);
562 ok(hr
== S_OK
, "IStream_Seek error %#x\n", hr
);
564 hr
= IWICImagingFactory_CreateDecoderFromStream(factory
, stream
, NULL
, 0, &decoder
);
565 ok(hr
== S_OK
, "CreateDecoderFromStream error %#x\n", hr
);
567 frame_count
= 0xdeadbeef;
568 hr
= IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
569 ok(hr
== S_OK
, "GetFrameCount error %#x\n", hr
);
570 ok(frame_count
== 1, "expected 1, got %u\n", frame_count
);
572 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
573 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
574 IWICBitmapFrameDecode_Release(frame
);
576 hr
= IWICBitmapDecoder_Initialize(decoder
, stream
, WICDecodeMetadataCacheOnDemand
);
577 ok(hr
== WINCODEC_ERR_WRONGSTATE
, "expected WINCODEC_ERR_WRONGSTATE, got %#x\n", hr
);
579 hr
= IWICBitmapDecoder_QueryCapability(decoder
, stream
, &capability
);
580 ok(hr
== WINCODEC_ERR_WRONGSTATE
, "expected WINCODEC_ERR_WRONGSTATE, got %#x\n", hr
);
582 IWICBitmapDecoder_Release(decoder
);
583 IStream_Release(stream
);
586 static void test_tiff_8bpp_alpha(void)
589 IWICBitmapDecoder
*decoder
;
590 IWICBitmapFrameDecode
*frame
;
591 UINT frame_count
, width
, height
, i
;
593 IWICPalette
*palette
;
597 static const BYTE expected_data
[16] = { 0x11,0x11,0x11,0x22,0x33,0x33,0x33,0x44,
598 0x55,0x55,0x55,0x66,0x77,0x77,0x77,0x88 };
600 hr
= create_decoder(&tiff_8bpp_alpha
, sizeof(tiff_8bpp_alpha
), &decoder
);
601 ok(hr
== S_OK
, "Failed to load TIFF image data %#x\n", hr
);
602 if (hr
!= S_OK
) return;
604 hr
= IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
605 ok(hr
== S_OK
, "GetFrameCount error %#x\n", hr
);
606 ok(frame_count
== 1, "expected 1, got %u\n", frame_count
);
608 EXPECT_REF(decoder
, 1);
609 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
610 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
611 EXPECT_REF(decoder
, 2);
612 IWICBitmapDecoder_Release(decoder
);
614 hr
= IWICBitmapFrameDecode_GetSize(frame
, &width
, &height
);
615 ok(hr
== S_OK
, "GetSize error %#x\n", hr
);
616 ok(width
== 2, "expected 2, got %u\n", width
);
617 ok(height
== 2, "expected 2, got %u\n", height
);
619 hr
= IWICBitmapFrameDecode_GetResolution(frame
, &dpi_x
, &dpi_y
);
620 ok(hr
== S_OK
, "GetResolution error %#x\n", hr
);
621 ok(dpi_x
== 96.0, "expected 96.0, got %f\n", dpi_x
);
622 ok(dpi_y
== 96.0, "expected 96.0, got %f\n", dpi_y
);
624 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &format
);
625 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
626 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat32bppPBGRA
),
627 "got wrong format %s\n", wine_dbgstr_guid(&format
));
629 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
630 ok(hr
== S_OK
, "CreatePalette error %#x\n", hr
);
631 hr
= IWICBitmapFrameDecode_CopyPalette(frame
, palette
);
632 ok(hr
== WINCODEC_ERR_PALETTEUNAVAILABLE
,
633 "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %#x\n", hr
);
634 IWICPalette_Release(palette
);
640 hr
= IWICBitmapFrameDecode_CopyPixels(frame
, &rc
, 8, sizeof(data
), data
);
641 ok(hr
== S_OK
, "CopyPixels error %#x\n", hr
);
643 for (i
= 0; i
< sizeof(data
); i
++)
644 ok(data
[i
] == expected_data
[i
], "%u: expected %02x, got %02x\n", i
, expected_data
[i
], data
[i
]);
646 IWICBitmapFrameDecode_Release(frame
);
649 static void generate_tiff_palette(void *buf
, unsigned count
)
651 unsigned short *r
, *g
, *b
;
671 for (i
= 4; i
< count
; i
++)
674 g
[i
] = (i
| 0x40) * 257;
675 b
[i
] = (i
| 0x80) * 257;
679 static void test_tiff_8bpp_palette(void)
681 char buf
[sizeof(tiff_8bpp_data
)];
683 IWICBitmapDecoder
*decoder
;
684 IWICBitmapFrameDecode
*frame
;
685 IWICPalette
*palette
;
690 memcpy(buf
, &tiff_8bpp_data
, sizeof(tiff_8bpp_data
));
691 generate_tiff_palette(buf
+ FIELD_OFFSET(struct tiff_8bpp_data
, palette_data
), 256);
693 hr
= create_decoder(buf
, sizeof(buf
), &decoder
);
694 ok(hr
== S_OK
, "Failed to load TIFF image data %#x\n", hr
);
695 if (hr
!= S_OK
) return;
697 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
698 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
700 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &format
);
701 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
702 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat8bppIndexed
),
703 "expected GUID_WICPixelFormat8bppIndexed, got %s\n", wine_dbgstr_guid(&format
));
705 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
706 ok(hr
== S_OK
, "CreatePalette error %#x\n", hr
);
707 hr
= IWICBitmapFrameDecode_CopyPalette(frame
, palette
);
708 ok(hr
== S_OK
, "CopyPalette error %#x\n", hr
);
710 hr
= IWICPalette_GetColorCount(palette
, &count
);
711 ok(hr
== S_OK
, "GetColorCount error %#x\n", hr
);
712 ok(count
== 256, "expected 256, got %u\n", count
);
714 hr
= IWICPalette_GetColors(palette
, 256, color
, &ret
);
715 ok(hr
== S_OK
, "GetColors error %#x\n", hr
);
716 ok(ret
== count
, "expected %u, got %u\n", count
, ret
);
717 ok(color
[0] == 0xff112233, "got %#x\n", color
[0]);
718 ok(color
[1] == 0xff445566, "got %#x\n", color
[1]);
719 ok(color
[2] == 0xff778899, "got %#x\n", color
[2]);
720 ok(color
[3] == 0xffa1b5ff, "got %#x\n", color
[3]);
722 IWICPalette_Release(palette
);
723 IWICBitmapFrameDecode_Release(frame
);
724 IWICBitmapDecoder_Release(decoder
);
727 static void test_tiff_resolution(void)
730 IWICBitmapDecoder
*decoder
;
731 IWICBitmapFrameDecode
*frame
;
735 for (i
= 0; i
< ARRAY_SIZE(tiff_resolution_test_data
); i
++)
737 const struct tiff_resolution_test_data
*test_data
= &tiff_resolution_test_data
[i
];
738 tiff_resolution_image_data
.resx
= test_data
->resx
;
739 tiff_resolution_image_data
.resy
= test_data
->resy
;
740 tiff_resolution_image_data
.entry
[12].value
= test_data
->resolution_unit
;
742 hr
= create_decoder(&tiff_resolution_image_data
, sizeof(tiff_resolution_image_data
), &decoder
);
743 ok(hr
== S_OK
, "Failed to load TIFF image data %#x\n", hr
);
744 if (hr
!= S_OK
) return;
746 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
747 ok(hr
== S_OK
, "%d: GetFrame error %#x\n", i
, hr
);
749 hr
= IWICBitmapFrameDecode_GetResolution(frame
, &dpi_x
, &dpi_y
);
750 ok(hr
== S_OK
, "%d: GetResolution error %#x\n", i
, hr
);
752 if (test_data
->broken_dpi_x
!= 0)
754 ok(fabs(dpi_x
- test_data
->expected_dpi_x
) < 0.01 || broken(fabs(dpi_x
- test_data
->broken_dpi_x
) < 0.01),
755 "%d: x: expected %f or %f, got %f\n", i
, test_data
->expected_dpi_x
, test_data
->broken_dpi_x
, dpi_x
);
759 ok(fabs(dpi_x
- test_data
->expected_dpi_x
) < 0.01,
760 "%d: x: expected %f, got %f\n", i
, test_data
->expected_dpi_x
, dpi_x
);
763 if (test_data
->broken_dpi_y
!= 0)
765 ok(fabs(dpi_y
- test_data
->expected_dpi_y
) < 0.01 || broken(fabs(dpi_y
- test_data
->broken_dpi_y
) < 0.01),
766 "%d: y: expected %f or %f, got %f\n", i
, test_data
->expected_dpi_y
, test_data
->broken_dpi_y
, dpi_y
);
770 ok(fabs(dpi_y
- test_data
->expected_dpi_y
) < 0.01,
771 "%d: y: expected %f, got %f\n", i
, test_data
->expected_dpi_y
, dpi_y
);
774 IWICBitmapFrameDecode_Release(frame
);
775 IWICBitmapDecoder_Release(decoder
);
779 static void test_tiff_24bpp(void)
782 IWICBitmapDecoder
*decoder
;
783 IWICBitmapFrameDecode
*frame
;
784 UINT count
, width
, height
, i
, stride
;
789 static const BYTE expected_data
[] = { 0x33,0x22,0x11 };
791 hr
= create_decoder(&tiff_24bpp_data
, sizeof(tiff_24bpp_data
), &decoder
);
792 ok(hr
== S_OK
, "Failed to load TIFF image data %#x\n", hr
);
793 if (hr
!= S_OK
) return;
794 ok(decoder
!= NULL
, "Failed to load TIFF image data\n");
796 hr
= IWICBitmapDecoder_GetFrameCount(decoder
, &count
);
797 ok(hr
== S_OK
, "GetFrameCount error %#x\n", hr
);
798 ok(count
== 1, "got %u\n", count
);
800 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
801 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
803 hr
= IWICBitmapFrameDecode_GetSize(frame
, &width
, &height
);
804 ok(hr
== S_OK
, "GetSize error %#x\n", hr
);
805 ok(width
== 1, "got %u\n", width
);
806 ok(height
== 1, "got %u\n", height
);
808 hr
= IWICBitmapFrameDecode_GetResolution(frame
, &dpi_x
, &dpi_y
);
809 ok(hr
== S_OK
, "GetResolution error %#x\n", hr
);
810 ok(dpi_x
== 300.0, "got %f\n", dpi_x
);
811 ok(dpi_y
== 300.0, "got %f\n", dpi_y
);
813 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &format
);
814 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
815 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat24bppBGR
),
816 "got wrong format %s\n", wine_dbgstr_guid(&format
));
818 for (stride
= 0; stride
<= 32; stride
++)
820 memset(data
, 0, sizeof(data
));
825 hr
= IWICBitmapFrameDecode_CopyPixels(frame
, &rc
, stride
, sizeof(data
), data
);
827 ok(hr
== E_INVALIDARG
, "CopyPixels(%u) should fail: %#x\n", stride
, hr
);
830 ok(hr
== S_OK
, "CopyPixels(%u) error %#x\n", stride
, hr
);
832 for (i
= 0; i
< sizeof(data
); i
++)
833 ok(data
[i
] == expected_data
[i
], "%u: expected %02x, got %02x\n", i
, expected_data
[i
], data
[i
]);
837 IWICBitmapFrameDecode_Release(frame
);
838 IWICBitmapDecoder_Release(decoder
);
841 #include "pshpack2.h"
842 static const struct tiff_1x1_data
847 USHORT number_of_entries
;
848 struct IFD_entry entry
[13];
850 struct IFD_rational res
;
851 short palette_data
[3][256];
856 #ifdef WORDS_BIGENDIAN
862 FIELD_OFFSET(struct tiff_1x1_data
, number_of_entries
),
865 { 0xff, IFD_SHORT
, 1, 0 }, /* SUBFILETYPE */
866 { 0x100, IFD_LONG
, 1, 1 }, /* IMAGEWIDTH */
867 { 0x101, IFD_LONG
, 1, 1 }, /* IMAGELENGTH */
868 { 0x102, IFD_SHORT
, 3, FIELD_OFFSET(struct tiff_1x1_data
, bps_data
) }, /* BITSPERSAMPLE */
869 { 0x103, IFD_SHORT
, 1, 1 }, /* COMPRESSION: XP doesn't accept IFD_LONG here */
870 { 0x106, IFD_SHORT
, 1, 2 }, /* PHOTOMETRIC */
871 { 0x111, IFD_LONG
, 1, FIELD_OFFSET(struct tiff_1x1_data
, pixel_data
) }, /* STRIPOFFSETS */
872 { 0x115, IFD_SHORT
, 1, 3 }, /* SAMPLESPERPIXEL */
873 { 0x11a, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_1x1_data
, res
) },
874 { 0x11b, IFD_RATIONAL
, 1, FIELD_OFFSET(struct tiff_1x1_data
, res
) },
875 { 0x128, IFD_SHORT
, 1, 2 }, /* RESOLUTIONUNIT */
876 { 0x140, IFD_SHORT
, 256*3, FIELD_OFFSET(struct tiff_1x1_data
, palette_data
) }, /* COLORMAP */
877 { 0x152, IFD_SHORT
, 1, 1 } /* EXTRASAMPLES: 1 - Associated alpha with pre-multiplied color */
883 { 1,0,2,3,4,5,6,7,8,9,0,1,2,3,4,5 }
887 static UINT
width_bytes(UINT width
, UINT bpp
)
889 return (width
* bpp
+ 7) / 8;
892 static void test_color_formats(void)
899 const WICPixelFormatGUID
*format
;
902 static const BYTE bits_1bpsBGR
[] = { 0,255,0,255,0,255,255,255,0,0,0,255,255,0,0,0,255,255,255,255,255,0,0,0,0,255,0,255,0,255 };
903 static const struct bitmap_data data_1bpsBGR
=
905 24, 10, 2, &GUID_WICPixelFormat24bppBGR
, bits_1bpsBGR
907 static const BYTE bits_4bpsBGR
[] = { 204,85,85,136,187,51,0,85,85,85,0,68,0,102,0,136,0,119,0,153,0 };
908 static const struct bitmap_data data_4bpsBGR
=
910 24, 5, 2, &GUID_WICPixelFormat24bppBGR
, bits_4bpsBGR
912 static const BYTE bits_8bpsBGR
[] = { 2,0,1,5,4,3,8,7,6 };
913 static const struct bitmap_data data_8bpsBGR
=
915 24, 3, 1, &GUID_WICPixelFormat24bppBGR
, bits_8bpsBGR
917 static const BYTE bits_48bppRGB
[] = { 1,0,2,3,4,5,6,7,8,9,0,1 };
918 static const struct bitmap_data data_48bppRGB
=
920 48, 2, 1, &GUID_WICPixelFormat48bppRGB
, bits_48bppRGB
922 static const BYTE bits_1bpsBGRA
[] = { 0,255,0,255,0,255,0,255,0,255,255,0,255,0,0,255,255,0,255,255,0,0,255,0,0,255,0,255,0,255,0,255,0,0,0,0,0,255,0,0 };
923 static const struct bitmap_data data_1bpsBGRA
=
925 32, 5, 2, &GUID_WICPixelFormat32bppBGRA
, bits_1bpsBGRA
927 static const struct bitmap_data data_1bpsPBGRA
=
929 32, 5, 2, &GUID_WICPixelFormat32bppPBGRA
, bits_1bpsBGRA
931 static const BYTE bits_4bpsBGRA
[] = { 204,85,85,51,85,136,187,85,0,68,0,85,0,102,0,119,0,136,0,153,0,0,0,17,0,34,0,51 };
932 static const struct bitmap_data data_4bpsBGRA
=
934 32, 5, 2, &GUID_WICPixelFormat32bppBGRA
, bits_4bpsBGRA
936 static const struct bitmap_data data_4bpsPBGRA
=
938 32, 5, 2, &GUID_WICPixelFormat32bppPBGRA
, bits_4bpsBGRA
940 static const BYTE bits_8bpsBGRA
[] = { 2,0,1,3,6,5,4,7,0,9,8,1,4,3,2,5 };
941 static const struct bitmap_data data_8bpsBGRA
=
943 32, 4, 1, &GUID_WICPixelFormat32bppBGRA
, bits_8bpsBGRA
945 static const struct bitmap_data data_8bpsPBGRA
=
947 32, 4, 1, &GUID_WICPixelFormat32bppPBGRA
, bits_8bpsBGRA
949 static const BYTE bits_64bppRGBA
[] = { 1,0,2,3,4,5,6,7,8,9,0,1,2,3,4,5 };
950 static const struct bitmap_data data_64bppRGBA
=
952 64, 2, 1, &GUID_WICPixelFormat64bppRGBA
, bits_64bppRGBA
954 static const struct bitmap_data data_64bppPRGBA
=
956 64, 2, 1, &GUID_WICPixelFormat64bppPRGBA
, bits_64bppRGBA
958 static const BYTE bits_BlackWhite
[] = { 85,195,184,85 };
959 static const struct bitmap_data data_BlackWhite
=
961 1, 30, 1, &GUID_WICPixelFormatBlackWhite
, bits_BlackWhite
963 static const BYTE bits_BlackWhite_xp
[] = { 85,195,184,84 };
964 static const struct bitmap_data data_BlackWhite_xp
=
966 1, 30, 1, &GUID_WICPixelFormatBlackWhite
, bits_BlackWhite_xp
968 static const BYTE bits_4bppGray
[] = { 85,195,184,85 };
969 static const struct bitmap_data data_4bppGray
=
971 4, 7, 1, &GUID_WICPixelFormat4bppGray
, bits_4bppGray
973 static const BYTE bits_4bppGray_xp
[] = { 85,195,184,80 };
974 static const struct bitmap_data data_4bppGray_xp
=
976 4, 7, 1, &GUID_WICPixelFormat4bppGray
, bits_4bppGray_xp
978 static const BYTE bits_8bppGray
[] = { 1,0,2,3,4,5,6,7,8,9 };
979 static const struct bitmap_data data_8bppGray
=
981 8, 10, 1, &GUID_WICPixelFormat8bppGray
, bits_8bppGray
983 static const BYTE bits_16bppGray
[] = { 1,0,2,3,4,5 };
984 static const struct bitmap_data data_16bppGray
=
986 16, 3, 1, &GUID_WICPixelFormat16bppGray
, bits_16bppGray
988 static const BYTE bits_32bppGrayFloat
[] = { 1,0,2,3,4,5,6,7,8,9,0,1 };
989 static const struct bitmap_data data_32bppGrayFloat
=
991 32, 3, 1, &GUID_WICPixelFormat32bppGrayFloat
, bits_32bppGrayFloat
993 static const BYTE bits_96bppRGBFloat
[] = { 1,0,2,3,4,5,6,7,8,9,0,1 };
994 static const struct bitmap_data data_96bppRGBFloat
=
996 96, 1, 1, &GUID_WICPixelFormat96bppRGBFloat
, bits_96bppRGBFloat
998 static const BYTE bits_128bppRGBAFloat
[] = { 1,0,2,3,4,5,6,7,8,9,0,1,2,3,4,5 };
999 static const struct bitmap_data data_128bppRGBAFloat
=
1001 128, 1, 1, &GUID_WICPixelFormat128bppRGBAFloat
, bits_128bppRGBAFloat
1003 static const struct bitmap_data data_128bppPRGBAFloat
=
1005 128, 1, 1, &GUID_WICPixelFormat128bppPRGBAFloat
, bits_128bppRGBAFloat
1007 static const BYTE bits_1bppIndexed
[] = { 85,195,184,85 };
1008 static const struct bitmap_data data_1bppIndexed
=
1010 1, 32, 1, &GUID_WICPixelFormat1bppIndexed
, bits_1bppIndexed
1012 static const BYTE bits_4bppIndexed
[] = { 85,195,184,85 };
1013 static const struct bitmap_data data_4bppIndexed
=
1015 4, 7, 1, &GUID_WICPixelFormat4bppIndexed
, bits_4bppIndexed
1017 static const BYTE bits_4bppIndexed_xp
[] = { 85,195,184,80 };
1018 static const struct bitmap_data data_4bppIndexed_xp
=
1020 4, 7, 1, &GUID_WICPixelFormat4bppIndexed
, bits_4bppIndexed_xp
1022 static const BYTE bits_8bppIndexed
[] = { 1,0,2,3,4,5,6,7,8,9 };
1023 static const struct bitmap_data data_8bppIndexed
=
1025 8, 3, 1, &GUID_WICPixelFormat8bppIndexed
, bits_8bppIndexed
1027 static const BYTE bits_32bppCMYK
[] = { 1,0,2,3,4,5,6,7,8,9,0,1 };
1028 static const struct bitmap_data data_32bppCMYK
=
1030 32, 3, 1, &GUID_WICPixelFormat32bppCMYK
, bits_32bppCMYK
1032 static const BYTE bits_64bppCMYK
[] = { 1,0,2,3,4,5,6,7,8,9,0,1,2,3,4,5 };
1033 static const struct bitmap_data data_64bppCMYK
=
1035 64, 2, 1, &GUID_WICPixelFormat64bppCMYK
, bits_64bppCMYK
1039 int photometric
; /* PhotometricInterpretation */
1040 int samples
; /* SamplesPerPixel */
1041 int bps
; /* BitsPerSample */
1042 int extra_samples
; /* ExtraSamples */
1043 const struct bitmap_data
*data
;
1044 const struct bitmap_data
*alt_data
;
1048 { 2, 3, 1, 0, &data_1bpsBGR
},
1049 { 2, 3, 4, 0, &data_4bpsBGR
},
1050 { 2, 3, 8, 0, &data_8bpsBGR
},
1051 { 2, 3, 16, 0, &data_48bppRGB
},
1052 { 2, 3, 24, 0, NULL
},
1053 { 2, 3, 32, 0, &data_96bppRGBFloat
},
1054 { 2, 4, 1, 0, &data_1bpsBGRA
},
1055 { 2, 4, 1, 1, &data_1bpsPBGRA
},
1056 { 2, 4, 4, 0, &data_4bpsBGRA
},
1057 { 2, 4, 4, 1, &data_4bpsPBGRA
},
1058 { 2, 4, 8, 0, &data_8bpsBGRA
},
1059 { 2, 4, 8, 1, &data_8bpsPBGRA
},
1060 { 2, 4, 16, 0, &data_64bppRGBA
},
1061 { 2, 4, 16, 1, &data_64bppPRGBA
},
1062 { 2, 4, 24, 0, NULL
},
1063 { 2, 4, 32, 0, &data_128bppRGBAFloat
},
1064 { 2, 4, 32, 1, &data_128bppPRGBAFloat
},
1065 /* 1 - BlackIsZero (Bilevel) */
1066 { 1, 1, 1, 0, &data_BlackWhite
, &data_BlackWhite_xp
},
1067 { 1, 1, 4, 0, &data_4bppGray
, &data_4bppGray_xp
},
1068 { 1, 1, 8, 0, &data_8bppGray
},
1069 { 1, 1, 16, 0, &data_16bppGray
},
1070 { 1, 1, 24, 0, NULL
},
1071 { 1, 1, 32, 0, &data_32bppGrayFloat
},
1072 /* 3 - Palette Color */
1073 { 3, 1, 1, 0, &data_1bppIndexed
},
1074 { 3, 1, 4, 0, &data_4bppIndexed
, &data_4bppIndexed_xp
},
1075 { 3, 1, 8, 0, &data_8bppIndexed
},
1076 #if 0 /* FIXME: for some reason libtiff replaces photometric 3 by 1 for bps > 8 */
1077 { 3, 1, 16, 0, &data_8bppIndexed
},
1078 { 3, 1, 24, 0, &data_8bppIndexed
},
1079 { 3, 1, 32, 0, &data_8bppIndexed
},
1082 { 5, 4, 1, 0, NULL
},
1083 { 5, 4, 4, 0, NULL
},
1084 { 5, 4, 8, 0, &data_32bppCMYK
},
1085 { 5, 4, 16, 0, &data_64bppCMYK
},
1086 { 5, 4, 24, 0, NULL
},
1087 { 5, 4, 32, 0, NULL
},
1089 BYTE buf
[sizeof(tiff_1x1_data
)];
1092 IWICBitmapDecoder
*decoder
;
1093 IWICBitmapFrameDecode
*frame
;
1095 UINT count
, i
, bpp
, channels
, ret
;
1097 struct IFD_entry
*tag
, *tag_photo
= NULL
, *tag_bps
= NULL
, *tag_samples
= NULL
, *tag_colormap
= NULL
;
1098 struct IFD_entry
*tag_width
= NULL
, *tag_height
= NULL
, *tag_extra_samples
= NULL
;
1101 memcpy(buf
, &tiff_1x1_data
, sizeof(tiff_1x1_data
));
1102 generate_tiff_palette(buf
+ FIELD_OFFSET(struct tiff_1x1_data
, palette_data
), 256);
1104 count
= *(short *)(buf
+ tiff_1x1_data
.dir_offset
);
1105 tag
= (struct IFD_entry
*)(buf
+ tiff_1x1_data
.dir_offset
+ sizeof(short));
1107 /* verify the TIFF structure */
1108 for (i
= 0; i
< count
; i
++)
1110 if (tag
[i
].id
== 0x100) /* ImageWidth */
1111 tag_width
= &tag
[i
];
1112 else if (tag
[i
].id
== 0x101) /* ImageLength */
1113 tag_height
= &tag
[i
];
1114 else if (tag
[i
].id
== 0x102) /* BitsPerSample */
1116 else if (tag
[i
].id
== 0x106) /* PhotometricInterpretation */
1117 tag_photo
= &tag
[i
];
1118 else if (tag
[i
].id
== 0x115) /* SamplesPerPixel */
1119 tag_samples
= &tag
[i
];
1120 else if (tag
[i
].id
== 0x140) /* ColorMap */
1121 tag_colormap
= &tag
[i
];
1122 else if (tag
[i
].id
== 0x152) /* ExtraSamples */
1123 tag_extra_samples
= &tag
[i
];
1126 ok(tag_bps
&& tag_photo
&& tag_samples
&& tag_colormap
&& tag_extra_samples
, "tag 0x102,0x106,0x115,0x140 or 0x152 is missing\n");
1127 if (!tag_bps
|| !tag_photo
|| !tag_samples
|| !tag_colormap
|| !tag_extra_samples
) return;
1129 ok(tag_bps
->type
== IFD_SHORT
, "tag 0x102 should have type IFD_SHORT\n");
1130 bps
= (short *)(buf
+ tag_bps
->value
);
1131 ok(bps
[0] == 8 && bps
[1] == 8 && bps
[2] == 8 && bps
[3] == 0,
1132 "expected bps 8,8,8,0 got %d,%d,%d,%d\n", bps
[0], bps
[1], bps
[2], bps
[3]);
1134 for (i
= 0; i
< ARRAY_SIZE(td
); i
++)
1138 bpp
= td
[i
].samples
* td
[i
].bps
;
1139 if (winetest_debug
> 1)
1140 trace("photometric %d, samples %d, extra samples %d, bps %d, bpp %u, width %u => width_bytes %u\n",
1141 td
[i
].photometric
, td
[i
].samples
, td
[i
].extra_samples
, td
[i
].bps
, bpp
,
1142 td
[i
].data
->width
, width_bytes(td
[i
].data
->width
, bpp
));
1143 tag_width
->value
= td
[i
].data
->width
;
1144 tag_height
->value
= td
[i
].data
->height
;
1148 tag_width
->value
= 1;
1149 tag_height
->value
= 1;
1152 tag_colormap
->count
= (1 << td
[i
].bps
) * 3;
1156 buf
[FIELD_OFFSET(struct tiff_1x1_data
, pixel_data
)] = 0x55;
1157 buf
[FIELD_OFFSET(struct tiff_1x1_data
, pixel_data
) + 1] = 0xc3;
1158 buf
[FIELD_OFFSET(struct tiff_1x1_data
, pixel_data
) + 2] = 0xb8;
1159 buf
[FIELD_OFFSET(struct tiff_1x1_data
, pixel_data
) + 3] = 0x55;
1163 buf
[FIELD_OFFSET(struct tiff_1x1_data
, pixel_data
)] = 1;
1164 buf
[FIELD_OFFSET(struct tiff_1x1_data
, pixel_data
) + 1] = 0;
1165 buf
[FIELD_OFFSET(struct tiff_1x1_data
, pixel_data
) + 2] = 2;
1166 buf
[FIELD_OFFSET(struct tiff_1x1_data
, pixel_data
) + 3] = 3;
1169 tag_photo
->value
= td
[i
].photometric
;
1170 tag_bps
->count
= td
[i
].samples
;
1171 tag_samples
->value
= td
[i
].samples
;
1173 if (td
[i
].samples
== 1)
1174 tag_bps
->value
= td
[i
].bps
;
1175 else if (td
[i
].samples
== 2)
1176 tag_bps
->value
= MAKELONG(td
[i
].bps
, td
[i
].bps
);
1177 else if (td
[i
].samples
== 3)
1179 tag_bps
->value
= (BYTE
*)bps
- buf
;
1180 bps
[0] = bps
[1] = bps
[2] = td
[i
].bps
;
1182 else if (td
[i
].samples
== 4)
1184 tag_bps
->value
= (BYTE
*)bps
- buf
;
1185 bps
[0] = bps
[1] = bps
[2] = bps
[3] = td
[i
].bps
;
1189 ok(0, "%u: unsupported samples count %d\n", i
, td
[i
].samples
);
1193 if (td
[i
].extra_samples
)
1195 tag_extra_samples
->id
= 0x152; /* ExtraSamples */
1196 tag_extra_samples
->value
= td
[i
].extra_samples
;
1198 else /* remove ExtraSamples tag */
1200 tag_extra_samples
->id
= 0x14e; /* NumberOfInks */
1201 tag_extra_samples
->value
= td
[i
].samples
;
1204 hr
= create_decoder(buf
, sizeof(buf
), &decoder
);
1207 ok(hr
== WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT
|| hr
== WINCODEC_ERR_COMPONENTNOTFOUND
/* win8+ */ || hr
== WINCODEC_ERR_BADIMAGE
/* XP */,
1208 "%u: (%d,%d,%d,%d) wrong error %#x\n", i
, td
[i
].photometric
, td
[i
].samples
, td
[i
].extra_samples
, td
[i
].bps
, hr
);
1211 IWICBitmapDecoder_Release(decoder
);
1217 ok(hr
== S_OK
|| broken(hr
== WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT
|| hr
== WINCODEC_ERR_BADIMAGE
) /* XP */,
1218 "%u: failed to load TIFF image data (%d,%d,%d,%d) %#x\n",
1219 i
, td
[i
].photometric
, td
[i
].samples
, td
[i
].extra_samples
, td
[i
].bps
, hr
);
1220 if (hr
!= S_OK
) continue;
1222 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
1223 ok(hr
== S_OK
, "%u: GetFrame error %#x\n", i
, hr
);
1225 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &format
);
1226 ok(hr
== S_OK
, "%u: GetPixelFormat error %#x\n", i
, hr
);
1227 if (IsEqualGUID(td
[i
].data
->format
, &GUID_WICPixelFormat96bppRGBFloat
) && IsEqualGUID(&format
, &GUID_WICPixelFormat128bppRGBFloat
))
1229 win_skip("Windows Server 2008 misinterprets 96bppRGBFloat as 128bppRGBFloat, skipping the tests\n");
1230 IWICBitmapFrameDecode_Release(frame
);
1231 IWICBitmapDecoder_Release(decoder
);
1234 ok(IsEqualGUID(&format
, td
[i
].data
->format
),
1235 "%u (%d,%d,%d,%d): expected %s, got %s\n",
1236 i
, td
[i
].photometric
, td
[i
].samples
, td
[i
].extra_samples
, td
[i
].bps
,
1237 wine_dbgstr_guid(td
[i
].data
->format
), wine_dbgstr_guid(&format
));
1239 transparency
= (td
[i
].photometric
== 2 && td
[i
].samples
== 4); /* for XP */
1240 hr
= get_pixelformat_info(&format
, &bpp
, &channels
, &transparency
);
1241 ok(hr
== S_OK
, "%u: get_pixelformat_bpp error %#x\n", i
, hr
);
1242 ok(bpp
== td
[i
].data
->bpp
, "%u: expected %u, got %u\n", i
, td
[i
].data
->bpp
, bpp
);
1243 ok(channels
== td
[i
].samples
, "%u: expected %u, got %u\n", i
, td
[i
].samples
, channels
);
1244 ok(transparency
== (td
[i
].photometric
== 2 && td
[i
].samples
== 4), "%u: got %u\n", i
, transparency
);
1246 memset(pixels
, 0, sizeof(pixels
));
1247 hr
= IWICBitmapFrameDecode_CopyPixels(frame
, NULL
, width_bytes(td
[i
].data
->width
, bpp
), sizeof(pixels
), pixels
);
1248 ok(hr
== S_OK
, "%u: CopyPixels error %#x\n", i
, hr
);
1249 ret
= memcmp(pixels
, td
[i
].data
->bits
, width_bytes(td
[i
].data
->width
, bpp
));
1250 if (ret
&& td
[i
].alt_data
)
1251 ret
= memcmp(pixels
, td
[i
].alt_data
->bits
, width_bytes(td
[i
].data
->width
, bpp
));
1252 ok(ret
== 0, "%u: (%d,%d,%d,%d) wrong pixel data\n", i
, td
[i
].photometric
, td
[i
].samples
, td
[i
].extra_samples
, td
[i
].bps
);
1255 UINT j
, n
= width_bytes(td
[i
].data
->width
, bpp
);
1256 for (j
= 0; j
< n
; j
++)
1257 printf("%u%s", pixels
[j
], (j
+ 1) < n
? "," : "\n");
1260 IWICBitmapFrameDecode_Release(frame
);
1261 IWICBitmapDecoder_Release(decoder
);
1265 static void test_tiff_4bps_bgra(void)
1268 IWICBitmapDecoder
*decoder
;
1269 IWICBitmapFrameDecode
*frame
;
1270 UINT frame_count
, width
, height
, i
;
1271 double dpi_x
, dpi_y
;
1272 IWICPalette
*palette
;
1276 static const BYTE expected_data
[24] = { 0,0,0,0xff, 0xff,0,0,0, 0xff,0,0,0xff,
1277 0,0xff,0,0, 0xff,0xff,0,0xff, 0xff,0xff,0xff,0 };
1279 hr
= create_decoder(&tiff_4bps_bgra
, sizeof(tiff_4bps_bgra
), &decoder
);
1280 ok(hr
== S_OK
, "Failed to load TIFF image data %#x\n", hr
);
1281 if (hr
!= S_OK
) return;
1283 hr
= IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
1284 ok(hr
== S_OK
, "GetFrameCount error %#x\n", hr
);
1285 ok(frame_count
== 1, "expected 1, got %u\n", frame_count
);
1287 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
1288 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
1290 hr
= IWICBitmapFrameDecode_GetSize(frame
, &width
, &height
);
1291 ok(hr
== S_OK
, "GetSize error %#x\n", hr
);
1292 ok(width
== 3, "got %u\n", width
);
1293 ok(height
== 2, "got %u\n", height
);
1295 hr
= IWICBitmapFrameDecode_GetResolution(frame
, &dpi_x
, &dpi_y
);
1296 ok(hr
== S_OK
, "GetResolution error %#x\n", hr
);
1297 ok(dpi_x
== 96.0, "expected 96.0, got %f\n", dpi_x
);
1298 ok(dpi_y
== 96.0, "expected 96.0, got %f\n", dpi_y
);
1300 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &format
);
1301 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
1302 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat32bppBGRA
),
1303 "got wrong format %s\n", wine_dbgstr_guid(&format
));
1305 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
1306 ok(hr
== S_OK
, "CreatePalette error %#x\n", hr
);
1307 hr
= IWICBitmapFrameDecode_CopyPalette(frame
, palette
);
1308 ok(hr
== WINCODEC_ERR_PALETTEUNAVAILABLE
,
1309 "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %#x\n", hr
);
1310 IWICPalette_Release(palette
);
1312 memset(data
, 0xaa, sizeof(data
));
1317 hr
= IWICBitmapFrameDecode_CopyPixels(frame
, &rc
, 12, sizeof(data
), data
);
1318 ok(hr
== S_OK
, "CopyPixels error %#x\n", hr
);
1320 for (i
= 0; i
< sizeof(data
); i
++)
1321 ok(data
[i
] == expected_data
[i
], "%u: expected %02x, got %02x\n", i
, expected_data
[i
], data
[i
]);
1323 IWICBitmapFrameDecode_Release(frame
);
1324 IWICBitmapDecoder_Release(decoder
);
1327 START_TEST(tiffformat
)
1331 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
1333 hr
= CoCreateInstance(&CLSID_WICImagingFactory
, NULL
, CLSCTX_INPROC_SERVER
,
1334 &IID_IWICImagingFactory
, (void **)&factory
);
1335 ok(hr
== S_OK
, "CoCreateInstance error %#x\n", hr
);
1336 if (FAILED(hr
)) return;
1338 test_tiff_4bps_bgra();
1339 test_color_formats();
1340 test_tiff_1bpp_palette();
1341 test_tiff_8bpp_palette();
1342 test_QueryCapability();
1343 test_tiff_8bpp_alpha();
1344 test_tiff_resolution();
1347 IWICImagingFactory_Release(factory
);