digiKam
iccjpeg.c File Reference

Macros

#define ICC_MARKER   (JPEG_APP0 + 2) /* JPEG marker code for ICC */
 
#define ICC_OVERHEAD_LEN   14 /* size of non-profile data in APP2 */
 
#define MAX_BYTES_IN_MARKER   65533 /* maximum data len of a JPEG marker */
 
#define MAX_DATA_BYTES_IN_MARKER   (MAX_BYTES_IN_MARKER - ICC_OVERHEAD_LEN)
 
#define MAX_SEQ_NO   255 /* sufficient since marker numbers are bytes */
 

Functions

boolean read_icc_profile (j_decompress_ptr cinfo, JOCTET **icc_data_ptr, unsigned int *icc_data_len)
 
void setup_read_icc_profile (j_decompress_ptr cinfo)
 
void write_icc_profile (j_compress_ptr cinfo, const JOCTET *icc_data_ptr, unsigned int icc_data_len)
 

Macro Definition Documentation

◆ ICC_MARKER

#define ICC_MARKER   (JPEG_APP0 + 2) /* JPEG marker code for ICC */

Since an ICC profile can be larger than the maximum size of a JPEG marker (64K), we need provisions to split it into multiple markers. The format defined by the ICC specifies one or more APP2 markers containing the following data: Identifying string ASCII "ICC_PROFILE\0" (12 bytes) Marker sequence number 1 for first APP2, 2 for next, etc (1 byte) Number of markers Total number of APP2's used (1 byte) Profile data (remainder of APP2 data) Decoders should use the marker sequence numbers to reassemble the profile, rather than assuming that the APP2 markers appear in the correct sequence.

◆ ICC_OVERHEAD_LEN

#define ICC_OVERHEAD_LEN   14 /* size of non-profile data in APP2 */

◆ MAX_BYTES_IN_MARKER

#define MAX_BYTES_IN_MARKER   65533 /* maximum data len of a JPEG marker */

◆ MAX_DATA_BYTES_IN_MARKER

#define MAX_DATA_BYTES_IN_MARKER   (MAX_BYTES_IN_MARKER - ICC_OVERHEAD_LEN)

◆ MAX_SEQ_NO

#define MAX_SEQ_NO   255 /* sufficient since marker numbers are bytes */

Function Documentation

◆ read_icc_profile()

boolean read_icc_profile ( j_decompress_ptr  cinfo,
JOCTET **  icc_data_ptr,
unsigned int *  icc_data_len 
)

See if there was an ICC profile in the JPEG file being read; if so, reassemble and return the profile data.

TRUE is returned if an ICC profile was found, FALSE if not. If TRUE is returned, *icc_data_ptr is set to point to the returned data, and *icc_data_len is set to its length.

IMPORTANT: the data at **icc_data_ptr has been allocated with malloc() and must be freed by the caller with free() when the caller no longer needs it. (Alternatively, we could write this routine to use the IJG library's memory allocator, so that the data would be freed implicitly at jpeg_finish_decompress() time. But it seems likely that many apps will prefer to have the data stick around after decompression finishes.)

NOTE: if the file contains invalid ICC APP2 markers, we just silently return FALSE. You might want to issue an error message instead.

References MAX_SEQ_NO.

Referenced by DigikamJPEGDImgPlugin::DImgJPEGLoader::load().

◆ setup_read_icc_profile()

void setup_read_icc_profile ( j_decompress_ptr  cinfo)

Prepare for reading an ICC profile

References ICC_MARKER.

Referenced by DigikamJPEGDImgPlugin::DImgJPEGLoader::load().

◆ write_icc_profile()

void write_icc_profile ( j_compress_ptr  cinfo,
const JOCTET *  icc_data_ptr,
unsigned int  icc_data_len 
)

This routine writes the given ICC profile data into a JPEG file. It must be called AFTER calling jpeg_start_compress() and BEFORE the first call to jpeg_write_scanlines(). (This ordering ensures that the APP2 marker(s) will appear after the SOI and JFIF or Adobe markers, but before all else.)

References ICC_MARKER, ICC_OVERHEAD_LEN, and MAX_DATA_BYTES_IN_MARKER.

Referenced by DigikamJPEGDImgPlugin::DImgJPEGLoader::save().