icc

    MoonBit module to parse International Color Consortium (ICC) profiles.

    icc
    color
    colour
    profile
    Download zip
    Version
    0.1.1
    License
    Apache-2.0
    Last updated
    last year
    Downloads
    25

    Dependencies

    #ICC Profile Parser for MoonBit

    This package provides a lightweight ICC profile inspector written in MoonBit. It loads raw ICC data, performs structural validation, and exposes key metadata such as version, device class, color spaces, white point, readable descriptions, and more.


    #Features

    • Extracts ICC header information (CMM, platform, manufacturer, model, version, intent, white point, etc.).
    • Decodes common text tags (desc, dmnd, dmdd, vued, view, cprt).
    • Handles desc, text, mluc tag data (UTF-16BE aware and defensive against malformed surrogate pairs).
    • Expands common four-character signatures to human-friendly labels (mntr -> Monitor, msft -> Microsoft, ...).
    • Defensive parsing: validates profile size, tag table bounds, filters non-printable viewing descriptions, and returns descriptive ParseError values.


    #Installation

    moon update moon add enanandesu/icc

    #Public API

    FunctionDescription
    parse(path)Backwards-compatible alias for parse_from_file.
    parse_from_file(path)Read an ICC file from disk and return metadata.
    parse_from_bytes(bytes)Parse an ICC profile represented as Bytes.
    parse_from_buffer(buffer)Parse ICC data already staged in @buffer.Buffer.
    parse_from_string(text)Parse ICC bytes carried inside a String; every UTF-16 code unit must match the original byte.

    The return value is always Map[String, String] and each function may raise ParseError. Typical keys include cmm, platform, manufacturer, model, version, deviceClass, colorSpace, connectionSpace, intent, whitepoint, description, deviceManufacturerDescription, deviceModelDescription, and viewingConditionsDescription.


    #Usage Examples

    #Parse from file

    let profile = @enanandesu/icc.parse_from_file("./test/sRGB_IEC61966-2-1_black_scaled.icc")
    inspect(profile.get_or_default("colorSpace", ""), content="RGB")

    #Parse from bytes

    let bytes = @fs.read_file_to_bytes("./test/sRGB_ICC_v4_Appearance.icc")
    let profile = @enanandesu/icc.parse_from_bytes(bytes)
    inspect(profile.get_or_default("version", ""), content="4.3.0")

    #Parse from buffer

    let bytes = @fs.read_file_to_bytes("./test/D65_XYZ.icc")
    let buf = @buffer.new(size_hint=bytes.length())
    buf.write_bytes(bytes)
    let profile = @enanandesu/icc.parse_from_buffer(buf)
    inspect(profile.get_or_default("creator", ""), content="none")

    #Parse from raw-string bytes

    let bytes = @fs.read_file_to_bytes("./test/D65_XYZ.icc")
    let text = bytes.to_unchecked_string() // UTF-16 code units equal to raw bytes
    let profile = @enanandesu/icc.parse_from_string(text)
    inspect(profile.get_or_default("creator", ""), content="none")

    Note: parse_from_string expects the string to store the original ICC bytes in its UTF-16 code units. Supplying a normal UTF-8 string (for example, "Hello UTF-8 text!") will cause parsing to fail with ParseError.


    #Error Handling

    ParseError explains the failure reason. Examples:

    • ICC profile is too small (expected at least 132 bytes) - profile truncated.
    • ICC profile tag table is invalid - tag directory would extend past buffer.
    • Failed to parse string content: ... - converting the provided string into bytes failed before parsing.

    Use try/catch to handle individual cases as needed.


    #License

    Apache-2.0

    ParseError

    type ParseError

    impl Show for ParseError

    parse

    fn parse(path : String) -> Map[String, String] raise ParseError

    Parses an ICC profile file from the specified file path (alias for parse_from_file).

    parse_from_buffer

    fn parse_from_buffer(content :
    Buffer
    ) -> Map[String, String] raise ParseError

    Parses an ICC profile from a buffer containing ICC profile data.

    Parameters:

    • content : A buffer containing the raw ICC profile data to be parsed.

    Returns a Map[String, String] containing the parsed ICC profile metadata as key-value pairs. Common keys include "description", "manufacturer", "model", "colorSpace", "connectionSpace", "intent", "version", "whitepoint", and others depending on the profile content.

    Throws an error of type ParseError if the ICC profile data is invalid, corrupted, or does not meet the minimum size requirements.

    Example:

    // Assuming you have ICC profile data as a buffer
    let icc_data_buffer = @buffer.new() // Your ICC profile data as buffer
    let profile_data = @enanandesu/icc.parse_from_buffer(icc_data_buffer)
    inspect(profile_data.get_or_default("colorSpace", ""), content="RGB")

    parse_from_bytes

    fn parse_from_bytes(data : Bytes) -> Map[String, String] raise ParseError

    Parses an ICC profile from raw bytes data.

    Parameters:

    • data : The raw ICC profile data as bytes to be parsed.

    Returns a Map[String, String] containing the parsed ICC profile metadata as key-value pairs. Common keys include "description", "manufacturer", "model", "colorSpace", "connectionSpace", "intent", "version", "whitepoint", and others depending on the profile content.

    Throws an error of type ParseError if the ICC profile data is invalid, corrupted, or does not meet the minimum size requirements.

    Example:

    // Assuming you have ICC profile data as bytes
    let icc_bytes = b"..." // Your ICC profile data as bytes
    let profile_data = @enanandesu/icc.parse_from_bytes(icc_bytes)
    inspect(profile_data.get_or_default("colorSpace", ""), content="RGB")

    parse_from_file

    fn parse_from_file(path : String) -> Map[String, String] raise ParseError

    Load an ICC file from disk and decode it into a key-value map containing profile metadata.

    Parameters:

    • path : The file system path to the ICC profile file to be loaded and parsed.

    Returns a Map[String, String] containing the parsed ICC profile metadata as key-value pairs. Common keys include "description", "manufacturer", "model", "colorSpace", "connectionSpace", "intent", "version", "whitepoint", and others depending on the profile content.

    Throws an error of type ParseError if the file cannot be read from disk or if the ICC profile data is invalid or corrupted.

    Example:

    let profile_data = @enanandesu/icc.parse_from_file("./test/sRGB_IEC61966-2-1_black_scaled.icc")
    inspect(profile_data.get_or_default("colorSpace", ""), content="RGB")
    inspect(profile_data.get_or_default("creator", ""), content="")

    parse_from_string

    fn parse_from_string(data : String) -> Map[String, String] raise ParseError

    Parse ICC bytes carried inside a String (each code unit is treated as raw byte data; callers must ensure the string contains the original profile bytes, e.g. by using to_unchecked_string()).

    Parameters:

    • data : A string whose UTF-16 code units contain the raw ICC bytes. Typical use cases are round-tripping binary data through Bytes -> String::from_bytes_unchecked() (or similar) after base64 decoding.

    Returns a Map[String, String] containing the parsed ICC metadata.

    Throws ParseError when the string cannot be treated as ICC bytes or the profile violates format constraints.

    Source Files

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io