[SHELL32] CDrivesFolder: Implement the eject and disconnect menu items. CORE-13841
[reactos.git] / dll / win32 / windowscodecs / colortransform.c
1 /*
2 * Copyright 2013 Hans Leidekker 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 "wincodecs_private.h"
20
21 typedef struct ColorTransform {
22 IWICColorTransform IWICColorTransform_iface;
23 LONG ref;
24 IWICBitmapSource *dst;
25 } ColorTransform;
26
27 static inline ColorTransform *impl_from_IWICColorTransform(IWICColorTransform *iface)
28 {
29 return CONTAINING_RECORD(iface, ColorTransform, IWICColorTransform_iface);
30 }
31
32 static HRESULT WINAPI ColorTransform_QueryInterface(IWICColorTransform *iface, REFIID iid,
33 void **ppv)
34 {
35 ColorTransform *This = impl_from_IWICColorTransform(iface);
36 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv);
37
38 if (!ppv) return E_INVALIDARG;
39
40 if (IsEqualIID(&IID_IUnknown, iid) ||
41 IsEqualIID(&IID_IWICBitmapSource, iid) ||
42 IsEqualIID(&IID_IWICColorTransform, iid))
43 {
44 *ppv = &This->IWICColorTransform_iface;
45 }
46 else
47 {
48 *ppv = NULL;
49 return E_NOINTERFACE;
50 }
51
52 IUnknown_AddRef((IUnknown*)*ppv);
53 return S_OK;
54 }
55
56 static ULONG WINAPI ColorTransform_AddRef(IWICColorTransform *iface)
57 {
58 ColorTransform *This = impl_from_IWICColorTransform(iface);
59 ULONG ref = InterlockedIncrement(&This->ref);
60
61 TRACE("(%p) refcount=%u\n", iface, ref);
62
63 return ref;
64 }
65
66 static ULONG WINAPI ColorTransform_Release(IWICColorTransform *iface)
67 {
68 ColorTransform *This = impl_from_IWICColorTransform(iface);
69 ULONG ref = InterlockedDecrement(&This->ref);
70
71 TRACE("(%p) refcount=%u\n", iface, ref);
72
73 if (ref == 0)
74 {
75 if (This->dst) IWICBitmapSource_Release(This->dst);
76 HeapFree(GetProcessHeap(), 0, This);
77 }
78
79 return ref;
80 }
81
82 static HRESULT WINAPI ColorTransform_GetSize(IWICColorTransform *iface,
83 UINT *puiWidth, UINT *puiHeight)
84 {
85 ColorTransform *This = impl_from_IWICColorTransform(iface);
86 TRACE("(%p,%p,%p)\n", iface, puiWidth, puiHeight);
87
88 return IWICBitmapSource_GetSize(This->dst, puiWidth, puiHeight);
89 }
90
91 static HRESULT WINAPI ColorTransform_GetPixelFormat(IWICColorTransform *iface,
92 WICPixelFormatGUID *pPixelFormat)
93 {
94 ColorTransform *This = impl_from_IWICColorTransform(iface);
95 TRACE("(%p,%p)\n", iface, pPixelFormat);
96
97 return IWICBitmapSource_GetPixelFormat(This->dst, pPixelFormat);
98 }
99
100 static HRESULT WINAPI ColorTransform_GetResolution(IWICColorTransform *iface,
101 double *pDpiX, double *pDpiY)
102 {
103 ColorTransform *This = impl_from_IWICColorTransform(iface);
104 TRACE("(%p,%p,%p)\n", iface, pDpiX, pDpiY);
105
106 return IWICBitmapSource_GetResolution(This->dst, pDpiX, pDpiY);
107 }
108
109 static HRESULT WINAPI ColorTransform_CopyPalette(IWICColorTransform *iface,
110 IWICPalette *pIPalette)
111 {
112 ColorTransform *This = impl_from_IWICColorTransform(iface);
113 TRACE("(%p,%p)\n", iface, pIPalette);
114
115 return IWICBitmapSource_CopyPalette(This->dst, pIPalette);
116 }
117
118 static HRESULT WINAPI ColorTransform_CopyPixels(IWICColorTransform *iface,
119 const WICRect *prc, UINT cbStride, UINT cbBufferSize, BYTE *pbBuffer)
120 {
121 ColorTransform *This = impl_from_IWICColorTransform(iface);
122 TRACE("(%p,%p,%u,%u,%p)\n", iface, prc, cbStride, cbBufferSize, pbBuffer);
123
124 return IWICBitmapSource_CopyPixels(This->dst, prc, cbStride, cbBufferSize, pbBuffer);
125 }
126
127 static HRESULT WINAPI ColorTransform_Initialize(IWICColorTransform *iface,
128 IWICBitmapSource *pIBitmapSource, IWICColorContext *pIContextSource,
129 IWICColorContext *pIContextDest, REFWICPixelFormatGUID pixelFmtDest)
130 {
131 ColorTransform *This = impl_from_IWICColorTransform(iface);
132 IWICBitmapSource *dst;
133 HRESULT hr;
134
135 TRACE("(%p,%p,%p,%p,%s)\n", iface, pIBitmapSource, pIContextSource,
136 pIContextDest, debugstr_guid(pixelFmtDest));
137
138 FIXME("ignoring color contexts\n");
139
140 hr = WICConvertBitmapSource(pixelFmtDest, pIBitmapSource, &dst);
141 if (FAILED(hr)) return hr;
142
143 if (This->dst) IWICBitmapSource_Release(This->dst);
144 This->dst = dst;
145 return S_OK;
146 }
147
148 static const IWICColorTransformVtbl ColorTransform_Vtbl = {
149 ColorTransform_QueryInterface,
150 ColorTransform_AddRef,
151 ColorTransform_Release,
152 ColorTransform_GetSize,
153 ColorTransform_GetPixelFormat,
154 ColorTransform_GetResolution,
155 ColorTransform_CopyPalette,
156 ColorTransform_CopyPixels,
157 ColorTransform_Initialize
158 };
159
160 HRESULT ColorTransform_Create(IWICColorTransform **colortransform)
161 {
162 ColorTransform *This;
163
164 if (!colortransform) return E_INVALIDARG;
165
166 This = HeapAlloc(GetProcessHeap(), 0, sizeof(ColorTransform));
167 if (!This) return E_OUTOFMEMORY;
168
169 This->IWICColorTransform_iface.lpVtbl = &ColorTransform_Vtbl;
170 This->ref = 1;
171 This->dst = NULL;
172
173 *colortransform = &This->IWICColorTransform_iface;
174
175 return S_OK;
176 }