GRASS Programmer's Manual
6.4.2(2012)
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
cairodriver/write_bmp.c
Go to the documentation of this file.
1
2
#include <stdio.h>
3
#include <stdlib.h>
4
#include <string.h>
5
6
#include <grass/gis.h>
7
#include "
cairodriver.h
"
8
9
static
unsigned
char
*put_2(
unsigned
char
*p,
unsigned
int
n)
10
{
11
*p++ = n & 0xFF;
12
n >>= 8;
13
*p++ = n & 0xFF;
14
return
p;
15
}
16
17
static
unsigned
char
*put_4(
unsigned
char
*p,
unsigned
int
n)
18
{
19
*p++ = n & 0xFF;
20
n >>= 8;
21
*p++ = n & 0xFF;
22
n >>= 8;
23
*p++ = n & 0xFF;
24
n >>= 8;
25
*p++ = n & 0xFF;
26
return
p;
27
}
28
29
static
void
make_bmp_header(
unsigned
char
*p)
30
{
31
*p++ =
'B'
;
32
*p++ =
'M'
;
33
34
p = put_4(p,
HEADER_SIZE
+
width
*
height
* 4);
35
p = put_4(p, 0);
36
p = put_4(p,
HEADER_SIZE
);
37
38
p = put_4(p, 40);
39
p = put_4(p,
width
);
40
p = put_4(p, -
height
);
41
p = put_2(p, 1);
42
p = put_2(p, 32);
43
p = put_4(p, 0);
44
p = put_4(p,
width
*
height
* 4);
45
p = put_4(p, 0);
46
p = put_4(p, 0);
47
p = put_4(p, 0);
48
p = put_4(p, 0);
49
}
50
51
void
write_bmp
(
void
)
52
{
53
char
header[
HEADER_SIZE
];
54
FILE *
output
;
55
56
output = fopen(
file_name
,
"wb"
);
57
if
(!output)
58
G_fatal_error
(
"cairo: couldn't open output file %s"
,
file_name
);
59
60
memset(header, 0,
sizeof
(header));
61
make_bmp_header(header);
62
fwrite(header,
sizeof
(header), 1, output);
63
64
fwrite(
grid
,
stride
,
height
, output);
65
66
fclose(output);
67
}
lib
cairodriver
write_bmp.c
Generated on Sun Mar 16 2014 05:07:49 for GRASS Programmer's Manual by
1.8.1.2