5 Module N_ICC
gullradriel edited this page 2026-10-09 00:55:18 +02:00

ICC: embedded colour profiles of image files

Functions

Name
int n_icc_is_profile(const unsigned char * data, size_t len)
Does a buffer look like an ICC profile: at least a header, a size field no larger than the buffer, and "acsp" at byte 36.
int n_icc_from_file(const char * path, unsigned char ** icc, size_t * icc_len)
Find the profile embedded in an image file.
int n_icc_from_buffer(const unsigned char * data, size_t len, unsigned char ** icc, size_t * icc_len)
Find the profile embedded in an image file held in memory.

Defines

Name
N_ICC_MAX_BYTES
Largest profile returned.
N_ICC_HEAD_BYTES
Bytes of a file n_icc_from_file() reads to look for a JPEG, PNG or WebP profile, which those formats keep before the image data.

Functions Documentation

function n_icc_is_profile

int n_icc_is_profile(
    const unsigned char * data,
    size_t len
)

Does a buffer look like an ICC profile: at least a header, a size field no larger than the buffer, and "acsp" at byte 36.

Parameters:

  • data the bytes
  • len how many

Return: 1 when it does, 0 otherwise

function n_icc_from_file

int n_icc_from_file(
    const char * path,
    unsigned char ** icc,
    size_t * icc_len
)

Find the profile embedded in an image file.

Parameters:

Return: as n_icc_from_buffer(), and -1 when the file cannot be read

A TIFF's profile is read where its directory says, which may be at the end of a large file; for the other formats the first N_ICC_HEAD_BYTES are read.

function n_icc_from_buffer

int n_icc_from_buffer(
    const unsigned char * data,
    size_t len,
    unsigned char ** icc,
    size_t * icc_len
)

Find the profile embedded in an image file held in memory.

Parameters:

  • data the file's bytes, from its start
  • len how many
  • icc receives the profile, allocated here and released with free(), or NULL when there is none
  • icc_len receives its length, 0 when there is none

Return: 1 when a profile was found, 0 when the file has none or is not a format read here, -1 on a NULL argument, no memory or a profile that is there but broken

The format is told from the buffer's first bytes, not from a name.

Macros Documentation

define N_ICC_MAX_BYTES

#define N_ICC_MAX_BYTES (16u * 1024u * 1024u)

Largest profile returned.

Real ones are a few hundred bytes to a few hundred kilobytes, a large lookup table profile a few megabytes.

define N_ICC_HEAD_BYTES

#define N_ICC_HEAD_BYTES (N_ICC_MAX_BYTES + 1024u * 1024u)

Bytes of a file n_icc_from_file() reads to look for a JPEG, PNG or WebP profile, which those formats keep before the image data.