ReactOS 0.4.16-dev-297-gc569aee
main.c
Go to the documentation of this file.
1/*
2 * Copyright 2009 Vincent Povirk for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19
20#define COBJMACROS
21#include "config.h"
22
23#include <stdarg.h>
24
25#include "windef.h"
26#include "winbase.h"
27#include "objbase.h"
28
29#include "wincodecs_private.h"
30
31#include "wine/debug.h"
32
34
36
38{
39
40 switch (fdwReason)
41 {
44 break;
47 break;
48 }
49
50 return WIC_DllMain(hinstDLL, fdwReason, lpvReserved);
51}
52
54{
55 return S_FALSE;
56}
57
58HRESULT copy_pixels(UINT bpp, const BYTE *srcbuffer,
59 UINT srcwidth, UINT srcheight, INT srcstride,
60 const WICRect *rc, UINT dststride, UINT dstbuffersize, BYTE *dstbuffer)
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}
122
126 INT width, INT height, double xres, double yres)
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}
154
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}
211
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}
230
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}
251
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}
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define FIXME(fmt,...)
Definition: precomp.h:53
#define ERR(fmt,...)
Definition: precomp.h:57
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
Definition: main.c:26
HRESULT WINAPI DllCanUnloadNow(void)
Definition: main.c:204
DWORD bpp
Definition: surface.c:185
#define DECLSPEC_HIDDEN
Definition: precomp.h:8
#define GetProcessHeap()
Definition: compat.h:736
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
pixelformat
Definition: converter.c:40
HRESULT CreateComponentInfo(REFCLSID clsid, IWICComponentInfo **ppIInfo)
Definition: info.c:2075
HRESULT WINAPI WICConvertBitmapSource(REFWICPixelFormatGUID dstFormat, IWICBitmapSource *pISrc, IWICBitmapSource **ppIDst)
Definition: info.c:2474
void ReleaseComponentInfos(void)
Definition: info.c:2155
HRESULT write_source(IWICBitmapFrameEncode *iface, IWICBitmapSource *source, const WICRect *prc, const WICPixelFormatGUID *format, UINT bpp, INT width, INT height)
Definition: main.c:155
void reverse_bgr8(UINT bytesperpixel, LPBYTE bits, UINT width, UINT height, INT stride)
Definition: main.c:212
HRESULT get_pixelformat_bpp(const GUID *pixelformat, UINT *bpp)
Definition: main.c:252
HRESULT configure_write_source(IWICBitmapFrameEncode *iface, IWICBitmapSource *source, const WICRect *prc, const WICPixelFormatGUID *format, INT width, INT height, double xres, double yres)
Definition: main.c:123
void convert_rgba_to_bgra(UINT bytesperpixel, LPBYTE bits, UINT width, UINT height, INT stride)
Definition: main.c:231
HRESULT copy_pixels(UINT bpp, const BYTE *srcbuffer, UINT srcwidth, UINT srcheight, INT srcstride, const WICRect *rc, UINT dststride, UINT dstbuffersize, BYTE *dstbuffer)
Definition: main.c:58
BOOL WINAPI WIC_DllMain(HINSTANCE, DWORD, LPVOID)
Definition: main.c:35
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
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
GLsizei stride
Definition: glext.h:5848
GLenum src
Definition: glext.h:6340
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
Definition: glext.h:10929
GLenum GLenum dst
Definition: glext.h:6340
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define debugstr_guid
Definition: kernel32.h:35
static IN DWORD IN LPVOID lpvReserved
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define for
Definition: utility.h:88
unsigned int UINT
Definition: ndis.h:50
_Out_ LPRECT prc
Definition: ntgdi.h:1658
static calc_node_t temp
Definition: rpn_ieee.c:38
HRESULT hr
Definition: shlfolder.c:183
& rect
Definition: startmenu.cpp:1413
INT Height
Definition: wincodec.idl:301
INT Width
Definition: wincodec.idl:300
Definition: format.c:58
unsigned char * LPBYTE
Definition: typedefs.h:53
int32_t INT
Definition: typedefs.h:58
#define WINAPI
Definition: msvc.h:6
#define S_FALSE
Definition: winerror.h:2357
#define WINCODEC_ERR_WRONGSTATE
Definition: winerror.h:3281
unsigned char BYTE
Definition: xxhash.c:193