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
pngdriver/write_ppm.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 "
pngdriver.h
"
8
9
void
write_ppm
(
void
)
10
{
11
FILE *
output
;
12
int
x, y;
13
unsigned
int
*p;
14
15
output = fopen(
file_name
,
"wb"
);
16
if
(!output)
17
G_fatal_error
(
"PNG: couldn't open output file %s"
,
file_name
);
18
19
fprintf(output,
"P6\n%d %d\n255\n"
,
width
,
height
);
20
21
for
(y = 0, p =
grid
; y <
height
; y++) {
22
for
(x = 0; x <
width
; x++, p++) {
23
unsigned
int
c = *p;
24
int
r
,
g
,
b
, a;
25
26
get_pixel
(c, &r, &g, &b, &a);
27
28
fputc((
unsigned
char
)r, output);
29
fputc((
unsigned
char
)g, output);
30
fputc((
unsigned
char
)b, output);
31
}
32
}
33
34
fclose(output);
35
}
36
37
void
write_pgm
(
void
)
38
{
39
char
*mask_name =
G_store
(
file_name
);
40
FILE *
output
;
41
int
x, y;
42
unsigned
int
*p;
43
44
mask_name[strlen(mask_name) - 2] =
'g'
;
45
46
output = fopen(mask_name,
"wb"
);
47
if
(!output)
48
G_fatal_error
(
"PNG: couldn't open mask file %s"
, mask_name);
49
50
G_free
(mask_name);
51
52
fprintf(output,
"P5\n%d %d\n255\n"
,
width
,
height
);
53
54
for
(y = 0, p =
grid
; y <
height
; y++) {
55
for
(x = 0; x <
width
; x++, p++) {
56
unsigned
int
c = *p;
57
int
r
,
g
,
b
, a;
58
59
get_pixel
(c, &r, &g, &b, &a);
60
61
fputc((
unsigned
char
)(255 - a), output);
62
}
63
}
64
65
fclose(output);
66
}
lib
pngdriver
write_ppm.c
Generated on Wed Jun 6 2012 14:04:30 for GRASS Programmer's Manual by
1.8.1