Box.c 835 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include <math.h>
  2. #include "pngdriver.h"
  3. void PNG_Box(double fx1, double fy1, double fx2, double fy2)
  4. {
  5. int x1 = (int) floor(fx1 + 0.5);
  6. int y1 = (int) floor(fy1 + 0.5);
  7. int x2 = (int) floor(fx2 + 0.5);
  8. int y2 = (int) floor(fy2 + 0.5);
  9. int tmp;
  10. int x, y;
  11. if (x1 > x2)
  12. tmp = x1, x1 = x2, x2 = tmp;
  13. if (y1 > y2)
  14. tmp = y1, y1 = y2, y2 = tmp;
  15. if (x2 < 0 || x1 > png.width)
  16. return;
  17. if (y2 < 0 || y1 > png.height)
  18. return;
  19. if (x1 < png.clip_left)
  20. x1 = png.clip_left;
  21. if (x2 > png.clip_rite)
  22. x2 = png.clip_rite;
  23. if (y1 < png.clip_top)
  24. y1 = png.clip_top;
  25. if (y2 > png.clip_bot)
  26. y2 = png.clip_bot;
  27. for (y = y1; y < y2; y++) {
  28. unsigned int *p = &png.grid[y * png.width + x1];
  29. for (x = x1; x < x2; x++)
  30. *p++ = png.current_color;
  31. }
  32. png.modified = 1;
  33. }