JFLib

img_core/icc.rs#

Source: lib/img_core/icc.rs

icc -- ICC profile container helpers (no colour conversion: that is icc_xform)
                                                                          [src/img/icc.s]

  icc_check(data) -> profile size / ERR_TRUNC / ERR_HDR / ERR_UNSUPPORTED
  icc_jpeg_collect(data) -> (1 found / 0 none / ERR_CHUNK, profile)
  icc_jpeg_segments(icc) -> Ok(APP2 segments) / Err(ERR_LIMIT)

icc_check validates the 128-byte header and the tag table: declared size >= 132 and
<= len, 'acsp' at byte 36, major version 2..5, the tag count fits, every tag's data lies
inside the declared size.  JPEG embeds a profile in APP2 segments "ICC_PROFILE\0" + seq
(1-based) + count + data; icc_jpeg_collect walks the segments before the first SOS and
reassembles them in sequence order, rejecting (ERR_CHUNK) like libjpeg's
read_icc_profile: a count of 0, counts that differ, a sequence number of 0 or > count, a
duplicate, a missing one and an empty result.  icc_jpeg_segments produces the complete
APP2 segments (FF E2, length, header, <= 65519 data bytes each); more than 255 segments
-> ERR_LIMIT.
  • fn icc_check(data: &[u8]) -> i64 the declared profile size or ERR_TRUNC (shorter than the header / the declared size), ERR_HDR (bad signature, size, tag table), ERR_UNSUPPORTED (major version not 2..5) [icc_check]

  • fn icc_jpeg_collect(data: &[u8]) -> (i32, Vec<u8>) reassemble the APP2 ICC_PROFILE segments of a JPEG file -> (1 profile / 0 no ICC_PROFILE segment / ERR_CHUNK inconsistent segments, profile bytes) [icc_jpeg_collect]

  • fn icc_jpeg_segments(icc: &[u8]) -> Result<Vec<u8>, i32> the complete APP2 marker segments that embed an ICC profile in a JPEG (written after APP0 / APP1); empty for an empty profile [icc_jpeg_segments]

Source: docs/API.md in the JFLib repository.