Statistics
| Revision:

gvsig-raster / libjni-potrace / trunk / libjni-potrace / src / main / native / jpotrace / greymap.h @ 1780

History | View | Annotate | Download (2.29 KB)

1
/* Copyright (C) 2001-2007 Peter Selinger.
2
   This file is part of Potrace. It is free software and it is covered
3
   by the GNU General Public License. See the file COPYING for details. */
4

    
5
/* $Id: greymap.h 147 2007-04-09 00:44:09Z selinger $ */
6

    
7
#ifndef PGM_H
8
#define PGM_H
9

    
10
#include <stdio.h>
11

    
12
/* internal format for greymaps. Note: in this format, rows are
13
   ordered from bottom to top. The pixels in each row are given from
14
   left to right. */
15

    
16
struct greymap_s {
17
  int w;                 /* width, in pixels */
18
  int h;                 /* height, in pixels */
19
  signed short int *map;    /* raw data, w*h values */
20
};
21
typedef struct greymap_s greymap_t;
22

    
23
/* macros for accessing pixel at index (x,y). Note that the origin is
24
   in the *lower* left corner. U* macros omit the bounds check. */
25

    
26
#define gm_index(gm, x, y) (&(gm)->map[(x)+(y)*(gm)->w])
27
#define gm_safe(gm, x, y) ((int)(x)>=0 && (int)(x)<(gm)->w && (int)(y)>=0 && (int)(y)<(gm)->h)
28
#define gm_bound(x, m) ((x)<0 ? 0 : (x)>=(m) ? (m)-1 : (x))
29
#define GM_UGET(gm, x, y) (*gm_index(gm, x, y))
30
#define GM_UINC(gm, x, y, b) (*gm_index(gm, x, y) += (short int)(b))
31
#define GM_UINV(gm, x, y) (*gm_index(gm, x, y) = 255 - *gm_index(gm, x, y))
32
#define GM_UPUT(gm, x, y, b) (*gm_index(gm, x, y) = (short int)(b))
33
#define GM_GET(gm, x, y) (gm_safe(gm, x, y) ? GM_UGET(gm, x, y) : 0)
34
#define GM_INC(gm, x, y, b) (gm_safe(gm, x, y) ? GM_UINC(gm, x, y, b) : 0)
35
#define GM_INV(gm, x, y) (gm_safe(gm, x, y) ? GM_UINV(gm, x, y) : 0)
36
#define GM_PUT(gm, x, y, b) (gm_safe(gm, x, y) ? GM_UPUT(gm, x, y, b) : 0)
37
#define GM_BGET(gm, x, y) GM_UGET(gm, gm_bound(x, gm->w), gm_bound(y, gm->h))
38

    
39
/* modes for cutting off out-of-range values. The following names
40
   refer to winding numbers. I.e., make a pixel black if winding
41
   number is nonzero, odd, or positive, respectively. We assume that 0
42
   winding number corresponds to white (255). */
43
#define GM_MODE_NONZERO 1
44
#define GM_MODE_ODD 2
45
#define GM_MODE_POSITIVE 3
46
#define GM_MODE_NEGATIVE 4
47

    
48
extern char *gm_read_error;
49

    
50
greymap_t *gm_new(int w, int h);
51
greymap_t *gm_dup(greymap_t *gm);
52
void gm_free(greymap_t *gm);
53
void gm_clear(greymap_t *gm, int b);
54
int gm_read(FILE *f, greymap_t **gmp);
55
int gm_writepgm(FILE *f, greymap_t *gm, char *comment, int raw, int mode, double gamma);
56
int gm_print(FILE *f, greymap_t *gm);
57

    
58
#endif /* PGM_H */