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
26 #include "wine/test.h"
32 #define IFD_RATIONAL 5
34 #define IFD_UNDEFINED 7
37 #define IFD_SRATIONAL 10
56 static const struct tiff_1bpp_data
61 USHORT number_of_entries;
62 struct IFD_entry entry[13];
64 struct IFD_rational res;
68 #ifdef WORDS_BIGENDIAN
74 FIELD_OFFSET(struct tiff_1bpp_data, number_of_entries),
77 { 0xff, IFD_SHORT, 1, 0 }, /* SUBFILETYPE */
78 { 0x100, IFD_LONG, 1, 1 }, /* IMAGEWIDTH */
79 { 0x101, IFD_LONG, 1, 1 }, /* IMAGELENGTH */
80 { 0x102, IFD_SHORT, 1, 1 }, /* BITSPERSAMPLE */
81 { 0x103, IFD_SHORT, 1, 1 }, /* COMPRESSION: XP doesn't accept IFD_LONG here */
82 { 0x106, IFD_SHORT, 1, 1 }, /* PHOTOMETRIC */
83 { 0x111, IFD_LONG, 1, FIELD_OFFSET(struct tiff_1bpp_data, pixel_data) }, /* STRIPOFFSETS */
84 { 0x115, IFD_SHORT, 1, 1 }, /* SAMPLESPERPIXEL */
85 { 0x116, IFD_LONG, 1, 1 }, /* ROWSPERSTRIP */
86 { 0x117, IFD_LONG, 1, 1 }, /* STRIPBYTECOUNT */
87 { 0x11a, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_1bpp_data, res) },
88 { 0x11b, IFD_RATIONAL, 1, FIELD_OFFSET(struct tiff_1bpp_data, res) },
89 { 0x128, IFD_SHORT, 1, 2 }, /* RESOLUTIONUNIT */
93 { 0x11, 0x22, 0x33, 0 }
97 static const char *debugstr_guid(const GUID *guid)
101 if (!guid) return "(null)";
102 sprintf(buf, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
103 guid->Data1, guid->Data2, guid->Data3, guid->Data4[0],
104 guid->Data4[1], guid->Data4[2], guid->Data4[3], guid->Data4[4],
105 guid->Data4[5], guid->Data4[6], guid->Data4[7]);
109 static IWICBitmapDecoder *create_decoder(IWICImagingFactory *factory,
110 const void *image_data, UINT image_size)
115 IWICBitmapDecoder *decoder = NULL;
119 hmem = GlobalAlloc(0, image_size);
120 data = GlobalLock(hmem);
121 memcpy(data, image_data, image_size);
124 hr = CreateStreamOnHGlobal(hmem, TRUE, &stream);
125 ok(hr == S_OK, "CreateStreamOnHGlobal error %#x\n", hr);
127 hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder);
128 ok(hr == S_OK, "CreateDecoderFromStream error %#x\n", hr);
130 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guid);
131 ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
132 ok(IsEqualGUID(&guid, &GUID_ContainerFormatTiff), "container format is not TIFF\n");
134 IStream_Release(stream);
139 static void test_tiff_palette(void)
142 IWICImagingFactory *factory;
143 IWICBitmapDecoder *decoder;
144 IWICBitmapFrameDecode *frame;
145 IWICPalette *palette;
148 hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
149 &IID_IWICImagingFactory, (void **)&factory);
150 ok(hr == S_OK, "CoCreateInstance error %#x\n", hr);
151 if (FAILED(hr)) return;
153 decoder = create_decoder(factory, &tiff_1bpp_data, sizeof(tiff_1bpp_data));
154 ok(decoder != 0, "Failed to load TIFF image data\n");
155 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
156 ok(hr == S_OK, "GetFrame error %#x\n", hr);
158 hr = IWICBitmapFrameDecode_GetPixelFormat(frame, &format);
159 ok(hr == S_OK, "GetPixelFormat error %#x\n", hr);
160 ok(IsEqualGUID(&format, &GUID_WICPixelFormatBlackWhite),
161 "got wrong format %s\n", debugstr_guid(&format));
163 hr = IWICImagingFactory_CreatePalette(factory, &palette);
164 ok(hr == S_OK, "CreatePalette error %#x\n", hr);
165 hr = IWICBitmapFrameDecode_CopyPalette(frame, palette);
166 ok(hr == WINCODEC_ERR_PALETTEUNAVAILABLE,
167 "expected WINCODEC_ERR_PALETTEUNAVAILABLE, got %#x\n", hr);
169 IWICPalette_Release(palette);
170 IWICBitmapFrameDecode_Release(frame);
171 IWICBitmapDecoder_Release(decoder);
172 IWICImagingFactory_Release(factory);
175 START_TEST(tiffformat)
177 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);