PageRenderTime 33ms CodeModel.GetById 19ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/binding/win32/gdipluspixelformats.d

http://github.com/wilkie/djehuty
D | 185 lines | 88 code | 42 blank | 55 comment | 4 complexity | f3c33f7bb2fe4f1fc24ad0302792e78a MD5 | raw file
  1/*
  2 * gdipluspixelformats.d
  3 *
  4 * This module binds GdiPlusPixelFormats.h to D. The original copyright
  5 * notice is preserved below.
  6 *
  7 * Author: Dave Wilkinson
  8 * Originated: November 25th, 2009
  9 *
 10 */
 11
 12module binding.win32.gdipluspixelformats;
 13
 14import binding.win32.windef;
 15import binding.win32.winbase;
 16import binding.win32.winnt;
 17
 18import binding.win32.gdiplustypes;
 19
 20/**************************************************************************\
 21*
 22* Copyright (c) 1998-2001, Microsoft Corp.  All Rights Reserved.
 23*
 24* Module Name:
 25*
 26*   Gdiplus Pixel Formats
 27*
 28* Abstract:
 29*
 30*   GDI+ Pixel Formats
 31*
 32\**************************************************************************/
 33
 34alias DWORD ARGB;
 35alias DWORDLONG ARGB64;
 36
 37const auto ALPHA_SHIFT = 24;
 38const auto RED_SHIFT   = 16;
 39const auto GREEN_SHIFT = 8;
 40const auto BLUE_SHIFT  = 0;
 41const auto ALPHA_MASK  = (cast(ARGB) 0xff << ALPHA_SHIFT);
 42
 43// In-memory pixel data formats:
 44// bits 0-7 = format index
 45// bits 8-15 = pixel size (in bits)
 46// bits 16-23 = flags
 47// bits 24-31 = reserved
 48
 49alias INT PixelFormat;
 50
 51const auto    PixelFormatIndexed      = 0x00010000; // Indexes into a palette
 52const auto    PixelFormatGDI          = 0x00020000; // Is a GDI-supported format
 53const auto    PixelFormatAlpha        = 0x00040000; // Has an alpha component
 54const auto    PixelFormatPAlpha       = 0x00080000; // Pre-multiplied alpha
 55const auto    PixelFormatExtended     = 0x00100000; // Extended color 16 bits/channel
 56const auto    PixelFormatCanonical    = 0x00200000;
 57
 58const auto    PixelFormatUndefined       = 0;
 59const auto    PixelFormatDontCare        = 0;
 60
 61const auto    PixelFormat1bppIndexed     = (1 | ( 1 << 8) | PixelFormatIndexed | PixelFormatGDI);
 62const auto    PixelFormat4bppIndexed     = (2 | ( 4 << 8) | PixelFormatIndexed | PixelFormatGDI);
 63const auto    PixelFormat8bppIndexed     = (3 | ( 8 << 8) | PixelFormatIndexed | PixelFormatGDI);
 64const auto    PixelFormat16bppGrayScale  = (4 | (16 << 8) | PixelFormatExtended);
 65const auto    PixelFormat16bppRGB555     = (5 | (16 << 8) | PixelFormatGDI);
 66const auto    PixelFormat16bppRGB565     = (6 | (16 << 8) | PixelFormatGDI);
 67const auto    PixelFormat16bppARGB1555   = (7 | (16 << 8) | PixelFormatAlpha | PixelFormatGDI);
 68const auto    PixelFormat24bppRGB        = (8 | (24 << 8) | PixelFormatGDI);
 69const auto    PixelFormat32bppRGB        = (9 | (32 << 8) | PixelFormatGDI);
 70const auto    PixelFormat32bppARGB       = (10 | (32 << 8) | PixelFormatAlpha | PixelFormatGDI | PixelFormatCanonical);
 71const auto    PixelFormat32bppPARGB      = (11 | (32 << 8) | PixelFormatAlpha | PixelFormatPAlpha | PixelFormatGDI);
 72const auto    PixelFormat48bppRGB        = (12 | (48 << 8) | PixelFormatExtended);
 73const auto    PixelFormat64bppARGB       = (13 | (64 << 8) | PixelFormatAlpha  | PixelFormatCanonical | PixelFormatExtended);
 74const auto    PixelFormat64bppPARGB      = (14 | (64 << 8) | PixelFormatAlpha  | PixelFormatPAlpha | PixelFormatExtended);
 75const auto    PixelFormat32bppCMYK       = (15 | (32 << 8));
 76const auto    PixelFormatMax             = 16;
 77
 78UINT GetPixelFormatSize(PixelFormat pixfmt) {
 79    return (pixfmt >> 8) & 0xff;
 80}
 81
 82BOOL IsIndexedPixelFormat(PixelFormat pixfmt) {
 83    return (pixfmt & PixelFormatIndexed) != 0;
 84}
 85
 86BOOL IsAlphaPixelFormat(PixelFormat pixfmt) {
 87   return (pixfmt & PixelFormatAlpha) != 0;
 88}
 89
 90BOOL IsExtendedPixelFormat(PixelFormat pixfmt) {
 91   return (pixfmt & PixelFormatExtended) != 0;
 92}
 93
 94//--------------------------------------------------------------------------
 95// Determine if the Pixel Format is Canonical format:
 96//   PixelFormat32bppARGB
 97//   PixelFormat32bppPARGB
 98//   PixelFormat64bppARGB
 99//   PixelFormat64bppPARGB
100//--------------------------------------------------------------------------
101
102BOOL IsCanonicalPixelFormat(PixelFormat pixfmt) {
103   return (pixfmt & PixelFormatCanonical) != 0;
104}
105
106//----------------------------------------------------------------------------
107// Color format conversion parameters
108//----------------------------------------------------------------------------
109
110enum PaletteType {
111    // Arbitrary custom palette provided by caller.
112
113    PaletteTypeCustom           = 0,
114
115    // Optimal palette generated using a median-cut algorithm.
116
117    PaletteTypeOptimal        = 1,
118
119    // Black and white palette.
120
121    PaletteTypeFixedBW          = 2,
122
123    // Symmetric halftone palettes.
124    // Each of these halftone palettes will be a superset of the system palette.
125    // E.g. Halftone8 will have it's 8-color on-off primaries and the 16 system
126    // colors added. With duplicates removed, that leaves 16 colors.
127
128    PaletteTypeFixedHalftone8   = 3, // 8-color, on-off primaries
129    PaletteTypeFixedHalftone27  = 4, // 3 intensity levels of each color
130    PaletteTypeFixedHalftone64  = 5, // 4 intensity levels of each color
131    PaletteTypeFixedHalftone125 = 6, // 5 intensity levels of each color
132    PaletteTypeFixedHalftone216 = 7, // 6 intensity levels of each color
133
134    // Assymetric halftone palettes.
135    // These are somewhat less useful than the symmetric ones, but are
136    // included for completeness. These do not include all of the system
137    // colors.
138
139    PaletteTypeFixedHalftone252 = 8, // 6-red, 7-green, 6-blue intensities
140    PaletteTypeFixedHalftone256 = 9, // 8-red, 8-green, 4-blue intensities
141}
142
143enum DitherType {
144    DitherTypeNone          = 0,
145
146    // Solid color - picks the nearest matching color with no attempt to
147    // halftone or dither. May be used on an arbitrary palette.
148
149    DitherTypeSolid         = 1,
150
151    // Ordered dithers and spiral dithers must be used with a fixed palette.
152
153    // NOTE: DitherOrdered4x4 is unique in that it may apply to 16bpp
154    // conversions also.
155
156    DitherTypeOrdered4x4    = 2,
157
158    DitherTypeOrdered8x8    = 3,
159    DitherTypeOrdered16x16  = 4,
160    DitherTypeSpiral4x4     = 5,
161    DitherTypeSpiral8x8     = 6,
162    DitherTypeDualSpiral4x4 = 7,
163    DitherTypeDualSpiral8x8 = 8,
164    
165    // Error diffusion. May be used with any palette.
166    
167    DitherTypeErrorDiffusion   = 9,
168
169    DitherTypeMax              = 10
170}
171
172enum PaletteFlags {
173    PaletteFlagsHasAlpha    = 0x0001,
174    PaletteFlagsGrayScale   = 0x0002,
175    PaletteFlagsHalftone    = 0x0004
176}
177
178struct ColorPalette {
179public:
180
181    UINT Flags;             // Palette flags
182    UINT Count;             // Number of color entries
183    ARGB[1] Entries;        // Palette color entries
184}
185