imageattributes.c 7.55 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright (C) 2007 Google (Evan Stade)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include "windef.h"
20
#include "wingdi.h"
21

22 23
#include "objbase.h"

24 25 26 27 28 29
#include "gdiplus.h"
#include "gdiplus_private.h"
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);

30 31 32
GpStatus WINGDIPAPI GdipCloneImageAttributes(GDIPCONST GpImageAttributes *imageattr,
    GpImageAttributes **cloneImageattr)
{
33 34
    GpStatus stat;

35 36
    TRACE("(%p, %p)\n", imageattr, cloneImageattr);

37 38 39
    if(!imageattr || !cloneImageattr)
        return InvalidParameter;

40
    stat = GdipCreateImageAttributes(cloneImageattr);
41

42 43 44 45
    if (stat == Ok)
        **cloneImageattr = *imageattr;

    return stat;
46 47
}

48 49 50 51 52
GpStatus WINGDIPAPI GdipCreateImageAttributes(GpImageAttributes **imageattr)
{
    if(!imageattr)
        return InvalidParameter;

53
    *imageattr = heap_alloc_zero(sizeof(GpImageAttributes));
54
    if(!*imageattr)    return OutOfMemory;
55

56 57
    (*imageattr)->wrap = WrapModeClamp;

58 59
    TRACE("<-- %p\n", *imageattr);

60
    return Ok;
61 62 63 64
}

GpStatus WINGDIPAPI GdipDisposeImageAttributes(GpImageAttributes *imageattr)
{
65 66
    int i;

67 68
    TRACE("(%p)\n", imageattr);

69 70 71
    if(!imageattr)
        return InvalidParameter;

72
    for (i=0; i<ColorAdjustTypeCount; i++)
73
        heap_free(imageattr->colorremaptables[i].colormap);
74

75
    heap_free(imageattr);
76

77
    return Ok;
78 79
}

80 81 82
GpStatus WINGDIPAPI GdipSetImageAttributesColorKeys(GpImageAttributes *imageattr,
    ColorAdjustType type, BOOL enableFlag, ARGB colorLow, ARGB colorHigh)
{
83
    TRACE("(%p,%u,%i,%08x,%08x)\n", imageattr, type, enableFlag, colorLow, colorHigh);
84

85
    if(!imageattr || type >= ColorAdjustTypeCount)
86 87
        return InvalidParameter;

88 89 90
    imageattr->colorkeys[type].enabled = enableFlag;
    imageattr->colorkeys[type].low = colorLow;
    imageattr->colorkeys[type].high = colorHigh;
91

92
    return Ok;
93 94
}

95 96 97 98
GpStatus WINGDIPAPI GdipSetImageAttributesColorMatrix(GpImageAttributes *imageattr,
    ColorAdjustType type, BOOL enableFlag, GDIPCONST ColorMatrix* colorMatrix,
    GDIPCONST ColorMatrix* grayMatrix, ColorMatrixFlags flags)
{
99 100
    TRACE("(%p,%u,%i,%p,%p,%u)\n", imageattr, type, enableFlag, colorMatrix,
        grayMatrix, flags);
101

102
    if(!imageattr || type >= ColorAdjustTypeCount || flags > ColorMatrixFlagsAltGray)
103 104
        return InvalidParameter;

105 106 107 108 109 110 111 112 113
    if (enableFlag)
    {
        if (!colorMatrix)
            return InvalidParameter;

        if (flags == ColorMatrixFlagsAltGray)
        {
            if (!grayMatrix)
                return InvalidParameter;
114

115 116 117 118 119 120 121 122 123 124
            imageattr->colormatrices[type].graymatrix = *grayMatrix;
        }

        imageattr->colormatrices[type].colormatrix = *colorMatrix;
        imageattr->colormatrices[type].flags = flags;
    }

    imageattr->colormatrices[type].enabled = enableFlag;

    return Ok;
125 126
}

127 128 129
GpStatus WINGDIPAPI GdipSetImageAttributesWrapMode(GpImageAttributes *imageAttr,
    WrapMode wrap, ARGB argb, BOOL clamp)
{
130 131
    TRACE("(%p,%u,%08x,%i)\n", imageAttr, wrap, argb, clamp);

132
    if(!imageAttr || wrap > WrapModeClamp)
133 134
        return InvalidParameter;

135 136 137
    imageAttr->wrap = wrap;
    imageAttr->outside_color = argb;
    imageAttr->clamp = clamp;
138

139
    return Ok;
140
}
141 142 143 144 145 146

GpStatus WINGDIPAPI GdipSetImageAttributesCachedBackground(GpImageAttributes *imageAttr,
    BOOL enableFlag)
{
    static int calls;

147 148
    TRACE("(%p,%i)\n", imageAttr, enableFlag);

149 150 151 152 153
    if(!(calls++))
        FIXME("not implemented\n");

    return NotImplemented;
}
154 155 156 157

GpStatus WINGDIPAPI GdipSetImageAttributesGamma(GpImageAttributes *imageAttr,
    ColorAdjustType type, BOOL enableFlag, REAL gamma)
{
158 159
    TRACE("(%p,%u,%i,%0.2f)\n", imageAttr, type, enableFlag, gamma);

160 161
    if (!imageAttr || (enableFlag && gamma <= 0.0) || type >= ColorAdjustTypeCount)
        return InvalidParameter;
162

163 164 165 166
    imageAttr->gamma_enabled[type] = enableFlag;
    imageAttr->gamma[type] = gamma;

    return Ok;
167
}
168 169 170 171 172 173

GpStatus WINGDIPAPI GdipSetImageAttributesNoOp(GpImageAttributes *imageAttr,
    ColorAdjustType type, BOOL enableFlag)
{
    static int calls;

174 175
    TRACE("(%p,%u,%i)\n", imageAttr, type, enableFlag);

176 177 178 179 180
    if(!(calls++))
        FIXME("not implemented\n");

    return NotImplemented;
}
181 182 183 184 185 186

GpStatus WINGDIPAPI GdipSetImageAttributesOutputChannel(GpImageAttributes *imageAttr,
    ColorAdjustType type, BOOL enableFlag, ColorChannelFlags channelFlags)
{
    static int calls;

187 188
    TRACE("(%p,%u,%i,%x)\n", imageAttr, type, enableFlag, channelFlags);

189 190 191 192 193
    if(!(calls++))
        FIXME("not implemented\n");

    return NotImplemented;
}
194 195 196 197 198 199 200

GpStatus WINGDIPAPI GdipSetImageAttributesOutputChannelColorProfile(GpImageAttributes *imageAttr,
    ColorAdjustType type, BOOL enableFlag,
    GDIPCONST WCHAR *colorProfileFilename)
{
    static int calls;

201 202
    TRACE("(%p,%u,%i,%s)\n", imageAttr, type, enableFlag, debugstr_w(colorProfileFilename));

203 204 205 206 207
    if(!(calls++))
        FIXME("not implemented\n");

    return NotImplemented;
}
208 209 210 211 212

GpStatus WINGDIPAPI GdipSetImageAttributesRemapTable(GpImageAttributes *imageAttr,
    ColorAdjustType type, BOOL enableFlag, UINT mapSize,
    GDIPCONST ColorMap *map)
{
213 214
    ColorMap *new_map;

215 216
    TRACE("(%p,%u,%i,%u,%p)\n", imageAttr, type, enableFlag, mapSize, map);

217 218
    if(!imageAttr || type >= ColorAdjustTypeCount)
	return InvalidParameter;
219

220 221 222 223 224
    if (enableFlag)
    {
        if(!map || !mapSize)
	    return InvalidParameter;

225
        new_map = heap_alloc_zero(sizeof(*map) * mapSize);
226 227 228 229 230 231

        if (!new_map)
            return OutOfMemory;

        memcpy(new_map, map, sizeof(*map) * mapSize);

232
        heap_free(imageAttr->colorremaptables[type].colormap);
233

234
        imageAttr->colorremaptables[type].mapsize = mapSize;
235 236 237 238
        imageAttr->colorremaptables[type].colormap = new_map;
    }
    else
    {
239
        heap_free(imageAttr->colorremaptables[type].colormap);
240
        imageAttr->colorremaptables[type].colormap = NULL;
241 242 243 244 245
    }

    imageAttr->colorremaptables[type].enabled = enableFlag;

    return Ok;
246
}
247 248 249 250 251 252

GpStatus WINGDIPAPI GdipSetImageAttributesThreshold(GpImageAttributes *imageAttr,
    ColorAdjustType type, BOOL enableFlag, REAL threshold)
{
    static int calls;

253 254
    TRACE("(%p,%u,%i,%0.2f)\n", imageAttr, type, enableFlag, threshold);

255 256 257 258 259
    if(!(calls++))
        FIXME("not implemented\n");

    return NotImplemented;
}
260 261 262 263 264 265

GpStatus WINGDIPAPI GdipSetImageAttributesToIdentity(GpImageAttributes *imageAttr,
    ColorAdjustType type)
{
    static int calls;

266 267
    TRACE("(%p,%u)\n", imageAttr, type);

268 269 270 271 272
    if(!(calls++))
        FIXME("not implemented\n");

    return NotImplemented;
}
273 274 275 276 277 278 279 280 281 282

GpStatus WINGDIPAPI GdipResetImageAttributes(GpImageAttributes *imageAttr,
    ColorAdjustType type)
{
    TRACE("(%p,%u)\n", imageAttr, type);

    if(!imageAttr || type >= ColorAdjustTypeCount)
        return InvalidParameter;

    memset(&imageAttr->colormatrices[type], 0, sizeof(imageAttr->colormatrices[type]));
283 284 285
    GdipSetImageAttributesColorKeys(imageAttr, type, FALSE, 0, 0);
    GdipSetImageAttributesRemapTable(imageAttr, type, FALSE, 0, NULL);
    GdipSetImageAttributesGamma(imageAttr, type, FALSE, 0.0);
286 287 288

    return Ok;
}