/* Floating-point color images, and image files in PPM format */ /* Last edited on 2007-11-07 11:59:58 by stolfi */ #ifndef frgb_image_H #define frgb_image_H /* TO DO: uniformize names, fields, procs with {float_image.h}. */ #include #include #include #include typedef struct { nat_t NX, NY; frgb_t **pix; } frgb_image_t; /* MAIN PROCEDURES */ frgb_image_t frgb_image_new (nat_t NX, nat_t NY); /* Allocates a new color image of width NX and height NY. */ frgb_image_t frgb_image_read_ppm (FILE *f, float gamma); /* Reads a PPM image (P6 or P3) from file "f". */ void frgb_image_write_ppm (FILE *f, float gamma, frgb_image_t im); /* Writes an image to disk in raw PPM (P6) format. */ void frgb_image_normalize (frgb_image_t im); /* Maps the colors of all pixels to fit in the [0..1] cube, by scaling uniformly the three components and and adding or subtracting a constant amount of white. This transformation preserves hue, and rescales brightness and chroma independently of each other. So grays remain gray, and equally bright colors remain equally bright. */ /* LOW-LEVEL PROCEDURES */ void frgb_image_read_ppm_header (FILE *f, nat_t *NX, nat_t *NY, nat_t *maxval, bool_t *raw); /* Reads the header of a PPM image (P6 or P3), returnd header data. The "raw" bit is TRUE for binary pixels (P6), FALSE for ascii (P3). */ void frgb_image_read_ppm_raw_pixels (FILE *f, nat_t maxval, float gamma, nat_t NX, frgb_t px[]); void frgb_image_read_ppm_ascii_pixels (FILE *f, nat_t maxval, float gamma, nat_t NX, frgb_t pix[]); /* Reads one row of pixels from file "f" */ void frgb_image_write_ppm_header (FILE *f, nat_t NX, nat_t NY, nat_t maxval, bool_t raw); /* Writes the header of a PPM image (P6 or P3). */ void frgb_image_write_ppm_raw_pixels (FILE *f, nat_t maxval, float gamma, nat_t NX, frgb_t pix[]); void frgb_image_write_ppm_ascii_pixels (FILE *f, nat_t maxval, float gamma, nat_t NX, frgb_t pix[]); /* Writes one row of pixels to file "f". */ float frgb_image_undo_gamma (int pixel, nat_t maxval, float gamma); /* Converts from integer pixel [0..maxval] to float intensity [0..1], taking into account the gamma correction: intensity = (pixel/maxval)^gamma. */ int frgb_image_apply_gamma (float intensity, nat_t maxval, float gamma); /* Converts from float intensity [0..1] to integer pixel [0..maxval], taking into account the gamma correction: intensity = (pixel/maxval)^gamma. */ #endif