rasapi32: Update spec file.
[wine/zf.git] / dlls / gdiplus / imageattributes.c
blobab197a4f616e8553ff2343a8950973816009ab2e
1 /*
2 * Copyright (C) 2007 Google (Evan Stade)
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 "windef.h"
20 #include "wingdi.h"
22 #include "objbase.h"
24 #include "gdiplus.h"
25 #include "gdiplus_private.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
30 GpStatus WINGDIPAPI GdipCloneImageAttributes(GDIPCONST GpImageAttributes *imageattr,
31 GpImageAttributes **cloneImageattr)
33 GpStatus stat = Ok;
34 struct color_remap_table remap_tables[ColorAdjustTypeCount] = {{0}};
35 int i;
37 TRACE("(%p, %p)\n", imageattr, cloneImageattr);
39 if(!imageattr || !cloneImageattr)
40 return InvalidParameter;
42 for (i=0; i<ColorAdjustTypeCount; i++)
44 if (imageattr->colorremaptables[i].enabled)
46 remap_tables[i].enabled = TRUE;
47 remap_tables[i].mapsize = imageattr->colorremaptables[i].mapsize;
48 remap_tables[i].colormap = heap_alloc(sizeof(ColorMap) * remap_tables[i].mapsize);
50 if (remap_tables[i].colormap)
52 memcpy(remap_tables[i].colormap, imageattr->colorremaptables[i].colormap,
53 sizeof(ColorMap) * remap_tables[i].mapsize);
55 else
57 stat = OutOfMemory;
58 break;
63 if (stat == Ok)
64 stat = GdipCreateImageAttributes(cloneImageattr);
66 if (stat == Ok)
68 **cloneImageattr = *imageattr;
70 memcpy((*cloneImageattr)->colorremaptables, remap_tables, sizeof(remap_tables));
73 if (stat != Ok)
75 for (i=0; i<ColorAdjustTypeCount; i++)
76 heap_free(remap_tables[i].colormap);
79 return stat;
82 GpStatus WINGDIPAPI GdipCreateImageAttributes(GpImageAttributes **imageattr)
84 if(!imageattr)
85 return InvalidParameter;
87 *imageattr = heap_alloc_zero(sizeof(GpImageAttributes));
88 if(!*imageattr) return OutOfMemory;
90 (*imageattr)->wrap = WrapModeClamp;
92 TRACE("<-- %p\n", *imageattr);
94 return Ok;
97 GpStatus WINGDIPAPI GdipDisposeImageAttributes(GpImageAttributes *imageattr)
99 int i;
101 TRACE("(%p)\n", imageattr);
103 if(!imageattr)
104 return InvalidParameter;
106 for (i=0; i<ColorAdjustTypeCount; i++)
107 heap_free(imageattr->colorremaptables[i].colormap);
109 heap_free(imageattr);
111 return Ok;
114 GpStatus WINGDIPAPI GdipGetImageAttributesAdjustedPalette(GpImageAttributes *imageattr,
115 ColorPalette *palette, ColorAdjustType type)
117 TRACE("(%p,%p,%u)\n", imageattr, palette, type);
119 if (!imageattr || !palette || !palette->Count ||
120 type >= ColorAdjustTypeCount || type == ColorAdjustTypeDefault)
121 return InvalidParameter;
123 apply_image_attributes(imageattr, (LPBYTE)palette->Entries, palette->Count, 1, 0,
124 type, PixelFormat32bppARGB);
126 return Ok;
129 GpStatus WINGDIPAPI GdipSetImageAttributesColorKeys(GpImageAttributes *imageattr,
130 ColorAdjustType type, BOOL enableFlag, ARGB colorLow, ARGB colorHigh)
132 TRACE("(%p,%u,%i,%08x,%08x)\n", imageattr, type, enableFlag, colorLow, colorHigh);
134 if(!imageattr || type >= ColorAdjustTypeCount)
135 return InvalidParameter;
137 imageattr->colorkeys[type].enabled = enableFlag;
138 imageattr->colorkeys[type].low = colorLow;
139 imageattr->colorkeys[type].high = colorHigh;
141 return Ok;
144 GpStatus WINGDIPAPI GdipSetImageAttributesColorMatrix(GpImageAttributes *imageattr,
145 ColorAdjustType type, BOOL enableFlag, GDIPCONST ColorMatrix* colorMatrix,
146 GDIPCONST ColorMatrix* grayMatrix, ColorMatrixFlags flags)
148 TRACE("(%p,%u,%i,%p,%p,%u)\n", imageattr, type, enableFlag, colorMatrix,
149 grayMatrix, flags);
151 if(!imageattr || type >= ColorAdjustTypeCount || flags > ColorMatrixFlagsAltGray)
152 return InvalidParameter;
154 if (enableFlag)
156 if (!colorMatrix)
157 return InvalidParameter;
159 if (flags == ColorMatrixFlagsAltGray)
161 if (!grayMatrix)
162 return InvalidParameter;
164 imageattr->colormatrices[type].graymatrix = *grayMatrix;
167 imageattr->colormatrices[type].colormatrix = *colorMatrix;
168 imageattr->colormatrices[type].flags = flags;
171 imageattr->colormatrices[type].enabled = enableFlag;
173 return Ok;
176 GpStatus WINGDIPAPI GdipSetImageAttributesWrapMode(GpImageAttributes *imageAttr,
177 WrapMode wrap, ARGB argb, BOOL clamp)
179 TRACE("(%p,%u,%08x,%i)\n", imageAttr, wrap, argb, clamp);
181 if(!imageAttr || wrap > WrapModeClamp)
182 return InvalidParameter;
184 imageAttr->wrap = wrap;
185 imageAttr->outside_color = argb;
186 imageAttr->clamp = clamp;
188 return Ok;
191 GpStatus WINGDIPAPI GdipSetImageAttributesCachedBackground(GpImageAttributes *imageAttr,
192 BOOL enableFlag)
194 static int calls;
196 TRACE("(%p,%i)\n", imageAttr, enableFlag);
198 if(!(calls++))
199 FIXME("not implemented\n");
201 return NotImplemented;
204 GpStatus WINGDIPAPI GdipSetImageAttributesGamma(GpImageAttributes *imageAttr,
205 ColorAdjustType type, BOOL enableFlag, REAL gamma)
207 TRACE("(%p,%u,%i,%0.2f)\n", imageAttr, type, enableFlag, gamma);
209 if (!imageAttr || (enableFlag && gamma <= 0.0) || type >= ColorAdjustTypeCount)
210 return InvalidParameter;
212 imageAttr->gamma_enabled[type] = enableFlag;
213 imageAttr->gamma[type] = gamma;
215 return Ok;
218 GpStatus WINGDIPAPI GdipSetImageAttributesNoOp(GpImageAttributes *imageAttr,
219 ColorAdjustType type, BOOL enableFlag)
221 TRACE("(%p,%u,%i)\n", imageAttr, type, enableFlag);
223 if (type >= ColorAdjustTypeCount)
224 return InvalidParameter;
226 imageAttr->noop[type] = enableFlag ? IMAGEATTR_NOOP_SET : IMAGEATTR_NOOP_CLEAR;
228 return Ok;
231 GpStatus WINGDIPAPI GdipSetImageAttributesOutputChannel(GpImageAttributes *imageAttr,
232 ColorAdjustType type, BOOL enableFlag, ColorChannelFlags channelFlags)
234 static int calls;
236 TRACE("(%p,%u,%i,%x)\n", imageAttr, type, enableFlag, channelFlags);
238 if(!(calls++))
239 FIXME("not implemented\n");
241 return NotImplemented;
244 GpStatus WINGDIPAPI GdipSetImageAttributesOutputChannelColorProfile(GpImageAttributes *imageAttr,
245 ColorAdjustType type, BOOL enableFlag,
246 GDIPCONST WCHAR *colorProfileFilename)
248 static int calls;
250 TRACE("(%p,%u,%i,%s)\n", imageAttr, type, enableFlag, debugstr_w(colorProfileFilename));
252 if(!(calls++))
253 FIXME("not implemented\n");
255 return NotImplemented;
258 GpStatus WINGDIPAPI GdipSetImageAttributesRemapTable(GpImageAttributes *imageAttr,
259 ColorAdjustType type, BOOL enableFlag, UINT mapSize,
260 GDIPCONST ColorMap *map)
262 ColorMap *new_map;
264 TRACE("(%p,%u,%i,%u,%p)\n", imageAttr, type, enableFlag, mapSize, map);
266 if(!imageAttr || type >= ColorAdjustTypeCount)
267 return InvalidParameter;
269 if (enableFlag)
271 if(!map || !mapSize)
272 return InvalidParameter;
274 new_map = heap_alloc_zero(sizeof(*map) * mapSize);
276 if (!new_map)
277 return OutOfMemory;
279 memcpy(new_map, map, sizeof(*map) * mapSize);
281 heap_free(imageAttr->colorremaptables[type].colormap);
283 imageAttr->colorremaptables[type].mapsize = mapSize;
284 imageAttr->colorremaptables[type].colormap = new_map;
286 else
288 heap_free(imageAttr->colorremaptables[type].colormap);
289 imageAttr->colorremaptables[type].colormap = NULL;
292 imageAttr->colorremaptables[type].enabled = enableFlag;
294 return Ok;
297 GpStatus WINGDIPAPI GdipSetImageAttributesThreshold(GpImageAttributes *imageAttr,
298 ColorAdjustType type, BOOL enableFlag, REAL threshold)
300 static int calls;
302 TRACE("(%p,%u,%i,%0.2f)\n", imageAttr, type, enableFlag, threshold);
304 if(!(calls++))
305 FIXME("not implemented\n");
307 return NotImplemented;
310 GpStatus WINGDIPAPI GdipSetImageAttributesToIdentity(GpImageAttributes *imageAttr,
311 ColorAdjustType type)
313 static int calls;
315 TRACE("(%p,%u)\n", imageAttr, type);
317 if(!(calls++))
318 FIXME("not implemented\n");
320 return NotImplemented;
323 GpStatus WINGDIPAPI GdipResetImageAttributes(GpImageAttributes *imageAttr,
324 ColorAdjustType type)
326 TRACE("(%p,%u)\n", imageAttr, type);
328 if(!imageAttr || type >= ColorAdjustTypeCount)
329 return InvalidParameter;
331 memset(&imageAttr->colormatrices[type], 0, sizeof(imageAttr->colormatrices[type]));
332 GdipSetImageAttributesColorKeys(imageAttr, type, FALSE, 0, 0);
333 GdipSetImageAttributesRemapTable(imageAttr, type, FALSE, 0, NULL);
334 GdipSetImageAttributesGamma(imageAttr, type, FALSE, 0.0);
335 imageAttr->noop[type] = IMAGEATTR_NOOP_UNDEFINED;
337 return Ok;