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