| 1 |
# Rust ICC profile parser |
| 2 |
|
| 3 |
This directory contains helpers and wrappers for exposing ICC (International |
| 4 |
Color Consortium) profile parsing from the `moxcms` Rust crate to Skia codecs: |
| 5 |
|
| 6 |
* Used by `SkPngRustCodec` and `SkBmpRustCodec` |
| 7 |
|
| 8 |
## Architecture |
| 9 |
|
| 10 |
``` |
| 11 |
Image Codec → ICC bytes → rust_icc::parse_icc_profile() |
| 12 |
↓ (moxcms parsing) |
| 13 |
IccProfile struct |
| 14 |
↓ |
| 15 |
rust_icc::ToSkcmsIccProfile() |
| 16 |
↓ |
| 17 |
skcms_ICCProfile |
| 18 |
↓ |
| 19 |
Skia color transformations |
| 20 |
``` |
| 21 |
|
| 22 |
### Memory Safety |
| 23 |
|
| 24 |
All ICC profile parsing happens in Rust using the `moxcms` crate. This prevents |
| 25 |
memory safety vulnerabilities from malformed ICC data. The validated, parsed |
| 26 |
data is then converted to `skcms_ICCProfile` structures for use by Skia's |
| 27 |
color management system (skcms). |
| 28 |
|
| 29 |
### Profile Support |
| 30 |
|
| 31 |
The parser supports: |
| 32 |
- Matrix-based profiles (RGB/Gray with toXYZD50 matrix + transfer curves) |
| 33 |
- CICP metadata (for HDR/wide-gamut color spaces) |
| 34 |
- Complex LUT-based profiles (A2B/B2A transforms with multi-dimensional lookup tables) |
| 35 |
|
| 36 |
## Building |
| 37 |
|
| 38 |
### Bazel |
| 39 |
|
| 40 |
``` |
| 41 |
$ cd skia-repo-root |
| 42 |
$ bazelisk build //rust/icc:ffi_rs |
| 43 |
$ bazelisk test //rust/icc:ffi_rs_test |
| 44 |
``` |
| 45 |
|
| 46 |
### gn / ninja |
| 47 |
|
| 48 |
Enabled automatically when Rust codecs are enabled: |
| 49 |
|
| 50 |
``` |
| 51 |
$ gn args out/RustEnabled |
| 52 |
# Set: skia_use_rust_png_decode = true |
| 53 |
$ gn gen out/RustEnabled |
| 54 |
$ autoninja -C out/RustEnabled |
| 55 |
``` |
| 56 |
|
| 57 |
## Testing |
| 58 |
|
| 59 |
### Unit Tests |
| 60 |
|
| 61 |
**Rust unit tests** (test Rust-side parsing and FFI data structures): |
| 62 |
|
| 63 |
```bash |
| 64 |
$ bazelisk test //rust/icc:ffi_rs_test --test_output=all |
| 65 |
``` |
| 66 |
|
| 67 |
**C++ unit tests** (test the complete FFI bridge to skcms): |
| 68 |
|
| 69 |
Build and run via Skia's `dm` test runner: |
| 70 |
|
| 71 |
```bash |
| 72 |
$ gn gen out/Debug --args='skia_use_rust_png_decode=true' |
| 73 |
$ ninja -C out/Debug dm |
| 74 |
$ out/Debug/dm --src tests --match RustIcc |
| 75 |
``` |
| 76 |
|
| 77 |
The C++ tests are located in `tests/RustIccTest.cpp`. |
| 78 |
|
| 79 |
## Dependencies |
| 80 |
|
| 81 |
- **cxx**: FFI bridge between Rust and C++ |
| 82 |
- **moxcms** 0.7.9: ICC profile parser |
| 83 |
- **rust/common**: Shared FFI utilities |
| 84 |
|
| 85 |
## References |
| 86 |
|
| 87 |
- ICC Specification: https://www.color.org/specification/ICC.1-2022-05.pdf |
| 88 |
- moxcms: https://crates.io/crates/moxcms |
| 89 |
- skcms: https://skia.googlesource.com/skcms/ |