[NTOSKRNL] Drop the useless Timestamp field
[reactos.git] / dll / win32 / gdiplus / imageattributes.c
1 /*
2 * Copyright (C) 2007 Google (Evan Stade)
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 "windef.h"
20 #include "wingdi.h"
21
22 #include "objbase.h"
23
24 #include "gdiplus.h"
25 #include "gdiplus_private.h"
26 #include "wine/debug.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
29
30 GpStatus WINGDIPAPI GdipCloneImageAttributes(GDIPCONST GpImageAttributes *imageattr,
31 GpImageAttributes **cloneImageattr)
32 {
33 GpStatus stat = Ok;
34 struct color_remap_table remap_tables[ColorAdjustTypeCount] = {{0}};
35 int i;
36
37 TRACE("(%p, %p)\n", imageattr, cloneImageattr);
38
39 if(!imageattr || !cloneImageattr)
40 return InvalidParameter;
41
42 for (i=0; i<ColorAdjustTypeCount; i++)
43 {
44 if (imageattr->colorremaptables[i].enabled)
45 {
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);
49
50 if (remap_tables[i].colormap)
51 {
52 memcpy(remap_tables[i].colormap, imageattr->colorremaptables[i].colormap,
53 sizeof(ColorMap) * remap_tables[i].mapsize);
54 }
55 else
56 {
57 stat = OutOfMemory;
58 break;
59 }
60 }
61 }
62
63 if (stat == Ok)
64 stat = GdipCreateImageAttributes(cloneImageattr);
65
66 if (stat == Ok)
67 {
68 **cloneImageattr = *imageattr;
69
70 memcpy((*cloneImageattr)->colorremaptables, remap_tables, sizeof(remap_tables));
71 }
72
73 if (stat != Ok)
74 {
75 for (i=0; i<ColorAdjustTypeCount; i++)
76 heap_free(remap_tables[i].colormap);
77 }
78
79 return stat;
80 }
81
82 GpStatus WINGDIPAPI GdipCreateImageAttributes(GpImageAttributes **imageattr)
83 {
84 if(!imageattr)
85 return InvalidParameter;
86
87 *imageattr = heap_alloc_zero(sizeof(GpImageAttributes));
88 if(!*imageattr) return OutOfMemory;
89
90 (*imageattr)->wrap = WrapModeClamp;
91
92 TRACE("<-- %p\n", *imageattr);
93
94 return Ok;
95 }
96
97 GpStatus WINGDIPAPI GdipDisposeImageAttributes(GpImageAttributes *imageattr)
98 {
99 int i;
100
101 TRACE("(%p)\n", imageattr);
102
103 if(!imageattr)
104 return InvalidParameter;
105
106 for (i=0; i<ColorAdjustTypeCount; i++)
107 heap_free(imageattr->colorremaptables[i].colormap);
108
109 heap_free(imageattr);
110
111 return Ok;
112 }
113
114 GpStatus WINGDIPAPI GdipGetImageAttributesAdjustedPalette(GpImageAttributes *imageattr,
115 ColorPalette *palette, ColorAdjustType type)
116 {
117 TRACE("(%p,%p,%u)\n", imageattr, palette, type);
118
119 if (!imageattr || !palette || !palette->Count ||
120 type >= ColorAdjustTypeCount || type == ColorAdjustTypeDefault)
121 return InvalidParameter;
122
123 apply_image_attributes(imageattr, (LPBYTE)palette->Entries, palette->Count, 1, 0,
124 type, PixelFormat32bppARGB);
125
126 return Ok;
127 }
128
129 GpStatus WINGDIPAPI GdipSetImageAttributesColorKeys(GpImageAttributes *imageattr,
130 ColorAdjustType type, BOOL enableFlag, ARGB colorLow, ARGB colorHigh)
131 {
132 TRACE("(%p,%u,%i,%08x,%08x)\n", imageattr, type, enableFlag, colorLow, colorHigh);
133
134 if(!imageattr || type >= ColorAdjustTypeCount)
135 return InvalidParameter;
136
137 imageattr->colorkeys[type].enabled = enableFlag;
138 imageattr->colorkeys[type].low = colorLow;
139 imageattr->colorkeys[type].high = colorHigh;
140
141 return Ok;
142 }
143
144 GpStatus WINGDIPAPI GdipSetImageAttributesColorMatrix(GpImageAttributes *imageattr,
145 ColorAdjustType type, BOOL enableFlag, GDIPCONST ColorMatrix* colorMatrix,
146 GDIPCONST ColorMatrix* grayMatrix, ColorMatrixFlags flags)
147 {
148 TRACE("(%p,%u,%i,%p,%p,%u)\n", imageattr, type, enableFlag, colorMatrix,
149 grayMatrix, flags);
150
151 if(!imageattr || type >= ColorAdjustTypeCount || flags > ColorMatrixFlagsAltGray)
152 return InvalidParameter;
153
154 if (enableFlag)
155 {
156 if (!colorMatrix)
157 return InvalidParameter;
158
159 if (flags == ColorMatrixFlagsAltGray)
160 {
161 if (!grayMatrix)
162 return InvalidParameter;
163
164 imageattr->colormatrices[type].graymatrix = *grayMatrix;
165 }
166
167 imageattr->colormatrices[type].colormatrix = *colorMatrix;
168 imageattr->colormatrices[type].flags = flags;
169 }
170
171 imageattr->colormatrices[type].enabled = enableFlag;
172
173 return Ok;
174 }
175
176 GpStatus WINGDIPAPI GdipSetImageAttributesWrapMode(GpImageAttributes *imageAttr,
177 WrapMode wrap, ARGB argb, BOOL clamp)
178 {
179 TRACE("(%p,%u,%08x,%i)\n", imageAttr, wrap, argb, clamp);
180
181 if(!imageAttr || wrap > WrapModeClamp)
182 return InvalidParameter;
183
184 imageAttr->wrap = wrap;
185 imageAttr->outside_color = argb;
186 imageAttr->clamp = clamp;
187
188 return Ok;
189 }
190
191 GpStatus WINGDIPAPI GdipSetImageAttributesCachedBackground(GpImageAttributes *imageAttr,
192 BOOL enableFlag)
193 {
194 static int calls;
195
196 TRACE("(%p,%i)\n", imageAttr, enableFlag);
197
198 if(!(calls++))
199 FIXME("not implemented\n");
200
201 return NotImplemented;
202 }
203
204 GpStatus WINGDIPAPI GdipSetImageAttributesGamma(GpImageAttributes *imageAttr,
205 ColorAdjustType type, BOOL enableFlag, REAL gamma)
206 {
207 TRACE("(%p,%u,%i,%0.2f)\n", imageAttr, type, enableFlag, gamma);
208
209 if (!imageAttr || (enableFlag && gamma <= 0.0) || type >= ColorAdjustTypeCount)
210 return InvalidParameter;
211
212 imageAttr->gamma_enabled[type] = enableFlag;
213 imageAttr->gamma[type] = gamma;
214
215 return Ok;
216 }
217
218 GpStatus WINGDIPAPI GdipSetImageAttributesNoOp(GpImageAttributes *imageAttr,
219 ColorAdjustType type, BOOL enableFlag)
220 {
221 TRACE("(%p,%u,%i)\n", imageAttr, type, enableFlag);
222
223 if (type >= ColorAdjustTypeCount)
224 return InvalidParameter;
225
226 imageAttr->noop[type] = enableFlag ? IMAGEATTR_NOOP_SET : IMAGEATTR_NOOP_CLEAR;
227
228 return Ok;
229 }
230
231 GpStatus WINGDIPAPI GdipSetImageAttributesOutputChannel(GpImageAttributes *imageAttr,
232 ColorAdjustType type, BOOL enableFlag, ColorChannelFlags channelFlags)
233 {
234 static int calls;
235
236 TRACE("(%p,%u,%i,%x)\n", imageAttr, type, enableFlag, channelFlags);
237
238 if(!(calls++))
239 FIXME("not implemented\n");
240
241 return NotImplemented;
242 }
243
244 GpStatus WINGDIPAPI GdipSetImageAttributesOutputChannelColorProfile(GpImageAttributes *imageAttr,
245 ColorAdjustType type, BOOL enableFlag,
246 GDIPCONST WCHAR *colorProfileFilename)
247 {
248 static int calls;
249
250 TRACE("(%p,%u,%i,%s)\n", imageAttr, type, enableFlag, debugstr_w(colorProfileFilename));
251
252 if(!(calls++))
253 FIXME("not implemented\n");
254
255 return NotImplemented;
256 }
257
258 GpStatus WINGDIPAPI GdipSetImageAttributesRemapTable(GpImageAttributes *imageAttr,
259 ColorAdjustType type, BOOL enableFlag, UINT mapSize,
260 GDIPCONST ColorMap *map)
261 {
262 ColorMap *new_map;
263
264 TRACE("(%p,%u,%i,%u,%p)\n", imageAttr, type, enableFlag, mapSize, map);
265
266 if(!imageAttr || type >= ColorAdjustTypeCount)
267 return InvalidParameter;
268
269 if (enableFlag)
270 {
271 if(!map || !mapSize)
272 return InvalidParameter;
273
274 new_map = heap_alloc_zero(sizeof(*map) * mapSize);
275
276 if (!new_map)
277 return OutOfMemory;
278
279 memcpy(new_map, map, sizeof(*map) * mapSize);
280
281 heap_free(imageAttr->colorremaptables[type].colormap);
282
283 imageAttr->colorremaptables[type].mapsize = mapSize;
284 imageAttr->colorremaptables[type].colormap = new_map;
285 }
286 else
287 {
288 heap_free(imageAttr->colorremaptables[type].colormap);
289 imageAttr->colorremaptables[type].colormap = NULL;
290 }
291
292 imageAttr->colorremaptables[type].enabled = enableFlag;
293
294 return Ok;
295 }
296
297 GpStatus WINGDIPAPI GdipSetImageAttributesThreshold(GpImageAttributes *imageAttr,
298 ColorAdjustType type, BOOL enableFlag, REAL threshold)
299 {
300 static int calls;
301
302 TRACE("(%p,%u,%i,%0.2f)\n", imageAttr, type, enableFlag, threshold);
303
304 if(!(calls++))
305 FIXME("not implemented\n");
306
307 return NotImplemented;
308 }
309
310 GpStatus WINGDIPAPI GdipSetImageAttributesToIdentity(GpImageAttributes *imageAttr,
311 ColorAdjustType type)
312 {
313 static int calls;
314
315 TRACE("(%p,%u)\n", imageAttr, type);
316
317 if(!(calls++))
318 FIXME("not implemented\n");
319
320 return NotImplemented;
321 }
322
323 GpStatus WINGDIPAPI GdipResetImageAttributes(GpImageAttributes *imageAttr,
324 ColorAdjustType type)
325 {
326 TRACE("(%p,%u)\n", imageAttr, type);
327
328 if(!imageAttr || type >= ColorAdjustTypeCount)
329 return InvalidParameter;
330
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;
336
337 return Ok;
338 }