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.

218 lines
4.0 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1999 Microsoft Corporation
  4. *
  5. * Module Name:
  6. *
  7. * mesh.hxx
  8. *
  9. * Abstract:
  10. *
  11. * Spline mesh declarations
  12. *
  13. * Revision History:
  14. *
  15. * 01/18/1999 davidx
  16. * Created it.
  17. *
  18. \**************************************************************************/
  19. #ifndef _MESH_HXX
  20. #define _MESH_HXX
  21. //
  22. // Represent a double-precision point
  23. //
  24. class PointX
  25. {
  26. public:
  27. double x;
  28. double y;
  29. static VOID convertToPOINT(const PointX* srcPts, POINT* dstPts, INT count)
  30. {
  31. for ( ; count--; srcPts++, dstPts++)
  32. {
  33. dstPts->x = ROUND2INT(srcPts->x);
  34. dstPts->y = ROUND2INT(srcPts->y);
  35. }
  36. }
  37. static double getSquareDist(const PointX& p1, const PointX& p2)
  38. {
  39. return (p2.x - p1.x) * (p2.x - p1.x) +
  40. (p2.y - p1.y) * (p2.y - p1.y);
  41. }
  42. };
  43. //
  44. // Represent a mesh configuration
  45. //
  46. class Mesh
  47. {
  48. friend class MeshIterator;
  49. public:
  50. Mesh(INT gridRows, INT gridCols);
  51. ~Mesh();
  52. VOID initMesh();
  53. INT getGridRows() { return gridRows; }
  54. INT getGridColumns() { return gridCols; }
  55. VOID setDstSize(INT width, INT height)
  56. {
  57. dstSize.cx = width;
  58. dstSize.cy = height;
  59. }
  60. POINT*
  61. getMeshRowBeziers(
  62. INT row,
  63. INT* pointCount
  64. );
  65. POINT*
  66. getMeshColumnBeziers(
  67. INT col,
  68. INT* pointCount
  69. );
  70. POINT*
  71. getMeshRowPoints(
  72. INT row,
  73. INT* pointCount
  74. );
  75. VOID
  76. getMeshPoint(
  77. INT row,
  78. INT col,
  79. POINT* point
  80. );
  81. BOOL
  82. setMeshPoint(
  83. INT row,
  84. INT col,
  85. INT x,
  86. INT y
  87. );
  88. MeshIterator*
  89. getYIterator(
  90. INT srcWidth,
  91. INT dstWidth,
  92. INT ySteps
  93. );
  94. MeshIterator*
  95. getXIterator(
  96. INT srcHeight,
  97. INT dstHeight,
  98. INT xSteps
  99. );
  100. private:
  101. INT gridRows; // number of rows
  102. INT gridCols; // number of columns
  103. PointX* mesh; // mesh control points (in 0-1 logical space)
  104. SIZE dstSize; // current destination size
  105. // temporary working memory
  106. POINT* ptTemp;
  107. PointX* ptxTemp1;
  108. PointX* ptxTemp2;
  109. INT indexOf(INT row, INT col = 0) { return row*gridCols + col; }
  110. VOID allocTempPoints();
  111. static VOID spline2Bezier(const PointX* srcPts, PointX* dstPts, INT count);
  112. BOOL verifyRow(INT row);
  113. BOOL verifyColumn(INT col);
  114. static BOOL verifyBezierX(PointX* pts);
  115. static BOOL verifyBezierY(PointX* pts);
  116. PointX*
  117. getMeshRowBeziers(
  118. INT row,
  119. INT* pointCount,
  120. double sx,
  121. double sy
  122. );
  123. PointX*
  124. getMeshColumnBeziers(
  125. INT col,
  126. INT* pointCount,
  127. double sx,
  128. double sy
  129. );
  130. };
  131. //
  132. // Represent a flattened spline curve
  133. //
  134. class FlatCurve
  135. {
  136. public:
  137. FlatCurve(const PointX* pts, INT count);
  138. ~FlatCurve();
  139. double getPos(double x);
  140. private:
  141. INT capacity;
  142. INT elementCount;
  143. INT allocIncr;
  144. PointX* pointArray;
  145. INT lastIndex;
  146. VOID addBezierFlatten(const PointX* pts);
  147. VOID addLine(const PointX& p1, const PointX& p2);
  148. };
  149. //
  150. // Helper class to calculate the intersection of
  151. // vertical meshes with each scanline, or the intersection
  152. // of horizontal meshes with each pixel column.
  153. //
  154. class MeshIterator
  155. {
  156. public:
  157. MeshIterator(INT srcLen, INT dstLen, INT steps, INT maxCurves);
  158. ~MeshIterator();
  159. VOID getOutPos(INT index, double* outpos);
  160. VOID addCurve(const PointX* pts, INT count);
  161. private:
  162. enum { MAXCURVES = 32 };
  163. INT srcLen;
  164. INT dstLen;
  165. INT steps;
  166. INT maxCurves;
  167. INT curveCount;
  168. FlatCurve* curves[MAXCURVES];
  169. double stops[MAXCURVES];
  170. };
  171. #endif // !_MESH_HXX