GRASS 8 Programmer's Manual 8.6.0dev(2026)-55de52a352
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 SPDX-FileCopyrightText: 2003-2014 Per Henrik Johansen
7 SPDX-FileCopyrightText: GRASS Development Team
8 SPDX-License-Identifier: GPL-2.0-or-later
9
10 \author Per Henrik Johansen (original contributor)
11 \author Glynn Clements
12 */
13
14#include <math.h>
15#include "pngdriver.h"
16
17/*!
18 \brief Draw a (filled) rectangle
19
20 \param fx1,fy1,fx2,fy2 rectangle coordinates
21 */
22void PNG_Box(double fx1, double fy1, double fx2, double fy2)
23{
24 int x1 = (int)floor(fx1 + 0.5);
25 int y1 = (int)floor(fy1 + 0.5);
26 int x2 = (int)floor(fx2 + 0.5);
27 int y2 = (int)floor(fy2 + 0.5);
28 int tmp;
29 int x, y;
30
31 if (x1 > x2)
32 tmp = x1, x1 = x2, x2 = tmp;
33
34 if (y1 > y2)
35 tmp = y1, y1 = y2, y2 = tmp;
36
37 if (x2 < 0 || x1 > png.width)
38 return;
39
40 if (y2 < 0 || y1 > png.height)
41 return;
42
43 if (x1 < png.clip_left)
44 x1 = png.clip_left;
45
46 if (x2 > png.clip_rite)
47 x2 = png.clip_rite;
48
49 if (y1 < png.clip_top)
50 y1 = png.clip_top;
51
52 if (y2 > png.clip_bot)
53 y2 = png.clip_bot;
54
55 for (y = y1; y < y2; y++) {
56 unsigned int *p = &png.grid[y * png.width + x1];
57
58 for (x = x1; x < x2; x++)
59 *p++ = png.current_color;
60 }
61
62 png.modified = 1;
63}
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.
#define x