greymap.h
Go to the documentation of this file.
00001 /* Copyright (C) 2001-2007 Peter Selinger.
00002    This file is part of Potrace. It is free software and it is covered
00003    by the GNU General Public License. See the file COPYING for details. */
00004 
00005 /* $Id: greymap.h 147 2007-04-09 00:44:09Z selinger $ */
00006 
00007 #ifndef PGM_H
00008 #define PGM_H
00009 
00010 #include <stdio.h>
00011 
00012 /* internal format for greymaps. Note: in this format, rows are
00013    ordered from bottom to top. The pixels in each row are given from
00014    left to right. */
00015 
00016 struct greymap_s {
00017   int w;                 /* width, in pixels */
00018   int h;                 /* height, in pixels */
00019   signed short int *map;    /* raw data, w*h values */
00020 };
00021 typedef struct greymap_s greymap_t;
00022 
00023 /* macros for accessing pixel at index (x,y). Note that the origin is
00024    in the *lower* left corner. U* macros omit the bounds check. */
00025 
00026 #define gm_index(gm, x, y) (&(gm)->map[(x)+(y)*(gm)->w])
00027 #define gm_safe(gm, x, y) ((int)(x)>=0 && (int)(x)<(gm)->w && (int)(y)>=0 && (int)(y)<(gm)->h)
00028 #define gm_bound(x, m) ((x)<0 ? 0 : (x)>=(m) ? (m)-1 : (x))
00029 #define GM_UGET(gm, x, y) (*gm_index(gm, x, y))
00030 #define GM_UINC(gm, x, y, b) (*gm_index(gm, x, y) += (short int)(b))
00031 #define GM_UINV(gm, x, y) (*gm_index(gm, x, y) = 255 - *gm_index(gm, x, y))
00032 #define GM_UPUT(gm, x, y, b) (*gm_index(gm, x, y) = (short int)(b))
00033 #define GM_GET(gm, x, y) (gm_safe(gm, x, y) ? GM_UGET(gm, x, y) : 0)
00034 #define GM_INC(gm, x, y, b) (gm_safe(gm, x, y) ? GM_UINC(gm, x, y, b) : 0)
00035 #define GM_INV(gm, x, y) (gm_safe(gm, x, y) ? GM_UINV(gm, x, y) : 0)
00036 #define GM_PUT(gm, x, y, b) (gm_safe(gm, x, y) ? GM_UPUT(gm, x, y, b) : 0)
00037 #define GM_BGET(gm, x, y) GM_UGET(gm, gm_bound(x, gm->w), gm_bound(y, gm->h))
00038 
00039 /* modes for cutting off out-of-range values. The following names
00040    refer to winding numbers. I.e., make a pixel black if winding
00041    number is nonzero, odd, or positive, respectively. We assume that 0
00042    winding number corresponds to white (255). */
00043 #define GM_MODE_NONZERO 1
00044 #define GM_MODE_ODD 2
00045 #define GM_MODE_POSITIVE 3
00046 #define GM_MODE_NEGATIVE 4
00047 
00048 extern char *gm_read_error;
00049 
00050 greymap_t *gm_new(int w, int h);
00051 greymap_t *gm_dup(greymap_t *gm);
00052 void gm_free(greymap_t *gm);
00053 void gm_clear(greymap_t *gm, int b);
00054 int gm_read(FILE *f, greymap_t **gmp);
00055 int gm_writepgm(FILE *f, greymap_t *gm, char *comment, int raw, int mode, double gamma);
00056 int gm_print(FILE *f, greymap_t *gm);
00057 
00058 #endif /* PGM_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


portrait_painter
Author(s): Niklas Meinzer, Ina Baumgarten
autogenerated on Wed Dec 26 2012 16:00:43