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.

189 lines
4.7 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1999-2000 Microsoft Corporation
  4. *
  5. * Module Name:
  6. *
  7. * Halftoning (for GIF codec)
  8. *
  9. * Abstract:
  10. *
  11. * Halftone 32 bpp to 8 bpp using 216-color halftoning
  12. *
  13. * Revision History:
  14. *
  15. * 02/21/2000 dcurtis
  16. * Created it.
  17. *
  18. \**************************************************************************/
  19. #include "precomp.hpp"
  20. #if defined(_USE_X86_ASSEMBLY)
  21. #define QUOTIENT_REMAINDER(ulNumerator, ulDenominator, ulQuotient, ulRemainder)\
  22. { \
  23. __asm mov eax, ulNumerator \
  24. __asm sub edx, edx \
  25. __asm div ulDenominator \
  26. __asm mov ulQuotient, eax \
  27. __asm mov ulRemainder, edx \
  28. }
  29. #else
  30. #define QUOTIENT_REMAINDER(ulNumerator, ulDenominator, ulQuotient, ulRemainder)\
  31. { \
  32. ulQuotient = (ULONG) ulNumerator / (ULONG) ulDenominator; \
  33. ulRemainder = (ULONG) ulNumerator % (ULONG) ulDenominator; \
  34. }
  35. #endif
  36. /**************************************************************************\
  37. *
  38. * Operation Description:
  39. *
  40. * Halftone from 32bpp ARGB to 8bpp, using the 216-color halftone palette.
  41. *
  42. * Arguments:
  43. *
  44. * d - The destination scan
  45. * s - The source scan (32bpp ARGB)
  46. * count - The length of the scan, in pixels
  47. * orgX - X origin
  48. * orgY - Y origin
  49. *
  50. * Return Value:
  51. *
  52. * None
  53. *
  54. * Notes:
  55. *
  56. * This version doesn't use a palette map and doesn't care about the
  57. * 20 Windows system colors.
  58. *
  59. * History:
  60. *
  61. * 2/21/2000 DCurtis
  62. *
  63. \**************************************************************************/
  64. VOID
  65. Halftone_sRGB_8_216(
  66. BYTE* d,
  67. const BYTE* s,
  68. UINT count,
  69. INT orgX,
  70. INT orgY
  71. )
  72. {
  73. orgX %= 91;
  74. orgY %= 91;
  75. INT htStartX = orgX;
  76. INT htStartRow = orgY * 91;
  77. INT htIndex = htStartRow + orgX;
  78. ULONG r, g, b;
  79. ULONG rQuo, gQuo, bQuo;
  80. ULONG rRem, gRem, bRem;
  81. ULONG divisor = 0x33;
  82. for (;;)
  83. {
  84. r = s[2];
  85. g = s[1];
  86. b = s[0];
  87. s += 4;
  88. QUOTIENT_REMAINDER(r, divisor, rQuo, rRem);
  89. QUOTIENT_REMAINDER(g, divisor, gQuo, gRem);
  90. QUOTIENT_REMAINDER(b, divisor, bQuo, bRem);
  91. // MUST do >, not >= so that a remainder of 0 works correctly
  92. r = rQuo + (rRem > HT_SuperCell_Red216 [htIndex]);
  93. g = gQuo + (gRem > HT_SuperCell_Green216[htIndex]);
  94. b = bQuo + (bRem > HT_SuperCell_Blue216 [htIndex]);
  95. *d++ = (BYTE)((r*36) + (g*6) + b + 40);
  96. if (--count == 0)
  97. {
  98. break;
  99. }
  100. htIndex++;
  101. if (++orgX >= 91)
  102. {
  103. orgX = 0;
  104. htIndex = htStartRow;
  105. }
  106. }
  107. }
  108. /**************************************************************************\
  109. *
  110. * Function Description:
  111. *
  112. * Halftone an image from 32bpp to 8bpp. See the .hpp file for caveats.
  113. *
  114. * Arguments:
  115. *
  116. * [IN] src - pointer to scan0 of source image
  117. * [IN] srcStride - stride of src image (can be negative)
  118. * [IN] dst - pointer to scan0 of destination 8-bpp image
  119. * [IN] dstStride - stride of dst image (can be negative)
  120. * [IN] width - image width
  121. * [IN] height - image height
  122. * [IN] orgX - where the upper-left corner of image starts
  123. * [IN] orgY - for computing the halftone cell origin
  124. *
  125. * Return Value:
  126. *
  127. * NONE
  128. *
  129. * History:
  130. *
  131. * 10/29/1999 DCurtis
  132. * Created it.
  133. * 01/20/2000 AGodfrey
  134. * Moved it from Imaging\Api\Colorpal.cpp/hpp.
  135. *
  136. \**************************************************************************/
  137. VOID
  138. Halftone32bppTo8bpp(
  139. const BYTE* src,
  140. INT srcStride,
  141. BYTE* dst,
  142. INT dstStride,
  143. UINT width,
  144. UINT height,
  145. INT orgX,
  146. INT orgY
  147. )
  148. {
  149. ASSERT (((srcStride >= 0) && (srcStride >= (INT)(width * 4))) ||
  150. ((srcStride < 0) && (-srcStride >= (INT)(width * 4))));
  151. ASSERT (((dstStride >= 0) && (dstStride >= (INT)width)) ||
  152. ((dstStride < 0) && (-dstStride >= (INT)width)));
  153. ASSERT((src != NULL) && (dst != NULL));
  154. if (width == 0)
  155. {
  156. return;
  157. }
  158. for (; height > 0; height--)
  159. {
  160. Halftone_sRGB_8_216(dst, src, width, orgX, orgY);
  161. orgY++;
  162. src += srcStride;
  163. dst += dstStride;
  164. }
  165. }
  166. extern "C" {
  167. }