Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
ICC: embedded colour profiles of image files

Macros

#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.
#define N_ICC_MAX_BYTES   (16u * 1024u * 1024u)
 Largest profile returned.

Functions

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.
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_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.

Detailed Description

Macro Definition Documentation

◆ 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.

Definition at line 67 of file n_icc.h.

Referenced by n_icc_from_file().

◆ 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.

Definition at line 63 of file n_icc.h.

Referenced by _from_jpeg(), _from_png(), _give(), and _tiff_file().

Function Documentation

◆ 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.

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

Parameters
datathe file's bytes, from its start
lenhow many
iccreceives the profile, allocated here and released with free(), or NULL when there is none
icc_lenreceives its length, 0 when there is none
Returns
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

Definition at line 309 of file n_icc.c.

References __n_assert, _from_buffer(), and N_ICC_MORE.

Referenced by expect(), and main().

Here is the call graph for this function:
Here is the caller graph for this 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.

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.

Parameters
paththe file
iccas n_icc_from_buffer()
icc_lenas n_icc_from_buffer()
Returns
as n_icc_from_buffer(), and -1 when the file cannot be read

Definition at line 366 of file n_icc.c.

References __n_assert, _from_buffer(), _tiff_file(), N_ICC_FIRST_READ, N_ICC_HEAD_BYTES, and N_ICC_MORE.

Referenced by expect(), and main().

Here is the call graph for this function:
Here is the caller graph for this 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
datathe bytes
lenhow many
Returns
1 when it does, 0 otherwise

Definition at line 70 of file n_icc.c.

References _be32(), and N_ICC_MIN_BYTES.

Referenced by _from_jpeg(), _from_png(), _give(), _tiff_file(), and main().

Here is the call graph for this function:
Here is the caller graph for this function: