An LGPL/GPL-licensed artwork library
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.

124 lines
3.3KB

  1. /* Libart_LGPL - library of basic graphic primitives
  2. * Copyright (C) 1998 Raph Levien
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library 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 GNU
  12. * Library General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Library General Public
  15. * License along with this library; if not, write to the
  16. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17. * Boston, MA 02111-1307, USA.
  18. */
  19. /* Render a sorted vector path into a graymap. */
  20. #include "config.h"
  21. #include "art_gray_svp.h"
  22. #include <string.h> /* for memset */
  23. #include "art_misc.h"
  24. #include "art_svp.h"
  25. #include "art_svp_render_aa.h"
  26. typedef struct _ArtGraySVPData ArtGraySVPData;
  27. struct _ArtGraySVPData {
  28. art_u8 *buf;
  29. int rowstride;
  30. int x0, x1;
  31. };
  32. static void
  33. art_gray_svp_callback (void *callback_data, int y,
  34. int start, ArtSVPRenderAAStep *steps, int n_steps)
  35. {
  36. ArtGraySVPData *data = (ArtGraySVPData *)callback_data;
  37. art_u8 *linebuf;
  38. int run_x0, run_x1;
  39. int running_sum = start;
  40. int x0, x1;
  41. int k;
  42. #if 0
  43. printf ("start = %d", start);
  44. running_sum = start;
  45. for (k = 0; k < n_steps; k++)
  46. {
  47. running_sum += steps[k].delta;
  48. printf (" %d:%d", steps[k].x, running_sum >> 16);
  49. }
  50. printf ("\n");
  51. #endif
  52. linebuf = data->buf;
  53. x0 = data->x0;
  54. x1 = data->x1;
  55. if (n_steps > 0)
  56. {
  57. run_x1 = steps[0].x;
  58. if (run_x1 > x0)
  59. memset (linebuf, running_sum >> 16, run_x1 - x0);
  60. for (k = 0; k < n_steps - 1; k++)
  61. {
  62. running_sum += steps[k].delta;
  63. run_x0 = run_x1;
  64. run_x1 = steps[k + 1].x;
  65. if (run_x1 > run_x0)
  66. memset (linebuf + run_x0 - x0, running_sum >> 16, run_x1 - run_x0);
  67. }
  68. running_sum += steps[k].delta;
  69. if (x1 > run_x1)
  70. memset (linebuf + run_x1 - x0, running_sum >> 16, x1 - run_x1);
  71. }
  72. else
  73. {
  74. memset (linebuf, running_sum >> 16, x1 - x0);
  75. }
  76. data->buf += data->rowstride;
  77. }
  78. /**
  79. * art_gray_svp_aa: Render the vector path into the bytemap.
  80. * @svp: The SVP to render.
  81. * @x0: The view window's left coord.
  82. * @y0: The view window's top coord.
  83. * @x1: The view window's right coord.
  84. * @y1: The view window's bottom coord.
  85. * @buf: The buffer where the bytemap is stored.
  86. * @rowstride: the rowstride for @buf.
  87. *
  88. * Each pixel gets a value proportional to the area within the pixel
  89. * overlapping the (filled) SVP. Pixel (x, y) is stored at:
  90. *
  91. * @buf[(y - * @y0) * @rowstride + (x - @x0)]
  92. *
  93. * All pixels @x0 <= x < @x1, @y0 <= y < @y1 are generated. A
  94. * stored value of zero is no coverage, and a value of 255 is full
  95. * coverage. The area within the pixel (x, y) is the region covered
  96. * by [x..x+1] and [y..y+1].
  97. **/
  98. void
  99. art_gray_svp_aa (const ArtSVP *svp,
  100. int x0, int y0, int x1, int y1,
  101. art_u8 *buf, int rowstride)
  102. {
  103. ArtGraySVPData data;
  104. data.buf = buf;
  105. data.rowstride = rowstride;
  106. data.x0 = x0;
  107. data.x1 = x1;
  108. art_svp_render_aa (svp, x0, y0, x1, y1, art_gray_svp_callback, &data);
  109. }