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_ppm.c
Go to the documentation of this file.
1
#include "
cairodriver.h
"
2
3
void
write_ppm
(
void
)
4
{
5
char
*mask_name =
G_store
(
file_name
);
6
FILE *
output
, *mask;
7
int
x, y;
8
9
output = fopen(
file_name
,
"wb"
);
10
if
(!output)
11
G_fatal_error
(
"cairo: couldn't open output file %s"
,
file_name
);
12
13
mask_name[strlen(mask_name) - 2] =
'g'
;
14
15
mask = fopen(mask_name,
"wb"
);
16
if
(!mask)
17
G_fatal_error
(
"cairo: couldn't open mask file %s"
, mask_name);
18
19
G_free
(mask_name);
20
21
fprintf(output,
"P6\n%d %d\n255\n"
,
width
,
height
);
22
fprintf(mask,
"P5\n%d %d\n255\n"
,
width
,
height
);
23
24
for
(y = 0; y <
height
; y++) {
25
const
unsigned
int
*row = (
const
unsigned
int
*)(
grid
+ y *
stride
);
26
27
for
(x = 0; x <
width
; x++) {
28
unsigned
int
c = row[x];
29
int
a = (c >> 24) & 0xFF;
30
int
r
= (c >> 16) & 0xFF;
31
int
g
= (c >> 8) & 0xFF;
32
int
b
= (c >> 0) & 0xFF;
33
34
if
(a > 0 && a < 0xFF) {
35
r = r * 0xFF / a;
36
g = g * 0xFF / a;
37
b = b * 0xFF / a;
38
}
39
40
fputc((
unsigned
char
)r, output);
41
fputc((
unsigned
char
)g, output);
42
fputc((
unsigned
char
)b, output);
43
fputc((
unsigned
char
)a, mask);
44
}
45
}
46
47
fclose(output);
48
fclose(mask);
49
}
lib
cairodriver
write_ppm.c
Generated on Sun Sep 9 2012 18:55:35 for GRASS Programmer's Manual by
1.8.1.2