GRASS GIS 8 Programmer's Manual 8.3.2(2024)-exported
Loading...
Searching...
No Matches
pngdriver/box.c
Go to the documentation of this file.
1/*!
2 \file lib/pngdriver/box.c
3
4 \brief GRASS png display driver - draw box
5
6 (C) 2003-2014 by Per Henrik Johansen and the GRASS Development Team
7
8 This program is free software under the GNU General Public License
9 (>=v2). Read the file COPYING that comes with GRASS for details.
10
11 \author Per Henrik Johansen (original contributor)
12 \author Glynn Clements
13 */
14
15#include <math.h>
16#include "pngdriver.h"
17
18/*!
19 \brief Draw a (filled) rectangle
20
21 \param fx1,fy1,fx2,fy2 rectangle coordinates
22 */
23
24void PNG_Box(double fx1, double fy1, double fx2, double fy2)
25{
26 int x1 = (int)floor(fx1 + 0.5);
27 int y1 = (int)floor(fy1 + 0.5);
28 int x2 = (int)floor(fx2 + 0.5);
29 int y2 = (int)floor(fy2 + 0.5);
30 int tmp;
31 int x, y;
32
33 if (x1 > x2)
34 tmp = x1, x1 = x2, x2 = tmp;
35
36 if (y1 > y2)
37 tmp = y1, y1 = y2, y2 = tmp;
38
39 if (x2 < 0 || x1 > png.width)
40 return;
41
42 if (y2 < 0 || y1 > png.height)
43 return;
44
45 if (x1 < png.clip_left)
46 x1 = png.clip_left;
47
48 if (x2 > png.clip_rite)
49 x2 = png.clip_rite;
50
51 if (y1 < png.clip_top)
52 y1 = png.clip_top;
53
54 if (y2 > png.clip_bot)
55 y2 = png.clip_bot;
56
57 for (y = y1; y < y2; y++) {
58 unsigned int *p = &png.grid[y * png.width + x1];
59
60 for (x = x1; x < x2; x++)
61 *p++ = png.current_color;
62 }
63
64 png.modified = 1;
65}
void PNG_Box(double fx1, double fy1, double fx2, double fy2)
Draw a (filled) rectangle.
struct png_state png
GRASS png display driver - header file.
double clip_left
Definition pngdriver.h:41
double clip_bot
Definition pngdriver.h:41
double clip_top
Definition pngdriver.h:41
int current_color
Definition pngdriver.h:33
int height
Definition pngdriver.h:42
unsigned int * grid
Definition pngdriver.h:43
int width
Definition pngdriver.h:42
double clip_rite
Definition pngdriver.h:41
int modified
Definition pngdriver.h:46
#define x