ddraw/tests: Add basic tests for DrawIndexedPrimitiveStrided.
[wine] / dlls / 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;
34
35     TRACE("(%p, %p)\n", imageattr, cloneImageattr);
36
37     if(!imageattr || !cloneImageattr)
38         return InvalidParameter;
39
40     stat = GdipCreateImageAttributes(cloneImageattr);
41
42     if (stat == Ok)
43         **cloneImageattr = *imageattr;
44
45     return stat;
46 }
47
48 GpStatus WINGDIPAPI GdipCreateImageAttributes(GpImageAttributes **imageattr)
49 {
50     if(!imageattr)
51         return InvalidParameter;
52
53     *imageattr = GdipAlloc(sizeof(GpImageAttributes));
54     if(!*imageattr)    return OutOfMemory;
55
56     (*imageattr)->wrap = WrapModeClamp;
57
58     TRACE("<-- %p\n", *imageattr);
59
60     return Ok;
61 }
62
63 GpStatus WINGDIPAPI GdipDisposeImageAttributes(GpImageAttributes *imageattr)
64 {
65     int i;
66
67     TRACE("(%p)\n", imageattr);
68
69     if(!imageattr)
70         return InvalidParameter;
71
72     for (i=0; i<ColorAdjustTypeCount; i++)
73         GdipFree(imageattr->colorremaptables[i].colormap);
74
75     GdipFree(imageattr);
76
77     return Ok;
78 }
79
80 GpStatus WINGDIPAPI GdipSetImageAttributesColorKeys(GpImageAttributes *imageattr,
81     ColorAdjustType type, BOOL enableFlag, ARGB colorLow, ARGB colorHigh)
82 {
83     TRACE("(%p,%u,%i,%08x,%08x)\n", imageattr, type, enableFlag, colorLow, colorHigh);
84
85     if(!imageattr || type >= ColorAdjustTypeCount)
86         return InvalidParameter;
87
88     imageattr->colorkeys[type].enabled = enableFlag;
89     imageattr->colorkeys[type].low = colorLow;
90     imageattr->colorkeys[type].high = colorHigh;
91
92     return Ok;
93 }
94
95 GpStatus WINGDIPAPI GdipSetImageAttributesColorMatrix(GpImageAttributes *imageattr,
96     ColorAdjustType type, BOOL enableFlag, GDIPCONST ColorMatrix* colorMatrix,
97     GDIPCONST ColorMatrix* grayMatrix, ColorMatrixFlags flags)
98 {
99     TRACE("(%p,%u,%i,%p,%p,%u)\n", imageattr, type, enableFlag, colorMatrix,
100         grayMatrix, flags);
101
102     if(!imageattr || type >= ColorAdjustTypeCount || flags > ColorMatrixFlagsAltGray)
103         return InvalidParameter;
104
105     if (enableFlag)
106     {
107         if (!colorMatrix)
108             return InvalidParameter;
109
110         if (flags == ColorMatrixFlagsAltGray)
111         {
112             if (!grayMatrix)
113                 return InvalidParameter;
114
115             imageattr->colormatrices[type].graymatrix = *grayMatrix;
116         }
117
118         imageattr->colormatrices[type].colormatrix = *colorMatrix;
119         imageattr->colormatrices[type].flags = flags;
120     }
121
122     imageattr->colormatrices[type].enabled = enableFlag;
123
124     return Ok;
125 }
126
127 GpStatus WINGDIPAPI GdipSetImageAttributesWrapMode(GpImageAttributes *imageAttr,
128     WrapMode wrap, ARGB argb, BOOL clamp)
129 {
130     TRACE("(%p,%u,%08x,%i)\n", imageAttr, wrap, argb, clamp);
131
132     if(!imageAttr || wrap > WrapModeClamp)
133         return InvalidParameter;
134
135     imageAttr->wrap = wrap;
136     imageAttr->outside_color = argb;
137     imageAttr->clamp = clamp;
138
139     return Ok;
140 }
141
142 GpStatus WINGDIPAPI GdipSetImageAttributesCachedBackground(GpImageAttributes *imageAttr,
143     BOOL enableFlag)
144 {
145     static int calls;
146
147     TRACE("(%p,%i)\n", imageAttr, enableFlag);
148
149     if(!(calls++))
150         FIXME("not implemented\n");
151
152     return NotImplemented;
153 }
154
155 GpStatus WINGDIPAPI GdipSetImageAttributesGamma(GpImageAttributes *imageAttr,
156     ColorAdjustType type, BOOL enableFlag, REAL gamma)
157 {
158     TRACE("(%p,%u,%i,%0.2f)\n", imageAttr, type, enableFlag, gamma);
159
160     if (!imageAttr || (enableFlag && gamma <= 0.0) || type >= ColorAdjustTypeCount)
161         return InvalidParameter;
162
163     imageAttr->gamma_enabled[type] = enableFlag;
164     imageAttr->gamma[type] = gamma;
165
166     return Ok;
167 }
168
169 GpStatus WINGDIPAPI GdipSetImageAttributesNoOp(GpImageAttributes *imageAttr,
170     ColorAdjustType type, BOOL enableFlag)
171 {
172     static int calls;
173
174     TRACE("(%p,%u,%i)\n", imageAttr, type, enableFlag);
175
176     if(!(calls++))
177         FIXME("not implemented\n");
178
179     return NotImplemented;
180 }
181
182 GpStatus WINGDIPAPI GdipSetImageAttributesOutputChannel(GpImageAttributes *imageAttr,
183     ColorAdjustType type, BOOL enableFlag, ColorChannelFlags channelFlags)
184 {
185     static int calls;
186
187     TRACE("(%p,%u,%i,%x)\n", imageAttr, type, enableFlag, channelFlags);
188
189     if(!(calls++))
190         FIXME("not implemented\n");
191
192     return NotImplemented;
193 }
194
195 GpStatus WINGDIPAPI GdipSetImageAttributesOutputChannelColorProfile(GpImageAttributes *imageAttr,
196     ColorAdjustType type, BOOL enableFlag,
197     GDIPCONST WCHAR *colorProfileFilename)
198 {
199     static int calls;
200
201     TRACE("(%p,%u,%i,%s)\n", imageAttr, type, enableFlag, debugstr_w(colorProfileFilename));
202
203     if(!(calls++))
204         FIXME("not implemented\n");
205
206     return NotImplemented;
207 }
208
209 GpStatus WINGDIPAPI GdipSetImageAttributesRemapTable(GpImageAttributes *imageAttr,
210     ColorAdjustType type, BOOL enableFlag, UINT mapSize,
211     GDIPCONST ColorMap *map)
212 {
213     ColorMap *new_map;
214
215     TRACE("(%p,%u,%i,%u,%p)\n", imageAttr, type, enableFlag, mapSize, map);
216
217     if(!imageAttr || type >= ColorAdjustTypeCount)
218         return InvalidParameter;
219
220     if (enableFlag)
221     {
222         if(!map || !mapSize)
223             return InvalidParameter;
224
225         new_map = GdipAlloc(sizeof(*map) * mapSize);
226
227         if (!new_map)
228             return OutOfMemory;
229
230         memcpy(new_map, map, sizeof(*map) * mapSize);
231
232         GdipFree(imageAttr->colorremaptables[type].colormap);
233
234         imageAttr->colorremaptables[type].mapsize = mapSize;
235         imageAttr->colorremaptables[type].colormap = new_map;
236     }
237     else
238     {
239         GdipFree(imageAttr->colorremaptables[type].colormap);
240         imageAttr->colorremaptables[type].colormap = NULL;
241     }
242
243     imageAttr->colorremaptables[type].enabled = enableFlag;
244
245     return Ok;
246 }
247
248 GpStatus WINGDIPAPI GdipSetImageAttributesThreshold(GpImageAttributes *imageAttr,
249     ColorAdjustType type, BOOL enableFlag, REAL threshold)
250 {
251     static int calls;
252
253     TRACE("(%p,%u,%i,%0.2f)\n", imageAttr, type, enableFlag, threshold);
254
255     if(!(calls++))
256         FIXME("not implemented\n");
257
258     return NotImplemented;
259 }
260
261 GpStatus WINGDIPAPI GdipSetImageAttributesToIdentity(GpImageAttributes *imageAttr,
262     ColorAdjustType type)
263 {
264     static int calls;
265
266     TRACE("(%p,%u)\n", imageAttr, type);
267
268     if(!(calls++))
269         FIXME("not implemented\n");
270
271     return NotImplemented;
272 }