ReactOS 0.4.16-dev-983-g23ad936
wincodecs_common.c File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winternl.h"
#include "objbase.h"
#include "wincodecs_private.h"
#include "wine/debug.h"
#include "wincodecs_common.h"
Include dependency graph for wincodecs_common.c:

Go to the source code of this file.

Macros

#define COBJMACROS
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (wincodecs)
 
HRESULT configure_write_source (IWICBitmapFrameEncode *iface, IWICBitmapSource *source, const WICRect *prc, const WICPixelFormatGUID *format, INT width, INT height, double xres, double yres)
 
HRESULT write_source (IWICBitmapFrameEncode *iface, IWICBitmapSource *source, const WICRect *prc, const WICPixelFormatGUID *format, UINT bpp, BOOL need_palette, INT width, INT height)
 
HRESULT CDECL stream_getsize (IStream *stream, ULONGLONG *size)
 
HRESULT CDECL stream_read (IStream *stream, void *buffer, ULONG read, ULONG *bytes_read)
 
HRESULT CDECL stream_seek (IStream *stream, LONGLONG ofs, DWORD origin, ULONGLONG *new_position)
 
HRESULT CDECL stream_write (IStream *stream, const void *buffer, ULONG write, ULONG *bytes_written)
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 21 of file wincodecs_common.c.

Function Documentation

◆ configure_write_source()

HRESULT configure_write_source ( IWICBitmapFrameEncode iface,
IWICBitmapSource source,
const WICRect prc,
const WICPixelFormatGUID format,
INT  width,
INT  height,
double  xres,
double  yres 
)

Definition at line 38 of file wincodecs_common.c.

42{
43 UINT src_width, src_height;
44 HRESULT hr = S_OK;
45
46 if (width == 0 && height == 0)
47 {
48 if (prc)
49 {
50 if (prc->Width <= 0 || prc->Height <= 0) return E_INVALIDARG;
51 width = prc->Width;
52 height = prc->Height;
53 }
54 else
55 {
56 hr = IWICBitmapSource_GetSize(source, &src_width, &src_height);
57 if (FAILED(hr)) return hr;
58 if (src_width == 0 || src_height == 0) return E_INVALIDARG;
59 width = src_width;
60 height = src_height;
61 }
62 hr = IWICBitmapFrameEncode_SetSize(iface, (UINT)width, (UINT)height);
63 if (FAILED(hr)) return hr;
64 }
65 if (width == 0 || height == 0) return E_INVALIDARG;
66
67 if (!format)
68 {
69 WICPixelFormatGUID src_format;
70
71 hr = IWICBitmapSource_GetPixelFormat(source, &src_format);
72 if (FAILED(hr)) return hr;
73
74 hr = IWICBitmapFrameEncode_SetPixelFormat(iface, &src_format);
75 if (FAILED(hr)) return hr;
76 }
77
78 if (xres == 0.0 || yres == 0.0)
79 {
80 hr = IWICBitmapSource_GetResolution(source, &xres, &yres);
81 if (FAILED(hr)) return hr;
82 hr = IWICBitmapFrameEncode_SetResolution(iface, xres, yres);
83 if (FAILED(hr)) return hr;
84 }
85
86 return hr;
87}
#define E_INVALIDARG
Definition: ddrawi.h:101
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
unsigned int UINT
Definition: ndis.h:50
_Out_ LPRECT prc
Definition: ntgdi.h:1658
HRESULT hr
Definition: shlfolder.c:183
Definition: format.c:58

Referenced by BmpFrameEncode_WriteSource(), CommonEncoderFrame_WriteSource(), and GifFrameEncode_WriteSource().

◆ stream_getsize()

HRESULT CDECL stream_getsize ( IStream stream,
ULONGLONG size 
)

Definition at line 176 of file wincodecs_common.c.

177{
178 STATSTG statstg;
179 HRESULT hr;
180
181 hr = IStream_Stat(stream, &statstg, STATFLAG_NONAME);
182
183 if (SUCCEEDED(hr))
184 *size = statstg.cbSize.QuadPart;
185
186 return hr;
187}
GLsizeiptr size
Definition: glext.h:5919
#define SUCCEEDED(hr)
Definition: intsafe.h:50
Definition: parse.h:23

Referenced by tiff_stream_size().

◆ stream_read()

HRESULT CDECL stream_read ( IStream stream,
void buffer,
ULONG  read,
ULONG bytes_read 
)

Definition at line 189 of file wincodecs_common.c.

190{
191 return IStream_Read(stream, buffer, read, bytes_read);
192}
#define read
Definition: acwin.h:96
GLuint buffer
Definition: glext.h:5915

◆ stream_seek()

HRESULT CDECL stream_seek ( IStream stream,
LONGLONG  ofs,
DWORD  origin,
ULONGLONG new_position 
)

Definition at line 194 of file wincodecs_common.c.

195{
196 HRESULT hr;
197 LARGE_INTEGER ofs_large;
198 ULARGE_INTEGER pos_large;
199
200 ofs_large.QuadPart = ofs;
201 hr = IStream_Seek(stream, ofs_large, origin, &pos_large);
202 if (new_position)
203 *new_position = pos_large.QuadPart;
204
205 return hr;
206}
voidpf uLong int origin
Definition: ioapi.h:144
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by jpeg_decoder_initialize(), png_decoder_get_metadata_blocks(), png_decoder_initialize(), source_mgr_skip_input_data(), tiff_open_stream(), and tiff_stream_seek().

◆ stream_write()

HRESULT CDECL stream_write ( IStream stream,
const void buffer,
ULONG  write,
ULONG bytes_written 
)

Definition at line 208 of file wincodecs_common.c.

209{
210 return IStream_Write(stream, buffer, write, bytes_written);
211}
#define write
Definition: acwin.h:97

Referenced by dest_mgr_empty_output_buffer(), dest_mgr_term_destination(), tiff_stream_write(), and user_write_data().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( wincodecs  )

◆ write_source()

HRESULT write_source ( IWICBitmapFrameEncode iface,
IWICBitmapSource source,
const WICRect prc,
const WICPixelFormatGUID format,
UINT  bpp,
BOOL  need_palette,
INT  width,
INT  height 
)

Definition at line 89 of file wincodecs_common.c.

93{
94 IWICBitmapSource *converted_source;
96 WICRect rc;
98 BYTE* pixeldata;
99
100 if (!prc)
101 {
102 UINT src_width, src_height;
103 hr = IWICBitmapSource_GetSize(source, &src_width, &src_height);
104 if (FAILED(hr)) return hr;
105 rc.X = 0;
106 rc.Y = 0;
107 rc.Width = src_width;
108 rc.Height = src_height;
109 prc = &rc;
110 }
111
112 if (prc->Width != width || prc->Height <= 0)
113 return E_INVALIDARG;
114
115 hr = WICConvertBitmapSource(format, source, &converted_source);
116 if (FAILED(hr))
117 {
118 ERR("Failed to convert source, target format %s, %#lx\n", debugstr_guid(format), hr);
119 return E_NOTIMPL;
120 }
121
122 if (need_palette)
123 {
126
127 hr = create_instance(&CLSID_WICImagingFactory, &IID_IWICImagingFactory, (void**)&factory);
128
129 if (SUCCEEDED(hr))
130 {
131 hr = IWICImagingFactory_CreatePalette(factory, &palette);
132 IWICImagingFactory_Release(factory);
133 }
134
135 if (SUCCEEDED(hr))
136 {
137 hr = IWICBitmapSource_CopyPalette(converted_source, palette);
138
139 if (SUCCEEDED(hr))
140 hr = IWICBitmapFrameEncode_SetPalette(iface, palette);
141
142 IWICPalette_Release(palette);
143 }
144
145 if (FAILED(hr))
146 {
147 IWICBitmapSource_Release(converted_source);
148 return hr;
149 }
150 }
151
152 stride = (bpp * width + 7)/8;
153
154 pixeldata = malloc(stride * prc->Height);
155 if (!pixeldata)
156 {
157 IWICBitmapSource_Release(converted_source);
158 return E_OUTOFMEMORY;
159 }
160
161 hr = IWICBitmapSource_CopyPixels(converted_source, prc, stride,
162 stride*prc->Height, pixeldata);
163
164 if (SUCCEEDED(hr))
165 {
166 hr = IWICBitmapFrameEncode_WritePixels(iface, prc->Height, stride,
167 stride*prc->Height, pixeldata);
168 }
169
170 free(pixeldata);
171 IWICBitmapSource_Release(converted_source);
172
173 return hr;
174}
#define ERR(fmt,...)
Definition: precomp.h:57
HRESULT create_instance(const CLSID *clsid, const IID *iid, void **ppv)
Definition: clsfactory.c:212
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_NOTIMPL
Definition: ddrawi.h:99
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
DWORD bpp
Definition: surface.c:185
HRESULT WINAPI WICConvertBitmapSource(REFWICPixelFormatGUID dstFormat, IWICBitmapSource *pISrc, IWICBitmapSource **ppIDst)
Definition: info.c:2437
GLsizei stride
Definition: glext.h:5848
#define debugstr_guid
Definition: kernel32.h:35
static HPALETTE palette
Definition: clipboard.c:1345
INT Height
Definition: wincodec.idl:335
INT Width
Definition: wincodec.idl:334
Definition: main.c:439
unsigned char BYTE
Definition: xxhash.c:193

Referenced by BmpFrameEncode_WriteSource(), CommonEncoderFrame_WriteSource(), and GifFrameEncode_WriteSource().