ImageLineRenderer.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  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. #if true
  20. using MatterHackers.Agg.Image;
  21. using System;
  22. namespace MatterHackers.Agg
  23. {
  24. /*
  25. //========================================================line_image_scale
  26. public class line_image_scale
  27. {
  28. IImage m_source;
  29. double m_height;
  30. double m_scale;
  31. public line_image_scale(IImage src, double height)
  32. {
  33. m_source = (src);
  34. m_height = (height);
  35. m_scale = (src.height() / height);
  36. }
  37. public double width() { return m_source.width(); }
  38. public double height() { return m_height; }
  39. public RGBA_Bytes pixel(int x, int y)
  40. {
  41. double src_y = (y + 0.5) * m_scale - 0.5;
  42. int h = m_source.height() - 1;
  43. int y1 = ufloor(src_y);
  44. int y2 = y1 + 1;
  45. RGBA_Bytes pix1 = (y1 < 0) ? new no_color() : m_source.pixel(x, y1);
  46. RGBA_Bytes pix2 = (y2 > h) ? no_color() : m_source.pixel(x, y2);
  47. return pix1.gradient(pix2, src_y - y1);
  48. }
  49. };
  50. */
  51. //======================================================line_image_pattern
  52. public class line_image_pattern : ImageBuffer
  53. {
  54. private IPatternFilter m_filter;
  55. private int m_dilation;
  56. private int m_dilation_hr;
  57. private ImageBuffer m_buf = new ImageBuffer();
  58. private byte[] m_data = null;
  59. private int m_DataSizeInBytes = 0;
  60. private int m_width;
  61. private int m_height;
  62. private int m_width_hr;
  63. private int m_half_height_hr;
  64. private int m_offset_y_hr;
  65. //--------------------------------------------------------------------
  66. public line_image_pattern(IPatternFilter filter)
  67. {
  68. m_filter = filter;
  69. m_dilation = (filter.dilation() + 1);
  70. m_dilation_hr = (m_dilation << LineAABasics.line_subpixel_shift);
  71. m_width = (0);
  72. m_height = (0);
  73. m_width_hr = (0);
  74. m_half_height_hr = (0);
  75. m_offset_y_hr = (0);
  76. }
  77. ~line_image_pattern()
  78. {
  79. if (m_DataSizeInBytes > 0)
  80. {
  81. m_data = null;
  82. }
  83. }
  84. // Create
  85. //--------------------------------------------------------------------
  86. public line_image_pattern(IPatternFilter filter, line_image_pattern src)
  87. {
  88. m_filter = (filter);
  89. m_dilation = (filter.dilation() + 1);
  90. m_dilation_hr = (m_dilation << LineAABasics.line_subpixel_shift);
  91. m_width = 0;
  92. m_height = 0;
  93. m_width_hr = 0;
  94. m_half_height_hr = 0;
  95. m_offset_y_hr = (0);
  96. create(src);
  97. }
  98. // Create
  99. //--------------------------------------------------------------------
  100. public void create(IImageByte src)
  101. {
  102. // we are going to create a dilated image for filtering
  103. // we add m_dilation pixels to every side of the image and then copy the image in the x
  104. // direction into each end so that we can sample into this image to get filtering on x repeating
  105. // if the original image look like this
  106. //
  107. // 123456
  108. //
  109. // the new image would look like this
  110. //
  111. // 0000000000
  112. // 0000000000
  113. // 5612345612
  114. // 0000000000
  115. // 0000000000
  116. m_height = (int)Util.uceil(src.Height);
  117. m_width = (int)Util.uceil(src.Width);
  118. m_width_hr = (int)Util.uround(src.Width * LineAABasics.line_subpixel_scale);
  119. m_half_height_hr = (int)Util.uround(src.Height * LineAABasics.line_subpixel_scale / 2);
  120. m_offset_y_hr = m_dilation_hr + m_half_height_hr - LineAABasics.line_subpixel_scale / 2;
  121. m_half_height_hr += LineAABasics.line_subpixel_scale / 2;
  122. int bufferWidth = m_width + m_dilation * 2;
  123. int bufferHeight = m_height + m_dilation * 2;
  124. int bytesPerPixel = src.BitDepth / 8;
  125. int NewSizeInBytes = bufferWidth * bufferHeight * bytesPerPixel;
  126. if (m_DataSizeInBytes < NewSizeInBytes)
  127. {
  128. m_DataSizeInBytes = NewSizeInBytes;
  129. m_data = new byte[m_DataSizeInBytes];
  130. }
  131. m_buf.AttachBuffer(m_data, 0, bufferWidth, bufferHeight, bufferWidth * bytesPerPixel, src.BitDepth, bytesPerPixel);
  132. byte[] destBuffer = m_buf.GetBuffer();
  133. byte[] sourceBuffer = src.GetBuffer();
  134. // copy the image into the middle of the dest
  135. for (int y = 0; y < m_height; y++)
  136. {
  137. for (int x = 0; x < m_width; x++)
  138. {
  139. int sourceOffset = src.GetBufferOffsetXY(x, y);
  140. int destOffset = m_buf.GetBufferOffsetXY(m_dilation, y + m_dilation);
  141. for (int channel = 0; channel < bytesPerPixel; channel++)
  142. {
  143. destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
  144. }
  145. }
  146. }
  147. // copy the first two pixels form the end into the beginning and from the beginning into the end
  148. for (int y = 0; y < m_height; y++)
  149. {
  150. int s1Offset = src.GetBufferOffsetXY(0, y);
  151. int d1Offset = m_buf.GetBufferOffsetXY(m_dilation + m_width, y);
  152. int s2Offset = src.GetBufferOffsetXY(m_width - m_dilation, y);
  153. int d2Offset = m_buf.GetBufferOffsetXY(0, y);
  154. for (int x = 0; x < m_dilation; x++)
  155. {
  156. for (int channel = 0; channel < bytesPerPixel; channel++)
  157. {
  158. destBuffer[d1Offset++] = sourceBuffer[s1Offset++];
  159. destBuffer[d2Offset++] = sourceBuffer[s2Offset++];
  160. }
  161. }
  162. }
  163. }
  164. //--------------------------------------------------------------------
  165. public int pattern_width()
  166. {
  167. return m_width_hr;
  168. }
  169. public int line_width()
  170. {
  171. return m_half_height_hr;
  172. }
  173. public double width()
  174. {
  175. return m_height;
  176. }
  177. //--------------------------------------------------------------------
  178. public void pixel(Color[] destBuffer, int destBufferOffset, int x, int y)
  179. {
  180. m_filter.pixel_high_res(m_buf, destBuffer, destBufferOffset,
  181. x % m_width_hr + m_dilation_hr,
  182. y + m_offset_y_hr);
  183. }
  184. //--------------------------------------------------------------------
  185. public IPatternFilter filter()
  186. {
  187. return m_filter;
  188. }
  189. };
  190. /*
  191. //=================================================line_image_pattern_pow2
  192. public class line_image_pattern_pow2 :
  193. line_image_pattern<IPatternFilter>
  194. {
  195. uint m_mask;
  196. //--------------------------------------------------------------------
  197. public line_image_pattern_pow2(IPatternFilter filter) :
  198. line_image_pattern<IPatternFilter>(filter), m_mask(line_subpixel_mask) {}
  199. //--------------------------------------------------------------------
  200. public line_image_pattern_pow2(IPatternFilter filter, ImageBuffer src) :
  201. line_image_pattern<IPatternFilter>(filter), m_mask(line_subpixel_mask)
  202. {
  203. create(src);
  204. }
  205. //--------------------------------------------------------------------
  206. public void create(ImageBuffer src)
  207. {
  208. line_image_pattern<IPatternFilter>::create(src);
  209. m_mask = 1;
  210. while(m_mask < base_type::m_width)
  211. {
  212. m_mask <<= 1;
  213. m_mask |= 1;
  214. }
  215. m_mask <<= line_subpixel_shift - 1;
  216. m_mask |= line_subpixel_mask;
  217. base_type::m_width_hr = m_mask + 1;
  218. }
  219. //--------------------------------------------------------------------
  220. public void pixel(RGBA_Bytes* p, int x, int y)
  221. {
  222. base_type::m_filter->pixel_high_res(
  223. base_type::m_buf.rows(),
  224. p,
  225. (x & m_mask) + base_type::m_dilation_hr,
  226. y + base_type::m_offset_y_hr);
  227. }
  228. };
  229. */
  230. //===================================================distance_interpolator4
  231. public class distance_interpolator4
  232. {
  233. private int m_dx;
  234. private int m_dy;
  235. private int m_dx_start;
  236. private int m_dy_start;
  237. private int m_dx_pict;
  238. private int m_dy_pict;
  239. private int m_dx_end;
  240. private int m_dy_end;
  241. private int m_dist;
  242. private int m_dist_start;
  243. private int m_dist_pict;
  244. private int m_dist_end;
  245. private int m_len;
  246. //---------------------------------------------------------------------
  247. public distance_interpolator4()
  248. {
  249. }
  250. public distance_interpolator4(int x1, int y1, int x2, int y2,
  251. int sx, int sy, int ex, int ey,
  252. int len, double scale, int x, int y)
  253. {
  254. m_dx = (x2 - x1);
  255. m_dy = (y2 - y1);
  256. m_dx_start = (LineAABasics.line_mr(sx) - LineAABasics.line_mr(x1));
  257. m_dy_start = (LineAABasics.line_mr(sy) - LineAABasics.line_mr(y1));
  258. m_dx_end = (LineAABasics.line_mr(ex) - LineAABasics.line_mr(x2));
  259. m_dy_end = (LineAABasics.line_mr(ey) - LineAABasics.line_mr(y2));
  260. m_dist = (Util.iround((double)(x + LineAABasics.line_subpixel_scale / 2 - x2) * (double)(m_dy) -
  261. (double)(y + LineAABasics.line_subpixel_scale / 2 - y2) * (double)(m_dx)));
  262. m_dist_start = ((LineAABasics.line_mr(x + LineAABasics.line_subpixel_scale / 2) - LineAABasics.line_mr(sx)) * m_dy_start -
  263. (LineAABasics.line_mr(y + LineAABasics.line_subpixel_scale / 2) - LineAABasics.line_mr(sy)) * m_dx_start);
  264. m_dist_end = ((LineAABasics.line_mr(x + LineAABasics.line_subpixel_scale / 2) - LineAABasics.line_mr(ex)) * m_dy_end -
  265. (LineAABasics.line_mr(y + LineAABasics.line_subpixel_scale / 2) - LineAABasics.line_mr(ey)) * m_dx_end);
  266. m_len = (int)(Util.uround(len / scale));
  267. double d = len * scale;
  268. int dx = Util.iround(((x2 - x1) << LineAABasics.line_subpixel_shift) / d);
  269. int dy = Util.iround(((y2 - y1) << LineAABasics.line_subpixel_shift) / d);
  270. m_dx_pict = -dy;
  271. m_dy_pict = dx;
  272. m_dist_pict = ((x + LineAABasics.line_subpixel_scale / 2 - (x1 - dy)) * m_dy_pict -
  273. (y + LineAABasics.line_subpixel_scale / 2 - (y1 + dx)) * m_dx_pict) >>
  274. LineAABasics.line_subpixel_shift;
  275. m_dx <<= LineAABasics.line_subpixel_shift;
  276. m_dy <<= LineAABasics.line_subpixel_shift;
  277. m_dx_start <<= LineAABasics.line_mr_subpixel_shift;
  278. m_dy_start <<= LineAABasics.line_mr_subpixel_shift;
  279. m_dx_end <<= LineAABasics.line_mr_subpixel_shift;
  280. m_dy_end <<= LineAABasics.line_mr_subpixel_shift;
  281. }
  282. //---------------------------------------------------------------------
  283. public void inc_x()
  284. {
  285. m_dist += m_dy;
  286. m_dist_start += m_dy_start;
  287. m_dist_pict += m_dy_pict;
  288. m_dist_end += m_dy_end;
  289. }
  290. //---------------------------------------------------------------------
  291. public void dec_x()
  292. {
  293. m_dist -= m_dy;
  294. m_dist_start -= m_dy_start;
  295. m_dist_pict -= m_dy_pict;
  296. m_dist_end -= m_dy_end;
  297. }
  298. //---------------------------------------------------------------------
  299. public void inc_y()
  300. {
  301. m_dist -= m_dx;
  302. m_dist_start -= m_dx_start;
  303. m_dist_pict -= m_dx_pict;
  304. m_dist_end -= m_dx_end;
  305. }
  306. //---------------------------------------------------------------------
  307. public void dec_y()
  308. {
  309. m_dist += m_dx;
  310. m_dist_start += m_dx_start;
  311. m_dist_pict += m_dx_pict;
  312. m_dist_end += m_dx_end;
  313. }
  314. //---------------------------------------------------------------------
  315. public void inc_x(int dy)
  316. {
  317. m_dist += m_dy;
  318. m_dist_start += m_dy_start;
  319. m_dist_pict += m_dy_pict;
  320. m_dist_end += m_dy_end;
  321. if (dy > 0)
  322. {
  323. m_dist -= m_dx;
  324. m_dist_start -= m_dx_start;
  325. m_dist_pict -= m_dx_pict;
  326. m_dist_end -= m_dx_end;
  327. }
  328. if (dy < 0)
  329. {
  330. m_dist += m_dx;
  331. m_dist_start += m_dx_start;
  332. m_dist_pict += m_dx_pict;
  333. m_dist_end += m_dx_end;
  334. }
  335. }
  336. //---------------------------------------------------------------------
  337. public void dec_x(int dy)
  338. {
  339. m_dist -= m_dy;
  340. m_dist_start -= m_dy_start;
  341. m_dist_pict -= m_dy_pict;
  342. m_dist_end -= m_dy_end;
  343. if (dy > 0)
  344. {
  345. m_dist -= m_dx;
  346. m_dist_start -= m_dx_start;
  347. m_dist_pict -= m_dx_pict;
  348. m_dist_end -= m_dx_end;
  349. }
  350. if (dy < 0)
  351. {
  352. m_dist += m_dx;
  353. m_dist_start += m_dx_start;
  354. m_dist_pict += m_dx_pict;
  355. m_dist_end += m_dx_end;
  356. }
  357. }
  358. //---------------------------------------------------------------------
  359. public void inc_y(int dx)
  360. {
  361. m_dist -= m_dx;
  362. m_dist_start -= m_dx_start;
  363. m_dist_pict -= m_dx_pict;
  364. m_dist_end -= m_dx_end;
  365. if (dx > 0)
  366. {
  367. m_dist += m_dy;
  368. m_dist_start += m_dy_start;
  369. m_dist_pict += m_dy_pict;
  370. m_dist_end += m_dy_end;
  371. }
  372. if (dx < 0)
  373. {
  374. m_dist -= m_dy;
  375. m_dist_start -= m_dy_start;
  376. m_dist_pict -= m_dy_pict;
  377. m_dist_end -= m_dy_end;
  378. }
  379. }
  380. //---------------------------------------------------------------------
  381. public void dec_y(int dx)
  382. {
  383. m_dist += m_dx;
  384. m_dist_start += m_dx_start;
  385. m_dist_pict += m_dx_pict;
  386. m_dist_end += m_dx_end;
  387. if (dx > 0)
  388. {
  389. m_dist += m_dy;
  390. m_dist_start += m_dy_start;
  391. m_dist_pict += m_dy_pict;
  392. m_dist_end += m_dy_end;
  393. }
  394. if (dx < 0)
  395. {
  396. m_dist -= m_dy;
  397. m_dist_start -= m_dy_start;
  398. m_dist_pict -= m_dy_pict;
  399. m_dist_end -= m_dy_end;
  400. }
  401. }
  402. //---------------------------------------------------------------------
  403. public int dist()
  404. {
  405. return m_dist;
  406. }
  407. public int dist_start()
  408. {
  409. return m_dist_start;
  410. }
  411. public int dist_pict()
  412. {
  413. return m_dist_pict;
  414. }
  415. public int dist_end()
  416. {
  417. return m_dist_end;
  418. }
  419. //---------------------------------------------------------------------
  420. public int dx()
  421. {
  422. return m_dx;
  423. }
  424. public int dy()
  425. {
  426. return m_dy;
  427. }
  428. public int dx_start()
  429. {
  430. return m_dx_start;
  431. }
  432. public int dy_start()
  433. {
  434. return m_dy_start;
  435. }
  436. public int dx_pict()
  437. {
  438. return m_dx_pict;
  439. }
  440. public int dy_pict()
  441. {
  442. return m_dy_pict;
  443. }
  444. public int dx_end()
  445. {
  446. return m_dx_end;
  447. }
  448. public int dy_end()
  449. {
  450. return m_dy_end;
  451. }
  452. public int len()
  453. {
  454. return m_len;
  455. }
  456. };
  457. #if true
  458. #if false
  459. //==================================================line_interpolator_image
  460. public class line_interpolator_image
  461. {
  462. line_parameters m_lp;
  463. dda2_line_interpolator m_li;
  464. distance_interpolator4 m_di;
  465. IImageByte m_ren;
  466. int m_plen;
  467. int m_x;
  468. int m_y;
  469. int m_old_x;
  470. int m_old_y;
  471. int m_width;
  472. int m_max_extent;
  473. int m_start;
  474. int m_step;
  475. int[] m_dist_pos = new int[max_half_width + 1];
  476. RGBA_Bytes[] m_colors = new RGBA_Bytes[max_half_width * 2 + 4];
  477. //---------------------------------------------------------------------
  478. public const int max_half_width = 64;
  479. //---------------------------------------------------------------------
  480. public line_interpolator_image(renderer_outline_aa ren, line_parameters lp,
  481. int sx, int sy, int ex, int ey,
  482. int pattern_start,
  483. double scale_x)
  484. {
  485. throw new NotImplementedException();
  486. /*
  487. m_lp=(lp);
  488. m_li = new dda2_line_interpolator(lp.vertical ? LineAABasics.line_dbl_hr(lp.x2 - lp.x1) :
  489. LineAABasics.line_dbl_hr(lp.y2 - lp.y1),
  490. lp.vertical ? Math.Abs(lp.y2 - lp.y1) :
  491. Math.Abs(lp.x2 - lp.x1) + 1);
  492. m_di = new distance_interpolator4(lp.x1, lp.y1, lp.x2, lp.y2, sx, sy, ex, ey, lp.len, scale_x,
  493. lp.x1 & ~LineAABasics.line_subpixel_mask, lp.y1 & ~LineAABasics.line_subpixel_mask);
  494. m_ren=ren;
  495. m_x = (lp.x1 >> LineAABasics.line_subpixel_shift);
  496. m_y = (lp.y1 >> LineAABasics.line_subpixel_shift);
  497. m_old_x=(m_x);
  498. m_old_y=(m_y);
  499. m_count = ((lp.vertical ? Math.Abs((lp.y2 >> LineAABasics.line_subpixel_shift) - m_y) :
  500. Math.Abs((lp.x2 >> LineAABasics.line_subpixel_shift) - m_x)));
  501. m_width=(ren.subpixel_width());
  502. //m_max_extent(m_width >> (LineAABasics.line_subpixel_shift - 2));
  503. m_max_extent = ((m_width + LineAABasics.line_subpixel_scale) >> LineAABasics.line_subpixel_shift);
  504. m_start=(pattern_start + (m_max_extent + 2) * ren.pattern_width());
  505. m_step=(0);
  506. dda2_line_interpolator li = new dda2_line_interpolator(0, lp.vertical ?
  507. (lp.dy << LineAABasics.line_subpixel_shift) :
  508. (lp.dx << LineAABasics.line_subpixel_shift),
  509. lp.len);
  510. uint i;
  511. int stop = m_width + LineAABasics.line_subpixel_scale * 2;
  512. for(i = 0; i < max_half_width; ++i)
  513. {
  514. m_dist_pos[i] = li.y();
  515. if(m_dist_pos[i] >= stop) break;
  516. ++li;
  517. }
  518. m_dist_pos[i] = 0x7FFF0000;
  519. int dist1_start;
  520. int dist2_start;
  521. int npix = 1;
  522. if(lp.vertical)
  523. {
  524. do
  525. {
  526. --m_li;
  527. m_y -= lp.inc;
  528. m_x = (m_lp.x1 + m_li.y()) >> LineAABasics.line_subpixel_shift;
  529. if(lp.inc > 0) m_di.dec_y(m_x - m_old_x);
  530. else m_di.inc_y(m_x - m_old_x);
  531. m_old_x = m_x;
  532. dist1_start = dist2_start = m_di.dist_start();
  533. int dx = 0;
  534. if(dist1_start < 0) ++npix;
  535. do
  536. {
  537. dist1_start += m_di.dy_start();
  538. dist2_start -= m_di.dy_start();
  539. if(dist1_start < 0) ++npix;
  540. if(dist2_start < 0) ++npix;
  541. ++dx;
  542. }
  543. while(m_dist_pos[dx] <= m_width);
  544. if(npix == 0) break;
  545. npix = 0;
  546. }
  547. while(--m_step >= -m_max_extent);
  548. }
  549. else
  550. {
  551. do
  552. {
  553. --m_li;
  554. m_x -= lp.inc;
  555. m_y = (m_lp.y1 + m_li.y()) >> LineAABasics.line_subpixel_shift;
  556. if(lp.inc > 0) m_di.dec_x(m_y - m_old_y);
  557. else m_di.inc_x(m_y - m_old_y);
  558. m_old_y = m_y;
  559. dist1_start = dist2_start = m_di.dist_start();
  560. int dy = 0;
  561. if(dist1_start < 0) ++npix;
  562. do
  563. {
  564. dist1_start -= m_di.dx_start();
  565. dist2_start += m_di.dx_start();
  566. if(dist1_start < 0) ++npix;
  567. if(dist2_start < 0) ++npix;
  568. ++dy;
  569. }
  570. while(m_dist_pos[dy] <= m_width);
  571. if(npix == 0) break;
  572. npix = 0;
  573. }
  574. while(--m_step >= -m_max_extent);
  575. }
  576. m_li.adjust_forward();
  577. m_step -= m_max_extent;
  578. */
  579. }
  580. //---------------------------------------------------------------------
  581. public bool step_hor()
  582. {
  583. throw new NotImplementedException();
  584. /*
  585. ++m_li;
  586. m_x += m_lp.inc;
  587. m_y = (m_lp.y1 + m_li.y()) >> LineAABasics.line_subpixel_shift;
  588. if(m_lp.inc > 0) m_di.inc_x(m_y - m_old_y);
  589. else m_di.dec_x(m_y - m_old_y);
  590. m_old_y = m_y;
  591. int s1 = m_di.dist() / m_lp.len;
  592. int s2 = -s1;
  593. if(m_lp.inc < 0) s1 = -s1;
  594. int dist_start;
  595. int dist_pict;
  596. int dist_end;
  597. int dy;
  598. int dist;
  599. dist_start = m_di.dist_start();
  600. dist_pict = m_di.dist_pict() + m_start;
  601. dist_end = m_di.dist_end();
  602. RGBA_Bytes* p0 = m_colors + max_half_width + 2;
  603. RGBA_Bytes* p1 = p0;
  604. int npix = 0;
  605. p1->clear();
  606. if(dist_end > 0)
  607. {
  608. if(dist_start <= 0)
  609. {
  610. m_ren.pixel(p1, dist_pict, s2);
  611. }
  612. ++npix;
  613. }
  614. ++p1;
  615. dy = 1;
  616. while((dist = m_dist_pos[dy]) - s1 <= m_width)
  617. {
  618. dist_start -= m_di.dx_start();
  619. dist_pict -= m_di.dx_pict();
  620. dist_end -= m_di.dx_end();
  621. p1->clear();
  622. if(dist_end > 0 && dist_start <= 0)
  623. {
  624. if(m_lp.inc > 0) dist = -dist;
  625. m_ren.pixel(p1, dist_pict, s2 - dist);
  626. ++npix;
  627. }
  628. ++p1;
  629. ++dy;
  630. }
  631. dy = 1;
  632. dist_start = m_di.dist_start();
  633. dist_pict = m_di.dist_pict() + m_start;
  634. dist_end = m_di.dist_end();
  635. while((dist = m_dist_pos[dy]) + s1 <= m_width)
  636. {
  637. dist_start += m_di.dx_start();
  638. dist_pict += m_di.dx_pict();
  639. dist_end += m_di.dx_end();
  640. --p0;
  641. p0->clear();
  642. if(dist_end > 0 && dist_start <= 0)
  643. {
  644. if(m_lp.inc > 0) dist = -dist;
  645. m_ren.pixel(p0, dist_pict, s2 + dist);
  646. ++npix;
  647. }
  648. ++dy;
  649. }
  650. m_ren.blend_color_vspan(m_x,
  651. m_y - dy + 1,
  652. (uint)(p1 - p0),
  653. p0);
  654. return npix && ++m_step < m_count;
  655. */
  656. }
  657. //---------------------------------------------------------------------
  658. public bool step_ver()
  659. {
  660. throw new NotImplementedException();
  661. /*
  662. ++m_li;
  663. m_y += m_lp.inc;
  664. m_x = (m_lp.x1 + m_li.y()) >> LineAABasics.line_subpixel_shift;
  665. if(m_lp.inc > 0) m_di.inc_y(m_x - m_old_x);
  666. else m_di.dec_y(m_x - m_old_x);
  667. m_old_x = m_x;
  668. int s1 = m_di.dist() / m_lp.len;
  669. int s2 = -s1;
  670. if(m_lp.inc > 0) s1 = -s1;
  671. int dist_start;
  672. int dist_pict;
  673. int dist_end;
  674. int dist;
  675. int dx;
  676. dist_start = m_di.dist_start();
  677. dist_pict = m_di.dist_pict() + m_start;
  678. dist_end = m_di.dist_end();
  679. RGBA_Bytes* p0 = m_colors + max_half_width + 2;
  680. RGBA_Bytes* p1 = p0;
  681. int npix = 0;
  682. p1->clear();
  683. if(dist_end > 0)
  684. {
  685. if(dist_start <= 0)
  686. {
  687. m_ren.pixel(p1, dist_pict, s2);
  688. }
  689. ++npix;
  690. }
  691. ++p1;
  692. dx = 1;
  693. while((dist = m_dist_pos[dx]) - s1 <= m_width)
  694. {
  695. dist_start += m_di.dy_start();
  696. dist_pict += m_di.dy_pict();
  697. dist_end += m_di.dy_end();
  698. p1->clear();
  699. if(dist_end > 0 && dist_start <= 0)
  700. {
  701. if(m_lp.inc > 0) dist = -dist;
  702. m_ren.pixel(p1, dist_pict, s2 + dist);
  703. ++npix;
  704. }
  705. ++p1;
  706. ++dx;
  707. }
  708. dx = 1;
  709. dist_start = m_di.dist_start();
  710. dist_pict = m_di.dist_pict() + m_start;
  711. dist_end = m_di.dist_end();
  712. while((dist = m_dist_pos[dx]) + s1 <= m_width)
  713. {
  714. dist_start -= m_di.dy_start();
  715. dist_pict -= m_di.dy_pict();
  716. dist_end -= m_di.dy_end();
  717. --p0;
  718. p0->clear();
  719. if(dist_end > 0 && dist_start <= 0)
  720. {
  721. if(m_lp.inc > 0) dist = -dist;
  722. m_ren.pixel(p0, dist_pict, s2 - dist);
  723. ++npix;
  724. }
  725. ++dx;
  726. }
  727. m_ren.blend_color_hspan(m_x - dx + 1,
  728. m_y,
  729. (uint)(p1 - p0),
  730. p0);
  731. return npix && ++m_step < m_count;
  732. */
  733. }
  734. //---------------------------------------------------------------------
  735. public int pattern_end() { return m_start + m_di.len(); }
  736. //---------------------------------------------------------------------
  737. public bool vertical() { return m_lp.vertical; }
  738. public int width() { return m_width; }
  739. }
  740. #endif
  741. //===================================================renderer_outline_image
  742. //template<class BaseRenderer, class ImagePattern>
  743. public class ImageLineRenderer : LineRenderer
  744. {
  745. private IImageByte m_ren;
  746. private line_image_pattern m_pattern;
  747. private int m_start;
  748. private double m_scale_x;
  749. private RectangleInt m_clip_box;
  750. //private bool m_clipping;
  751. //---------------------------------------------------------------------
  752. //typedef renderer_outline_image<BaseRenderer, ImagePattern> self_type;
  753. //---------------------------------------------------------------------
  754. public ImageLineRenderer(IImageByte ren, line_image_pattern patt)
  755. {
  756. m_ren = ren;
  757. m_pattern = patt;
  758. m_start = (0);
  759. m_scale_x = (1.0);
  760. m_clip_box = new RectangleInt(0, 0, 0, 0);
  761. //m_clipping = (false);
  762. }
  763. public void attach(IImageByte ren)
  764. {
  765. m_ren = ren;
  766. }
  767. //---------------------------------------------------------------------
  768. public void pattern(line_image_pattern p)
  769. {
  770. m_pattern = p;
  771. }
  772. public line_image_pattern pattern()
  773. {
  774. return m_pattern;
  775. }
  776. //---------------------------------------------------------------------
  777. public void reset_clipping()
  778. {
  779. //m_clipping = false;
  780. }
  781. public void clip_box(double x1, double y1, double x2, double y2)
  782. {
  783. m_clip_box.Left = line_coord_sat.conv(x1);
  784. m_clip_box.Bottom = line_coord_sat.conv(y1);
  785. m_clip_box.Right = line_coord_sat.conv(x2);
  786. m_clip_box.Top = line_coord_sat.conv(y2);
  787. //m_clipping = true;
  788. }
  789. //---------------------------------------------------------------------
  790. public void scale_x(double s)
  791. {
  792. m_scale_x = s;
  793. }
  794. public double scale_x()
  795. {
  796. return m_scale_x;
  797. }
  798. //---------------------------------------------------------------------
  799. public void start_x(double s)
  800. {
  801. m_start = Util.iround(s * LineAABasics.line_subpixel_scale);
  802. }
  803. public double start_x()
  804. {
  805. return (double)(m_start) / LineAABasics.line_subpixel_scale;
  806. }
  807. //---------------------------------------------------------------------
  808. public int subpixel_width()
  809. {
  810. return m_pattern.line_width();
  811. }
  812. public int pattern_width()
  813. {
  814. return m_pattern.pattern_width();
  815. }
  816. public double width()
  817. {
  818. return (double)(subpixel_width()) / LineAABasics.line_subpixel_scale;
  819. }
  820. public void pixel(Color[] p, int offset, int x, int y)
  821. {
  822. throw new NotImplementedException();
  823. //m_pattern.pixel(p, x, y);
  824. }
  825. public void blend_color_hspan(int x, int y, uint len, Color[] colors, int colorsOffset)
  826. {
  827. throw new NotImplementedException();
  828. // m_ren.blend_color_hspan(x, y, len, colors, null, 0);
  829. }
  830. public void blend_color_vspan(int x, int y, uint len, Color[] colors, int colorsOffset)
  831. {
  832. throw new NotImplementedException();
  833. // m_ren.blend_color_vspan(x, y, len, colors, null, 0);
  834. }
  835. public static bool accurate_join_only()
  836. {
  837. return true;
  838. }
  839. public override void semidot(CompareFunction cmp, int xc1, int yc1, int xc2, int yc2)
  840. {
  841. }
  842. public override void semidot_hline(CompareFunction cmp,
  843. int xc1, int yc1, int xc2, int yc2,
  844. int x1, int y1, int x2)
  845. {
  846. }
  847. public override void pie(int xc, int yc, int x1, int y1, int x2, int y2)
  848. {
  849. }
  850. public override void line0(line_parameters lp)
  851. {
  852. }
  853. public override void line1(line_parameters lp, int sx, int sy)
  854. {
  855. }
  856. public override void line2(line_parameters lp, int ex, int ey)
  857. {
  858. }
  859. public void line3_no_clip(line_parameters lp,
  860. int sx, int sy, int ex, int ey)
  861. {
  862. throw new NotImplementedException();
  863. /*
  864. if(lp.len > LineAABasics.line_max_length)
  865. {
  866. line_parameters lp1, lp2;
  867. lp.divide(lp1, lp2);
  868. int mx = lp1.x2 + (lp1.y2 - lp1.y1);
  869. int my = lp1.y2 - (lp1.x2 - lp1.x1);
  870. line3_no_clip(lp1, (lp.x1 + sx) >> 1, (lp.y1 + sy) >> 1, mx, my);
  871. line3_no_clip(lp2, mx, my, (lp.x2 + ex) >> 1, (lp.y2 + ey) >> 1);
  872. return;
  873. }
  874. LineAABasics.fix_degenerate_bisectrix_start(lp, ref sx, ref sy);
  875. LineAABasics.fix_degenerate_bisectrix_end(lp, ref ex, ref ey);
  876. line_interpolator_image li = new line_interpolator_image(this, lp,
  877. sx, sy,
  878. ex, ey,
  879. m_start, m_scale_x);
  880. if(li.vertical())
  881. {
  882. while(li.step_ver());
  883. }
  884. else
  885. {
  886. while(li.step_hor());
  887. }
  888. m_start += uround(lp.len / m_scale_x);
  889. */
  890. }
  891. public override void line3(line_parameters lp,
  892. int sx, int sy, int ex, int ey)
  893. {
  894. throw new NotImplementedException();
  895. /*
  896. if(m_clipping)
  897. {
  898. int x1 = lp.x1;
  899. int y1 = lp.y1;
  900. int x2 = lp.x2;
  901. int y2 = lp.y2;
  902. uint flags = clip_line_segment(&x1, &y1, &x2, &y2, m_clip_box);
  903. int start = m_start;
  904. if((flags & 4) == 0)
  905. {
  906. if(flags)
  907. {
  908. line_parameters lp2(x1, y1, x2, y2,
  909. uround(calc_distance(x1, y1, x2, y2)));
  910. if(flags & 1)
  911. {
  912. m_start += uround(calc_distance(lp.x1, lp.y1, x1, y1) / m_scale_x);
  913. sx = x1 + (y2 - y1);
  914. sy = y1 - (x2 - x1);
  915. }
  916. else
  917. {
  918. while(Math.Abs(sx - lp.x1) + Math.Abs(sy - lp.y1) > lp2.len)
  919. {
  920. sx = (lp.x1 + sx) >> 1;
  921. sy = (lp.y1 + sy) >> 1;
  922. }
  923. }
  924. if(flags & 2)
  925. {
  926. ex = x2 + (y2 - y1);
  927. ey = y2 - (x2 - x1);
  928. }
  929. else
  930. {
  931. while(Math.Abs(ex - lp.x2) + Math.Abs(ey - lp.y2) > lp2.len)
  932. {
  933. ex = (lp.x2 + ex) >> 1;
  934. ey = (lp.y2 + ey) >> 1;
  935. }
  936. }
  937. line3_no_clip(lp2, sx, sy, ex, ey);
  938. }
  939. else
  940. {
  941. line3_no_clip(lp, sx, sy, ex, ey);
  942. }
  943. }
  944. m_start = start + uround(lp.len / m_scale_x);
  945. }
  946. else
  947. {
  948. line3_no_clip(lp, sx, sy, ex, ey);
  949. }
  950. */
  951. }
  952. };
  953. #endif
  954. }
  955. #endif