Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenpalette.c
Go to the documentation of this file.
00001 /* 00002 * Copyright 2009 Vincent Povirk for CodeWeavers 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00017 */ 00018 00019 #include "config.h" 00020 00021 #include <stdarg.h> 00022 00023 #define COBJMACROS 00024 00025 #include "windef.h" 00026 #include "winbase.h" 00027 #include "winreg.h" 00028 #include "objbase.h" 00029 #include "wincodec.h" 00030 00031 #include "wincodecs_private.h" 00032 00033 #include "wine/debug.h" 00034 00035 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs); 00036 00037 typedef struct { 00038 const IWICPaletteVtbl *lpIWICPaletteVtbl; 00039 LONG ref; 00040 UINT count; 00041 WICColor *colors; 00042 WICBitmapPaletteType type; 00043 CRITICAL_SECTION lock; /* must be held when count, colors, or type is accessed */ 00044 } PaletteImpl; 00045 00046 static HRESULT WINAPI PaletteImpl_QueryInterface(IWICPalette *iface, REFIID iid, 00047 void **ppv) 00048 { 00049 PaletteImpl *This = (PaletteImpl*)iface; 00050 TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv); 00051 00052 if (!ppv) return E_INVALIDARG; 00053 00054 if (IsEqualIID(&IID_IUnknown, iid) || IsEqualIID(&IID_IWICPalette, iid)) 00055 { 00056 *ppv = This; 00057 } 00058 else 00059 { 00060 *ppv = NULL; 00061 return E_NOINTERFACE; 00062 } 00063 00064 IUnknown_AddRef((IUnknown*)*ppv); 00065 return S_OK; 00066 } 00067 00068 static ULONG WINAPI PaletteImpl_AddRef(IWICPalette *iface) 00069 { 00070 PaletteImpl *This = (PaletteImpl*)iface; 00071 ULONG ref = InterlockedIncrement(&This->ref); 00072 00073 TRACE("(%p) refcount=%u\n", iface, ref); 00074 00075 return ref; 00076 } 00077 00078 static ULONG WINAPI PaletteImpl_Release(IWICPalette *iface) 00079 { 00080 PaletteImpl *This = (PaletteImpl*)iface; 00081 ULONG ref = InterlockedDecrement(&This->ref); 00082 00083 TRACE("(%p) refcount=%u\n", iface, ref); 00084 00085 if (ref == 0) 00086 { 00087 This->lock.DebugInfo->Spare[0] = 0; 00088 DeleteCriticalSection(&This->lock); 00089 HeapFree(GetProcessHeap(), 0, This->colors); 00090 HeapFree(GetProcessHeap(), 0, This); 00091 } 00092 00093 return ref; 00094 } 00095 00096 static HRESULT WINAPI PaletteImpl_InitializePredefined(IWICPalette *iface, 00097 WICBitmapPaletteType ePaletteType, BOOL fAddTransparentColor) 00098 { 00099 FIXME("(%p,%u,%i): stub\n", iface, ePaletteType, fAddTransparentColor); 00100 return E_NOTIMPL; 00101 } 00102 00103 static HRESULT WINAPI PaletteImpl_InitializeCustom(IWICPalette *iface, 00104 WICColor *pColors, UINT colorCount) 00105 { 00106 PaletteImpl *This = (PaletteImpl*)iface; 00107 WICColor *new_colors; 00108 00109 TRACE("(%p,%p,%u)\n", iface, pColors, colorCount); 00110 00111 if (colorCount == 0) 00112 { 00113 new_colors = NULL; 00114 } 00115 else 00116 { 00117 if (!pColors) return E_INVALIDARG; 00118 new_colors = HeapAlloc(GetProcessHeap(), 0, sizeof(WICColor) * colorCount); 00119 if (!new_colors) return E_OUTOFMEMORY; 00120 memcpy(new_colors, pColors, sizeof(WICColor) * colorCount); 00121 } 00122 00123 EnterCriticalSection(&This->lock); 00124 HeapFree(GetProcessHeap(), 0, This->colors); 00125 This->colors = new_colors; 00126 This->count = colorCount; 00127 This->type = WICBitmapPaletteTypeCustom; 00128 LeaveCriticalSection(&This->lock); 00129 00130 return S_OK; 00131 } 00132 00133 static HRESULT WINAPI PaletteImpl_InitializeFromBitmap(IWICPalette *iface, 00134 IWICBitmapSource *pISurface, UINT colorCount, BOOL fAddTransparentColor) 00135 { 00136 FIXME("(%p,%p,%u,%i): stub\n", iface, pISurface, colorCount, fAddTransparentColor); 00137 return E_NOTIMPL; 00138 } 00139 00140 static HRESULT WINAPI PaletteImpl_InitializeFromPalette(IWICPalette *iface, 00141 IWICPalette *pIPalette) 00142 { 00143 FIXME("(%p,%p): stub\n", iface, pIPalette); 00144 return E_NOTIMPL; 00145 } 00146 00147 static HRESULT WINAPI PaletteImpl_GetType(IWICPalette *iface, 00148 WICBitmapPaletteType *pePaletteType) 00149 { 00150 PaletteImpl *This = (PaletteImpl*)iface; 00151 00152 TRACE("(%p,%p)\n", iface, pePaletteType); 00153 00154 if (!pePaletteType) return E_INVALIDARG; 00155 00156 EnterCriticalSection(&This->lock); 00157 *pePaletteType = This->type; 00158 LeaveCriticalSection(&This->lock); 00159 00160 return S_OK; 00161 } 00162 00163 static HRESULT WINAPI PaletteImpl_GetColorCount(IWICPalette *iface, UINT *pcCount) 00164 { 00165 PaletteImpl *This = (PaletteImpl*)iface; 00166 00167 TRACE("(%p,%p)\n", iface, pcCount); 00168 00169 if (!pcCount) return E_INVALIDARG; 00170 00171 EnterCriticalSection(&This->lock); 00172 *pcCount = This->count; 00173 LeaveCriticalSection(&This->lock); 00174 00175 return S_OK; 00176 } 00177 00178 static HRESULT WINAPI PaletteImpl_GetColors(IWICPalette *iface, UINT colorCount, 00179 WICColor *pColors, UINT *pcActualColors) 00180 { 00181 PaletteImpl *This = (PaletteImpl*)iface; 00182 00183 TRACE("(%p,%i,%p,%p)\n", iface, colorCount, pColors, pcActualColors); 00184 00185 if (!pColors || !pcActualColors) return E_INVALIDARG; 00186 00187 EnterCriticalSection(&This->lock); 00188 00189 if (This->count < colorCount) colorCount = This->count; 00190 00191 memcpy(pColors, This->colors, sizeof(WICColor) * colorCount); 00192 00193 *pcActualColors = colorCount; 00194 00195 LeaveCriticalSection(&This->lock); 00196 00197 return S_OK; 00198 } 00199 00200 static HRESULT WINAPI PaletteImpl_IsBlackWhite(IWICPalette *iface, BOOL *pfIsBlackWhite) 00201 { 00202 PaletteImpl *This = (PaletteImpl*)iface; 00203 00204 TRACE("(%p,%p)\n", iface, pfIsBlackWhite); 00205 00206 if (!pfIsBlackWhite) return E_INVALIDARG; 00207 00208 EnterCriticalSection(&This->lock); 00209 if (This->type == WICBitmapPaletteTypeFixedBW) 00210 *pfIsBlackWhite = TRUE; 00211 else 00212 *pfIsBlackWhite = FALSE; 00213 LeaveCriticalSection(&This->lock); 00214 00215 return S_OK; 00216 } 00217 00218 static HRESULT WINAPI PaletteImpl_IsGrayscale(IWICPalette *iface, BOOL *pfIsGrayscale) 00219 { 00220 PaletteImpl *This = (PaletteImpl*)iface; 00221 00222 TRACE("(%p,%p)\n", iface, pfIsGrayscale); 00223 00224 if (!pfIsGrayscale) return E_INVALIDARG; 00225 00226 EnterCriticalSection(&This->lock); 00227 switch(This->type) 00228 { 00229 case WICBitmapPaletteTypeFixedBW: 00230 case WICBitmapPaletteTypeFixedGray4: 00231 case WICBitmapPaletteTypeFixedGray16: 00232 case WICBitmapPaletteTypeFixedGray256: 00233 *pfIsGrayscale = TRUE; 00234 break; 00235 default: 00236 *pfIsGrayscale = FALSE; 00237 } 00238 LeaveCriticalSection(&This->lock); 00239 00240 return S_OK; 00241 } 00242 00243 static HRESULT WINAPI PaletteImpl_HasAlpha(IWICPalette *iface, BOOL *pfHasAlpha) 00244 { 00245 PaletteImpl *This = (PaletteImpl*)iface; 00246 int i; 00247 00248 TRACE("(%p,%p)\n", iface, pfHasAlpha); 00249 00250 if (!pfHasAlpha) return E_INVALIDARG; 00251 00252 *pfHasAlpha = FALSE; 00253 00254 EnterCriticalSection(&This->lock); 00255 for (i=0; i<This->count; i++) 00256 if ((This->colors[i]&0xff000000) != 0xff000000) 00257 { 00258 *pfHasAlpha = TRUE; 00259 break; 00260 } 00261 LeaveCriticalSection(&This->lock); 00262 00263 return S_OK; 00264 } 00265 00266 static const IWICPaletteVtbl PaletteImpl_Vtbl = { 00267 PaletteImpl_QueryInterface, 00268 PaletteImpl_AddRef, 00269 PaletteImpl_Release, 00270 PaletteImpl_InitializePredefined, 00271 PaletteImpl_InitializeCustom, 00272 PaletteImpl_InitializeFromBitmap, 00273 PaletteImpl_InitializeFromPalette, 00274 PaletteImpl_GetType, 00275 PaletteImpl_GetColorCount, 00276 PaletteImpl_GetColors, 00277 PaletteImpl_IsBlackWhite, 00278 PaletteImpl_IsGrayscale, 00279 PaletteImpl_HasAlpha 00280 }; 00281 00282 HRESULT PaletteImpl_Create(IWICPalette **palette) 00283 { 00284 PaletteImpl *This; 00285 00286 This = HeapAlloc(GetProcessHeap(), 0, sizeof(PaletteImpl)); 00287 if (!This) return E_OUTOFMEMORY; 00288 00289 This->lpIWICPaletteVtbl = &PaletteImpl_Vtbl; 00290 This->ref = 1; 00291 This->count = 0; 00292 This->colors = NULL; 00293 This->type = WICBitmapPaletteTypeCustom; 00294 InitializeCriticalSection(&This->lock); 00295 This->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": PaletteImpl.lock"); 00296 00297 *palette = (IWICPalette*)This; 00298 00299 return S_OK; 00300 } Generated on Sun May 27 2012 04:17:05 for ReactOS by
1.7.6.1
|