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
);
179 if (FAILED(hr
)) return NULL
;
181 hr
= IWICBitmapDecoder_GetContainerFormat(decoder
, &guid
);
182 ok(hr
== S_OK
, "GetContainerFormat error %#x\n", hr
);
183 ok(IsEqualGUID(&guid
, &GUID_ContainerFormatTiff
), "container format is not TIFF\n");
185 IStream_Release(stream
);
190 static void test_tiff_palette(void)
193 IWICBitmapDecoder
*decoder
;
194 IWICBitmapFrameDecode
*frame
;
195 IWICPalette
*palette
;
198 decoder
= create_decoder(&tiff_1bpp_data
, sizeof(tiff_1bpp_data
));
199 ok(decoder
!= 0, "Failed to load TIFF image data\n");
200 if (!decoder
) return;
202 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
203 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
205 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &format
);
206 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
207 ok(IsEqualGUID(&format
, &GUID_WICPixelFormatBlackWhite
),
208 "got wrong format %s\n", wine_dbgstr_guid(&format
));
210 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
211 ok(hr
== S_OK
, "CreatePalette error %#x\n", hr
);
212 hr
= IWICBitmapFrameDecode_CopyPalette(frame
, palette
);
213 ok(hr
== WINCODEC_ERR_PALETTEUNAVAILABLE
,
214 "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %#x\n", hr
);
216 IWICPalette_Release(palette
);
217 IWICBitmapFrameDecode_Release(frame
);
218 IWICBitmapDecoder_Release(decoder
);
221 static void test_QueryCapability(void)
225 IWICBitmapDecoder
*decoder
;
226 IWICBitmapFrameDecode
*frame
;
227 static const DWORD exp_caps
= WICBitmapDecoderCapabilityCanDecodeAllImages
|
228 WICBitmapDecoderCapabilityCanDecodeSomeImages
|
229 WICBitmapDecoderCapabilityCanEnumerateMetadata
;
230 static const DWORD exp_caps_xp
= WICBitmapDecoderCapabilityCanDecodeAllImages
|
231 WICBitmapDecoderCapabilityCanDecodeSomeImages
;
234 ULARGE_INTEGER cur_pos
;
237 stream
= create_stream(&tiff_1bpp_data
, sizeof(tiff_1bpp_data
));
240 hr
= IWICImagingFactory_CreateDecoder(factory
, &GUID_ContainerFormatTiff
, NULL
, &decoder
);
241 ok(hr
== S_OK
, "CreateDecoder error %#x\n", hr
);
242 if (FAILED(hr
)) return;
244 frame_count
= 0xdeadbeef;
245 hr
= IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
246 ok(hr
== S_OK
|| broken(hr
== E_POINTER
) /* XP */, "GetFrameCount error %#x\n", hr
);
247 ok(frame_count
== 0, "expected 0, got %u\n", frame_count
);
249 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
250 ok(hr
== WINCODEC_ERR_FRAMEMISSING
|| broken(hr
== E_POINTER
) /* XP */, "expected WINCODEC_ERR_FRAMEMISSING, got %#x\n", hr
);
253 hr
= IStream_Seek(stream
, pos
, SEEK_SET
, NULL
);
254 ok(hr
== S_OK
, "IStream_Seek error %#x\n", hr
);
256 capability
= 0xdeadbeef;
257 hr
= IWICBitmapDecoder_QueryCapability(decoder
, stream
, &capability
);
258 ok(hr
== S_OK
, "QueryCapability error %#x\n", hr
);
259 ok(capability
== exp_caps
|| capability
== exp_caps_xp
,
260 "expected %#x, got %#x\n", exp_caps
, capability
);
262 frame_count
= 0xdeadbeef;
263 hr
= IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
264 ok(hr
== S_OK
, "GetFrameCount error %#x\n", hr
);
265 ok(frame_count
== 1, "expected 1, got %u\n", frame_count
);
267 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
268 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
269 IWICBitmapFrameDecode_Release(frame
);
272 hr
= IStream_Seek(stream
, pos
, SEEK_CUR
, &cur_pos
);
273 ok(hr
== S_OK
, "IStream_Seek error %#x\n", hr
);
274 ok(cur_pos
.QuadPart
> 4 && cur_pos
.QuadPart
< sizeof(tiff_1bpp_data
),
275 "current stream pos is at %x/%x\n", cur_pos
.u
.LowPart
, cur_pos
.u
.HighPart
);
277 hr
= IWICBitmapDecoder_QueryCapability(decoder
, stream
, &capability
);
278 ok(hr
== WINCODEC_ERR_WRONGSTATE
, "expected WINCODEC_ERR_WRONGSTATE, got %#x\n", hr
);
280 hr
= IWICBitmapDecoder_Initialize(decoder
, stream
, WICDecodeMetadataCacheOnDemand
);
281 ok(hr
== WINCODEC_ERR_WRONGSTATE
, "expected WINCODEC_ERR_WRONGSTATE, got %#x\n", hr
);
283 IWICBitmapDecoder_Release(decoder
);
285 hr
= IWICImagingFactory_CreateDecoderFromStream(factory
, stream
, NULL
, 0, &decoder
);
287 ok(hr
== WINCODEC_ERR_COMPONENTNOTFOUND
, "expected WINCODEC_ERR_COMPONENTNOTFOUND, got %#x\n", hr
);
290 IWICBitmapDecoder_Release(decoder
);
293 hr
= IStream_Seek(stream
, pos
, SEEK_SET
, NULL
);
294 ok(hr
== S_OK
, "IStream_Seek error %#x\n", hr
);
296 hr
= IWICImagingFactory_CreateDecoderFromStream(factory
, stream
, NULL
, 0, &decoder
);
297 ok(hr
== S_OK
, "CreateDecoderFromStream error %#x\n", hr
);
299 frame_count
= 0xdeadbeef;
300 hr
= IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
301 ok(hr
== S_OK
, "GetFrameCount error %#x\n", hr
);
302 ok(frame_count
== 1, "expected 1, got %u\n", frame_count
);
304 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
305 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
306 IWICBitmapFrameDecode_Release(frame
);
308 hr
= IWICBitmapDecoder_Initialize(decoder
, stream
, WICDecodeMetadataCacheOnDemand
);
309 ok(hr
== WINCODEC_ERR_WRONGSTATE
, "expected WINCODEC_ERR_WRONGSTATE, got %#x\n", hr
);
311 hr
= IWICBitmapDecoder_QueryCapability(decoder
, stream
, &capability
);
312 ok(hr
== WINCODEC_ERR_WRONGSTATE
, "expected WINCODEC_ERR_WRONGSTATE, got %#x\n", hr
);
314 IWICBitmapDecoder_Release(decoder
);
315 IStream_Release(stream
);
318 static void test_tiff_8bpp_alpha(void)
321 IWICBitmapDecoder
*decoder
;
322 IWICBitmapFrameDecode
*frame
;
323 UINT frame_count
, width
, height
, i
;
325 IWICPalette
*palette
;
329 static const BYTE expected_data
[16] = { 0x11,0x11,0x11,0x22,0x33,0x33,0x33,0x44,
330 0x55,0x55,0x55,0x66,0x77,0x77,0x77,0x88 };
332 decoder
= create_decoder(&tiff_8bpp_alpha
, sizeof(tiff_8bpp_alpha
));
333 ok(decoder
!= 0, "Failed to load TIFF image data\n");
334 if (!decoder
) return;
336 hr
= IWICBitmapDecoder_GetFrameCount(decoder
, &frame_count
);
337 ok(hr
== S_OK
, "GetFrameCount error %#x\n", hr
);
338 ok(frame_count
== 1, "expected 1, got %u\n", frame_count
);
340 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &frame
);
341 ok(hr
== S_OK
, "GetFrame error %#x\n", hr
);
343 hr
= IWICBitmapFrameDecode_GetSize(frame
, &width
, &height
);
344 ok(hr
== S_OK
, "GetSize error %#x\n", hr
);
345 ok(width
== 2, "expected 2, got %u\n", width
);
346 ok(height
== 2, "expected 2, got %u\n", height
);
348 hr
= IWICBitmapFrameDecode_GetResolution(frame
, &dpi_x
, &dpi_y
);
349 ok(hr
== S_OK
, "GetResolution error %#x\n", hr
);
350 ok(dpi_x
== 96.0, "expected 96.0, got %f\n", dpi_x
);
351 ok(dpi_y
== 96.0, "expected 96.0, got %f\n", dpi_y
);
353 hr
= IWICBitmapFrameDecode_GetPixelFormat(frame
, &format
);
354 ok(hr
== S_OK
, "GetPixelFormat error %#x\n", hr
);
355 ok(IsEqualGUID(&format
, &GUID_WICPixelFormat32bppPBGRA
),
356 "got wrong format %s\n", wine_dbgstr_guid(&format
));
358 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
359 ok(hr
== S_OK
, "CreatePalette error %#x\n", hr
);
360 hr
= IWICBitmapFrameDecode_CopyPalette(frame
, palette
);
361 ok(hr
== WINCODEC_ERR_PALETTEUNAVAILABLE
,
362 "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %#x\n", hr
);
363 IWICPalette_Release(palette
);
369 hr
= IWICBitmapFrameDecode_CopyPixels(frame
, &rc
, 8, sizeof(data
), data
);
370 ok(hr
== S_OK
, "CopyPixels error %#x\n", hr
);
372 for (i
= 0; i
< sizeof(data
); i
++)
373 ok(data
[i
] == expected_data
[i
], "%u: expected %02x, got %02x\n", i
, expected_data
[i
], data
[i
]);
375 IWICBitmapFrameDecode_Release(frame
);
376 IWICBitmapDecoder_Release(decoder
);
379 START_TEST(tiffformat
)
383 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
385 hr
= CoCreateInstance(&CLSID_WICImagingFactory
, NULL
, CLSCTX_INPROC_SERVER
,
386 &IID_IWICImagingFactory
, (void **)&factory
);
387 ok(hr
== S_OK
, "CoCreateInstance error %#x\n", hr
);
388 if (FAILED(hr
)) return;
391 test_QueryCapability();
392 test_tiff_8bpp_alpha();
394 IWICImagingFactory_Release(factory
);