GRASS Programmer's Manual
6.5.svn(2014)-r66266
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
}
HEADER_SIZE
#define HEADER_SIZE
Definition:
cairodriver.h:17
dialogs.width
tuple width
Definition:
psmap/dialogs.py:2959
write_bmp
void write_bmp(void)
Definition:
cairodriver/write_bmp.c:51
grid
unsigned char * grid
Definition:
cairodriver/Graph.c:50
stride
int stride
Definition:
cairodriver/Graph.c:49
file_name
char * file_name
Definition:
cairodriver/Graph.c:46
cairodriver.h
fclose
fclose(fd)
G_fatal_error
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
Definition:
lib/gis/error.c:150
height
int height
Definition:
cairodriver/Graph.c:49
n
int n
Definition:
dataquad.c:291
output
void output(const char *fmt,...)
Definition:
psdriver/Graph_set.c:224
lib
cairodriver
write_bmp.c
Generated on Sat Jan 2 2016 01:46:50 for GRASS Programmer's Manual by
1.8.5