1 /**************************************************************************\ 2 * 3 * Copyright (c) 1998-2000, Microsoft Corp. All Rights Reserved. 4 * 5 * Module Name: 6 * 7 * Image Attributes 8 * 9 * Abstract: 10 * 11 * Class for color adjustment object passed to Graphics.DrawImage 12 * 13 \**************************************************************************/ 14 15 #ifndef _GDIPLUSIMAGEATTRIBUTES_H 16 #define _GDIPLUSIMAGEATTRIBUTES_H 17 18 class GpImageAttributes; 19 20 // There are 5 possible sets of color adjustments: 21 // ColorAdjustDefault, 22 // ColorAdjustBitmap, 23 // ColorAdjustBrush, 24 // ColorAdjustPen, 25 // ColorAdjustText, 26 27 // Bitmaps, Brushes, Pens, and Text will all use any color adjustments 28 // that have been set into the default ImageAttributes until their own 29 // color adjustments have been set. So as soon as any "Set" method is 30 // called for Bitmaps, Brushes, Pens, or Text, then they start from 31 // scratch with only the color adjustments that have been set for them. 32 // Calling Reset removes any individual color adjustments for a type 33 // and makes it revert back to using all the default color adjustments 34 // (if any). The SetToIdentity method is a way to force a type to 35 // have no color adjustments at all, regardless of what previous adjustments 36 // have been set for the defaults or for that type. 37 38 class ImageAttributes : public GdiplusBase 39 { 40 friend class Graphics; 41 friend class TextureBrush; 42 43 public: 44 45 ImageAttributes() 46 { 47 nativeImageAttr = NULL; 48 lastResult = DllExports::GdipCreateImageAttributes(&nativeImageAttr); 49 } 50 51 ~ImageAttributes() 52 { 53 DllExports::GdipDisposeImageAttributes(nativeImageAttr); 54 } 55 56 ImageAttributes* Clone() const 57 { 58 GpImageAttributes* clone; 59 60 SetStatus(DllExports::GdipCloneImageAttributes( 61 nativeImageAttr, 62 &clone)); 63 64 return new ImageAttributes(clone, lastResult); 65 } 66 67 // Set to identity, regardless of what the default color adjustment is. 68 Status 69 SetToIdentity( 70 IN ColorAdjustType type = ColorAdjustTypeDefault 71 ) 72 { 73 return SetStatus(DllExports::GdipSetImageAttributesToIdentity( 74 nativeImageAttr, 75 type)); 76 } 77 78 // Remove any individual color adjustments, and go back to using the default 79 Status 80 Reset( 81 IN ColorAdjustType type = ColorAdjustTypeDefault 82 ) 83 { 84 return SetStatus(DllExports::GdipResetImageAttributes( 85 nativeImageAttr, 86 type)); 87 } 88 89 Status 90 SetColorMatrix( 91 IN const ColorMatrix *colorMatrix, 92 IN ColorMatrixFlags mode = ColorMatrixFlagsDefault, 93 IN ColorAdjustType type = ColorAdjustTypeDefault 94 ) 95 { 96 return SetStatus(DllExports::GdipSetImageAttributesColorMatrix( 97 nativeImageAttr, 98 type, 99 TRUE, 100 colorMatrix, 101 NULL, 102 mode)); 103 } 104 105 Status ClearColorMatrix( 106 IN ColorAdjustType type = ColorAdjustTypeDefault 107 ) 108 { 109 return SetStatus(DllExports::GdipSetImageAttributesColorMatrix( 110 nativeImageAttr, 111 type, 112 FALSE, 113 NULL, 114 NULL, 115 ColorMatrixFlagsDefault)); 116 } 117 118 Status 119 SetColorMatrices( 120 IN const ColorMatrix *colorMatrix, 121 IN const ColorMatrix *grayMatrix, 122 IN ColorMatrixFlags mode = ColorMatrixFlagsDefault, 123 IN ColorAdjustType type = ColorAdjustTypeDefault 124 ) 125 { 126 return SetStatus(DllExports::GdipSetImageAttributesColorMatrix( 127 nativeImageAttr, 128 type, 129 TRUE, 130 colorMatrix, 131 grayMatrix, 132 mode)); 133 } 134 135 Status ClearColorMatrices( 136 IN ColorAdjustType type = ColorAdjustTypeDefault 137 ) 138 { 139 return SetStatus(DllExports::GdipSetImageAttributesColorMatrix( 140 nativeImageAttr, 141 type, 142 FALSE, 143 NULL, 144 NULL, 145 ColorMatrixFlagsDefault)); 146 } 147 148 Status SetThreshold( 149 IN REAL threshold, 150 IN ColorAdjustType type = ColorAdjustTypeDefault 151 ) 152 { 153 return SetStatus(DllExports::GdipSetImageAttributesThreshold( 154 nativeImageAttr, 155 type, 156 TRUE, 157 threshold)); 158 } 159 160 Status ClearThreshold( 161 IN ColorAdjustType type = ColorAdjustTypeDefault 162 ) 163 { 164 return SetStatus(DllExports::GdipSetImageAttributesThreshold( 165 nativeImageAttr, 166 type, 167 FALSE, 168 0.0)); 169 } 170 171 Status SetGamma( 172 IN REAL gamma, 173 IN ColorAdjustType type = ColorAdjustTypeDefault 174 ) 175 { 176 return SetStatus(DllExports::GdipSetImageAttributesGamma( 177 nativeImageAttr, 178 type, 179 TRUE, 180 gamma)); 181 } 182 183 Status ClearGamma( 184 IN ColorAdjustType type = ColorAdjustTypeDefault 185 ) 186 { 187 return SetStatus(DllExports::GdipSetImageAttributesGamma( 188 nativeImageAttr, 189 type, 190 FALSE, 191 0.0)); 192 } 193 194 Status SetNoOp( 195 IN ColorAdjustType type = ColorAdjustTypeDefault 196 ) 197 { 198 return SetStatus(DllExports::GdipSetImageAttributesNoOp( 199 nativeImageAttr, 200 type, 201 TRUE)); 202 } 203 204 Status ClearNoOp( 205 IN ColorAdjustType type = ColorAdjustTypeDefault 206 ) 207 { 208 return SetStatus(DllExports::GdipSetImageAttributesNoOp( 209 nativeImageAttr, 210 type, 211 FALSE)); 212 } 213 214 Status SetColorKey( 215 IN const Color& colorLow, 216 IN const Color& colorHigh, 217 IN ColorAdjustType type = ColorAdjustTypeDefault 218 ) 219 { 220 return SetStatus(DllExports::GdipSetImageAttributesColorKeys( 221 nativeImageAttr, 222 type, 223 TRUE, 224 colorLow.GetValue(), 225 colorHigh.GetValue())); 226 } 227 228 Status ClearColorKey( 229 IN ColorAdjustType type = ColorAdjustTypeDefault 230 ) 231 { 232 return SetStatus(DllExports::GdipSetImageAttributesColorKeys( 233 nativeImageAttr, 234 type, 235 FALSE, 236 NULL, 237 NULL)); 238 } 239 240 Status SetOutputChannel( 241 IN ColorChannelFlags channelFlags, 242 IN ColorAdjustType type = ColorAdjustTypeDefault 243 ) 244 { 245 return SetStatus(DllExports::GdipSetImageAttributesOutputChannel( 246 nativeImageAttr, 247 type, 248 TRUE, 249 channelFlags)); 250 } 251 252 Status ClearOutputChannel( 253 IN ColorAdjustType type = ColorAdjustTypeDefault 254 ) 255 { 256 return SetStatus(DllExports::GdipSetImageAttributesOutputChannel( 257 nativeImageAttr, 258 type, 259 FALSE, 260 ColorChannelFlagsLast)); 261 } 262 263 Status SetOutputChannelColorProfile( 264 IN const WCHAR *colorProfileFilename, 265 IN ColorAdjustType type = ColorAdjustTypeDefault 266 ) 267 { 268 return SetStatus(DllExports::GdipSetImageAttributesOutputChannelColorProfile( 269 nativeImageAttr, 270 type, 271 TRUE, 272 colorProfileFilename)); 273 } 274 275 Status ClearOutputChannelColorProfile( 276 IN ColorAdjustType type = ColorAdjustTypeDefault 277 ) 278 { 279 return SetStatus(DllExports::GdipSetImageAttributesOutputChannelColorProfile( 280 nativeImageAttr, 281 type, 282 FALSE, 283 NULL)); 284 } 285 286 Status SetRemapTable( 287 IN UINT mapSize, 288 IN const ColorMap *map, 289 IN ColorAdjustType type = ColorAdjustTypeDefault 290 ) 291 { 292 return SetStatus(DllExports::GdipSetImageAttributesRemapTable( 293 nativeImageAttr, 294 type, 295 TRUE, 296 mapSize, 297 map)); 298 } 299 300 Status ClearRemapTable( 301 IN ColorAdjustType type = ColorAdjustTypeDefault 302 ) 303 { 304 return SetStatus(DllExports::GdipSetImageAttributesRemapTable( 305 nativeImageAttr, 306 type, 307 FALSE, 308 0, 309 NULL)); 310 } 311 312 Status SetBrushRemapTable(IN UINT mapSize, 313 IN const ColorMap *map) 314 { 315 return this->SetRemapTable(mapSize, map, ColorAdjustTypeBrush); 316 } 317 318 Status ClearBrushRemapTable() 319 { 320 return this->ClearRemapTable(ColorAdjustTypeBrush); 321 } 322 323 Status SetWrapMode(IN WrapMode wrap, 324 IN const Color& color = Color(), 325 IN BOOL clamp = FALSE) 326 { 327 ARGB argb = color.GetValue(); 328 329 return SetStatus(DllExports::GdipSetImageAttributesWrapMode( 330 nativeImageAttr, wrap, argb, clamp)); 331 } 332 333 #ifndef DCR_USE_NEW_145139 334 Status SetICMMode(IN BOOL on) 335 { 336 on; 337 // This is not implemented. 338 // The supported method for doing ICM conversion from the embedded 339 // ICC profile is to use the Bitmap constructor from a file or stream 340 // and specify TRUE for the useIcm parameter. This will cause the 341 // image to be ICM converted when it's loaded from the file/stream 342 // if the profile exists. 343 return SetStatus(NotImplemented); 344 // DllExports::GdipSetImageAttributesICMMode(nativeImageAttr, on) 345 } 346 #endif 347 348 // The flags of the palette are ignored. 349 Status GetAdjustedPalette(IN OUT ColorPalette* colorPalette, 350 IN ColorAdjustType colorAdjustType) const 351 { 352 return SetStatus(DllExports::GdipGetImageAttributesAdjustedPalette( 353 nativeImageAttr, colorPalette, colorAdjustType)); 354 } 355 356 Status GetLastStatus() const 357 { 358 Status lastStatus = lastResult; 359 lastResult = Ok; 360 361 return lastStatus; 362 } 363 364 #ifdef DCR_USE_NEW_250932 365 366 private: 367 ImageAttributes(const ImageAttributes &); 368 ImageAttributes& operator=(const ImageAttributes &); 369 370 #endif 371 372 protected: 373 ImageAttributes(GpImageAttributes* imageAttr, Status status) 374 { 375 SetNativeImageAttr(imageAttr); 376 lastResult = status; 377 } 378 379 VOID SetNativeImageAttr(GpImageAttributes* nativeImageAttr) 380 { 381 this->nativeImageAttr = nativeImageAttr; 382 } 383 384 Status SetStatus(Status status) const 385 { 386 if (status != Ok) 387 return (lastResult = status); 388 else 389 return status; 390 } 391 392 protected: 393 GpImageAttributes* nativeImageAttr; 394 mutable Status lastResult; 395 }; 396 397 #endif 398