ReactOS 0.4.15-dev-8135-g1bc6c90
clipper.c
Go to the documentation of this file.
1/*
2 * Copyright 2013 Nikolay Sivov 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#include <stdarg.h>
20
21#define COBJMACROS
22
23#include "windef.h"
24#include "winbase.h"
25#include "objbase.h"
26
27#include "wincodecs_private.h"
28
29#include "wine/debug.h"
30
32
33typedef struct BitmapClipper {
38 CRITICAL_SECTION lock; /* must be held when initialized */
40
42{
43 return CONTAINING_RECORD(iface, BitmapClipper, IWICBitmapClipper_iface);
44}
45
47 void **ppv)
48{
50 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
51
52 if (!ppv) return E_INVALIDARG;
53
54 if (IsEqualIID(&IID_IUnknown, iid) ||
55 IsEqualIID(&IID_IWICBitmapSource, iid) ||
56 IsEqualIID(&IID_IWICBitmapClipper, iid))
57 {
58 *ppv = &This->IWICBitmapClipper_iface;
59 }
60 else
61 {
62 *ppv = NULL;
63 return E_NOINTERFACE;
64 }
65
66 IUnknown_AddRef((IUnknown*)*ppv);
67 return S_OK;
68}
69
71{
74
75 TRACE("(%p) refcount=%u\n", iface, ref);
76
77 return ref;
78}
79
81{
84
85 TRACE("(%p) refcount=%u\n", iface, ref);
86
87 if (ref == 0)
88 {
89 This->lock.DebugInfo->Spare[0] = 0;
91 if (This->source) IWICBitmapSource_Release(This->source);
93 }
94
95 return ref;
96}
97
100{
102
103 TRACE("(%p,%p,%p)\n", iface, width, height);
104
105 if (!width || !height)
106 return E_INVALIDARG;
107
108 if (!This->source)
110
111 *width = This->rect.Width;
112 *height = This->rect.Height;
113
114 return S_OK;
115}
116
119{
121 TRACE("(%p,%p)\n", iface, format);
122
123 if (!format)
124 return E_INVALIDARG;
125
126 if (!This->source)
128
129 return IWICBitmapSource_GetPixelFormat(This->source, format);
130}
131
133 double *dpiX, double *dpiY)
134{
136
137 TRACE("(%p,%p,%p)\n", iface, dpiX, dpiY);
138
139 if (!dpiX || !dpiY)
140 return E_INVALIDARG;
141
142 if (!This->source)
144
145 return IWICBitmapSource_GetResolution(This->source, dpiX, dpiY);
146}
147
150{
152
153 TRACE("(%p,%p)\n", iface, palette);
154
155 if (!palette)
156 return E_INVALIDARG;
157
158 if (!This->source)
160
161 return IWICBitmapSource_CopyPalette(This->source, palette);
162}
163
166{
169
170 TRACE("(%p,%s,%u,%u,%p)\n", iface, debug_wic_rect(rc), stride, buffer_size, buffer);
171
172 if (!This->source)
174
175 if (rc)
176 {
177 rect = *rc;
178
179 /* transform to source coordinates */
180 rect.X += This->rect.X;
181 rect.Y += This->rect.Y;
182
183 if ((rect.X + rect.Width > This->rect.X + This->rect.Width) ||
184 (rect.Y + rect.Height > This->rect.Y + This->rect.Height))
185 return E_INVALIDARG;
186
187 rc = &rect;
188 }
189 else
190 rc = &This->rect;
191
192 return IWICBitmapSource_CopyPixels(This->source, rc, stride, buffer_size, buffer);
193}
194
196 IWICBitmapSource *source, const WICRect *rc)
197{
200 HRESULT hr = S_OK;
201
202 TRACE("(%p,%p,%s)\n", iface, source, debug_wic_rect(rc));
203
205
206 if (This->source)
207 {
209 goto end;
210 }
211
212 hr = IWICBitmapSource_GetSize(source, &width, &height);
213 if (FAILED(hr)) goto end;
214
215 if ((rc->X + rc->Width > width) || (rc->Y + rc->Height > height))
216 {
218 goto end;
219 }
220
221 This->rect = *rc;
222 This->source = source;
223 IWICBitmapSource_AddRef(This->source);
224
225end:
227
228 return hr;
229}
230
231static const IWICBitmapClipperVtbl BitmapClipper_Vtbl = {
241};
242
244{
246
248 if (!This) return E_OUTOFMEMORY;
249
250 This->IWICBitmapClipper_iface.lpVtbl = &BitmapClipper_Vtbl;
251 This->ref = 1;
252 This->source = NULL;
254 This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": BitmapClipper.lock");
255
256 *clipper = &This->IWICBitmapClipper_iface;
257
258 return S_OK;
259}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
const GUID IID_IUnknown
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
GLuint GLuint end
Definition: gl.h:1545
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
GLsizei stride
Definition: glext.h:5848
GLuint buffer
Definition: glext.h:5915
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
#define debugstr_guid
Definition: kernel32.h:35
static HPALETTE palette
Definition: clipboard.c:1345
unsigned int UINT
Definition: ndis.h:50
long LONG
Definition: pedump.c:60
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
#define REFIID
Definition: guiddef.h:118
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4
& rect
Definition: startmenu.cpp:1413
WICRect rect
Definition: clipper.c:37
IWICBitmapClipper IWICBitmapClipper_iface
Definition: clipper.c:34
CRITICAL_SECTION lock
Definition: clipper.c:38
IWICBitmapSource * source
Definition: clipper.c:36
LONG ref
Definition: clipper.c:35
INT Height
Definition: wincodec.idl:301
INT Width
Definition: wincodec.idl:300
Definition: send.c:48
static void buffer_size(GLcontext *ctx, GLuint *width, GLuint *height)
Definition: swimpl.c:888
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
#define DWORD_PTR
Definition: treelist.c:76
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
static ULONG WINAPI BitmapClipper_Release(IWICBitmapClipper *iface)
Definition: clipper.c:80
static HRESULT WINAPI BitmapClipper_GetResolution(IWICBitmapClipper *iface, double *dpiX, double *dpiY)
Definition: clipper.c:132
static HRESULT WINAPI BitmapClipper_CopyPalette(IWICBitmapClipper *iface, IWICPalette *palette)
Definition: clipper.c:148
static ULONG WINAPI BitmapClipper_AddRef(IWICBitmapClipper *iface)
Definition: clipper.c:70
static HRESULT WINAPI BitmapClipper_Initialize(IWICBitmapClipper *iface, IWICBitmapSource *source, const WICRect *rc)
Definition: clipper.c:195
static HRESULT WINAPI BitmapClipper_GetSize(IWICBitmapClipper *iface, UINT *width, UINT *height)
Definition: clipper.c:98
static HRESULT WINAPI BitmapClipper_GetPixelFormat(IWICBitmapClipper *iface, WICPixelFormatGUID *format)
Definition: clipper.c:117
static HRESULT WINAPI BitmapClipper_QueryInterface(IWICBitmapClipper *iface, REFIID iid, void **ppv)
Definition: clipper.c:46
HRESULT BitmapClipper_Create(IWICBitmapClipper **clipper)
Definition: clipper.c:243
static const IWICBitmapClipperVtbl BitmapClipper_Vtbl
Definition: clipper.c:231
static HRESULT WINAPI BitmapClipper_CopyPixels(IWICBitmapClipper *iface, const WICRect *rc, UINT stride, UINT buffer_size, BYTE *buffer)
Definition: clipper.c:164
static BitmapClipper * impl_from_IWICBitmapClipper(IWICBitmapClipper *iface)
Definition: clipper.c:41
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
static const char * debug_wic_rect(const WICRect *rect)
#define WINAPI
Definition: msvc.h:6
#define WINCODEC_ERR_WRONGSTATE
Definition: winerror.h:3281
#define E_NOINTERFACE
Definition: winerror.h:2364
unsigned char BYTE
Definition: xxhash.c:193