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.

223 lines
8.3 KiB

  1. // RegionDetector.h: interface for the CRegionDetector class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "32BitDib.h"
  5. struct CRegionList
  6. {
  7. private:
  8. CRegionList( const CRegionList & );
  9. CRegionList &operator=( const CRegionList & );
  10. public:
  11. CRegionList(int num);
  12. virtual ~CRegionList()
  13. {
  14. delete m_pRects;
  15. delete m_pixelsFilled;
  16. delete m_valid;
  17. delete m_type;
  18. delete m_totalColored;
  19. delete m_totalIntensity;
  20. delete m_totalEdge;
  21. delete m_backgroundColorPixels;
  22. }
  23. // public... number of valid rects
  24. int Size(int r)
  25. {
  26. return (m_pRects[r].right-m_pRects[r].left)*(m_pRects[r].bottom-m_pRects[r].top);
  27. }
  28. // public
  29. RECT operator[](int num)
  30. {
  31. return nthRegion(num);
  32. }
  33. // public
  34. int UnionIntersectingRegions();
  35. // public
  36. RECT unionAll();
  37. // private
  38. RECT nthRegion(int num);
  39. int RegionType(int region);
  40. bool largeRegion(int region);
  41. double ClassifyRegion(int region); // determine if the region is a text or a graphics region
  42. bool checkIfValidRegion(int region, int border = 0); // syncs whether a region is valid or not
  43. bool ValidRegion(int region, int border = 0); // determines if a region is likely a worthless speck of dust or shadow or if we should care about the region
  44. bool InsideRegion(int region, int x, int y, int border=0); // border is the amount of border space to place around the outside of the region
  45. void AddPixel(int region, ULONG pixel,ULONG edge, int x, int y);
  46. // unions two regions together... region b is invalidated
  47. bool UnionRegions(int a, int b);
  48. RECT UnionRects(RECT a, RECT b);
  49. bool MergerIntersectsPhoto(int a, int b); // if we merge these two regions, will we also be merging with a photo region (a taboo)
  50. // see InsideRegion for an explaination of what border is
  51. bool CheckIntersect(int a, int b, int border=0); // do regions a and b intersect?
  52. bool CheckIntersect(RECT r1, RECT r2, int border=0); // do regions a and b intersect?
  53. static RECT Intersect(RECT r1, RECT r2);
  54. static bool InsideRegion(RECT region, int x, int y, int border=0); // border is the amount of border space to place around the outside of the region
  55. // compact down ignores all other info aside from rect location
  56. // leads to faster access
  57. void CompactDown(int size);
  58. // dibs are stored upside down from normal screen coords
  59. // so apps will often want to flip the bitmap first
  60. void FlipVertically();
  61. int m_numRects;
  62. int m_validRects;
  63. int m_nBitmapWidth;
  64. int m_nBitmapHeight;
  65. RECT * m_pRects;
  66. bool * m_valid; // is the rectangle a valid rectangle or has it been sent to the region graveyard in the sky
  67. int * m_type; // is this region a text region or a photograph? PHOTOGRAPH_REGION TEXT_REGION
  68. // the following indicators are used to determine if a region is a valid region
  69. ULONG * m_pixelsFilled; // how many of the pixels in the region were actually selected?
  70. ULONG * m_totalColored; // accumulated color difference indicator
  71. ULONG * m_totalIntensity; // accumulated intensity indicator
  72. ULONG * m_totalEdge; // accumulated edge values
  73. int *m_backgroundColorPixels; // number of pixels which are very close to the background color (used for determining text region status... particularly useful in cases where part of a text region may have a shadow which could lead the program to think it was a photo region
  74. int m_maxRects;
  75. };
  76. class CRegionDetector
  77. {
  78. private:
  79. // Not implemented
  80. CRegionDetector( const CRegionDetector & );
  81. CRegionDetector &operator=( const CRegionDetector & );
  82. public: // will be made private when we are done debugging
  83. C32BitDibWrapper * m_pScan;
  84. C32BitDibWrapper * m_pScanBlurred;
  85. C32BitDibWrapper * m_pScanDoubleBlurred;
  86. C32BitDibWrapper * m_pScanTripleBlurred;
  87. C32BitDibWrapper * m_pScanHorizontalBlurred;
  88. C32BitDibWrapper * m_pScanVerticalBlurred;
  89. C32BitDibWrapper * m_pScanDoubleHorizontalBlurred;
  90. C32BitDibWrapper * m_pScanDoubleVerticalBlurred;
  91. C32BitDibWrapper * m_pScanEdges;
  92. C32BitDibWrapper * m_pScanDoubleEdges;
  93. C32BitDibWrapper * m_pScanTripleEdges;
  94. C32BitDibWrapper * m_pScanHorizontalEdges;
  95. C32BitDibWrapper * m_pScanDoubleHorizontalEdges;
  96. C32BitDibWrapper * m_pScanVerticalEdges;
  97. C32BitDibWrapper * m_pScanDoubleVerticalEdges;
  98. C32BitDibWrapper * m_pScanWithShadows;
  99. CRegionList * m_pRegions;
  100. int m_resampleFactor; // ratio between imageDimensions and origional image dimensions
  101. int m_intent; // either try to avoid deciding stray dots are images or try to avoid deciding real images aren't images
  102. // not used as yet
  103. public:
  104. CRegionDetector(BYTE* dib)
  105. {
  106. m_pScan = new C32BitDibWrapper(dib);
  107. m_pScanBlurred = new C32BitDibWrapper(); // create an empty wrapper
  108. m_pScanDoubleBlurred = new C32BitDibWrapper();
  109. m_pScanTripleBlurred = new C32BitDibWrapper();
  110. m_pScanHorizontalBlurred = new C32BitDibWrapper();
  111. m_pScanVerticalBlurred = new C32BitDibWrapper();
  112. m_pScanDoubleHorizontalBlurred = new C32BitDibWrapper();
  113. m_pScanDoubleVerticalBlurred = new C32BitDibWrapper();
  114. m_pScanEdges = new C32BitDibWrapper();
  115. m_pScanDoubleEdges = new C32BitDibWrapper();
  116. m_pScanTripleEdges = new C32BitDibWrapper();
  117. m_pScanHorizontalEdges = new C32BitDibWrapper();
  118. m_pScanVerticalEdges = new C32BitDibWrapper();
  119. m_pScanDoubleHorizontalEdges = new C32BitDibWrapper();
  120. m_pScanDoubleVerticalEdges = new C32BitDibWrapper();
  121. m_resampleFactor=1;
  122. m_pScanWithShadows = NULL;
  123. m_pRegions=NULL;
  124. m_intent=TRUE; // m_intent isn't yet implemented
  125. }
  126. CRegionDetector(BITMAP pBitmap)
  127. {
  128. m_pScan = new C32BitDibWrapper(pBitmap);
  129. m_pScanBlurred = new C32BitDibWrapper(); // create an empty wrapper
  130. m_pScanDoubleBlurred = new C32BitDibWrapper();
  131. m_pScanTripleBlurred = new C32BitDibWrapper();
  132. m_pScanHorizontalBlurred = new C32BitDibWrapper();
  133. m_pScanVerticalBlurred = new C32BitDibWrapper();
  134. m_pScanDoubleHorizontalBlurred = new C32BitDibWrapper();
  135. m_pScanDoubleVerticalBlurred = new C32BitDibWrapper();
  136. m_pScanEdges = new C32BitDibWrapper();
  137. m_pScanDoubleEdges = new C32BitDibWrapper();
  138. m_pScanTripleEdges = new C32BitDibWrapper();
  139. m_pScanHorizontalEdges = new C32BitDibWrapper();
  140. m_pScanVerticalEdges = new C32BitDibWrapper();
  141. m_pScanDoubleHorizontalEdges = new C32BitDibWrapper();
  142. m_pScanDoubleVerticalEdges = new C32BitDibWrapper();
  143. m_resampleFactor=1;
  144. m_pScanWithShadows = NULL;
  145. m_pRegions=NULL;
  146. m_intent=TRUE; // m_intent isn't yet implemented
  147. }
  148. virtual ~CRegionDetector()
  149. {
  150. if (m_pScan) delete m_pScan;
  151. if (m_pScanBlurred) delete m_pScanBlurred;
  152. if (m_pScanDoubleBlurred) delete m_pScanDoubleBlurred;
  153. if (m_pScanTripleBlurred) delete m_pScanTripleBlurred;
  154. if (m_pScanHorizontalBlurred) delete m_pScanHorizontalBlurred;
  155. if (m_pScanVerticalBlurred) delete m_pScanVerticalBlurred;
  156. if (m_pScanDoubleHorizontalBlurred) delete m_pScanDoubleHorizontalBlurred;
  157. if (m_pScanDoubleVerticalBlurred) delete m_pScanDoubleVerticalBlurred;
  158. if (m_pScanEdges) delete m_pScanEdges;
  159. if (m_pScanDoubleEdges) delete m_pScanDoubleEdges;
  160. if (m_pScanTripleEdges) delete m_pScanTripleEdges;
  161. if (m_pScanHorizontalEdges) delete m_pScanHorizontalEdges;
  162. if (m_pScanVerticalEdges) delete m_pScanVerticalEdges;
  163. if (m_pScanDoubleHorizontalEdges) delete m_pScanDoubleHorizontalEdges;
  164. if (m_pScanDoubleVerticalEdges) delete m_pScanDoubleVerticalEdges;
  165. if (m_pScanWithShadows) delete m_pScanWithShadows;
  166. if(m_pRegions!=NULL) delete m_pRegions;
  167. }
  168. public:
  169. int FindRegions();
  170. bool FindSingleRegion();
  171. bool CollisionDetection(RECT r1, RECT r2, C32BitDibWrapper* pImage);
  172. bool ConvertToOrigionalCoordinates();
  173. };