Leaked source code of windows server 2003
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.

217 lines
4.7 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1999-2000 Microsoft Corporation
  4. *
  5. * Module name:
  6. *
  7. * The "Quantize" scan operation.
  8. *
  9. * Abstract:
  10. *
  11. * See Gdiplus\Specs\ScanOperation.doc for an overview.
  12. *
  13. * This module implements scan operations for converting pixels from
  14. * one format, to another of less color precision.
  15. * "Quantize" uses a simple, fixed mapping, which maps each source color
  16. * level to a particular destination color level.
  17. *
  18. * Notes:
  19. *
  20. * The "Quantize" operation is fast but can cause Mach banding.
  21. * An alternative is the "Halftone" operation, in SOHalftone.cpp.
  22. *
  23. * Revision History:
  24. *
  25. * 05/13/1999 davidx
  26. * Created it.
  27. * 12/01/1999 agodfrey
  28. * Moved to it from Imaging\Api\convertfmt.cpp.
  29. *
  30. \**************************************************************************/
  31. #include "precomp.hpp"
  32. /**************************************************************************\
  33. *
  34. * Operation Description:
  35. *
  36. * Quantize: Quickly convert format down from 32bpp ARGB.
  37. *
  38. * Arguments:
  39. *
  40. * dst - The destination scan
  41. * src - The source scan (32bpp ARGB)
  42. * count - The length of the scan, in pixels
  43. * otherParams - Additional data. (Ignored.)
  44. *
  45. * Return Value:
  46. *
  47. * None
  48. *
  49. * History:
  50. *
  51. * 05/13/1999 davidx
  52. * Created it.
  53. * 12/02/1999 agodfrey
  54. * Moved & reorganized it.
  55. *
  56. \**************************************************************************/
  57. // Quantize from sRGB to 16bpp RGB555
  58. VOID FASTCALL
  59. ScanOperation::Quantize_sRGB_555(
  60. VOID *dst,
  61. const VOID *src,
  62. INT count,
  63. const OtherParams *otherParams
  64. )
  65. {
  66. DEFINE_POINTERS(ARGB, WORD)
  67. while (count--)
  68. {
  69. ARGB argb = *s++;
  70. *d++ = (WORD) ((((argb >> (RED_SHIFT+3)) & 0x1f) << 10) |
  71. (((argb >> (GREEN_SHIFT+3)) & 0x1f) << 5) |
  72. ((argb >> (BLUE_SHIFT+3)) & 0x1f));
  73. }
  74. }
  75. // Quantize from sRGB to 16bpp RGB565
  76. VOID FASTCALL
  77. ScanOperation::Quantize_sRGB_565(
  78. VOID *dst,
  79. const VOID *src,
  80. INT count,
  81. const OtherParams *otherParams
  82. )
  83. {
  84. DEFINE_POINTERS(ARGB, WORD)
  85. while (count--)
  86. {
  87. ARGB argb = *s++;
  88. *d++ = (WORD) ((((argb >> (RED_SHIFT+3)) & 0x1f) << 11) |
  89. (((argb >> (GREEN_SHIFT+2)) & 0x3f) << 5) |
  90. ((argb >> (BLUE_SHIFT+3)) & 0x1f));
  91. }
  92. }
  93. // Quantize from sRGB to 16bpp RGB1555
  94. VOID FASTCALL
  95. ScanOperation::Quantize_sRGB_1555(
  96. VOID *dst,
  97. const VOID *src,
  98. INT count,
  99. const OtherParams *otherParams
  100. )
  101. {
  102. DEFINE_POINTERS(ARGB, WORD)
  103. while (count--)
  104. {
  105. ARGB argb = *s++;
  106. // NOTE: Very crude conversion of alpha data
  107. // from 8bpp down to 1bpp
  108. *d++ = (WORD) ((((argb >> ALPHA_SHIFT) >= 128) ? 0x8000 : 0) |
  109. (((argb >> (RED_SHIFT+3)) & 0x1f) << 10) |
  110. (((argb >> (GREEN_SHIFT+3)) & 0x1f) << 5) |
  111. ((argb >> (BLUE_SHIFT+3)) & 0x1f));
  112. }
  113. }
  114. // Quantize from sRGB to 24bpp RGB
  115. VOID FASTCALL
  116. ScanOperation::Quantize_sRGB_24(
  117. VOID *dst,
  118. const VOID *src,
  119. INT count,
  120. const OtherParams *otherParams
  121. )
  122. {
  123. DEFINE_POINTERS(ARGB, BYTE)
  124. while (count--)
  125. {
  126. ARGB argb = *s++;
  127. d[0] = (BYTE) (argb >> BLUE_SHIFT);
  128. d[1] = (BYTE) (argb >> GREEN_SHIFT);
  129. d[2] = (BYTE) (argb >> RED_SHIFT);
  130. d += 3;
  131. }
  132. }
  133. // Quantize from sRGB to 24bpp BGR
  134. VOID FASTCALL
  135. ScanOperation::Quantize_sRGB_24BGR(
  136. VOID *dst,
  137. const VOID *src,
  138. INT count,
  139. const OtherParams *otherParams
  140. )
  141. {
  142. DEFINE_POINTERS(ARGB, BYTE)
  143. while (count--)
  144. {
  145. ARGB argb = *s++;
  146. d[0] = (BYTE) (argb >> RED_SHIFT);
  147. d[1] = (BYTE) (argb >> GREEN_SHIFT);
  148. d[2] = (BYTE) (argb >> BLUE_SHIFT);
  149. d += 3;
  150. }
  151. }
  152. // Quantize from sRGB to 32bpp RGB
  153. VOID FASTCALL
  154. ScanOperation::Quantize_sRGB_32RGB(
  155. VOID *dst,
  156. const VOID *src,
  157. INT count,
  158. const OtherParams *otherParams
  159. )
  160. {
  161. DEFINE_POINTERS(ARGB, ARGB)
  162. while (count--)
  163. {
  164. *d++ = *s++ | ALPHA_MASK;
  165. }
  166. }
  167. // Quantize from sRGB64 to 48bpp RGB
  168. VOID FASTCALL
  169. ScanOperation::Quantize_sRGB64_48(
  170. VOID *dst,
  171. const VOID *src,
  172. INT count,
  173. const OtherParams *otherParams
  174. )
  175. {
  176. DEFINE_POINTERS(ARGB64, INT16)
  177. while (count--)
  178. {
  179. sRGB::sRGB64Color c;
  180. c.argb = *s++;
  181. d[0] = c.b;
  182. d[1] = c.g;
  183. d[2] = c.r;
  184. d += 3;
  185. }
  186. }