Table of Contents
include/nilorea/n_icc.h
Finding the ICC colour profile embedded in an image file. More...
Detailed Description
Finding the ICC colour profile embedded in an image file.
Author: Castagnier Mickael
Version: 1.0
Date: 28/09/2026
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.
Source code
/*
* Nilorea Library
* Copyright (C) 2005-2026 Castagnier Mickael
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef N_ICC_HEADER_GUARD
#define N_ICC_HEADER_GUARD
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
#define N_ICC_MAX_BYTES (16u * 1024u * 1024u)
#define N_ICC_HEAD_BYTES (N_ICC_MAX_BYTES + 1024u * 1024u)
int n_icc_is_profile(const unsigned char* data, size_t len);
int n_icc_from_buffer(const unsigned char* data, size_t len, unsigned char** icc, size_t* icc_len);
int n_icc_from_file(const char* path, unsigned char** icc, size_t* icc_len);
#ifdef __cplusplus
}
#endif
#endif /* N_ICC_HEADER_GUARD */
Modules
- AABB3D
- ACCEPT_POOL
- ALLEGRO4
- ALLEGRO5
- ANIM_LIB
- ASTAR
- ATLAS_LIB
- AVRO
- CLOCK_SYNC
- COMMONS
- CONFIGFILE
- CYPHER_BASE64
- CYPHER_VIGENERE
- DEAD_RECKONING
- ENUMS
- EXCEPTIONS
- GAME_ENV
- GIT
- GUI
- HASH_TABLE
- ISOMETRIC_ENGINE
- LIST
- LOG
- LOGNODUP
- LZ4
- NETWORKING
- NETWORK_MSG
- N_COOKIES
- N_DIFF
- N_DIGEST
- N_DISK_CACHE
- N_DNS
- N_ECC
- N_ENTROPY
- N_FILES
- N_FLUIDS
- N_GUI_COLOR
- N_GUI_COLORWHEEL
- N_GUI_CURVE
- N_GUI_GRID
- N_GUI_POPUP
- N_HEX
- N_HTTP3
- N_HTTP_COOKIE
- N_HTTP_FORM
- N_HTTP_MIME
- N_HTTP_REQ
- N_HTTP_RESP
- N_HTTP_ROUTER
- N_HTTP_SERVER
- N_ICC
- N_JSON
- N_KAFKA
- N_LINALG
- N_MODULE
- N_OPENSSL_COMPAT
- N_PRETTY
- N_PTH
- N_QUERY
- N_RANDOM
- N_SHA256
- N_STR
- N_TIFF
- N_TIME
- N_USER
- N_X509
- N_ZIP
- PARTICLES
- PCRE
- PHYSICS
- SIGNALS
- STACK
- THREADS
- TRAJECTORY
- TREE
- ZLIB