~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/cairodriver/read_ppm.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*!
 
2
  \file lib/cairodriver/read_ppm.c
 
3
 
 
4
  \brief GRASS cairo display driver - read PPM image (lower level functions)
 
5
 
 
6
  (C) 2007-2008, 2011 by Lars Ahlzen and the GRASS Development Team
 
7
  
 
8
  This program is free software under the GNU General Public License
 
9
  (>=v2). Read the file COPYING that comes with GRASS for details.
 
10
  
 
11
  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
 
12
  \author Glynn Clements  
 
13
*/
 
14
 
 
15
#include <grass/glocale.h>
 
16
 
1
17
#include "cairodriver.h"
2
18
 
3
 
void read_ppm(void)
 
19
void cairo_read_ppm(void)
4
20
{
5
 
    char *mask_name = G_store(file_name);
 
21
    char *mask_name = G_store(ca.file_name);
6
22
    FILE *input, *mask;
7
23
    int x, y;
8
24
    int i_width, i_height, maxval;
9
25
 
10
 
    input = fopen(file_name, "rb");
 
26
    input = fopen(ca.file_name, "rb");
11
27
    if (!input)
12
 
        G_fatal_error("cairo: couldn't open input file %s", file_name);
 
28
        G_fatal_error(_("Cairo: unable to open input file <%s>"),
 
29
                      ca.file_name);
13
30
 
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>"),
 
33
                      ca.file_name);
16
34
 
17
35
    fgetc(input);
18
36
 
19
 
    if (i_width != width || i_height != height)
20
 
        G_fatal_error
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);
23
41
 
24
42
    mask_name[strlen(mask_name) - 2] = 'g';
25
43
 
26
44
    mask = fopen(mask_name, "rb");
27
45
    if (!mask)
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>"),
 
47
                      mask_name);
29
48
 
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>"),
 
51
                      mask_name);
32
52
 
33
53
    fgetc(mask);
34
54
 
35
 
    if (i_width != width || i_height != height)
36
 
        G_fatal_error
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);
39
59
 
40
60
    G_free(mask_name);
41
61
 
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);
44
64
 
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);