Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
4.7 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998-1999, Microsoft Corp. All Rights Reserved.
  4. *
  5. * Module Name:
  6. *
  7. * Gdiplus pixel formats
  8. *
  9. * Abstract:
  10. *
  11. * Definitions for color types, palettes, pixel format IDs.
  12. *
  13. * Notes:
  14. *
  15. * imaging.h
  16. *
  17. * Revision History:
  18. *
  19. * 10/13/1999 agodfrey
  20. * Separated it from imaging.h
  21. *
  22. \**************************************************************************/
  23. #ifndef _GDIPLUSPIXELFORMATS_H
  24. #define _GDIPLUSPIXELFORMATS_H
  25. //
  26. // 32-bit and 64-bit ARGB pixel value
  27. //
  28. typedef DWORD ARGB;
  29. typedef DWORDLONG ARGB64;
  30. #define ALPHA_SHIFT 24
  31. #define RED_SHIFT 16
  32. #define GREEN_SHIFT 8
  33. #define BLUE_SHIFT 0
  34. #define ALPHA_MASK ((ARGB) 0xff << ALPHA_SHIFT)
  35. #define MAKEARGB(a, r, g, b) \
  36. (((ARGB) ((a) & 0xff) << ALPHA_SHIFT) | \
  37. ((ARGB) ((r) & 0xff) << RED_SHIFT) | \
  38. ((ARGB) ((g) & 0xff) << GREEN_SHIFT) | \
  39. ((ARGB) ((b) & 0xff) << BLUE_SHIFT))
  40. //
  41. // In-memory pixel data formats:
  42. // bits 0-7 = format index
  43. // bits 8-15 = pixel size (in bits)
  44. // bits 16-23 = flags
  45. // bits 24-31 = reserved
  46. //
  47. typedef enum PixelFormatID
  48. {
  49. PIXFMTFLAG_INDEXED = 0x00010000, // Indexes into a palette
  50. PIXFMTFLAG_GDI = 0x00020000, // Is a GDI-supported format
  51. PIXFMTFLAG_ALPHA = 0x00040000, // Has an alpha component
  52. PIXFMTFLAG_PALPHA = 0x00080000, // Uses pre-multiplied alpha
  53. PIXFMTFLAG_EXTENDED = 0x00100000, // Uses extended color (16 bits per channel)
  54. PIXFMTFLAG_CANONICAL = 0x00200000, // ?
  55. PIXFMT_UNDEFINED = 0,
  56. PIXFMT_DONTCARE = 0,
  57. PIXFMT_1BPP_INDEXED = 1 | ( 1 << 8) | PIXFMTFLAG_INDEXED
  58. | PIXFMTFLAG_GDI,
  59. PIXFMT_4BPP_INDEXED = 2 | ( 4 << 8) | PIXFMTFLAG_INDEXED
  60. | PIXFMTFLAG_GDI,
  61. PIXFMT_8BPP_INDEXED = 3 | ( 8 << 8) | PIXFMTFLAG_INDEXED
  62. | PIXFMTFLAG_GDI,
  63. PIXFMT_16BPP_GRAYSCALE = 4 | (16 << 8) | PIXFMTFLAG_EXTENDED,
  64. PIXFMT_16BPP_RGB555 = 5 | (16 << 8) | PIXFMTFLAG_GDI,
  65. PIXFMT_16BPP_RGB565 = 6 | (16 << 8) | PIXFMTFLAG_GDI,
  66. PIXFMT_16BPP_ARGB1555 = 7 | (16 << 8) | PIXFMTFLAG_ALPHA
  67. | PIXFMTFLAG_GDI,
  68. PIXFMT_24BPP_RGB = 8 | (24 << 8) | PIXFMTFLAG_GDI,
  69. PIXFMT_32BPP_RGB = 9 | (32 << 8) | PIXFMTFLAG_GDI,
  70. PIXFMT_32BPP_ARGB = 10 | (32 << 8) | PIXFMTFLAG_ALPHA
  71. | PIXFMTFLAG_GDI
  72. | PIXFMTFLAG_CANONICAL,
  73. PIXFMT_32BPP_PARGB = 11 | (32 << 8) | PIXFMTFLAG_ALPHA
  74. | PIXFMTFLAG_PALPHA
  75. | PIXFMTFLAG_GDI,
  76. PIXFMT_48BPP_RGB = 12 | (48 << 8) | PIXFMTFLAG_EXTENDED,
  77. PIXFMT_64BPP_ARGB = 13 | (64 << 8) | PIXFMTFLAG_ALPHA
  78. | PIXFMTFLAG_CANONICAL
  79. | PIXFMTFLAG_EXTENDED,
  80. PIXFMT_64BPP_PARGB = 14 | (64 << 8) | PIXFMTFLAG_ALPHA
  81. | PIXFMTFLAG_PALPHA
  82. | PIXFMTFLAG_EXTENDED,
  83. PIXFMT_24BPP_BGR = 15 | (24 << 8) | PIXFMTFLAG_GDI,
  84. PIXFMT_MAX = 16
  85. } PixelFormatID;
  86. // Return the pixel size for the specified format (in bits)
  87. inline UINT
  88. GetPixelFormatSize(
  89. PixelFormatID pixfmt
  90. )
  91. {
  92. return (pixfmt >> 8) & 0xff;
  93. }
  94. // Determine if the specified pixel format is an indexed color format
  95. inline BOOL
  96. IsIndexedPixelFormat(
  97. PixelFormatID pixfmt
  98. )
  99. {
  100. return (pixfmt & PIXFMTFLAG_INDEXED) != 0;
  101. }
  102. // Determine if the pixel format can have alpha channel
  103. inline BOOL
  104. IsAlphaPixelFormat(
  105. PixelFormatID pixfmt
  106. )
  107. {
  108. return (pixfmt & PIXFMTFLAG_ALPHA) != 0;
  109. }
  110. // Determine if the pixel format is an extended format,
  111. // i.e. supports 16-bit per channel
  112. inline BOOL
  113. IsExtendedPixelFormat(
  114. PixelFormatID pixfmt
  115. )
  116. {
  117. return (pixfmt & PIXFMTFLAG_EXTENDED) != 0;
  118. }
  119. // Determine if the pixel format is canonical format:
  120. // PIXFMT_32BPP_ARGB
  121. // PIXFMT_32BPP_PARGB
  122. // PIXFMT_64BPP_ARGB
  123. // PIXFMT_64BPP_PARGB
  124. inline BOOL
  125. IsCanonicalPixelFormat(
  126. PixelFormatID pixfmt
  127. )
  128. {
  129. return (pixfmt & PIXFMTFLAG_CANONICAL) != 0;
  130. }
  131. //
  132. // Color palette
  133. // palette entries are limited to 32bpp ARGB pixel format
  134. //
  135. enum
  136. {
  137. PALFLAG_HASALPHA = 0x0001,
  138. PALFLAG_GRAYSCALE = 0x0002,
  139. PALFLAG_HALFTONE = 0x0004
  140. };
  141. typedef struct tagColorPalette
  142. {
  143. UINT Flags; // palette flags
  144. UINT Count; // number of color entries
  145. ARGB Entries[1]; // palette color entries
  146. } ColorPalette;
  147. #endif