Coverage Report

Created: 2026-07-25 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/skcms/src/skcms_public.h
Line
Count
Source
1
/*
2
 * Copyright 2018 Google Inc.
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
#pragma once
9
10
// skcms_public.h contains the entire public API for skcms.
11
12
// Modeled after the FOX example in https://gcc.gnu.org/wiki/Visibility
13
#if !defined(SKCMS_API)
14
    // Client has opted in to building skcms as part of a DLL/shared object file.
15
    #if defined(SKCMS_DLL)
16
        // If on Windows (MSVC or Clang pretending to be MSVC)
17
        #if defined(_MSC_VER)
18
            // Client needs to set this when compiling the skcms files (but *not* when compiling
19
            // other files which use the headers). In GN, this is handled with non-public configs.
20
            // With Bazel, this can be implemented with local_defines.
21
            #if defined(SKCMS_IMPLEMENTATION)
22
                // If SKCMS is being built as a standalone DLL, it must be explicitly exported
23
                // https://learn.microsoft.com/en-us/cpp/cpp/dllexport-dllimport?view=msvc-170
24
                #define SKCMS_API __declspec(dllexport)
25
            #else
26
                // If a client is compiling and using the skcms header, this is an optimization
27
                // to skip some indirection when resolving the function call.
28
                // https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-6.0/aa271769(v=vs.60)
29
                #define SKCMS_API __declspec(dllimport)
30
            #endif
31
        #else
32
            // On non-Windows platforms, we make sure the symbols are visible outside the
33
            // shared object file.
34
            #define SKCMS_API __attribute__((visibility("default")))
35
        #endif
36
    #else
37
        #define SKCMS_API
38
    #endif
39
#endif
40
41
#include <stdbool.h>
42
#include <stddef.h>
43
#include <stdint.h>
44
#include <string.h>
45
46
#ifdef __cplusplus
47
extern "C" {
48
#endif
49
50
// A row-major 3x3 matrix (ie vals[row][col])
51
typedef struct skcms_Matrix3x3 {
52
    float vals[3][3];
53
} skcms_Matrix3x3;
54
55
// It is _not_ safe to alias the pointers to invert in-place.
56
SKCMS_API bool            skcms_Matrix3x3_invert(const skcms_Matrix3x3*, skcms_Matrix3x3*);
57
SKCMS_API skcms_Matrix3x3 skcms_Matrix3x3_concat(const skcms_Matrix3x3*, const skcms_Matrix3x3*);
58
59
// A row-major 3x4 matrix (ie vals[row][col])
60
typedef struct skcms_Matrix3x4 {
61
    float vals[3][4];
62
} skcms_Matrix3x4;
63
64
// A transfer function mapping encoded values to linear values,
65
// represented by this 7-parameter piecewise function:
66
//
67
//   linear = sign(encoded) *  (c*|encoded| + f)       , 0 <= |encoded| < d
68
//          = sign(encoded) * ((a*|encoded| + b)^g + e), d <= |encoded|
69
//
70
// (A simple gamma transfer function sets g to gamma and a to 1.)
71
typedef struct skcms_TransferFunction {
72
    float g, a,b,c,d,e,f;
73
} skcms_TransferFunction;
74
75
SKCMS_API float skcms_TransferFunction_eval  (const skcms_TransferFunction*, float);
76
SKCMS_API bool  skcms_TransferFunction_invert(const skcms_TransferFunction*,
77
                                              skcms_TransferFunction*);
78
79
typedef enum skcms_TFType {
80
    skcms_TFType_Invalid,
81
    skcms_TFType_sRGBish,
82
    skcms_TFType_PQish,
83
    skcms_TFType_HLGish,
84
    skcms_TFType_HLGinvish,
85
    skcms_TFType_PQ,
86
    skcms_TFType_HLG,
87
} skcms_TFType;
88
89
// Identify which kind of transfer function is encoded in an skcms_TransferFunction
90
SKCMS_API skcms_TFType skcms_TransferFunction_getType(const skcms_TransferFunction*);
91
92
// We can jam a couple alternate transfer function forms into skcms_TransferFunction,
93
// including those matching the general forms of the SMPTE ST 2084 PQ function or HLG.
94
//
95
// PQish:
96
//                              max(A + B|encoded|^C, 0)
97
//    linear = sign(encoded) * (------------------------) ^ F
98
//                                  D + E|encoded|^C
99
SKCMS_API bool skcms_TransferFunction_makePQish(skcms_TransferFunction*,
100
                                                float A, float B, float C,
101
                                                float D, float E, float F);
102
// HLGish:
103
//            { K * sign(encoded) * ( (R|encoded|)^G )          when 0   <= |encoded| <= 1/R
104
//   linear = { K * sign(encoded) * ( e^(a(|encoded|-c)) + b )  when 1/R <  |encoded|
105
SKCMS_API bool skcms_TransferFunction_makeScaledHLGish(skcms_TransferFunction*,
106
                                                       float K, float R, float G,
107
                                                       float a, float b, float c);
108
109
// Compatibility shim with K=1 for old callers.
110
static inline bool skcms_TransferFunction_makeHLGish(skcms_TransferFunction* fn,
111
                                                     float R, float G,
112
36
                                                     float a, float b, float c) {
113
36
    return skcms_TransferFunction_makeScaledHLGish(fn, 1.0f, R,G, a,b,c);
114
36
}
skcms.cc:skcms_TransferFunction_makeHLGish(skcms_TransferFunction*, float, float, float, float, float)
Line
Count
Source
112
36
                                                     float a, float b, float c) {
113
36
    return skcms_TransferFunction_makeScaledHLGish(fn, 1.0f, R,G, a,b,c);
114
36
}
Unexecuted instantiation: skcms_TransformBaseline.cc:skcms_TransferFunction_makeHLGish(skcms_TransferFunction*, float, float, float, float, float)
Unexecuted instantiation: fuzz_iccprofile_info.c:skcms_TransferFunction_makeHLGish
Unexecuted instantiation: fuzz_iccprofile_atf.c:skcms_TransferFunction_makeHLGish
Unexecuted instantiation: fuzz_iccprofile_transform.c:skcms_TransferFunction_makeHLGish
115
116
// The PQ transfer function. The function skcms_TransferFunction_eval will always evaluate to the
117
// unit PQ EOTF, which maps [0, 1] to [0, 1], regardless of the other parameters.
118
// This is stored differently from PQish transfer functions. In particular:
119
//   - the constant -5 is stored in g
120
//   - the hdr_reference_white_luminance parameter is stored in a
121
//   - all other parameters are set to 0
122
// When this is used as an SkColorSpace, the transformation to XYZD50 will be as follows:
123
//   1. Apply the unit PQ EOTF to each channel
124
//   2. Multiply by 10,000 nits
125
//   3. Divide by hdr_reference_white_luminance nits (default is 203)
126
//   4. Transform primaries to XYZD50
127
SKCMS_API void skcms_TransferFunction_makePQ(
128
    skcms_TransferFunction*,
129
    float hdr_reference_white_luminance);
130
131
// The HLG transfer function. The function skcms_TransferFunction_eval will always evaluate to the
132
// HLG inverse OETF, which maps [0, 1] to [0, 1], regardless of the other parameters.
133
// This is stored differently from PQish transfer functions. In particular:
134
//   - the constant -6 is stored in g
135
//   - the hdr_reference_white_luminance parameter is stored in a
136
//   - the peak_white_luminance parameter is stored in b
137
//   - the system_gamma parameter is stored in c
138
//   - all other parameters are set to 0
139
// When this is used as an SkColorSpace, the transformation to XYZD50 will be as follows:
140
//   1. Apply the HLG inverse OETF to each channel
141
//   2. Transform primaries to Rec2020
142
//   3. Apply the channel-mixing HLG OOTF using system_gamma (default is 1.2)
143
//   4. Multiply by peak_luminance nits (default is 1,000)
144
//   5. Divide by hdr_reference_white nits (default is 203)
145
//   6. Transform primaries to XYZD50
146
SKCMS_API void skcms_TransferFunction_makeHLG(
147
    skcms_TransferFunction*,
148
    float hdr_reference_white_luminance,
149
    float peak_luminance,
150
    float system_gamma);
151
152
// Is this an ordinary sRGB-ish transfer function, or one of the HDR forms we support?
153
SKCMS_API bool skcms_TransferFunction_isSRGBish(const skcms_TransferFunction*);
154
SKCMS_API bool skcms_TransferFunction_isPQish  (const skcms_TransferFunction*);
155
SKCMS_API bool skcms_TransferFunction_isHLGish (const skcms_TransferFunction*);
156
SKCMS_API bool skcms_TransferFunction_isPQ     (const skcms_TransferFunction*);
157
SKCMS_API bool skcms_TransferFunction_isHLG    (const skcms_TransferFunction*);
158
159
// Unified representation of 'curv' or 'para' tag data, or a 1D table from 'mft1' or 'mft2'
160
typedef union skcms_Curve {
161
    struct {
162
        // this needs to line up with alias_of_table_entries so we can tell if there are or
163
        // are not table entries. If this is 0, this struct is a parametric function,
164
        // otherwise it's a table entry.
165
        uint32_t alias_of_table_entries;
166
        skcms_TransferFunction parametric;
167
    };
168
    struct {
169
        uint32_t table_entries;
170
        const uint8_t* table_8;
171
        const uint8_t* table_16;
172
    };
173
} skcms_Curve;
174
175
// Complex transforms between device space (A) and profile connection space (B):
176
//   A2B:  device -> [ "A" curves -> CLUT ] -> [ "M" curves -> matrix ] -> "B" curves -> PCS
177
//   B2A:  device <- [ "A" curves <- CLUT ] <- [ "M" curves <- matrix ] <- "B" curves <- PCS
178
179
typedef struct skcms_A2B {
180
    // Optional: N 1D "A" curves, followed by an N-dimensional CLUT.
181
    // If input_channels == 0, these curves and CLUT are skipped,
182
    // Otherwise, input_channels must be in [1, 4].
183
    skcms_Curve     input_curves[4];
184
    const uint8_t*  grid_8;
185
    const uint8_t*  grid_16;
186
    uint32_t        input_channels;
187
    uint8_t         grid_points[4];
188
189
    // Optional: 3 1D "M" curves, followed by a color matrix.
190
    // If matrix_channels == 0, these curves and matrix are skipped,
191
    // Otherwise, matrix_channels must be 3.
192
    skcms_Curve     matrix_curves[3];
193
    skcms_Matrix3x4 matrix;
194
    uint32_t        matrix_channels;
195
196
    // Required: 3 1D "B" curves. Always present, and output_channels must be 3.
197
    uint32_t        output_channels; // list first to pack with matrix_channels
198
    skcms_Curve     output_curves[3];
199
} skcms_A2B;
200
201
typedef struct skcms_B2A {
202
    // Required: 3 1D "B" curves. Always present, and input_channels must be 3.
203
    skcms_Curve     input_curves[3];
204
    uint32_t        input_channels;
205
206
    // Optional: a color matrix, followed by 3 1D "M" curves.
207
    // If matrix_channels == 0, this matrix and these curves are skipped,
208
    // Otherwise, matrix_channels must be 3.
209
    uint32_t        matrix_channels; // list first to pack with input_channels
210
    skcms_Curve     matrix_curves[3];
211
    skcms_Matrix3x4 matrix;
212
213
    // Optional: an N-dimensional CLUT, followed by N 1D "A" curves.
214
    // If output_channels == 0, this CLUT and these curves are skipped,
215
    // Otherwise, output_channels must be in [1, 4].
216
    skcms_Curve     output_curves[4];
217
    const uint8_t*  grid_8;
218
    const uint8_t*  grid_16;
219
    uint8_t         grid_points[4];
220
    uint32_t        output_channels;
221
} skcms_B2A;
222
223
typedef struct skcms_CICP {
224
    uint8_t color_primaries;
225
    uint8_t transfer_characteristics;
226
    uint8_t matrix_coefficients;
227
    uint8_t video_full_range_flag;
228
} skcms_CICP;
229
230
typedef struct skcms_ICCProfile {
231
    const uint8_t* buffer;
232
233
    uint32_t size;
234
    uint32_t data_color_space;
235
    uint32_t pcs;
236
    uint32_t tag_count;
237
238
    // skcms_Parse() will set commonly-used fields for you when possible:
239
240
    // If we can parse red, green and blue transfer curves from the profile,
241
    // trc will be set to those three curves, and has_trc will be true.
242
    skcms_Curve            trc[3];
243
244
    // If this profile's gamut can be represented by a 3x3 transform to XYZD50,
245
    // skcms_Parse() sets toXYZD50 to that transform and has_toXYZD50 to true.
246
    skcms_Matrix3x3        toXYZD50;
247
248
    // If the profile has a valid A2B0 or A2B1 tag, skcms_Parse() sets A2B to
249
    // that data, and has_A2B to true.  skcms_ParseWithA2BPriority() does the
250
    // same following any user-provided prioritization of A2B0, A2B1, or A2B2.
251
    skcms_A2B              A2B;
252
253
    // If the profile has a valid B2A0 or B2A1 tag, skcms_Parse() sets B2A to
254
    // that data, and has_B2A to true.  skcms_ParseWithA2BPriority() does the
255
    // same following any user-provided prioritization of B2A0, B2A1, or B2A2.
256
    skcms_B2A              B2A;
257
258
    // If the profile has a valid CICP tag, skcms_Parse() sets CICP to that data,
259
    // and has_CICP to true.
260
    skcms_CICP             CICP;
261
262
    bool                   has_trc;
263
    bool                   has_toXYZD50;
264
    bool                   has_A2B;
265
    bool                   has_B2A;
266
    bool                   has_CICP;
267
} skcms_ICCProfile;
268
269
// The sRGB color profile is so commonly used that we offer a canonical skcms_ICCProfile for it.
270
SKCMS_API const skcms_ICCProfile* skcms_sRGB_profile(void);
271
// Ditto for XYZD50, the most common profile connection space.
272
SKCMS_API const skcms_ICCProfile* skcms_XYZD50_profile(void);
273
274
SKCMS_API const skcms_TransferFunction* skcms_sRGB_TransferFunction(void);
275
SKCMS_API const skcms_TransferFunction* skcms_sRGB_Inverse_TransferFunction(void);
276
SKCMS_API const skcms_TransferFunction* skcms_Identity_TransferFunction(void);
277
278
// Practical equality test for two skcms_ICCProfiles.
279
// The implementation is subject to change, but it will always try to answer
280
// "can I substitute A for B?" and "can I skip transforming from A to B?".
281
SKCMS_API bool skcms_ApproximatelyEqualProfiles(const skcms_ICCProfile* A,
282
                                                const skcms_ICCProfile* B);
283
284
// Practical test that answers: Is curve roughly the inverse of inv_tf? Typically used by passing
285
// the inverse of a known parametric transfer function (like sRGB), to determine if a particular
286
// curve is very close to sRGB.
287
SKCMS_API bool skcms_AreApproximateInverses(const skcms_Curve* curve,
288
                                            const skcms_TransferFunction* inv_tf);
289
290
// Similar to above, answering the question for all three TRC curves of the given profile. Again,
291
// passing skcms_sRGB_InverseTransferFunction as inv_tf will answer the question:
292
// "Does this profile have a transfer function that is very close to sRGB?"
293
SKCMS_API bool skcms_TRCs_AreApproximateInverse(const skcms_ICCProfile* profile,
294
                                                const skcms_TransferFunction* inv_tf);
295
296
// Parse an ICC profile and return true if possible, otherwise return false.
297
// Selects an A2B profile (if present) according to priority list (each entry 0-2).
298
// The buffer is not copied; it must remain valid as long as the skcms_ICCProfile will be used.
299
// The parse will fail if there is not enough padding (typically 1-2 bytes) past the end of the
300
// profile for internally optimized read calls.
301
SKCMS_API bool skcms_ParseWithA2BPriority(const void*, size_t,
302
                                          const int priority[], int priorities,
303
                                          skcms_ICCProfile*);
304
305
10.9k
static inline bool skcms_Parse(const void* buf, size_t len, skcms_ICCProfile* profile) {
306
    // For continuity of existing user expectations,
307
    // prefer A2B0 (perceptual) over A2B1 (relative colormetric), and ignore A2B2 (saturation).
308
10.9k
    const int priority[] = {0,1};
309
10.9k
    return skcms_ParseWithA2BPriority(buf, len,
310
10.9k
                                      priority, sizeof(priority)/sizeof(*priority),
311
10.9k
                                      profile);
312
10.9k
}
Unexecuted instantiation: skcms.cc:skcms_Parse(void const*, unsigned long, skcms_ICCProfile*)
Unexecuted instantiation: skcms_TransformBaseline.cc:skcms_Parse(void const*, unsigned long, skcms_ICCProfile*)
fuzz_iccprofile_info.c:skcms_Parse
Line
Count
Source
305
3.05k
static inline bool skcms_Parse(const void* buf, size_t len, skcms_ICCProfile* profile) {
306
    // For continuity of existing user expectations,
307
    // prefer A2B0 (perceptual) over A2B1 (relative colormetric), and ignore A2B2 (saturation).
308
3.05k
    const int priority[] = {0,1};
309
3.05k
    return skcms_ParseWithA2BPriority(buf, len,
310
3.05k
                                      priority, sizeof(priority)/sizeof(*priority),
311
3.05k
                                      profile);
312
3.05k
}
fuzz_iccprofile_atf.c:skcms_Parse
Line
Count
Source
305
3.32k
static inline bool skcms_Parse(const void* buf, size_t len, skcms_ICCProfile* profile) {
306
    // For continuity of existing user expectations,
307
    // prefer A2B0 (perceptual) over A2B1 (relative colormetric), and ignore A2B2 (saturation).
308
3.32k
    const int priority[] = {0,1};
309
3.32k
    return skcms_ParseWithA2BPriority(buf, len,
310
3.32k
                                      priority, sizeof(priority)/sizeof(*priority),
311
3.32k
                                      profile);
312
3.32k
}
fuzz_iccprofile_transform.c:skcms_Parse
Line
Count
Source
305
4.57k
static inline bool skcms_Parse(const void* buf, size_t len, skcms_ICCProfile* profile) {
306
    // For continuity of existing user expectations,
307
    // prefer A2B0 (perceptual) over A2B1 (relative colormetric), and ignore A2B2 (saturation).
308
4.57k
    const int priority[] = {0,1};
309
4.57k
    return skcms_ParseWithA2BPriority(buf, len,
310
4.57k
                                      priority, sizeof(priority)/sizeof(*priority),
311
4.57k
                                      profile);
312
4.57k
}
313
314
SKCMS_API bool skcms_ApproximateCurve(const skcms_Curve* curve,
315
                                      skcms_TransferFunction* approx,
316
                                      float* max_error);
317
318
SKCMS_API bool skcms_GetCHAD(const skcms_ICCProfile*, skcms_Matrix3x3*);
319
SKCMS_API bool skcms_GetWTPT(const skcms_ICCProfile*, float xyz[3]);
320
321
// Returns the number of channels of input data that are expected on the "A" side of the profile.
322
// This is useful for image codecs, where the image data and the accompanying profile might have
323
// conflicting data shapes. In some cases, the result is unclear or invalid. In that case, the
324
// function will return a negative value to signal an error.
325
SKCMS_API int skcms_GetInputChannelCount(const skcms_ICCProfile*);
326
327
// These are common ICC signature values
328
typedef enum skcms_Signature {
329
    // common data_color_space values
330
    skcms_Signature_CMYK = 0x434D594B,
331
    skcms_Signature_Gray = 0x47524159,
332
    skcms_Signature_RGB  = 0x52474220,
333
334
    // pcs (or data_color_space)
335
    skcms_Signature_Lab  = 0x4C616220,
336
    skcms_Signature_XYZ  = 0x58595A20,
337
338
    // other, less common data_color_space values
339
    skcms_Signature_CIELUV = 0x4C757620,
340
    skcms_Signature_YCbCr  = 0x59436272,
341
    skcms_Signature_CIEYxy = 0x59787920,
342
    skcms_Signature_HSV    = 0x48535620,
343
    skcms_Signature_HLS    = 0x484C5320,
344
    skcms_Signature_CMY    = 0x434D5920,
345
    skcms_Signature_2CLR   = 0x32434C52,
346
    skcms_Signature_3CLR   = 0x33434C52,
347
    skcms_Signature_4CLR   = 0x34434C52,
348
    skcms_Signature_5CLR   = 0x35434C52,
349
    skcms_Signature_6CLR   = 0x36434C52,
350
    skcms_Signature_7CLR   = 0x37434C52,
351
    skcms_Signature_8CLR   = 0x38434C52,
352
    skcms_Signature_9CLR   = 0x39434C52,
353
    skcms_Signature_10CLR  = 0x41434C52,
354
    skcms_Signature_11CLR  = 0x42434C52,
355
    skcms_Signature_12CLR  = 0x43434C52,
356
    skcms_Signature_13CLR  = 0x44434C52,
357
    skcms_Signature_14CLR  = 0x45434C52,
358
    skcms_Signature_15CLR  = 0x46434C52,
359
} skcms_Signature;
360
361
typedef enum skcms_PixelFormat {
362
    skcms_PixelFormat_A_8,
363
    skcms_PixelFormat_A_8_,
364
    skcms_PixelFormat_G_8,
365
    skcms_PixelFormat_G_8_,
366
    skcms_PixelFormat_GA_88,  // Grayscale with alpha.
367
    skcms_PixelFormat_GA_88_,
368
369
    skcms_PixelFormat_RGB_565,
370
    skcms_PixelFormat_BGR_565,
371
372
    skcms_PixelFormat_ABGR_4444,
373
    skcms_PixelFormat_ARGB_4444,
374
375
    skcms_PixelFormat_RGB_888,
376
    skcms_PixelFormat_BGR_888,
377
    skcms_PixelFormat_RGBA_8888,
378
    skcms_PixelFormat_BGRA_8888,
379
    skcms_PixelFormat_RGBA_8888_sRGB,  // Automatic sRGB encoding / decoding.
380
    skcms_PixelFormat_BGRA_8888_sRGB,  // (Generally used with linear transfer functions.)
381
382
    skcms_PixelFormat_RGBA_1010102,
383
    skcms_PixelFormat_BGRA_1010102,
384
385
    skcms_PixelFormat_RGB_161616LE,  // Little-endian.  Pointers must be 16-bit aligned.
386
    skcms_PixelFormat_BGR_161616LE,
387
    skcms_PixelFormat_RGBA_16161616LE,
388
    skcms_PixelFormat_BGRA_16161616LE,
389
390
    skcms_PixelFormat_RGB_161616BE,  // Big-endian.  Pointers must be 16-bit aligned.
391
    skcms_PixelFormat_BGR_161616BE,
392
    skcms_PixelFormat_RGBA_16161616BE,
393
    skcms_PixelFormat_BGRA_16161616BE,
394
395
    skcms_PixelFormat_RGB_hhh_Norm,  // 1-5-10 half-precision float in [0,1]
396
    skcms_PixelFormat_BGR_hhh_Norm,  // Pointers must be 16-bit aligned.
397
    skcms_PixelFormat_RGBA_hhhh_Norm,
398
    skcms_PixelFormat_BGRA_hhhh_Norm,
399
400
    skcms_PixelFormat_RGB_hhh,  // 1-5-10 half-precision float.
401
    skcms_PixelFormat_BGR_hhh,  // Pointers must be 16-bit aligned.
402
    skcms_PixelFormat_RGBA_hhhh,
403
    skcms_PixelFormat_BGRA_hhhh,
404
405
    skcms_PixelFormat_RGB_fff,  // 1-8-23 single-precision float (the normal kind).
406
    skcms_PixelFormat_BGR_fff,  // Pointers must be 32-bit aligned.
407
    skcms_PixelFormat_RGBA_ffff,
408
    skcms_PixelFormat_BGRA_ffff,
409
410
    skcms_PixelFormat_RGB_101010x_XR,    // Note: This is located here to signal no clamping.
411
    skcms_PixelFormat_BGR_101010x_XR,    // Compatible with MTLPixelFormatBGR10_XR.
412
    skcms_PixelFormat_RGBA_10101010_XR,  // Note: This is located here to signal no clamping.
413
    skcms_PixelFormat_BGRA_10101010_XR,  // Compatible with MTLPixelFormatBGRA10_XR.
414
} skcms_PixelFormat;
415
416
// We always store any alpha channel linearly.  In the chart below, tf-1() is the inverse
417
// transfer function for the given color profile (applying the transfer function linearizes).
418
419
// We treat opaque as a strong requirement, not just a performance hint: we will ignore
420
// any source alpha and treat it as 1.0, and will make sure that any destination alpha
421
// channel is filled with the equivalent of 1.0.
422
423
// We used to offer multiple types of premultiplication, but now just one, PremulAsEncoded.
424
// This is the premul you're probably used to working with.
425
426
typedef enum skcms_AlphaFormat {
427
    skcms_AlphaFormat_Opaque,          // alpha is always opaque
428
                                       //   tf-1(r),   tf-1(g),   tf-1(b),   1.0
429
    skcms_AlphaFormat_Unpremul,        // alpha and color are unassociated
430
                                       //   tf-1(r),   tf-1(g),   tf-1(b),   a
431
    skcms_AlphaFormat_PremulAsEncoded, // premultiplied while encoded
432
                                       //   tf-1(r)*a, tf-1(g)*a, tf-1(b)*a, a
433
} skcms_AlphaFormat;
434
435
// Convert npixels pixels from src format and color profile to dst format and color profile
436
// and return true, otherwise return false.  It is safe to alias dst == src if dstFmt == srcFmt.
437
SKCMS_API bool skcms_Transform(const void*             src,
438
                               skcms_PixelFormat       srcFmt,
439
                               skcms_AlphaFormat       srcAlpha,
440
                               const skcms_ICCProfile* srcProfile,
441
                               void*                   dst,
442
                               skcms_PixelFormat       dstFmt,
443
                               skcms_AlphaFormat       dstAlpha,
444
                               const skcms_ICCProfile* dstProfile,
445
                               size_t                  npixels);
446
447
// If profile can be used as a destination in skcms_Transform, return true. Otherwise, attempt to
448
// rewrite it with approximations where reasonable. If successful, return true. If no reasonable
449
// approximation exists, leave the profile unchanged and return false.
450
SKCMS_API bool skcms_MakeUsableAsDestination(skcms_ICCProfile* profile);
451
452
// If profile can be used as a destination with a single parametric transfer function (ie for
453
// rasterization), return true. Otherwise, attempt to rewrite it with approximations where
454
// reasonable. If successful, return true. If no reasonable approximation exists, leave the
455
// profile unchanged and return false.
456
SKCMS_API bool skcms_MakeUsableAsDestinationWithSingleCurve(skcms_ICCProfile* profile);
457
458
// Returns a matrix to adapt XYZ color from given the whitepoint to D50.
459
SKCMS_API bool skcms_AdaptToXYZD50(float wx, float wy,
460
                                   skcms_Matrix3x3* toXYZD50);
461
462
// Returns a matrix to convert RGB color into XYZ adapted to D50, given the
463
// primaries and whitepoint of the RGB model.
464
SKCMS_API bool skcms_PrimariesToXYZD50(float rx, float ry,
465
                                       float gx, float gy,
466
                                       float bx, float by,
467
                                       float wx, float wy,
468
                                       skcms_Matrix3x3* toXYZD50);
469
470
// Call before your first call to skcms_Transform() to skip runtime CPU detection.
471
SKCMS_API void skcms_DisableRuntimeCPUDetection(void);
472
473
// Utilities for programmatically constructing profiles
474
0
static inline void skcms_Init(skcms_ICCProfile* p) {
475
0
    memset(p, 0, sizeof(*p));
476
0
    p->data_color_space = skcms_Signature_RGB;
477
0
    p->pcs = skcms_Signature_XYZ;
478
0
}
Unexecuted instantiation: skcms.cc:skcms_Init(skcms_ICCProfile*)
Unexecuted instantiation: skcms_TransformBaseline.cc:skcms_Init(skcms_ICCProfile*)
Unexecuted instantiation: fuzz_iccprofile_info.c:skcms_Init
Unexecuted instantiation: fuzz_iccprofile_atf.c:skcms_Init
Unexecuted instantiation: fuzz_iccprofile_transform.c:skcms_Init
479
480
static inline void skcms_SetTransferFunction(skcms_ICCProfile* p,
481
0
                                             const skcms_TransferFunction* tf) {
482
0
    p->has_trc = true;
483
0
    for (int i = 0; i < 3; ++i) {
484
0
        p->trc[i].table_entries = 0;
485
0
        p->trc[i].parametric = *tf;
486
0
    }
487
0
}
Unexecuted instantiation: skcms.cc:skcms_SetTransferFunction(skcms_ICCProfile*, skcms_TransferFunction const*)
Unexecuted instantiation: skcms_TransformBaseline.cc:skcms_SetTransferFunction(skcms_ICCProfile*, skcms_TransferFunction const*)
Unexecuted instantiation: fuzz_iccprofile_info.c:skcms_SetTransferFunction
Unexecuted instantiation: fuzz_iccprofile_atf.c:skcms_SetTransferFunction
Unexecuted instantiation: fuzz_iccprofile_transform.c:skcms_SetTransferFunction
488
489
0
static inline void skcms_SetXYZD50(skcms_ICCProfile* p, const skcms_Matrix3x3* m) {
490
0
    p->has_toXYZD50 = true;
491
0
    p->toXYZD50 = *m;
492
0
}
Unexecuted instantiation: skcms.cc:skcms_SetXYZD50(skcms_ICCProfile*, skcms_Matrix3x3 const*)
Unexecuted instantiation: skcms_TransformBaseline.cc:skcms_SetXYZD50(skcms_ICCProfile*, skcms_Matrix3x3 const*)
Unexecuted instantiation: fuzz_iccprofile_info.c:skcms_SetXYZD50
Unexecuted instantiation: fuzz_iccprofile_atf.c:skcms_SetXYZD50
Unexecuted instantiation: fuzz_iccprofile_transform.c:skcms_SetXYZD50
493
494
#ifdef __cplusplus
495
}
496
#endif