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.

180 lines
5.0 KiB

  1. /**************************************************************************
  2. *
  3. * Copyright (c) 2000 Microsoft Corporation
  4. *
  5. * Module Name & Abstract
  6. *
  7. * Stretch. This module contains the code to do various stretching
  8. * by applying a kernel filter. The code correctly handles minification.
  9. *
  10. * Notes:
  11. *
  12. * This code does not handle rotation or shear.
  13. *
  14. * Created:
  15. *
  16. * 04/17/2000 asecchia
  17. * Created it.
  18. *
  19. **************************************************************************/
  20. #ifndef _STRETCH_HPP
  21. #define _STRETCH_HPP
  22. // All the filter modes supported by DpOutputSpanStretch.
  23. enum FilterModeType {
  24. HighQualityBilinear = 0,
  25. HighQualityBicubic = 1,
  26. FilterModeMax
  27. };
  28. // Filter width is 1 for Bilinear and 2 for Bicubic.
  29. const INT FilterWidth[FilterModeMax] = {1, 2};
  30. template<FilterModeType FilterMode>
  31. class DpOutputSpanStretch : public DpOutputSpan
  32. {
  33. public:
  34. const DpBitmap *dBitmap;
  35. BitmapData BmpData;
  36. DpScanBuffer *Scan;
  37. GpRectF SrcRect;
  38. GpRectF DstRect;
  39. // Wrap mode state
  40. WrapMode QWrapMode;
  41. ARGB ClampColor;
  42. BYTE ClampColorA;
  43. BYTE ClampColorR;
  44. BYTE ClampColorG;
  45. BYTE ClampColorB;
  46. BOOL WrapZeroClamp;
  47. // Destination rectangle for valid bits.
  48. // The valid bits are the translation of the source valid bits to
  49. // the destination space.
  50. FIX16 fixDLeft;
  51. FIX16 fixDTop;
  52. FIX16 fixDRight;
  53. FIX16 fixDBottom;
  54. // x scale state.
  55. FIX16 xkci; // Initial x- kernel position
  56. FIX16 xw; // Width of x- kernel from center to edge
  57. FIX16 xa; // 1/xw
  58. FIX16 xscale; // x- scale factor (magnification or minification)
  59. FIX16 xscaleinv; // 1/xscale
  60. INT ixleft;
  61. // y scale state.
  62. FIX16 ykci; // Initial y- kernel position
  63. FIX16 yw; // Width of y- kernel from center to edge
  64. FIX16 ya; // 1/yw
  65. FIX16 yscale; // y- scale factor (magnification or minification)
  66. FIX16 yscaleinv; // 1/yscale
  67. // This is the last y scanline that contributed to the previous run.
  68. INT last_k;
  69. // This is the destination y scanline corresponding to the top of the
  70. // destination rectangle.
  71. INT iytop;
  72. // Buffer to store the temporary results for the 1D x-scale.
  73. // The xbuffer is implemented as a rotational buffer of scanlines.
  74. // Each scanline is the width required to hold one destination width
  75. // scanline and there are enough scanlines to fill a y-dimension kernel.
  76. ARGB *xbuffer;
  77. // This represents the first scanline in the rotational xbuffer.
  78. INT xbuffer_start_scanline;
  79. // These represent the dimensions of the xbuffer - height is the number
  80. // of scanlines and width is the x-size in pixels.
  81. INT xbuffer_height;
  82. INT xbuffer_width;
  83. // This is an array of y-coefficient values.
  84. // The kernel weights are computed for each contributing scanline and
  85. // stored in this array (1-1 correspondence with the xbuffer) so that
  86. // they don't have to be recomputed for every x coordinate.
  87. FIX16 *ycoeff;
  88. bool isValid;
  89. public:
  90. DpOutputSpanStretch(
  91. DpBitmap* bitmap,
  92. DpScanBuffer * scan,
  93. DpContext* context,
  94. DpImageAttributes imgAttributes,
  95. const GpRectF *dstRect,
  96. const GpRectF *srcRect
  97. )
  98. {
  99. InitializeClass(bitmap, scan, context, imgAttributes, dstRect, srcRect);
  100. }
  101. void InitializeClass(
  102. DpBitmap* bitmap,
  103. DpScanBuffer * scan,
  104. DpContext* context,
  105. DpImageAttributes imgAttributes,
  106. const GpRectF *dstRect,
  107. const GpRectF *srcRect
  108. );
  109. virtual GpStatus OutputSpan(
  110. INT y,
  111. INT xMin,
  112. INT xMax
  113. );
  114. void StretchScanline(
  115. ARGB *dst, // destination pointer
  116. ARGB *src, // source pointer
  117. INT dw, // destination width (pixels)
  118. INT sw, // source width (pixels)
  119. FIX16 kci, // initial position of the kernel center
  120. FIX16 scale, // scale factor
  121. FIX16 w, // width from center of the kernel to the edge
  122. FIX16 a // 1/w
  123. );
  124. void StretchMiddleScanline2_MMX(
  125. ARGB *dst,
  126. ARGB *src,
  127. INT dw,
  128. FIX16 kci
  129. );
  130. virtual BOOL IsValid() const { return (isValid && (dBitmap!=NULL)); }
  131. DpScanBuffer* GetScanBuffer(){ return Scan; }
  132. virtual ~DpOutputSpanStretch()
  133. {
  134. // throw away our working buffer.
  135. GpFree(xbuffer);
  136. GpFree(ycoeff);
  137. }
  138. };
  139. #endif