ReactOS 0.4.15-dev-8119-g4fb2fdb
jpegformat.c
Go to the documentation of this file.
1/*
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.
6 *
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.
11 *
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
15 */
16
17#define COBJMACROS
18
19#include "objbase.h"
20#include "wincodec.h"
21#include "wine/test.h"
22
23static 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";
45
46static void test_decode_adobe_cmyk(void)
47{
48 IWICBitmapDecoder *decoder;
49 IWICBitmapFrameDecode *framedecode;
50 HRESULT hr;
51 HGLOBAL hjpegdata;
52 char *jpegdata;
53 IStream *jpegstream;
54 GUID guidresult;
55 UINT count=0, width=0, height=0;
56 BYTE imagedata[5 * 4] = {1};
57 UINT i;
58
59 const BYTE expected_imagedata[5 * 4] = {
60 0x00, 0xb0, 0xfc, 0x6d,
61 0x00, 0xb0, 0xfc, 0x6d,
62 0x00, 0xb0, 0xfc, 0x6d,
63 0x00, 0xb0, 0xfc, 0x6d,
64 0x00, 0xb0, 0xfc, 0x6d,
65 };
66
67 const BYTE expected_imagedata_24bpp[5 * 4] = {
68 0x0d, 0x4b, 0x94, 0x00,
69 0x0d, 0x4b, 0x94, 0x00,
70 0x0d, 0x4b, 0x94, 0x00,
71 0x0d, 0x4b, 0x94, 0x00,
72 0x0d, 0x4b, 0x94, 0x00,
73 };
74
75 hr = CoCreateInstance(&CLSID_WICJpegDecoder, NULL, CLSCTX_INPROC_SERVER,
76 &IID_IWICBitmapDecoder, (void**)&decoder);
77 ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr);
78 if (FAILED(hr)) return;
79
80 hjpegdata = GlobalAlloc(GMEM_MOVEABLE, sizeof(jpeg_adobe_cmyk_1x5));
81 ok(hjpegdata != 0, "GlobalAlloc failed\n");
82 if (hjpegdata)
83 {
84 jpegdata = GlobalLock(hjpegdata);
86 GlobalUnlock(hjpegdata);
87
88 hr = CreateStreamOnHGlobal(hjpegdata, FALSE, &jpegstream);
89 ok(SUCCEEDED(hr), "CreateStreamOnHGlobal failed, hr=%x\n", hr);
90 if (SUCCEEDED(hr))
91 {
92 hr = IWICBitmapDecoder_Initialize(decoder, jpegstream, WICDecodeMetadataCacheOnLoad);
93 ok(hr == S_OK, "Initialize failed, hr=%x\n", hr);
94
95 hr = IWICBitmapDecoder_GetContainerFormat(decoder, &guidresult);
96 ok(SUCCEEDED(hr), "GetContainerFormat failed, hr=%x\n", hr);
97 ok(IsEqualGUID(&guidresult, &GUID_ContainerFormatJpeg), "unexpected container format\n");
98
99 hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
100 ok(SUCCEEDED(hr), "GetFrameCount failed, hr=%x\n", hr);
101 ok(count == 1, "unexpected count %u\n", count);
102
103 hr = IWICBitmapDecoder_GetFrame(decoder, 0, &framedecode);
104 ok(SUCCEEDED(hr), "GetFrame failed, hr=%x\n", hr);
105 if (SUCCEEDED(hr))
106 {
107 hr = IWICBitmapFrameDecode_GetSize(framedecode, &width, &height);
108 ok(SUCCEEDED(hr), "GetSize failed, hr=%x\n", hr);
109 ok(width == 1, "expected width=1, got %u\n", width);
110 ok(height == 5, "expected height=5, got %u\n", height);
111
112 hr = IWICBitmapFrameDecode_GetPixelFormat(framedecode, &guidresult);
113 ok(SUCCEEDED(hr), "GetPixelFormat failed, hr=%x\n", hr);
114 ok(IsEqualGUID(&guidresult, &GUID_WICPixelFormat32bppCMYK) ||
115 broken(IsEqualGUID(&guidresult, &GUID_WICPixelFormat24bppBGR)), /* xp/2003 */
116 "unexpected pixel format: %s\n", wine_dbgstr_guid(&guidresult));
117
118 /* We want to be sure our state tracking will not impact output
119 * data on subsequent calls */
120 for(i=2; i>0; --i)
121 {
122 hr = IWICBitmapFrameDecode_CopyPixels(framedecode, NULL, 4, sizeof(imagedata), imagedata);
123 ok(SUCCEEDED(hr), "CopyPixels failed, hr=%x\n", hr);
124 ok(!memcmp(imagedata, expected_imagedata, sizeof(imagedata)) ||
125 broken(!memcmp(imagedata, expected_imagedata_24bpp, sizeof(expected_imagedata))), /* xp/2003 */
126 "unexpected image data\n");
127 }
128 IWICBitmapFrameDecode_Release(framedecode);
129 }
130 IStream_Release(jpegstream);
131 }
132 GlobalFree(hjpegdata);
133 }
134 IWICBitmapDecoder_Release(decoder);
135}
136
137
138START_TEST(jpegformat)
139{
141
143
145}
#define broken(x)
Definition: _sntprintf.h:21
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:2002
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
HRESULT WINAPI CreateStreamOnHGlobal(HGLOBAL hGlobal, BOOL fDeleteOnRelease, LPSTREAM *ppstm)
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static const char jpeg_adobe_cmyk_1x5[]
Definition: jpegformat.c:23
static void test_decode_adobe_cmyk(void)
Definition: jpegformat.c:46
unsigned int UINT
Definition: ndis.h:50
@ COINIT_APARTMENTTHREADED
Definition: objbase.h:278
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
static __inline const char * wine_dbgstr_guid(const GUID *id)
Definition: debug.h:197
HRESULT hr
Definition: shlfolder.c:183
#define GMEM_MOVEABLE
Definition: winbase.h:294
@ WICDecodeMetadataCacheOnLoad
Definition: wincodec.idl:29
unsigned char BYTE
Definition: xxhash.c:193