box.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*!
  2. \file lib/pngdriver/box.c
  3. \brief GRASS png display driver - draw box
  4. (C) 2003-2014 by Per Henrik Johansen and the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Per Henrik Johansen (original contributor)
  8. \author Glynn Clements
  9. */
  10. #include <math.h>
  11. #include "pngdriver.h"
  12. /*!
  13. \brief Draw a (filled) rectangle
  14. \param fx1,fy1,fx2,fy2 rectangle coordinates
  15. */
  16. void PNG_Box(double fx1, double fy1, double fx2, double fy2)
  17. {
  18. int x1 = (int) floor(fx1 + 0.5);
  19. int y1 = (int) floor(fy1 + 0.5);
  20. int x2 = (int) floor(fx2 + 0.5);
  21. int y2 = (int) floor(fy2 + 0.5);
  22. int tmp;
  23. int x, y;
  24. if (x1 > x2)
  25. tmp = x1, x1 = x2, x2 = tmp;
  26. if (y1 > y2)
  27. tmp = y1, y1 = y2, y2 = tmp;
  28. if (x2 < 0 || x1 > png.width)
  29. return;
  30. if (y2 < 0 || y1 > png.height)
  31. return;
  32. if (x1 < png.clip_left)
  33. x1 = png.clip_left;
  34. if (x2 > png.clip_rite)
  35. x2 = png.clip_rite;
  36. if (y1 < png.clip_top)
  37. y1 = png.clip_top;
  38. if (y2 > png.clip_bot)
  39. y2 = png.clip_bot;
  40. for (y = y1; y < y2; y++) {
  41. unsigned int *p = &png.grid[y * png.width + x1];
  42. for (x = x1; x < x2; x++)
  43. *p++ = png.current_color;
  44. }
  45. png.modified = 1;
  46. }