/* bsutil.h - Edouard.Thiel@lim.univ-mrs.fr - 15/05/2001 Gestion du type image BsMap, lecture/écriture fichier PGM, visu XImage */ #ifndef BSUTIL__H #define BSUTIL__H /* * BsMap : type image de short avec un bord (Border short Map) * * * -bord 0 x xsiz-1 xmax-1 * -bord +-----+---------.-----------+-----+ ^ ^ * | | . | | | | * | | . | | | bord | * | | . | | v | * 0 +-----+---------.-----------+-----+ ^ | * | | . | | | | * | | . | | | | * | | . | | | | * | | | | | ysiz | ytot * y ............ tab[y][x] | | | | * | | | | | | * | | | | | | * | | | | | | * ysiz-1 +-----+---------------------+-----+ v | * | | | | ^ | * | | | | | bord | * | | | | | | * ymax-1 +-----+---------------------+-----+ v v * * <----><---------------------><----> * bord xsiz bord * * <---------------------------------> * xtot * * Pour créer une image : * BsMap *bm = NewBsMap (yhaut, xlarg, bord); * if (bm == NULL) return; * * Pour libérer l'image : * FreeBsMap(bm); bm = NULL; * * Pour balayer l'intérieur de l'image : * for (y = 0; y < bm->ysiz; y++) * for (x = 0; x < bm->xsiz; x++) * bm->tab[y][x] = ... * * Pour balayer toute l'image : * for (y = -bord; y < bm->ymax; y++) * for (x = -bord; x < bm->xmax; x++) * bm->tab[y][x] = ... * * Pour balayer linéairement toute l'image : * for (t = 0; t < bm->xytot; t++) * bm->vec[t] = ... */ #define BMAP_TITLE_MAX 128 typedef struct { char title[BMAP_TITLE_MAX]; /* titre */ int xsiz, ysiz, /* largeur en x, hauteur en y */ bord, /* taille du bord */ xmax, ymax, /* fin ligne, fin colonne */ xtot, ytot, /* largeur et hauteur totales */ xytot; /* nb total de pixels */ short *vec, /* tableau image linéaire */ **col, /* adresses débuts de lignes */ **tab; /* accès [y][x] aux pixels */ } BsMap; extern BsMap *NewBsMap (int ysiz, int xsiz, int bord); extern void FreeBsMap (BsMap *bm); extern BsMap *CopyBsMap (BsMap *bm); extern void SetTitleBsMap (BsMap *bm, char *title); extern int SetBorderBsMap (BsMap *bm, int bord); extern void InitWholeBsMap (BsMap *bm, short value); extern void InitInterBsMap (BsMap *bm, short value); extern void InitExterBsMap (BsMap *bm, short value); /* * Lecture/écriture de fichiers au format PGM */ extern BsMap *ReadBsMapFromPGM (char *filename, int bord); extern int WriteBsMapInPGM (char *filename, BsMap *bm); /* * Visualisation d'images BsMap avec une XImage */ /* Tables de couleurs (Look-Up Tables) périodiques */ enum { LUT_GREY, /* 256 niveaux de gris */ LUT_VGA, /* 15 couleurs vga */ LUT_VGA_GREY, /* <0 : 15 couleurs, >=0 : 256 gris */ LUT_RED_GREEN /* <0 : 256 rouges, >=0 : 256 verts */ }; extern XImage *NewXImageFromBsMap (BsMap *bm, int lut); extern void PaintXImage (XImage *xi, Window win); extern void FreeXImage (XImage *xi); #endif /* BSUTIL__H */