00001
00002
00003
00004
00005
00006
00007 #ifndef PGM_H
00008 #define PGM_H
00009
00010 #include <stdio.h>
00011
00012
00013
00014
00015
00016 struct greymap_s {
00017 int w;
00018 int h;
00019 signed short int *map;
00020 };
00021 typedef struct greymap_s greymap_t;
00022
00023
00024
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
00040
00041
00042
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