{"id":16115613,"url":"https://github.com/kornelski/rust-lcms2","last_synced_at":"2025-04-10T01:16:28.653Z","repository":{"id":62441900,"uuid":"63348142","full_name":"kornelski/rust-lcms2","owner":"kornelski","description":"ICC color profiles in Rust","archived":false,"fork":false,"pushed_at":"2024-04-08T12:33:39.000Z","size":407,"stargazers_count":45,"open_issues_count":0,"forks_count":9,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T01:16:23.026Z","etag":null,"topics":["color-profiles","ffi-wrapper","icc-profile","rust","rust-library"],"latest_commit_sha":null,"homepage":"https://lib.rs/crates/lcms2","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kornelski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2016-07-14T15:28:42.000Z","updated_at":"2025-03-12T02:27:18.000Z","dependencies_parsed_at":"2024-04-08T13:42:50.246Z","dependency_job_id":"087bc85f-97e8-4454-a91e-f7335eb5c458","html_url":"https://github.com/kornelski/rust-lcms2","commit_stats":{"total_commits":115,"total_committers":6,"mean_commits":"19.166666666666668","dds":0.06956521739130439,"last_synced_commit":"0d6656dcc7d7a2407d536cc3a153e62ad9a790d4"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kornelski%2Frust-lcms2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kornelski%2Frust-lcms2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kornelski%2Frust-lcms2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kornelski%2Frust-lcms2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kornelski","download_url":"https://codeload.github.com/kornelski/rust-lcms2/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137889,"owners_count":21053775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["color-profiles","ffi-wrapper","icc-profile","rust","rust-library"],"created_at":"2024-10-09T20:19:17.575Z","updated_at":"2025-04-10T01:16:28.633Z","avatar_url":"https://github.com/kornelski.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [Little CMS](http://www.littlecms.com) wrapper for [Rust](https://www.rust-lang.org/)\n\nConvert and apply color profiles with a safe abstraction layer for the LCMS library. LCMS2 is a mature, fully-featured color management engine. These bindings have been stable for years, and used in production at scale.\n\nSee [the API reference](https://docs.rs/lcms2/) for the Rust functions, and the LCMS2 documentation [in HTML](https://kornelski.github.io/rust-lcms2-sys/)/[or the original PDF](https://www.littlecms.com/LittleCMS2.15%20API.pdf) for more background information about the functions.\n\n\n```rust\nuse lcms2::*;\n\nfn example() -\u003e Result\u003c(), std::io::Error\u003e {\n    let icc_file = include_bytes!(\"custom_profile.icc\"); // You can use Profile::new_file(\"path\"), too\n    let custom_profile = Profile::new_icc(icc_file)?;\n\n    let srgb_profile = Profile::new_srgb();\n\n    let t = Transform::new(\u0026custom_profile, PixelFormat::RGB_8, \u0026srgb_profile, PixelFormat::RGB_8, Intent::Perceptual);\n\n    // Pixel struct must have layout compatible with PixelFormat specified in new()\n    let source_pixels: \u0026[rgb::RGB\u003cu8\u003e] = …;\n    t.transform_pixels(source_pixels, destination_pixels);\n\n    // If input and output pixel formats are the same, you can overwrite them instead of copying\n    t.transform_in_place(source_and_dest_pixels);\n\n    Ok(())\n}\n```\n\nTo apply an ICC profile from a JPEG:\n\n```rust\nif b\"ICC_PROFILE\\0\" == \u0026app2_marker_data[0..12] {\n   let icc = \u0026app2_marker_data[14..]; // Lazy assumption that the profile is smaller than 64KB\n   let profile = Profile::new_icc(icc)?;\n   let t = Transform::new(\u0026profile, PixelFormat::RGB_8,\n       \u0026Profile::new_srgb(), PixelFormat::RGB_8, Intent::Perceptual);\n   t.transform_in_place(\u0026mut rgb);\n}\n```\n\nThere's more in the `examples` directory.\n\nThis crate requires Rust 1.64 or later. It's up to date with LCMS 2.15, and should work with a wide range of versions.\n\n## Threads\n\nIn LCMS all functions are in 2 flavors: global and `*THR()` functions. In this crate this is represented by having functions with `GlobalContext` and `ThreadContext`. Create profiles, transforms, etc. using `*_context()` constructors to give them their private context, which makes them sendable between threads (i.e. they're `Send`).\n\nBy default `Transform` does not implement `Sync`, because LCMS2 has a thread-unsafe cache in the transform. You can set `Flags::NO_CACHE` to make it safe (this is checked at compile time).\n\n## Upgrading from v5\n\nIf you're using a custom RGB type with `Transform`, implement [`bytemuck::Pod`](https://lib.rs/crates/bytemuck) and `Zeroable` for it. Make sure you use arrays or `#[repr(C)]` struct types for pixels. Rust tuples have a technically undefined layout, and can't be used as as a pixel format.\n\n```\nunsafe impl Pod for RGB {}\nunsafe impl Zeroable for RGB {}\n```\n\nYou don't need to do this if you use the [`rgb` crate](https://lib.rs/crates/rgb).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkornelski%2Frust-lcms2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkornelski%2Frust-lcms2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkornelski%2Frust-lcms2/lists"}