Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_icc.h File Reference

Finding the ICC colour profile embedded in an image file. More...

#include <stddef.h>
Include dependency graph for n_icc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

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

Finding the ICC colour profile embedded in an image file.

A JPEG, PNG, TIFF or WebP file can carry the ICC profile that says what its numbers mean: Adobe RGB, Display P3, ProPhoto, a camera's or a scanner's. Each format keeps it its own way, and this returns the profile's bytes whichever it is:

  • JPEG: APP2 markers starting "ICC_PROFILE", a sequence number and a count, the profile split across them in order (they may be stored out of order)
  • PNG: the iCCP chunk, a name and the profile deflated
  • TIFF: tag 34675 of the first directory
  • WebP: the ICCP chunk of the extended format

What is found is checked to look like a profile (its size field and the "acsp" signature) before it is returned. Nothing here interprets the profile: that is a colour management library's work.

Everything is bounded by the buffer's length and by N_ICC_MAX_BYTES; a truncated or hostile file makes the search fail, never read out of bounds.

Author
Castagnier Mickael
Version
1.0
Date
28/09/2026

Definition in file n_icc.h.