2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/test.h"
23 static const char jpeg_adobe_cmyk_1x5
[] =
24 "\xff\xd8\xff\xe0\x00\x10\x4a\x46\x49\x46\x00\x01\x01\x01\x01\x2c"
25 "\x01\x2c\x00\x00\xff\xee\x00\x0e\x41\x64\x6f\x62\x65\x00\x64\x00"
26 "\x00\x00\x00\x02\xff\xfe\x00\x13\x43\x72\x65\x61\x74\x65\x64\x20"
27 "\x77\x69\x74\x68\x20\x47\x49\x4d\x50\xff\xdb\x00\x43\x00\x01\x01"
28 "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
29 "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
30 "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
31 "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\xff\xdb"
32 "\x00\x43\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
33 "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
34 "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
35 "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01"
36 "\x01\x01\x01\xff\xc0\x00\x14\x08\x00\x05\x00\x01\x04\x01\x11\x00"
37 "\x02\x11\x01\x03\x11\x01\x04\x11\x00\xff\xc4\x00\x15\x00\x01\x01"
38 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06\x08"
39 "\xff\xc4\x00\x14\x10\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
40 "\x00\x00\x00\x00\x00\x00\xff\xc4\x00\x14\x01\x01\x00\x00\x00\x00"
41 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0a\xff\xc4\x00\x14"
42 "\x11\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
43 "\x00\x00\xff\xda\x00\x0e\x04\x01\x00\x02\x11\x03\x11\x04\x00\x00"
44 "\x3f\x00\x40\x44\x02\x1e\xa4\x1f\xff\xd9";
46 static void test_decode_adobe_cmyk(void)
48 IWICBitmapDecoder
*decoder
;
49 IWICBitmapFrameDecode
*framedecode
;
50 IWICImagingFactory
*factory
;
57 UINT count
=0, width
=0, height
=0;
58 BYTE imagedata
[5 * 4] = {1};
61 const BYTE expected_imagedata
[5 * 4] = {
62 0x00, 0xb0, 0xfc, 0x6d,
63 0x00, 0xb0, 0xfc, 0x6d,
64 0x00, 0xb0, 0xfc, 0x6d,
65 0x00, 0xb0, 0xfc, 0x6d,
66 0x00, 0xb0, 0xfc, 0x6d,
69 const BYTE expected_imagedata_24bpp
[5 * 4] = {
70 0x0d, 0x4b, 0x94, 0x00,
71 0x0d, 0x4b, 0x94, 0x00,
72 0x0d, 0x4b, 0x94, 0x00,
73 0x0d, 0x4b, 0x94, 0x00,
74 0x0d, 0x4b, 0x94, 0x00,
77 hr
= CoCreateInstance(&CLSID_WICJpegDecoder
, NULL
, CLSCTX_INPROC_SERVER
,
78 &IID_IWICBitmapDecoder
, (void**)&decoder
);
79 ok(SUCCEEDED(hr
), "CoCreateInstance failed, hr=%x\n", hr
);
80 if (FAILED(hr
)) return;
82 hr
= CoCreateInstance(&CLSID_WICImagingFactory
, NULL
, CLSCTX_INPROC_SERVER
,
83 &IID_IWICImagingFactory
, (void **)&factory
);
84 ok(SUCCEEDED(hr
), "CoCreateInstance failed, hr=%x\n", hr
);
86 hjpegdata
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(jpeg_adobe_cmyk_1x5
));
87 ok(hjpegdata
!= 0, "GlobalAlloc failed\n");
90 jpegdata
= GlobalLock(hjpegdata
);
91 memcpy(jpegdata
, jpeg_adobe_cmyk_1x5
, sizeof(jpeg_adobe_cmyk_1x5
));
92 GlobalUnlock(hjpegdata
);
94 hr
= CreateStreamOnHGlobal(hjpegdata
, FALSE
, &jpegstream
);
95 ok(SUCCEEDED(hr
), "CreateStreamOnHGlobal failed, hr=%x\n", hr
);
98 hr
= IWICBitmapDecoder_Initialize(decoder
, jpegstream
, WICDecodeMetadataCacheOnLoad
);
99 ok(hr
== S_OK
, "Initialize failed, hr=%x\n", hr
);
101 hr
= IWICBitmapDecoder_GetContainerFormat(decoder
, &guidresult
);
102 ok(SUCCEEDED(hr
), "GetContainerFormat failed, hr=%x\n", hr
);
103 ok(IsEqualGUID(&guidresult
, &GUID_ContainerFormatJpeg
), "unexpected container format\n");
105 hr
= IWICBitmapDecoder_GetFrameCount(decoder
, &count
);
106 ok(SUCCEEDED(hr
), "GetFrameCount failed, hr=%x\n", hr
);
107 ok(count
== 1, "unexpected count %u\n", count
);
109 hr
= IWICBitmapDecoder_GetFrame(decoder
, 0, &framedecode
);
110 ok(SUCCEEDED(hr
), "GetFrame failed, hr=%x\n", hr
);
113 hr
= IWICBitmapFrameDecode_GetSize(framedecode
, &width
, &height
);
114 ok(SUCCEEDED(hr
), "GetSize failed, hr=%x\n", hr
);
115 ok(width
== 1, "expected width=1, got %u\n", width
);
116 ok(height
== 5, "expected height=5, got %u\n", height
);
118 hr
= IWICBitmapFrameDecode_GetPixelFormat(framedecode
, &guidresult
);
119 ok(SUCCEEDED(hr
), "GetPixelFormat failed, hr=%x\n", hr
);
120 ok(IsEqualGUID(&guidresult
, &GUID_WICPixelFormat32bppCMYK
) ||
121 broken(IsEqualGUID(&guidresult
, &GUID_WICPixelFormat24bppBGR
)), /* xp/2003 */
122 "unexpected pixel format: %s\n", wine_dbgstr_guid(&guidresult
));
124 /* We want to be sure our state tracking will not impact output
125 * data on subsequent calls */
128 hr
= IWICBitmapFrameDecode_CopyPixels(framedecode
, NULL
, 4, sizeof(imagedata
), imagedata
);
129 ok(SUCCEEDED(hr
), "CopyPixels failed, hr=%x\n", hr
);
130 ok(!memcmp(imagedata
, expected_imagedata
, sizeof(imagedata
)) ||
131 broken(!memcmp(imagedata
, expected_imagedata_24bpp
, sizeof(expected_imagedata
))), /* xp/2003 */
132 "unexpected image data\n");
135 hr
= IWICImagingFactory_CreatePalette(factory
, &palette
);
136 ok(SUCCEEDED(hr
), "CreatePalette failed, hr=%x\n", hr
);
138 hr
= IWICBitmapDecoder_CopyPalette(decoder
, palette
);
139 ok(hr
== WINCODEC_ERR_PALETTEUNAVAILABLE
, "Unexpected hr %#x.\n", hr
);
141 hr
= IWICBitmapFrameDecode_CopyPalette(framedecode
, palette
);
142 ok(hr
== WINCODEC_ERR_PALETTEUNAVAILABLE
, "Unexpected hr %#x.\n", hr
);
144 IWICPalette_Release(palette
);
146 IWICBitmapFrameDecode_Release(framedecode
);
148 IStream_Release(jpegstream
);
150 GlobalFree(hjpegdata
);
153 IWICBitmapDecoder_Release(decoder
);
154 IWICImagingFactory_Release(factory
);
158 START_TEST(jpegformat
)
160 CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
162 test_decode_adobe_cmyk();