ReactOS 0.4.16-dev-197-g92996da
main.c File Reference
#include "config.h"
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "objbase.h"
#include "wincodecs_private.h"
#include "wine/debug.h"
Include dependency graph for main.c:

Go to the source code of this file.

Macros

#define COBJMACROS
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (wincodecs)
 
BOOL WINAPI WIC_DllMain (HINSTANCE, DWORD, LPVOID)
 
HRESULT WINAPI DllCanUnloadNow (void)
 
HRESULT copy_pixels (UINT bpp, const BYTE *srcbuffer, UINT srcwidth, UINT srcheight, INT srcstride, const WICRect *rc, UINT dststride, UINT dstbuffersize, BYTE *dstbuffer)
 
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, INT width, INT height)
 
void reverse_bgr8 (UINT bytesperpixel, LPBYTE bits, UINT width, UINT height, INT stride)
 
void convert_rgba_to_bgra (UINT bytesperpixel, LPBYTE bits, UINT width, UINT height, INT stride)
 
HRESULT get_pixelformat_bpp (const GUID *pixelformat, UINT *bpp)
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 20 of file main.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 123 of file main.c.

127{
128 HRESULT hr = S_OK;
129
130 if (width == 0 || height == 0)
132
133 if (!format)
134 {
135 WICPixelFormatGUID src_format;
136
137 hr = IWICBitmapSource_GetPixelFormat(source, &src_format);
138 if (FAILED(hr)) return hr;
139
140 hr = IWICBitmapFrameEncode_SetPixelFormat(iface, &src_format);
141 if (FAILED(hr)) return hr;
142 }
143
144 if (xres == 0.0 || yres == 0.0)
145 {
146 hr = IWICBitmapSource_GetResolution(source, &xres, &yres);
147 if (FAILED(hr)) return hr;
148 hr = IWICBitmapFrameEncode_SetResolution(iface, xres, yres);
149 if (FAILED(hr)) return hr;
150 }
151
152 return hr;
153}
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
HRESULT hr
Definition: shlfolder.c:183
Definition: format.c:58
#define WINCODEC_ERR_WRONGSTATE
Definition: winerror.h:3281

Referenced by BmpFrameEncode_WriteSource(), and GifFrameEncode_WriteSource().

◆ convert_rgba_to_bgra()

void convert_rgba_to_bgra ( UINT  bytesperpixel,
LPBYTE  bits,
UINT  width,
UINT  height,
INT  stride 
)

Definition at line 231 of file main.c.

232{
233 UINT x, y;
234 BYTE *pixel, temp;
235
236 for (y=0; y<height; y++)
237 {
238 pixel = bits + stride * y;
239
240 for (x=0; x<width; x++)
241 {
242 temp = pixel[3];
243 pixel[3] = pixel[0];
244 pixel[0] = pixel[1];
245 pixel[1] = pixel[2];
246 pixel[2] = temp;
247 pixel += bytesperpixel;
248 }
249 }
250}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLsizei stride
Definition: glext.h:5848
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
Definition: glext.h:10929
unsigned int UINT
Definition: ndis.h:50
static calc_node_t temp
Definition: rpn_ieee.c:38
unsigned char BYTE
Definition: xxhash.c:193

Referenced by copypixels_to_32bppBGRA().

◆ copy_pixels()

HRESULT copy_pixels ( UINT  bpp,
const BYTE srcbuffer,
UINT  srcwidth,
UINT  srcheight,
INT  srcstride,
const WICRect rc,
UINT  dststride,
UINT  dstbuffersize,
BYTE dstbuffer 
)

Definition at line 58 of file main.c.

61{
62 UINT bytesperrow;
63 UINT row_offset; /* number of bits into the source rows where the data starts */
65
66 if (!rc)
67 {
68 rect.X = 0;
69 rect.Y = 0;
70 rect.Width = srcwidth;
71 rect.Height = srcheight;
72 rc = &rect;
73 }
74 else
75 {
76 if (rc->X < 0 || rc->Y < 0 || rc->X+rc->Width > srcwidth || rc->Y+rc->Height > srcheight)
77 return E_INVALIDARG;
78 }
79
80 bytesperrow = ((bpp * rc->Width)+7)/8;
81
82 if (dststride < bytesperrow)
83 return E_INVALIDARG;
84
85 if ((dststride * (rc->Height-1)) + bytesperrow > dstbuffersize)
86 return E_INVALIDARG;
87
88 /* if the whole bitmap is copied and the buffer format matches then it's a matter of a single memcpy */
89 if (rc->X == 0 && rc->Y == 0 && rc->Width == srcwidth && rc->Height == srcheight &&
90 srcstride == dststride && srcstride == bytesperrow)
91 {
92 memcpy(dstbuffer, srcbuffer, srcstride * srcheight);
93 return S_OK;
94 }
95
96 row_offset = rc->X * bpp;
97
98 if (row_offset % 8 == 0)
99 {
100 /* everything lines up on a byte boundary */
101 INT row;
102 const BYTE *src;
103 BYTE *dst;
104
105 src = srcbuffer + (row_offset / 8) + srcstride * rc->Y;
106 dst = dstbuffer;
107 for (row=0; row < rc->Height; row++)
108 {
109 memcpy(dst, src, bytesperrow);
110 src += srcstride;
111 dst += dststride;
112 }
113 return S_OK;
114 }
115 else
116 {
117 /* we have to do a weird bitwise copy. eww. */
118 FIXME("cannot reliably copy bitmap data if bpp < 8\n");
119 return E_FAIL;
120 }
121}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_FAIL
Definition: ddrawi.h:102
DWORD bpp
Definition: surface.c:185
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:78
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define for
Definition: utility.h:88
& rect
Definition: startmenu.cpp:1413
INT Height
Definition: wincodec.idl:301
INT Width
Definition: wincodec.idl:300
int32_t INT
Definition: typedefs.h:58

◆ DllCanUnloadNow()

HRESULT WINAPI DllCanUnloadNow ( void  )

Definition at line 53 of file main.c.

54{
55 return S_FALSE;
56}
#define S_FALSE
Definition: winerror.h:2357

◆ get_pixelformat_bpp()

HRESULT get_pixelformat_bpp ( const GUID pixelformat,
UINT bpp 
)

Definition at line 252 of file main.c.

253{
254 HRESULT hr;
256 IWICPixelFormatInfo *formatinfo;
257
259 if (SUCCEEDED(hr))
260 {
261 hr = IWICComponentInfo_QueryInterface(info, &IID_IWICPixelFormatInfo, (void**)&formatinfo);
262
263 if (SUCCEEDED(hr))
264 {
265 hr = IWICPixelFormatInfo_GetBitsPerPixel(formatinfo, bpp);
266
267 IWICPixelFormatInfo_Release(formatinfo);
268 }
269
270 IWICComponentInfo_Release(info);
271 }
272
273 return hr;
274}
pixelformat
Definition: converter.c:40
HRESULT CreateComponentInfo(REFCLSID clsid, IWICComponentInfo **ppIInfo)
Definition: info.c:2075
#define SUCCEEDED(hr)
Definition: intsafe.h:50

Referenced by BitmapImpl_Create(), BitmapScaler_Initialize(), FormatConverter_CopyPalette(), FormatConverter_Initialize(), and WICCreateBitmapFromSectionEx().

◆ reverse_bgr8()

void reverse_bgr8 ( UINT  bytesperpixel,
LPBYTE  bits,
UINT  width,
UINT  height,
INT  stride 
)

Definition at line 212 of file main.c.

213{
214 UINT x, y;
215 BYTE *pixel, temp;
216
217 for (y=0; y<height; y++)
218 {
219 pixel = bits + stride * y;
220
221 for (x=0; x<width; x++)
222 {
223 temp = pixel[2];
224 pixel[2] = pixel[0];
225 pixel[0] = temp;
226 pixel += bytesperpixel;
227 }
228 }
229}

Referenced by BmpFrameDecode_ReadRGB8(), copypixels_to_24bppBGR(), copypixels_to_24bppRGB(), and copypixels_to_32bppRGBA().

◆ WIC_DllMain()

BOOL WINAPI WIC_DllMain ( HINSTANCE  ,
DWORD  ,
LPVOID   
)

Definition at line 35 of file main.c.

38{
39
40 switch (fdwReason)
41 {
44 break;
47 break;
48 }
49
50 return WIC_DllMain(hinstDLL, fdwReason, lpvReserved);
51}
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
void ReleaseComponentInfos(void)
Definition: info.c:2155
BOOL WINAPI WIC_DllMain(HINSTANCE, DWORD, LPVOID)
Definition: main.c:35
static IN DWORD IN LPVOID lpvReserved

Referenced by WIC_DllMain().

◆ 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,
INT  width,
INT  height 
)

Definition at line 155 of file main.c.

159{
160 IWICBitmapSource *converted_source;
162 WICRect rc;
163 UINT stride;
164 BYTE* pixeldata;
165
166 if (!prc)
167 {
168 UINT src_width, src_height;
169 hr = IWICBitmapSource_GetSize(source, &src_width, &src_height);
170 if (FAILED(hr)) return hr;
171 rc.X = 0;
172 rc.Y = 0;
173 rc.Width = src_width;
174 rc.Height = src_height;
175 prc = &rc;
176 }
177
178 if (prc->Width != width || prc->Height <= 0)
179 return E_INVALIDARG;
180
181 hr = WICConvertBitmapSource(format, source, &converted_source);
182 if (FAILED(hr))
183 {
184 ERR("Failed to convert source, target format %s, %#x\n", debugstr_guid(format), hr);
185 return E_NOTIMPL;
186 }
187
188 stride = (bpp * width + 7)/8;
189
190 pixeldata = HeapAlloc(GetProcessHeap(), 0, stride * prc->Height);
191 if (!pixeldata)
192 {
193 IWICBitmapSource_Release(converted_source);
194 return E_OUTOFMEMORY;
195 }
196
197 hr = IWICBitmapSource_CopyPixels(converted_source, prc, stride,
198 stride*prc->Height, pixeldata);
199
200 if (SUCCEEDED(hr))
201 {
202 hr = IWICBitmapFrameEncode_WritePixels(iface, prc->Height, stride,
203 stride*prc->Height, pixeldata);
204 }
205
206 HeapFree(GetProcessHeap(), 0, pixeldata);
207 IWICBitmapSource_Release(converted_source);
208
209 return hr;
210}
#define ERR(fmt,...)
Definition: precomp.h:57
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_NOTIMPL
Definition: ddrawi.h:99
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
HRESULT WINAPI WICConvertBitmapSource(REFWICPixelFormatGUID dstFormat, IWICBitmapSource *pISrc, IWICBitmapSource **ppIDst)
Definition: info.c:2474
#define debugstr_guid
Definition: kernel32.h:35
_Out_ LPRECT prc
Definition: ntgdi.h:1658

Referenced by BmpFrameEncode_WriteSource(), and GifFrameEncode_WriteSource().