2
\file lib/cairodriver/read_ppm.c
4
\brief GRASS cairo display driver - read PPM image (lower level functions)
6
(C) 2007-2008, 2011 by Lars Ahlzen and the GRASS Development Team
8
This program is free software under the GNU General Public License
9
(>=v2). Read the file COPYING that comes with GRASS for details.
11
\author Lars Ahlzen <lars ahlzen.com> (original contibutor)
12
\author Glynn Clements
15
#include <grass/glocale.h>
1
17
#include "cairodriver.h"
19
void cairo_read_ppm(void)
5
char *mask_name = G_store(file_name);
21
char *mask_name = G_store(ca.file_name);
8
24
int i_width, i_height, maxval;
10
input = fopen(file_name, "rb");
26
input = fopen(ca.file_name, "rb");
12
G_fatal_error("cairo: couldn't open input file %s", file_name);
28
G_fatal_error(_("Cairo: unable to open input file <%s>"),
14
31
if (fscanf(input, "P6 %d %d %d", &i_width, &i_height, &maxval) != 3)
15
G_fatal_error("cairo: invalid input file %s", file_name);
32
G_fatal_error(_("Cairo: invalid input file <%s>"),
19
if (i_width != width || i_height != height)
21
("cairo: input file has incorrect dimensions: expected: %dx%d got: %dx%d",
22
width, height, i_width, i_height);
37
if (i_width != ca.width || i_height != ca.height)
38
G_fatal_error(_("Cairo: input file has incorrect dimensions: "
39
"expected: %dx%d got: %dx%d"),
40
ca.width, ca.height, i_width, i_height);
24
42
mask_name[strlen(mask_name) - 2] = 'g';
26
44
mask = fopen(mask_name, "rb");
28
G_fatal_error("cairo: couldn't open input mask file %s", mask_name);
46
G_fatal_error(_("Cairo: unable to open input mask file <%s>"),
30
49
if (fscanf(mask, "P5 %d %d %d", &i_width, &i_height, &maxval) != 3)
31
G_fatal_error("cairo: invalid input mask file %s", mask_name);
50
G_fatal_error(_("Cairo: invalid input mask file <%s>"),
35
if (i_width != width || i_height != height)
37
("cairo: input mask file has incorrect dimensions: expected: %dx%d got: %dx%d",
38
width, height, i_width, i_height);
55
if (i_width != ca.width || i_height != ca.height)
56
G_fatal_error(_("Cairo: input mask file has incorrect dimensions: "
57
"expected: %dx%d got: %dx%d"),
58
ca.width, ca.height, i_width, i_height);
42
for (y = 0; y < height; y++) {
43
unsigned int *row = (unsigned int *)(grid + y * stride);
62
for (y = 0; y < ca.height; y++) {
63
unsigned int *row = (unsigned int *)(ca.grid + y * ca.stride);
45
for (x = 0; x < width; x++) {
65
for (x = 0; x < ca.width; x++) {
46
66
int r = fgetc(input);
47
67
int g = fgetc(input);
48
68
int b = fgetc(input);