GRASS 8 Programmer's Manual
8.5.0(2026)-8d6ceba290
Toggle main menu visibility
Loading...
Searching...
No Matches
pngdriver/draw_bitmap.c
Go to the documentation of this file.
1
/*!
2
\file lib/pngdriver/draw_bitmap.c
3
4
\brief GRASS png display driver - draw bitmap
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
#ifndef min
19
#define min(a, b) ((a) < (b) ? (a) : (b))
20
#endif
21
#ifndef max
22
#define max(a, b) ((a) > (b) ? (a) : (b))
23
#endif
24
25
/*!
26
\brief Draw bitmap
27
28
\param ncols,nrows number of columns and rows
29
\param threshold threshold value
30
\param buf data buffer
31
*/
32
void
PNG_draw_bitmap
(
int
ncols,
int
nrows,
int
threshold,
33
const
unsigned
char
*buf)
34
{
35
int
i0 =
max
(
png
.clip_left -
cur_x
, 0);
36
int
i1 =
min
(
png
.clip_rite -
cur_x
, ncols);
37
int
j0 =
max
(
png
.clip_top -
cur_y
, 0);
38
int
j1 =
min
(
png
.clip_bot -
cur_y
, nrows);
39
40
if
(!
png
.true_color) {
41
int
i, j;
42
43
for
(j = j0; j < j1; j++) {
44
int
y =
cur_y
+ j;
45
46
for
(i = i0; i < i1; i++) {
47
int
x
=
cur_x
+ i;
48
unsigned
int
k = buf[j * ncols + i];
49
unsigned
int
*p = &
png
.grid[y *
png
.width +
x
];
50
51
if
(k > (
unsigned
int
)threshold)
52
*p =
png
.current_color;
53
}
54
}
55
}
56
else
{
57
int
r1, g1, b1, a1;
58
int
i, j;
59
60
png_get_pixel
(
png
.current_color, &r1, &g1, &b1, &a1);
61
62
for
(j = j0; j < j1; j++) {
63
int
y =
cur_y
+ j;
64
65
for
(i = i0; i < i1; i++) {
66
int
x
=
cur_x
+ i;
67
unsigned
int
k = buf[j * ncols + i];
68
unsigned
int
*p = &
png
.grid[y *
png
.width +
x
];
69
int
a0, r0, g0, b0;
70
unsigned
int
a,
r
,
g
,
b
;
71
72
png_get_pixel
(*p, &r0, &g0, &b0, &a0);
73
74
a = (a0 * (255 - k) + a1 * k) / 255;
75
r
= (r0 * (255 - k) + r1 * k) / 255;
76
g
= (g0 * (255 - k) + g1 * k) / 255;
77
b
= (b0 * (255 - k) + b1 * k) / 255;
78
79
*p =
png_get_color
(
r
,
g
,
b
, a);
80
}
81
}
82
}
83
84
png
.modified = 1;
85
}
png_get_color
unsigned int png_get_color(int r, int g, int b, int a)
Definition
color_table.c:118
png_get_pixel
void png_get_pixel(unsigned int pixel, int *r, int *g, int *b, int *a)
Definition
color_table.c:110
b
double b
Definition
driver/set_window.c:5
r
double r
Definition
driver/set_window.c:5
cur_x
double cur_x
Definition
driver/init.c:32
cur_y
double cur_y
Definition
driver/init.c:33
g
float g
Definition
named_colr.c:7
PNG_draw_bitmap
void PNG_draw_bitmap(int ncols, int nrows, int threshold, const unsigned char *buf)
Draw bitmap.
Definition
pngdriver/draw_bitmap.c:32
min
#define min(a, b)
Definition
pngdriver/draw_bitmap.c:19
max
#define max(a, b)
Definition
pngdriver/draw_bitmap.c:22
png
struct png_state png
Definition
pngdriver/graph_set.c:32
pngdriver.h
GRASS png display driver - header file.
x
#define x
pngdriver
draw_bitmap.c
Generated on
for GRASS 8 Programmer's Manual by
1.17.0