qcms.h (8130B)
1 #ifndef QCMS_H 2 #define QCMS_H 3 4 /* clang-format off */ 5 6 #ifdef __cplusplus 7 extern "C" { 8 #endif 9 10 /* if we've already got an ICC_H header we can ignore the following */ 11 #ifndef ICC_H 12 /* icc34 defines */ 13 14 /***************************************************************** 15 Copyright (c) 1994-1996 SunSoft, Inc. 16 17 Rights Reserved 18 19 Permission is hereby granted, free of charge, to any person 20 obtaining a copy of this software and associated documentation 21 files (the "Software"), to deal in the Software without restrict- 22 ion, including without limitation the rights to use, copy, modify, 23 merge, publish distribute, sublicense, and/or sell copies of the 24 Software, and to permit persons to whom the Software is furnished 25 to do so, subject to the following conditions: 26 27 The above copyright notice and this permission notice shall be 28 included in all copies or substantial portions of the Software. 29 30 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 31 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 32 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON- 33 INFRINGEMENT. IN NO EVENT SHALL SUNSOFT, INC. OR ITS PARENT 34 COMPANY BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 35 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 36 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 37 OTHER DEALINGS IN THE SOFTWARE. 38 39 Except as contained in this notice, the name of SunSoft, Inc. 40 shall not be used in advertising or otherwise to promote the 41 sale, use or other dealings in this Software without written 42 authorization from SunSoft Inc. 43 ******************************************************************/ 44 45 /* 46 * QCMS, in general, is not threadsafe. However, it should be safe to create 47 * profile and transformation objects on different threads, so long as you 48 * don't use the same objects on different threads at the same time. 49 */ 50 51 /* 52 * Color Space Signatures 53 * Note that only icSigXYZData and icSigLabData are valid 54 * Profile Connection Spaces (PCSs) 55 */ 56 typedef enum { 57 icSigXYZData = 0x58595A20L, /* 'XYZ ' */ 58 icSigLabData = 0x4C616220L, /* 'Lab ' */ 59 icSigLuvData = 0x4C757620L, /* 'Luv ' */ 60 icSigYCbCrData = 0x59436272L, /* 'YCbr' */ 61 icSigYxyData = 0x59787920L, /* 'Yxy ' */ 62 icSigRgbData = 0x52474220L, /* 'RGB ' */ 63 icSigGrayData = 0x47524159L, /* 'GRAY' */ 64 icSigHsvData = 0x48535620L, /* 'HSV ' */ 65 icSigHlsData = 0x484C5320L, /* 'HLS ' */ 66 icSigCmykData = 0x434D594BL, /* 'CMYK' */ 67 icSigCmyData = 0x434D5920L, /* 'CMY ' */ 68 icSig2colorData = 0x32434C52L, /* '2CLR' */ 69 icSig3colorData = 0x33434C52L, /* '3CLR' */ 70 icSig4colorData = 0x34434C52L, /* '4CLR' */ 71 icSig5colorData = 0x35434C52L, /* '5CLR' */ 72 icSig6colorData = 0x36434C52L, /* '6CLR' */ 73 icSig7colorData = 0x37434C52L, /* '7CLR' */ 74 icSig8colorData = 0x38434C52L, /* '8CLR' */ 75 icSig9colorData = 0x39434C52L, /* '9CLR' */ 76 icSig10colorData = 0x41434C52L, /* 'ACLR' */ 77 icSig11colorData = 0x42434C52L, /* 'BCLR' */ 78 icSig12colorData = 0x43434C52L, /* 'CCLR' */ 79 icSig13colorData = 0x44434C52L, /* 'DCLR' */ 80 icSig14colorData = 0x45434C52L, /* 'ECLR' */ 81 icSig15colorData = 0x46434C52L, /* 'FCLR' */ 82 icMaxEnumData = 0xFFFFFFFFL 83 } icColorSpaceSignature; 84 #endif 85 86 #include <stdio.h> 87 #include <stdbool.h> 88 #include <cstdint> 89 90 struct _qcms_transform; 91 typedef struct _qcms_transform qcms_transform; 92 93 struct _qcms_profile; 94 typedef struct _qcms_profile qcms_profile; 95 96 /* these values match the Rendering Intent values from the ICC spec */ 97 typedef enum { 98 QCMS_INTENT_MIN = 0, 99 QCMS_INTENT_PERCEPTUAL = 0, 100 QCMS_INTENT_RELATIVE_COLORIMETRIC = 1, 101 QCMS_INTENT_SATURATION = 2, 102 QCMS_INTENT_ABSOLUTE_COLORIMETRIC = 3, 103 QCMS_INTENT_MAX = 3, 104 105 /* Chris Murphy (CM consultant) suggests this as a default in the event that we 106 * cannot reproduce relative + Black Point Compensation. BPC brings an 107 * unacceptable performance overhead, so we go with perceptual. */ 108 QCMS_INTENT_DEFAULT = QCMS_INTENT_PERCEPTUAL, 109 } qcms_intent; 110 111 //XXX: I don't really like the _DATA_ prefix 112 typedef enum { 113 QCMS_DATA_RGB_8, 114 QCMS_DATA_RGBA_8, 115 QCMS_DATA_BGRA_8, 116 QCMS_DATA_GRAY_8, 117 QCMS_DATA_GRAYA_8, 118 QCMS_DATA_CMYK 119 } qcms_data_type; 120 121 /* the names for the following two types are sort of ugly */ 122 typedef struct 123 { 124 double x; 125 double y; 126 double Y; 127 } qcms_CIE_xyY; 128 129 typedef struct 130 { 131 qcms_CIE_xyY red; 132 qcms_CIE_xyY green; 133 qcms_CIE_xyY blue; 134 } qcms_CIE_xyYTRIPLE; 135 136 qcms_profile* qcms_profile_create_rgb_with_gamma_set( 137 qcms_CIE_xyY white_point, 138 qcms_CIE_xyYTRIPLE primaries, 139 float redGamma, 140 float blueGamma, 141 float greenGamma); 142 143 qcms_profile* qcms_profile_create_rgb_with_gamma( 144 qcms_CIE_xyY white_point, 145 qcms_CIE_xyYTRIPLE primaries, 146 float gamma); 147 148 void qcms_data_create_rgb_with_gamma( 149 qcms_CIE_xyY white_point, 150 qcms_CIE_xyYTRIPLE primaries, 151 float gamma, 152 void **mem, 153 size_t *size); 154 155 /* The arguments are standardized Coding-independent Code Points 156 * See [Rec. ITU-T H.273 (12/2016)](https://www.itu.int/rec/T-REC-H.273-201612-I/en) 157 * 158 * Don't use enums here because they can't go safely across FFI. */ 159 qcms_profile* qcms_profile_create_cicp(uint8_t colour_primaries, 160 uint8_t transfer_characteristics); 161 162 qcms_profile* qcms_profile_from_memory(const void *mem, size_t size); 163 qcms_profile* qcms_profile_from_memory_curves_only(const void *mem, size_t size); 164 165 qcms_profile* qcms_profile_from_file(FILE *file); 166 qcms_profile* qcms_profile_from_path(const char *path); 167 168 void qcms_data_from_path(const char *path, void **mem, size_t *size); 169 170 #ifdef _WIN32 171 qcms_profile* qcms_profile_from_unicode_path(const wchar_t *path); 172 void qcms_data_from_unicode_path(const wchar_t *path, void **mem, size_t *size); 173 #endif 174 175 qcms_CIE_xyY qcms_white_point_sRGB(void); 176 qcms_profile* qcms_profile_sRGB(void); 177 qcms_profile* qcms_profile_displayP3(void); 178 179 void qcms_profile_release(qcms_profile *profile); 180 181 bool qcms_profile_is_bogus(qcms_profile *profile); 182 qcms_intent qcms_profile_get_rendering_intent(qcms_profile *profile); 183 icColorSpaceSignature qcms_profile_get_color_space(qcms_profile *profile); 184 bool qcms_profile_is_sRGB(qcms_profile *profile); 185 186 void qcms_profile_precache_output_transform(qcms_profile *profile); 187 188 qcms_transform* qcms_transform_create( 189 qcms_profile *in, qcms_data_type in_type, 190 qcms_profile* out, qcms_data_type out_type, 191 qcms_intent intent); 192 193 void qcms_transform_release(qcms_transform *); 194 195 void qcms_transform_data(qcms_transform *transform, const void *src, void *dest, size_t length); 196 197 void qcms_enable_iccv4(); 198 void qcms_enable_neon(); 199 void qcms_enable_avx(); 200 201 202 203 // - 204 /* 205 struct qcms_mat3r3 { 206 struct row { 207 float cols[3]; 208 }; 209 row rows[3]; 210 }; 211 */ 212 struct qcms_profile_data { 213 uint32_t class_type; 214 uint32_t color_space; 215 uint32_t pcs; 216 qcms_intent rendering_intent; 217 float red_colorant_xyzd50[3]; 218 float blue_colorant_xyzd50[3]; 219 float green_colorant_xyzd50[3]; 220 int32_t linear_from_trc_red_samples; 221 int32_t linear_from_trc_blue_samples; 222 int32_t linear_from_trc_green_samples; 223 }; 224 225 void qcms_profile_get_data(const qcms_profile*, qcms_profile_data* out_data); 226 227 228 enum class qcms_color_channel : uint8_t { 229 Red, 230 Green, 231 Blue, 232 }; 233 234 void qcms_profile_get_lut(const qcms_profile*, qcms_color_channel, 235 float* begin, float* end); 236 237 #ifdef __cplusplus 238 } 239 #endif 240 241 #endif