agg_scanline_bin.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. //----------------------------------------------------------------------------
  2. // Anti-Grain Geometry - Version 2.4
  3. // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
  4. //
  5. // C# port by: Lars Brubaker
  6. // larsbrubaker@gmail.com
  7. // Copyright (C) 2007
  8. //
  9. // Permission to copy, use, modify, sell and distribute this software
  10. // is granted provided this copyright notice appears in all copies.
  11. // This software is provided "as is" without express or implied
  12. // warranty, and with no claim as to its suitability for any purpose.
  13. //
  14. //----------------------------------------------------------------------------
  15. // Contact: mcseem@antigrain.com
  16. // mcseemagg@yahoo.com
  17. // http://www.antigrain.com
  18. //----------------------------------------------------------------------------
  19. //
  20. // Class scanline_bin - binary scanline.
  21. //
  22. //----------------------------------------------------------------------------
  23. //
  24. // Adaptation for 32-bit screen coordinates (scanline32_bin) has been sponsored by
  25. // Liberty Technology Systems, Inc., visit http://lib-sys.com
  26. //
  27. // Liberty Technology Systems, Inc. is the provider of
  28. // PostScript and PDF technology for software developers.
  29. //
  30. //----------------------------------------------------------------------------
  31. namespace MatterHackers.Agg
  32. {
  33. //=============================================================scanline_bin
  34. //
  35. // This is binary scanline container which supports the interface
  36. // used in the rasterizer::render(). See description of agg_scanline_u8
  37. // for details.
  38. //
  39. //------------------------------------------------------------------------
  40. public sealed class scanline_bin : IScanlineCache
  41. {
  42. private int m_last_x;
  43. private int m_y;
  44. private ArrayPOD<ScanlineSpan> m_spans;
  45. private int m_span_index;
  46. private int m_interator_index;
  47. public ScanlineSpan GetNextScanlineSpan()
  48. {
  49. m_interator_index++;
  50. return m_spans.Array[m_interator_index - 1];
  51. }
  52. //--------------------------------------------------------------------
  53. public scanline_bin()
  54. {
  55. m_last_x = (0x7FFFFFF0);
  56. m_spans = new ArrayPOD<ScanlineSpan>(1000);
  57. m_span_index = 0;
  58. }
  59. //--------------------------------------------------------------------
  60. public void reset(int min_x, int max_x)
  61. {
  62. int max_len = max_x - min_x + 3;
  63. if (max_len > m_spans.Size())
  64. {
  65. m_spans.Resize(max_len);
  66. }
  67. m_last_x = 0x7FFFFFF0;
  68. m_span_index = 0;
  69. }
  70. //--------------------------------------------------------------------
  71. public void add_cell(int x, int cover)
  72. {
  73. if (x == m_last_x + 1)
  74. {
  75. m_spans.Array[m_span_index].len++;
  76. }
  77. else
  78. {
  79. m_span_index++;
  80. m_spans.Array[m_span_index].x = (int)x;
  81. m_spans.Array[m_span_index].len = 1;
  82. }
  83. m_last_x = x;
  84. }
  85. //--------------------------------------------------------------------
  86. public void add_span(int x, int len, int cover)
  87. {
  88. if (x == m_last_x + 1)
  89. {
  90. m_spans.Array[m_span_index].len += (int)len;
  91. }
  92. else
  93. {
  94. m_span_index++;
  95. m_spans.Array[m_span_index].x = x;
  96. m_spans.Array[m_span_index].len = (int)len;
  97. }
  98. m_last_x = x + len - 1;
  99. }
  100. /*
  101. //--------------------------------------------------------------------
  102. public void add_cells(int x, int len, void*)
  103. {
  104. add_span(x, len, 0);
  105. }
  106. */
  107. //--------------------------------------------------------------------
  108. public void finalize(int y)
  109. {
  110. m_y = y;
  111. }
  112. //--------------------------------------------------------------------
  113. public void ResetSpans()
  114. {
  115. m_last_x = 0x7FFFFFF0;
  116. m_span_index = 0;
  117. }
  118. //--------------------------------------------------------------------
  119. public int y()
  120. {
  121. return m_y;
  122. }
  123. public int num_spans()
  124. {
  125. return (int)m_span_index;
  126. }
  127. public ScanlineSpan begin()
  128. {
  129. m_interator_index = 1;
  130. return GetNextScanlineSpan();
  131. }
  132. public byte[] GetCovers()
  133. {
  134. return null;
  135. }
  136. };
  137. /*
  138. //===========================================================scanline32_bin
  139. class scanline32_bin
  140. {
  141. public:
  142. typedef int32 coord_type;
  143. //--------------------------------------------------------------------
  144. struct span
  145. {
  146. span() {}
  147. span(coord_type x_, coord_type len_) : x(x_), len(len_) {}
  148. coord_type x;
  149. coord_type len;
  150. };
  151. typedef pod_bvector<span, 4> span_array_type;
  152. //--------------------------------------------------------------------
  153. class_iterator
  154. {
  155. public:
  156. _iterator(span_array_type& spans) :
  157. m_spans(spans),
  158. m_span_idx(0)
  159. {}
  160. span& operator*() { return m_spans[m_span_idx]; }
  161. span* operator->() { return &m_spans[m_span_idx]; }
  162. void operator ++ () { ++m_span_idx; }
  163. private:
  164. span_array_type& m_spans;
  165. int m_span_idx;
  166. };
  167. //--------------------------------------------------------------------
  168. scanline32_bin() : m_max_len(0), m_last_x(0x7FFFFFF0) {}
  169. //--------------------------------------------------------------------
  170. void reset(int min_x, int max_x)
  171. {
  172. m_last_x = 0x7FFFFFF0;
  173. m_spans.Clear;
  174. }
  175. //--------------------------------------------------------------------
  176. void add_cell(int x, int)
  177. {
  178. if(x == m_last_x+1)
  179. {
  180. m_spans.last().len++;
  181. }
  182. else
  183. {
  184. m_spans.add(span(coord_type(x), 1));
  185. }
  186. m_last_x = x;
  187. }
  188. //--------------------------------------------------------------------
  189. void add_span(int x, int len, int)
  190. {
  191. if(x == m_last_x+1)
  192. {
  193. m_spans.last().len += coord_type(len);
  194. }
  195. else
  196. {
  197. m_spans.add(span(coord_type(x), coord_type(len)));
  198. }
  199. m_last_x = x + len - 1;
  200. }
  201. //--------------------------------------------------------------------
  202. void add_cells(int x, int len, void*)
  203. {
  204. add_span(x, len, 0);
  205. }
  206. //--------------------------------------------------------------------
  207. void finalize(int y)
  208. {
  209. m_y = y;
  210. }
  211. //--------------------------------------------------------------------
  212. void reset_spans()
  213. {
  214. m_last_x = 0x7FFFFFF0;
  215. m_spans.Clear;
  216. }
  217. //--------------------------------------------------------------------
  218. int y() { return m_y; }
  219. int num_spans() { return m_spans.size(); }
  220. _iterator begin() { return_iterator(m_spans); }
  221. private:
  222. scanline32_bin(scanline32_bin&);
  223. scanline32_bin operator = (scanline32_bin&);
  224. int m_max_len;
  225. int m_last_x;
  226. int m_y;
  227. span_array_type m_spans;
  228. };
  229. */
  230. }