secur32/tests: Use importlib for functions available since Windows XP.
[wine.git] / dlls / windowscodecs / colortransform.c
blob5b1c7e8b70ebe989b83086c900619a06835e7baa
1 /*
2 * Copyright 2013 Hans Leidekker for CodeWeavers
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.
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.
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
19 #include "config.h"
21 #include <stdarg.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "objbase.h"
29 #include "wincodecs_private.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
35 typedef struct ColorTransform {
36 IWICColorTransform IWICColorTransform_iface;
37 LONG ref;
38 IWICBitmapSource *dst;
39 } ColorTransform;
41 static inline ColorTransform *impl_from_IWICColorTransform(IWICColorTransform *iface)
43 return CONTAINING_RECORD(iface, ColorTransform, IWICColorTransform_iface);
46 static HRESULT WINAPI ColorTransform_QueryInterface(IWICColorTransform *iface, REFIID iid,
47 void **ppv)
49 ColorTransform *This = impl_from_IWICColorTransform(iface);
50 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
52 if (!ppv) return E_INVALIDARG;
54 if (IsEqualIID(&IID_IUnknown, iid) ||
55 IsEqualIID(&IID_IWICBitmapSource, iid) ||
56 IsEqualIID(&IID_IWICColorTransform, iid))
58 *ppv = &This->IWICColorTransform_iface;
60 else
62 *ppv = NULL;
63 return E_NOINTERFACE;
66 IUnknown_AddRef((IUnknown*)*ppv);
67 return S_OK;
70 static ULONG WINAPI ColorTransform_AddRef(IWICColorTransform *iface)
72 ColorTransform *This = impl_from_IWICColorTransform(iface);
73 ULONG ref = InterlockedIncrement(&This->ref);
75 TRACE("(%p) refcount=%u\n", iface, ref);
77 return ref;
80 static ULONG WINAPI ColorTransform_Release(IWICColorTransform *iface)
82 ColorTransform *This = impl_from_IWICColorTransform(iface);
83 ULONG ref = InterlockedDecrement(&This->ref);
85 TRACE("(%p) refcount=%u\n", iface, ref);
87 if (ref == 0)
89 if (This->dst) IWICBitmapSource_Release(This->dst);
90 HeapFree(GetProcessHeap(), 0, This);
93 return ref;
96 static HRESULT WINAPI ColorTransform_GetSize(IWICColorTransform *iface,
97 UINT *puiWidth, UINT *puiHeight)
99 ColorTransform *This = impl_from_IWICColorTransform(iface);
100 TRACE("(%p,%p,%p)\n", iface, puiWidth, puiHeight);
102 return IWICBitmapSource_GetSize(This->dst, puiWidth, puiHeight);
105 static HRESULT WINAPI ColorTransform_GetPixelFormat(IWICColorTransform *iface,
106 WICPixelFormatGUID *pPixelFormat)
108 ColorTransform *This = impl_from_IWICColorTransform(iface);
109 TRACE("(%p,%p)\n", iface, pPixelFormat);
111 return IWICBitmapSource_GetPixelFormat(This->dst, pPixelFormat);
114 static HRESULT WINAPI ColorTransform_GetResolution(IWICColorTransform *iface,
115 double *pDpiX, double *pDpiY)
117 ColorTransform *This = impl_from_IWICColorTransform(iface);
118 TRACE("(%p,%p,%p)\n", iface, pDpiX, pDpiY);
120 return IWICBitmapSource_GetResolution(This->dst, pDpiX, pDpiY);
123 static HRESULT WINAPI ColorTransform_CopyPalette(IWICColorTransform *iface,
124 IWICPalette *pIPalette)
126 ColorTransform *This = impl_from_IWICColorTransform(iface);
127 TRACE("(%p,%p)\n", iface, pIPalette);
129 return IWICBitmapSource_CopyPalette(This->dst, pIPalette);
132 static HRESULT WINAPI ColorTransform_CopyPixels(IWICColorTransform *iface,
133 const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer)
135 ColorTransform *This = impl_from_IWICColorTransform(iface);
136 TRACE("(%p,%p,%u,%u,%p)\n", iface, prc, cbStride, cbBufferSize, pbBuffer);
138 return IWICBitmapSource_CopyPixels(This->dst, prc, cbStride, cbBufferSize, pbBuffer);
141 static HRESULT WINAPI ColorTransform_Initialize(IWICColorTransform *iface,
142 IWICBitmapSource *pIBitmapSource, IWICColorContext *pIContextSource,
143 IWICColorContext *pIContextDest, REFWICPixelFormatGUID pixelFmtDest)
145 ColorTransform *This = impl_from_IWICColorTransform(iface);
146 IWICBitmapSource *dst;
147 HRESULT hr;
149 TRACE("(%p,%p,%p,%p,%s)\n", iface, pIBitmapSource, pIContextSource,
150 pIContextDest, debugstr_guid(pixelFmtDest));
152 FIXME("ignoring color contexts\n");
154 hr = WICConvertBitmapSource(pixelFmtDest, pIBitmapSource, &dst);
155 if (FAILED(hr)) return hr;
157 if (This->dst) IWICBitmapSource_Release(This->dst);
158 This->dst = dst;
159 return S_OK;
162 static const IWICColorTransformVtbl ColorTransform_Vtbl = {
163 ColorTransform_QueryInterface,
164 ColorTransform_AddRef,
165 ColorTransform_Release,
166 ColorTransform_GetSize,
167 ColorTransform_GetPixelFormat,
168 ColorTransform_GetResolution,
169 ColorTransform_CopyPalette,
170 ColorTransform_CopyPixels,
171 ColorTransform_Initialize
174 HRESULT ColorTransform_Create(IWICColorTransform **colortransform)
176 ColorTransform *This;
178 if (!colortransform) return E_INVALIDARG;
180 This = HeapAlloc(GetProcessHeap(), 0, sizeof(ColorTransform));
181 if (!This) return E_OUTOFMEMORY;
183 This->IWICColorTransform_iface.lpVtbl = &ColorTransform_Vtbl;
184 This->ref = 1;
185 This->dst = NULL;
187 *colortransform = &This->IWICColorTransform_iface;
189 return S_OK;