/* jsjpeg_image.h - routines to read and write JPEG files. */ /* Last edited on 2012-06-09 19:29:11 by stolfilocal */ /* Created by R. Minetto (IC-UNICAMP) sometime in 2008--2009. */ /* Adapted by J. Stolfi (IC-UNICMP) on 2011-05-14. */ #ifndef jsjpeg_image_H #define jsjpeg_image_H #define _GNU_SOURCE #include #undef FALSE #undef TRUE #include #undef FALSE #undef TRUE #include #include /* These procedures read/write a JPEG file into/from the {pnm_image_t} memory format defined in {jspnm_image.h}. */ #define jsjpeg_BITS_PER_SAMPLE (BITS_PER_JSAMPLE) /* The number of bits per sample of decompressed images: either 8 or 12, usually 8. */ pnm_image_t *jsjpeg_image_read (char *name, bool_t verbose, int *kind); /* Reads an image from the named JPEG file. If {*kind} is not NULL, sets it to the image color space as in the {J_COLOR_SPACE} codes of {jpeglib.h}. Note that the PNM files support only {JCS_GRAYSCALE} and {JCS_RGB} spaces. Note also that {JCS_CMYK} and {JCS_YCCK} images have {chns=4}. The routine can read only JPEG files whose number of bits per pixel (8 or 12) is equal to the parameter {BITS_IN_JSAMPLE} in the {jpeglib.h} header and compiled into the JPEG library. If that parameter is defined as 8 then the JPEG library (and therefoe this procedure) cannot read 12-bit files, and vice-versa. What a crock. In any case the {maxval} of the returned image is set to the correct value (255 or 4095, respectively). If the {name} is "-", reads from {stdin}. If {verbose} is TRUE, prints a notice to {stderr}. */ void jsjpeg_image_write (char *name, pnm_image_t *img, int quality, bool_t verbose); /* Writes image {img} to the specified file in JPEG format. If {img.chns} is 1 uses colorspace {JCS_GRAYSCALE}, if 3 assumes {JCS_RGB}. Other values are invalid. The {quality} parameter is an integer in {1..100} that specifies the fidelity of the compressed image to the original: 100 means no compression; typical values range in {80..98}. The routine can write only JPEG files whose number of bits per pixel (8 or 12) is equal to the parameter {BITS_IN_JSAMPLE} in the {jpeglib.h} header and compiled into the JPEG library. If that parameter is defined as 8 then the JPEG library (and therefore this procedure) cannot write 12-bit files, and vice-versa. What a crock. In any case the samples of {img} are linearly scaled from the range {0..img.maxval} to the appropriate range, {0..255} or {0..4095}. If {name} is "-", writes to {stdout}. If {verbose} is TRUE, prints a notice to {stderr}. */ pnm_image_t *jsjpeg_image_fread (FILE *rd, int *kind); void jsjpeg_image_fwrite (FILE *wr, pnm_image_t *img, int quality); /* Same as {jsjpeg_image_read} and {jsjpeg_image_write}, but from/to a previously opened file handle. */ #endif