Debian Codegraph @

rust/icc/FFI.h

raw
1 /*
2 * Copyright 2025 Google LLC.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkRustIccFFI_DEFINED
9 #define SkRustIccFFI_DEFINED
10
11 #include <stddef.h>
12 #include <stdint.h>
13
14 // Forward declare skcms types
15 struct skcms_Matrix3x3;
16 struct skcms_TransferFunction;
17 struct skcms_ICCProfile;
18
19 // TODO(https://crbug.com/356698922): Use a real `#include` if possible.
20 namespace rust {
21 inline namespace cxxbridge1 {
22 template <typename T> class Slice;
23 } // namespace cxxbridge1
24 } // namespace rust
25
26 namespace rust_icc {
27
28 struct Matrix3x3;
29 struct TransferFunction;
30 struct IccProfile;
31
32 /// Wrapper for skcms_ApproximateCurve.
33 /// Used by cxx::bridge to avoid manual extern "C" declarations.
34 bool ApproximateCurveWrapper(rust::Slice<const uint16_t> table,
35 TransferFunction& out_approx,
36 float& out_max_error);
37
38 /// Convert rust_icc::Matrix3x3 to skcms_Matrix3x3.
39 void ToSkcmsMatrix3x3(const Matrix3x3& rust_matrix, skcms_Matrix3x3* out_skcms);
40
41 /// Convert rust_icc::TransferFunction to skcms_TransferFunction.
42 void ToSkcmsTransferFunction(const TransferFunction& rust_tf, skcms_TransferFunction* out_skcms);
43
44 /// Convert rust_icc::IccProfile to skcms_ICCProfile.
45 ///
46 /// Populates all skcms fields from moxcms-parsed ICC data:
47 /// - Color space metadata
48 /// - toXYZD50 matrix and transfer curves (for simple RGB/Gray profiles)
49 /// - CICP metadata (for HDR)
50 /// - A2B/B2A transforms (for complex LUT-based profiles)
51 ///
52 /// Note: The following skcms_ICCProfile members will NOT be populated:
53 /// - buffer: will be set to nullptr (raw ICC bytes not retained)
54 /// - size: will be set to 0
55 /// - tag_count: will be set to 0
56 ///
57 /// All LUT data is owned by Rust; C++ accesses via pointers.
58 ///
59 /// IMPORTANT: The caller must guarantee that the lifetime of `out_skcms` does not
60 /// exceed the lifetime of `rust_profile`. Pointers in `out_skcms` (e.g., for curve
61 /// table data) reference memory owned by the Rust-side `IccProfile`, which will be
62 /// invalidated when `rust_profile` is destroyed.
63 ///
64 /// TODO: Consider propagating 'input lifetime to enforce this at compile time.
65 ///
66 /// Returns true if successful, false if essential data is missing.
67 bool ToSkcmsIccProfile(const IccProfile& rust_profile, skcms_ICCProfile* out_skcms);
68
69 } // namespace rust_icc
70
71 #endif // SkRustIccFFI_DEFINED