widl: Always check the runtimeclass interfaces presence.
[wine/zf.git] / dlls / windowscodecs / colortransform.c
blobe8065950bc6cfe96ec89ad2d43b06d333eb60681
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 <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "objbase.h"
27 #include "wincodecs_private.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
33 typedef struct ColorTransform {
34 IWICColorTransform IWICColorTransform_iface;
35 LONG ref;
36 IWICBitmapSource *dst;
37 } ColorTransform;
39 static inline ColorTransform *impl_from_IWICColorTransform(IWICColorTransform *iface)
41 return CONTAINING_RECORD(iface, ColorTransform, IWICColorTransform_iface);
44 static HRESULT WINAPI ColorTransform_QueryInterface(IWICColorTransform *iface, REFIID iid,
45 void **ppv)
47 ColorTransform *This = impl_from_IWICColorTransform(iface);
48 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
50 if (!ppv) return E_INVALIDARG;
52 if (IsEqualIID(&IID_IUnknown, iid) ||
53 IsEqualIID(&IID_IWICBitmapSource, iid) ||
54 IsEqualIID(&IID_IWICColorTransform, iid))
56 *ppv = &This->IWICColorTransform_iface;
58 else
60 *ppv = NULL;
61 return E_NOINTERFACE;
64 IUnknown_AddRef((IUnknown*)*ppv);
65 return S_OK;
68 static ULONG WINAPI ColorTransform_AddRef(IWICColorTransform *iface)
70 ColorTransform *This = impl_from_IWICColorTransform(iface);
71 ULONG ref = InterlockedIncrement(&This->ref);
73 TRACE("(%p) refcount=%u\n", iface, ref);
75 return ref;
78 static ULONG WINAPI ColorTransform_Release(IWICColorTransform *iface)
80 ColorTransform *This = impl_from_IWICColorTransform(iface);
81 ULONG ref = InterlockedDecrement(&This->ref);
83 TRACE("(%p) refcount=%u\n", iface, ref);
85 if (ref == 0)
87 if (This->dst) IWICBitmapSource_Release(This->dst);
88 HeapFree(GetProcessHeap(), 0, This);
91 return ref;
94 static HRESULT WINAPI ColorTransform_GetSize(IWICColorTransform *iface,
95 UINT *puiWidth, UINT *puiHeight)
97 ColorTransform *This = impl_from_IWICColorTransform(iface);
98 TRACE("(%p,%p,%p)\n", iface, puiWidth, puiHeight);
100 return IWICBitmapSource_GetSize(This->dst, puiWidth, puiHeight);
103 static HRESULT WINAPI ColorTransform_GetPixelFormat(IWICColorTransform *iface,
104 WICPixelFormatGUID *pPixelFormat)
106 ColorTransform *This = impl_from_IWICColorTransform(iface);
107 TRACE("(%p,%p)\n", iface, pPixelFormat);
109 return IWICBitmapSource_GetPixelFormat(This->dst, pPixelFormat);
112 static HRESULT WINAPI ColorTransform_GetResolution(IWICColorTransform *iface,
113 double *pDpiX, double *pDpiY)
115 ColorTransform *This = impl_from_IWICColorTransform(iface);
116 TRACE("(%p,%p,%p)\n", iface, pDpiX, pDpiY);
118 return IWICBitmapSource_GetResolution(This->dst, pDpiX, pDpiY);
121 static HRESULT WINAPI ColorTransform_CopyPalette(IWICColorTransform *iface,
122 IWICPalette *pIPalette)
124 ColorTransform *This = impl_from_IWICColorTransform(iface);
125 TRACE("(%p,%p)\n", iface, pIPalette);
127 return IWICBitmapSource_CopyPalette(This->dst, pIPalette);
130 static HRESULT WINAPI ColorTransform_CopyPixels(IWICColorTransform *iface,
131 const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer)
133 ColorTransform *This = impl_from_IWICColorTransform(iface);
134 TRACE("(%p,%s,%u,%u,%p)\n", iface, debug_wic_rect(prc), cbStride, cbBufferSize, pbBuffer);
136 return IWICBitmapSource_CopyPixels(This->dst, prc, cbStride, cbBufferSize, pbBuffer);
139 static HRESULT WINAPI ColorTransform_Initialize(IWICColorTransform *iface,
140 IWICBitmapSource *pIBitmapSource, IWICColorContext *pIContextSource,
141 IWICColorContext *pIContextDest, REFWICPixelFormatGUID pixelFmtDest)
143 ColorTransform *This = impl_from_IWICColorTransform(iface);
144 IWICBitmapSource *dst;
145 HRESULT hr;
147 TRACE("(%p,%p,%p,%p,%s)\n", iface, pIBitmapSource, pIContextSource,
148 pIContextDest, debugstr_guid(pixelFmtDest));
150 FIXME("ignoring color contexts\n");
152 hr = WICConvertBitmapSource(pixelFmtDest, pIBitmapSource, &dst);
153 if (FAILED(hr)) return hr;
155 if (This->dst) IWICBitmapSource_Release(This->dst);
156 This->dst = dst;
157 return S_OK;
160 static const IWICColorTransformVtbl ColorTransform_Vtbl = {
161 ColorTransform_QueryInterface,
162 ColorTransform_AddRef,
163 ColorTransform_Release,
164 ColorTransform_GetSize,
165 ColorTransform_GetPixelFormat,
166 ColorTransform_GetResolution,
167 ColorTransform_CopyPalette,
168 ColorTransform_CopyPixels,
169 ColorTransform_Initialize
172 HRESULT ColorTransform_Create(IWICColorTransform **colortransform)
174 ColorTransform *This;
176 if (!colortransform) return E_INVALIDARG;
178 This = HeapAlloc(GetProcessHeap(), 0, sizeof(ColorTransform));
179 if (!This) return E_OUTOFMEMORY;
181 This->IWICColorTransform_iface.lpVtbl = &ColorTransform_Vtbl;
182 This->ref = 1;
183 This->dst = NULL;
185 *colortransform = &This->IWICColorTransform_iface;
187 return S_OK;