Question

J'utilise c ++, + RDB, WINDOWS. Comment vérifier si un jpeg est un RVB ou CMJN?

Était-ce utile?

La solution

Si vous utilisez la bibliothèque libjpeg IJG, vous pouvez ouvrir le fichier JPEG, lisez l'en-tête et voir si elle est en niveaux de gris (monochrome), RVB ou CMJN. (En fait, il existe plusieurs bibliothèques JPEG libres, mais le libjpeg IJG est probablement le plus couramment utilisé.) Vous pouvez trouver des sources libjpeg à:

http://www.ijg.org/files/jpegsrc.v8c. tar.gz

Un exemple approximatif de la façon de lire l'en-tête serait quelque chose comme:

struct jpeg_decompress_struct dinfo;
FILE* file = fopen(fname, "r");

/* Step 1: allocate and initialize JPEG decompression object */
jpeg_create_decompress(&dinfo);

/* Step 2: specify data source (eg, a file) */
jpeg_stdio_src(&dinfo, file);

/* Step 3: read file parameters with jpeg_read_header() */
(void) jpeg_read_header(dinfo, TRUE);

/* Step 4: set parameters for decompression
 * In this example, we don't need to change any of the 
 * defaults set by jpeg_read_header(), so we do nothing here.
 */
if (dinfo->jpeg_color_space == JCS_CMYK || dinfo->jpeg_color_space == JCS_YCCK) {
    // CMYK
} else if (dinfo->jpeg_color_space == JCS_RGB || dinfo->jpeg_color_space == JCS_YCbCr) {
    // RGB
} else if (dinfo->jpeg_color_space == JCS_GRAYSCALE) {
    // Grayscale
} else {
    ERREXIT(dinfo, JERR_CONVERSION_NOTIMPL);
    // error condition here...
}

/* You can skip the other steps involved in decompressing an image */

/* Step 8: Release JPEG decompression object */
jpeg_destroy_decompress(dinfo);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top