lasso.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // Lasso.h
  19. #ifndef LASSO_H
  20. #define LASSO_H
  21. //////////////////////////////////////////////////////////////////////////////
  22. // Includes.
  23. //////////////////////////////////////////////////////////////////////////////
  24. #include "System.h"
  25. // Green /////////////////////////////////////////////////////////////////////
  26. // If PATHS_IN_INCLUDES macro is defined, we can utilized relative
  27. // paths to a header file. In this case we generally go off of our
  28. // RSPiX root directory. System.h MUST be included before this macro
  29. // is evaluated. System.h is the header that, based on the current
  30. // platform (or more so in this case on the compiler), defines
  31. // PATHS_IN_INCLUDES. Blue.h includes system.h so you can include that
  32. // instead.
  33. #ifdef PATHS_IN_INCLUDES
  34. #include "GREEN/Image/Image.h"
  35. #else
  36. #include "Image.h"
  37. #endif // PATHS_IN_INCLUDES
  38. //////////////////////////////////////////////////////////////////////////////
  39. // Typedefs.
  40. //////////////////////////////////////////////////////////////////////////////
  41. // This callback is called to determine if a pixel is part of a shape or the
  42. // empty space between shapes. This function is never called for sX, sY pairs
  43. // that are outside of the rectangle specified in the call to rspLassoNext.
  44. typedef short (*RLassoNextEvalCall)( // Returns TRUE if the specified pixel
  45. // is part of a shape. FALSE if it is
  46. // the empty space between shapes.
  47. short sX, // X coordinate of pixel in question.
  48. // Already clipped.
  49. short sY); // Y coordinate of pixel in question.
  50. // Already clipped.
  51. //////////////////////////////////////////////////////////////////////////////
  52. // Protos.
  53. //////////////////////////////////////////////////////////////////////////////
  54. // Lasso the next shape in an image. If a shape is sliced by the sub
  55. // region specified, the shape will be sliced in output. The shape will
  56. // be removed (i.e., filled with the disjoining color) on successful return
  57. // so that the next rspLassoNext() will return the next shape.
  58. //
  59. // METHOD:
  60. // The shapes are scanned for left to right, top to bottom within the
  61. // provided rectangle (sSrcX, sSrcY, sSrcW, sSrcH).
  62. // Once a shape is found the current position is set such that a four pixel
  63. // window on the buffer would have the pixel found in the scan in its
  64. // lower, right corner. From then on each pixel in the window is converted
  65. // to a bit that is used, together with the last direction and the new pixel
  66. // values in that direction, as an index into the ms_au16EdgeInfo map which
  67. // produces the next bit pattern for the window. The intial value is composed
  68. // with only the pixel in the lower, right set, the direction set to right,
  69. // and the new pixel values as 0 and 0.
  70. // As we follow the shape clockwise, everytime we go down, we add an x pos
  71. // to our sorted list for that row, and, everytime we go up, we add an x
  72. // pos to our sorted list for that row.
  73. // Once we have followed the shape clockwise back to the start, we create
  74. // image data in pimDst, if not already allocated, that is the size of
  75. // the shape's minimum bounding rectangle. pimDst is then filled with
  76. // clrDstEmptyColor.
  77. // Each pair of points in the list for each row is then used as a line
  78. // segment to be copied inclusively into pimDst from pimSrc. This copy
  79. // is, of course, clipped to pimDst. As this copy occurs, we erase the
  80. // shape in pimSrc so that the next rspLassoNext will scan right by it.
  81. template <class COLOR> // Can be U8, U16, or U32.
  82. #ifdef WIN32 // Mac assumes extern.
  83. extern
  84. #endif // WIN32
  85. short rspLassoNext( // Returns 0 if a polygon found,
  86. // 1 if no polygon found,
  87. // negative if an error occurred (most likely
  88. // allocation problems or image bit depth mis-
  89. // matches).
  90. RImage* pimSrc, // In: Image to search in sub region sSrcX, sSrcY,
  91. // sSrcW, sSrcH.
  92. RImage* pimDst, // In/Out: Destination image. If too small, polygon
  93. // will be clipped. If not yet allocated, will be
  94. // allocated to the correct minimum size.
  95. short sSrcX, // In: X coordinate of sub region to search.
  96. short sSrcY, // In: Y coordinate of sub region to search.
  97. short sSrcW, // In: Width of sub region to search.
  98. short sSrcH, // In: Height of sub region to search.
  99. COLOR clrDisjoin, // In: Color that separates shapes. This is the
  100. // color that, to this function.
  101. // Cast or use U8 for 8 bit, U16 for 16 bit,
  102. // or U32 for 32 bit.
  103. COLOR clrDstEmpty, // In: Color that will be used to initialize
  104. // pimDst, if pimDst is allocated by this function.
  105. // Type must be same size as clrDisjoinColor/COLOR.
  106. short* psShapeX, // Out: X coordinate of poly relative to pimSrc 0,0;
  107. // NOT relative to sSrcX.
  108. short* psShapeY, // Out: Y coordinate of poly relative to pimSrc 0,0;
  109. // NOT relative to sSrcY.
  110. short* psShapeW, // Out: Width of shape output to pimDst.
  111. short* psShapeH, // Out: Height of shape output to pimDst.
  112. RLassoNextEvalCall fnEval); // In: Specifies function to call to determine
  113. // whether a pixel is part of a shape or not.
  114. // Values will be clipped before calling this
  115. // function. If this is not NULL, it is used
  116. // instead of clrDisjoin.
  117. #endif // LASSO_H
  118. //////////////////////////////////////////////////////////////////////////////
  119. // EOF
  120. //////////////////////////////////////////////////////////////////////////////