ReactOS 0.4.16-dev-125-g798ea90
pngformat.c File Reference
#include "config.h"
#include "wine/port.h"
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "objbase.h"
#include "wincodecs_private.h"
#include "wine/debug.h"
#include "wine/library.h"
Include dependency graph for pngformat.c:

Go to the source code of this file.

Macros

#define NONAMELESSUNION
 
#define COBJMACROS
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (wincodecs)
 
static ULONG read_ulong_be (BYTE *data)
 
static HRESULT read_png_chunk (IStream *stream, BYTE *type, BYTE **data, ULONG *data_size)
 
static HRESULT LoadTextMetadata (IStream *stream, const GUID *preferred_vendor, DWORD persist_options, MetadataItem **items, DWORD *item_count)
 
HRESULT PngTextReader_CreateInstance (REFIID iid, void **ppv)
 
static HRESULT LoadGamaMetadata (IStream *stream, const GUID *preferred_vendor, DWORD persist_options, MetadataItem **items, DWORD *item_count)
 
HRESULT PngGamaReader_CreateInstance (REFIID iid, void **ppv)
 
static HRESULT LoadChrmMetadata (IStream *stream, const GUID *preferred_vendor, DWORD persist_options, MetadataItem **items, DWORD *item_count)
 
HRESULT PngChrmReader_CreateInstance (REFIID iid, void **ppv)
 
HRESULT PngDecoder_CreateInstance (REFIID iid, void **ppv)
 
HRESULT PngEncoder_CreateInstance (REFIID iid, void **ppv)
 

Variables

static const MetadataHandlerVtbl TextReader_Vtbl
 
static const MetadataHandlerVtbl GamaReader_Vtbl
 
static const MetadataHandlerVtbl ChrmReader_Vtbl
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 30 of file pngformat.c.

◆ NONAMELESSUNION

#define NONAMELESSUNION

Definition at line 29 of file pngformat.c.

Function Documentation

◆ LoadChrmMetadata()

static HRESULT LoadChrmMetadata ( IStream stream,
const GUID preferred_vendor,
DWORD  persist_options,
MetadataItem **  items,
DWORD item_count 
)
static

Definition at line 222 of file pngformat.c.

224{
225 HRESULT hr;
226 BYTE type[4];
227 BYTE *data;
228 ULONG data_size;
229 static const WCHAR names[8][12] = {
230 {'W','h','i','t','e','P','o','i','n','t','X',0},
231 {'W','h','i','t','e','P','o','i','n','t','Y',0},
232 {'R','e','d','X',0},
233 {'R','e','d','Y',0},
234 {'G','r','e','e','n','X',0},
235 {'G','r','e','e','n','Y',0},
236 {'B','l','u','e','X',0},
237 {'B','l','u','e','Y',0},
238 };
239 LPWSTR dyn_names[8] = {0};
241 int i;
242
243 hr = read_png_chunk(stream, type, &data, &data_size);
244 if (FAILED(hr)) return hr;
245
246 if (data_size < 32)
247 {
249 return E_FAIL;
250 }
251
253 for (i=0; i<8; i++)
254 {
255 dyn_names[i] = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(lstrlenW(names[i])+1));
256 if (!dyn_names[i]) break;
257 }
258 if (!result || i < 8)
259 {
261 for (i=0; i<8; i++)
262 HeapFree(GetProcessHeap(), 0, dyn_names[i]);
264 return E_OUTOFMEMORY;
265 }
266
267 for (i=0; i<8; i++)
268 {
269 PropVariantInit(&result[i].schema);
270
271 PropVariantInit(&result[i].id);
272 result[i].id.vt = VT_LPWSTR;
273 result[i].id.u.pwszVal = dyn_names[i];
274 lstrcpyW(dyn_names[i], names[i]);
275
276 PropVariantInit(&result[i].value);
277 result[i].value.vt = VT_UI4;
278 result[i].value.u.ulVal = read_ulong_be(&data[i*4]);
279 }
280
281 *items = result;
282 *item_count = 8;
283
285
286 return S_OK;
287}
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_FAIL
Definition: ddrawi.h:102
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define lstrcpyW
Definition: compat.h:749
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
@ VT_LPWSTR
Definition: compat.h:2325
@ VT_UI4
Definition: compat.h:2313
#define lstrlenW
Definition: compat.h:750
static HRESULT read_png_chunk(IStream *stream, BYTE *type, BYTE **data, ULONG *data_size)
Definition: pngformat.c:48
static ULONG read_ulong_be(BYTE *data)
Definition: pngformat.c:43
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLuint GLuint * names
Definition: glext.h:11545
GLuint64EXT * result
Definition: glext.h:11304
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
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
const WCHAR * schema
static TCHAR * items[]
Definition: page1.c:45
HRESULT hr
Definition: shlfolder.c:183
Definition: parse.h:23
uint32_t ULONG
Definition: typedefs.h:59
Definition: pdh_main.c:94
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
unsigned char BYTE
Definition: xxhash.c:193

◆ LoadGamaMetadata()

static HRESULT LoadGamaMetadata ( IStream stream,
const GUID preferred_vendor,
DWORD  persist_options,
MetadataItem **  items,
DWORD item_count 
)
static

Definition at line 160 of file pngformat.c.

162{
163 HRESULT hr;
164 BYTE type[4];
165 BYTE *data;
166 ULONG data_size;
167 ULONG gamma;
168 static const WCHAR ImageGamma[] = {'I','m','a','g','e','G','a','m','m','a',0};
169 LPWSTR name;
171
172 hr = read_png_chunk(stream, type, &data, &data_size);
173 if (FAILED(hr)) return hr;
174
175 if (data_size < 4)
176 {
178 return E_FAIL;
179 }
180
181 gamma = read_ulong_be(data);
182
184
186 name = HeapAlloc(GetProcessHeap(), 0, sizeof(ImageGamma));
187 if (!result || !name)
188 {
191 return E_OUTOFMEMORY;
192 }
193
194 PropVariantInit(&result[0].schema);
195 PropVariantInit(&result[0].id);
196 PropVariantInit(&result[0].value);
197
198 memcpy(name, ImageGamma, sizeof(ImageGamma));
199
200 result[0].id.vt = VT_LPWSTR;
201 result[0].id.u.pwszVal = name;
202 result[0].value.vt = VT_UI4;
203 result[0].value.u.ulVal = gamma;
204
205 *items = result;
206 *item_count = 1;
207
208 return S_OK;
209}
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
Definition: name.c:39

◆ LoadTextMetadata()

static HRESULT LoadTextMetadata ( IStream stream,
const GUID preferred_vendor,
DWORD  persist_options,
MetadataItem **  items,
DWORD item_count 
)
static

Definition at line 89 of file pngformat.c.

91{
92 HRESULT hr;
93 BYTE type[4];
94 BYTE *data;
95 ULONG data_size;
96 ULONG name_len, value_len;
97 BYTE *name_end_ptr;
100
101 hr = read_png_chunk(stream, type, &data, &data_size);
102 if (FAILED(hr)) return hr;
103
104 name_end_ptr = memchr(data, 0, data_size);
105
106 name_len = name_end_ptr - data;
107
108 if (!name_end_ptr || name_len > 79)
109 {
111 return E_FAIL;
112 }
113
114 value_len = data_size - name_len - 1;
115
117 name = HeapAlloc(GetProcessHeap(), 0, name_len + 1);
118 value = HeapAlloc(GetProcessHeap(), 0, value_len + 1);
119 if (!result || !name || !value)
120 {
125 return E_OUTOFMEMORY;
126 }
127
128 PropVariantInit(&result[0].schema);
129 PropVariantInit(&result[0].id);
130 PropVariantInit(&result[0].value);
131
132 memcpy(name, data, name_len + 1);
133 memcpy(value, name_end_ptr + 1, value_len);
134 value[value_len] = 0;
135
136 result[0].id.vt = VT_LPSTR;
137 result[0].id.u.pszVal = name;
138 result[0].value.vt = VT_LPSTR;
139 result[0].value.u.pszVal = value;
140
141 *items = result;
142 *item_count = 1;
143
145
146 return S_OK;
147}
@ VT_LPSTR
Definition: compat.h:2324
#define memchr(s, c, n)
Definition: mkisofs.h:875
char * LPSTR
Definition: xmlstorage.h:182

◆ PngChrmReader_CreateInstance()

HRESULT PngChrmReader_CreateInstance ( REFIID  iid,
void **  ppv 
)

Definition at line 295 of file pngformat.c.

296{
298}
static const MetadataHandlerVtbl ChrmReader_Vtbl
Definition: pngformat.c:289
REFIID LPVOID * ppv
Definition: atlbase.h:39
HRESULT MetadataReader_Create(const MetadataHandlerVtbl *vtable, REFIID iid, void **ppv)

◆ PngDecoder_CreateInstance()

HRESULT PngDecoder_CreateInstance ( REFIID  iid,
void **  ppv 
)

Definition at line 2188 of file pngformat.c.

2189{
2190 ERR("Trying to load PNG picture, but PNG support is not compiled in.\n");
2191 return E_FAIL;
2192}
#define ERR(fmt,...)
Definition: precomp.h:57

Referenced by ReadIcoPng().

◆ PngEncoder_CreateInstance()

HRESULT PngEncoder_CreateInstance ( REFIID  iid,
void **  ppv 
)

Definition at line 2194 of file pngformat.c.

2195{
2196 ERR("Trying to save PNG picture, but PNG support is not compiled in.\n");
2197 return E_FAIL;
2198}

◆ PngGamaReader_CreateInstance()

HRESULT PngGamaReader_CreateInstance ( REFIID  iid,
void **  ppv 
)

Definition at line 217 of file pngformat.c.

218{
220}
static const MetadataHandlerVtbl GamaReader_Vtbl
Definition: pngformat.c:211

◆ PngTextReader_CreateInstance()

HRESULT PngTextReader_CreateInstance ( REFIID  iid,
void **  ppv 
)

Definition at line 155 of file pngformat.c.

156{
158}
static const MetadataHandlerVtbl TextReader_Vtbl
Definition: pngformat.c:149

◆ read_png_chunk()

static HRESULT read_png_chunk ( IStream stream,
BYTE type,
BYTE **  data,
ULONG data_size 
)
static

Definition at line 48 of file pngformat.c.

49{
50 BYTE header[8];
51 HRESULT hr;
52 ULONG bytesread;
53
54 hr = IStream_Read(stream, header, 8, &bytesread);
55 if (FAILED(hr) || bytesread < 8)
56 {
57 if (SUCCEEDED(hr))
58 hr = E_FAIL;
59 return hr;
60 }
61
62 *data_size = read_ulong_be(&header[0]);
63
64 memcpy(type, &header[4], 4);
65
66 if (data)
67 {
68 *data = HeapAlloc(GetProcessHeap(), 0, *data_size);
69 if (!*data)
70 return E_OUTOFMEMORY;
71
72 hr = IStream_Read(stream, *data, *data_size, &bytesread);
73
74 if (FAILED(hr) || bytesread < *data_size)
75 {
76 if (SUCCEEDED(hr))
77 hr = E_FAIL;
79 *data = NULL;
80 return hr;
81 }
82
83 /* Windows ignores CRC of the chunk */
84 }
85
86 return S_OK;
87}
#define NULL
Definition: types.h:112
#define SUCCEEDED(hr)
Definition: intsafe.h:50

Referenced by LoadChrmMetadata(), LoadGamaMetadata(), and LoadTextMetadata().

◆ read_ulong_be()

static ULONG read_ulong_be ( BYTE data)
inlinestatic

Definition at line 43 of file pngformat.c.

44{
45 return data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
46}

Referenced by LoadChrmMetadata(), LoadGamaMetadata(), and read_png_chunk().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( wincodecs  )

Variable Documentation

◆ ChrmReader_Vtbl

const MetadataHandlerVtbl ChrmReader_Vtbl
static
Initial value:
= {
0,
&CLSID_WICPngChrmMetadataReader,
}
static HRESULT LoadChrmMetadata(IStream *stream, const GUID *preferred_vendor, DWORD persist_options, MetadataItem **items, DWORD *item_count)
Definition: pngformat.c:222

Definition at line 289 of file pngformat.c.

Referenced by PngChrmReader_CreateInstance().

◆ GamaReader_Vtbl

const MetadataHandlerVtbl GamaReader_Vtbl
static
Initial value:
= {
0,
&CLSID_WICPngGamaMetadataReader,
}
static HRESULT LoadGamaMetadata(IStream *stream, const GUID *preferred_vendor, DWORD persist_options, MetadataItem **items, DWORD *item_count)
Definition: pngformat.c:160

Definition at line 211 of file pngformat.c.

Referenced by PngGamaReader_CreateInstance().

◆ TextReader_Vtbl

const MetadataHandlerVtbl TextReader_Vtbl
static
Initial value:
= {
0,
&CLSID_WICPngTextMetadataReader,
}
static HRESULT LoadTextMetadata(IStream *stream, const GUID *preferred_vendor, DWORD persist_options, MetadataItem **items, DWORD *item_count)
Definition: pngformat.c:89

Definition at line 149 of file pngformat.c.

Referenced by PngTextReader_CreateInstance().