GRASS GIS 7 Programmer's Manual
7.8.2(2019)-exported
cairodriver/write_bmp.c
Go to the documentation of this file.
1
/*!
2
\file lib/cairodriver/write_bmp.c
3
4
\brief GRASS cairo display driver - write bitmap (lower level functions)
5
6
(C) 2007-2008 by Lars Ahlzen 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 Lars Ahlzen <lars ahlzen.com> (original contibutor)
12
\author Glynn Clements
13
*/
14
15
#include <stdio.h>
16
#include <stdlib.h>
17
#include <string.h>
18
19
#include <grass/gis.h>
20
#include <grass/glocale.h>
21
#include "
cairodriver.h
"
22
23
static
unsigned
char
*put_2(
unsigned
char
*p,
unsigned
int
n)
24
{
25
*p++ = n & 0xFF;
26
n >>= 8;
27
*p++ = n & 0xFF;
28
return
p;
29
}
30
31
static
unsigned
char
*put_4(
unsigned
char
*p,
unsigned
int
n)
32
{
33
*p++ = n & 0xFF;
34
n >>= 8;
35
*p++ = n & 0xFF;
36
n >>= 8;
37
*p++ = n & 0xFF;
38
n >>= 8;
39
*p++ = n & 0xFF;
40
return
p;
41
}
42
43
static
void
make_bmp_header(
unsigned
char
*p)
44
{
45
*p++ =
'B'
;
46
*p++ =
'M'
;
47
48
p = put_4(p,
HEADER_SIZE
+
ca
.
width
*
ca
.
height
* 4);
49
p = put_4(p, 0);
50
p = put_4(p,
HEADER_SIZE
);
51
52
p = put_4(p, 40);
53
p = put_4(p,
ca
.
width
);
54
p = put_4(p, -
ca
.
height
);
55
p = put_2(p, 1);
56
p = put_2(p, 32);
57
p = put_4(p, 0);
58
p = put_4(p,
ca
.
width
*
ca
.
height
* 4);
59
p = put_4(p, 0);
60
p = put_4(p, 0);
61
p = put_4(p, 0);
62
p = put_4(p, 0);
63
}
64
65
void
cairo_write_bmp
(
void
)
66
{
67
char
header[
HEADER_SIZE
];
68
FILE *
output
;
69
70
output
= fopen(
ca
.
file_name
,
"wb"
);
71
if
(!
output
)
72
G_fatal_error
(_(
"Cairo: unable to open output file <%s>"
),
73
ca
.
file_name
);
74
75
memset(header, 0,
sizeof
(header));
76
make_bmp_header(header);
77
fwrite(header,
sizeof
(header), 1,
output
);
78
79
fwrite(
ca
.
grid
,
ca
.
stride
,
ca
.
height
,
output
);
80
81
fclose(
output
);
82
}
output
void output(const char *fmt,...)
Definition:
psdriver/graph_set.c:233
ca
struct cairo_state ca
Definition:
cairodriver/graph.c:42
cairo_state::grid
unsigned char * grid
Definition:
cairodriver.h:68
cairo_write_bmp
void cairo_write_bmp(void)
Definition:
cairodriver/write_bmp.c:65
G_fatal_error
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
Definition:
gis/error.c:160
cairo_state::width
int width
Definition:
cairodriver.h:67
cairo_state::height
int height
Definition:
cairodriver.h:67
cairo_state::file_name
char * file_name
Definition:
cairodriver.h:65
cairodriver.h
GRASS cairo display driver - header file.
cairo_state::stride
int stride
Definition:
cairodriver.h:67
HEADER_SIZE
#define HEADER_SIZE
Definition:
cairodriver.h:45
cairodriver
write_bmp.c
Generated on Tue Jan 14 2020 14:30:42 for GRASS GIS 7 Programmer's Manual by
1.8.16