Add ICU message format support
[chromium-blink-merge.git] / third_party / qcms / src / qcmsint.h
blob5dd00619f461acab679676107fd20cdbce051676
1 /* vim: set ts=8 sw=8 noexpandtab: */
2 // qcms
3 // Copyright (C) 2009 Mozilla Foundation
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the Software
10 // is furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
17 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #include "qcms.h"
24 #include "qcmstypes.h"
26 /* used as a lookup table for the output transformation.
27 * we refcount them so we only need to have one around per output
28 * profile, instead of duplicating them per transform */
29 struct precache_output
31 int ref_count;
32 /* We previously used a count of 65536 here but that seems like more
33 * precision than we actually need. By reducing the size we can
34 * improve startup performance and reduce memory usage. ColorSync on
35 * 10.5 uses 4097 which is perhaps because they use a fixed point
36 * representation where 1. is represented by 0x1000. */
37 #define PRECACHE_OUTPUT_SIZE 8192
38 #define PRECACHE_OUTPUT_MAX (PRECACHE_OUTPUT_SIZE-1)
39 uint8_t data[PRECACHE_OUTPUT_SIZE];
42 #ifdef _MSC_VER
43 #define ALIGN __declspec(align(16))
44 #else
45 #define ALIGN __attribute__(( aligned (16) ))
46 #endif
48 typedef struct _qcms_format_type {
49 int r;
50 int b;
51 } qcms_format_type;
53 struct _qcms_transform {
54 float ALIGN matrix[3][4];
55 float *input_gamma_table_r;
56 float *input_gamma_table_g;
57 float *input_gamma_table_b;
59 float *input_clut_table_r;
60 float *input_clut_table_g;
61 float *input_clut_table_b;
62 uint16_t input_clut_table_length;
63 float *r_clut;
64 float *g_clut;
65 float *b_clut;
66 uint16_t grid_size;
67 float *output_clut_table_r;
68 float *output_clut_table_g;
69 float *output_clut_table_b;
70 uint16_t output_clut_table_length;
72 float *input_gamma_table_gray;
74 float out_gamma_r;
75 float out_gamma_g;
76 float out_gamma_b;
78 float out_gamma_gray;
80 uint16_t *output_gamma_lut_r;
81 uint16_t *output_gamma_lut_g;
82 uint16_t *output_gamma_lut_b;
84 uint16_t *output_gamma_lut_gray;
86 size_t output_gamma_lut_r_length;
87 size_t output_gamma_lut_g_length;
88 size_t output_gamma_lut_b_length;
90 size_t output_gamma_lut_gray_length;
92 struct precache_output *output_table_r;
93 struct precache_output *output_table_g;
94 struct precache_output *output_table_b;
96 void (*transform_fn)(struct _qcms_transform *transform, unsigned char *src, unsigned char *dest, size_t length, struct _qcms_format_type output_format);
98 #define TRANSFORM_FLAG_MATRIX 0x0001
100 uint16_t transform_flags;
103 struct matrix {
104 float m[3][3];
105 bool invalid;
108 struct qcms_modular_transform;
110 typedef void (*transform_module_fn_t)(struct qcms_modular_transform *transform, float *src, float *dest, size_t length);
112 struct qcms_modular_transform {
113 struct matrix matrix;
114 float tx, ty, tz;
116 float *input_clut_table_r;
117 float *input_clut_table_g;
118 float *input_clut_table_b;
119 uint16_t input_clut_table_length;
120 float *r_clut;
121 float *g_clut;
122 float *b_clut;
123 uint16_t grid_size;
124 float *output_clut_table_r;
125 float *output_clut_table_g;
126 float *output_clut_table_b;
127 uint16_t output_clut_table_length;
129 uint16_t *output_gamma_lut_r;
130 uint16_t *output_gamma_lut_g;
131 uint16_t *output_gamma_lut_b;
133 size_t output_gamma_lut_r_length;
134 size_t output_gamma_lut_g_length;
135 size_t output_gamma_lut_b_length;
137 transform_module_fn_t transform_module_fn;
138 struct qcms_modular_transform *next_transform;
141 typedef int32_t s15Fixed16Number;
142 typedef uint16_t uInt16Number;
143 typedef uint8_t uInt8Number;
145 struct XYZNumber {
146 s15Fixed16Number X;
147 s15Fixed16Number Y;
148 s15Fixed16Number Z;
151 struct curveType {
152 uint32_t type;
153 uint32_t count;
154 float parameter[7];
155 uInt16Number data[];
158 struct lutmABType {
159 uint8_t num_in_channels;
160 uint8_t num_out_channels;
161 // 16 is the upperbound, actual is 0..num_in_channels.
162 uint8_t num_grid_points[16];
164 s15Fixed16Number e00;
165 s15Fixed16Number e01;
166 s15Fixed16Number e02;
167 s15Fixed16Number e03;
168 s15Fixed16Number e10;
169 s15Fixed16Number e11;
170 s15Fixed16Number e12;
171 s15Fixed16Number e13;
172 s15Fixed16Number e20;
173 s15Fixed16Number e21;
174 s15Fixed16Number e22;
175 s15Fixed16Number e23;
177 // reversed elements (for mBA)
178 bool reversed;
180 float *clut_table;
181 struct curveType *a_curves[10];
182 struct curveType *b_curves[10];
183 struct curveType *m_curves[10];
184 float clut_table_data[];
187 /* should lut8Type and lut16Type be different types? */
188 struct lutType { // used by lut8Type/lut16Type (mft2) only
189 uint8_t num_input_channels;
190 uint8_t num_output_channels;
191 uint8_t num_clut_grid_points;
193 s15Fixed16Number e00;
194 s15Fixed16Number e01;
195 s15Fixed16Number e02;
196 s15Fixed16Number e10;
197 s15Fixed16Number e11;
198 s15Fixed16Number e12;
199 s15Fixed16Number e20;
200 s15Fixed16Number e21;
201 s15Fixed16Number e22;
203 uint16_t num_input_table_entries;
204 uint16_t num_output_table_entries;
206 float *input_table;
207 float *clut_table;
208 float *output_table;
210 float table_data[];
213 struct vcgtType {
214 /* data contains three gamma channels: R[length], then G[length], then
215 * B[length]. */
216 uint16_t *data;
217 size_t length;
220 #if 0
221 /* this is from an intial idea of having the struct correspond to the data in
222 * the file. I decided that it wasn't a good idea.
224 struct tag_value {
225 uint32_t type;
226 union {
227 struct {
228 uint32_t reserved;
229 struct {
230 s15Fixed16Number X;
231 s15Fixed16Number Y;
232 s15Fixed16Number Z;
233 } XYZNumber;
234 } XYZType;
236 }; // I guess we need to pack this?
237 #endif
239 #define RGB_SIGNATURE 0x52474220
240 #define GRAY_SIGNATURE 0x47524159
241 #define XYZ_SIGNATURE 0x58595A20
242 #define LAB_SIGNATURE 0x4C616220
244 struct _qcms_profile {
245 char description[64];
246 uint32_t class;
247 uint32_t color_space;
248 uint32_t pcs;
249 qcms_intent rendering_intent;
250 struct XYZNumber redColorant;
251 struct XYZNumber blueColorant;
252 struct XYZNumber greenColorant;
253 struct curveType *redTRC;
254 struct curveType *blueTRC;
255 struct curveType *greenTRC;
256 struct curveType *grayTRC;
257 struct lutType *A2B0;
258 struct lutType *B2A0;
259 struct lutmABType *mAB;
260 struct lutmABType *mBA;
261 struct matrix chromaticAdaption;
262 struct vcgtType vcgt;
264 struct precache_output *output_table_r;
265 struct precache_output *output_table_g;
266 struct precache_output *output_table_b;
269 #ifdef _MSC_VER
270 #define inline _inline
271 #endif
273 /* produces the nearest float to 'a' with a maximum error
274 * of 1/1024 which happens for large values like 0x40000040 */
275 static inline float s15Fixed16Number_to_float(s15Fixed16Number a)
277 return ((int32_t)a)/65536.f;
280 static inline s15Fixed16Number double_to_s15Fixed16Number(double v)
282 return (int32_t)(v*65536);
285 static inline float uInt8Number_to_float(uInt8Number a)
287 return ((int32_t)a)/255.f;
290 static inline float uInt16Number_to_float(uInt16Number a)
292 return ((int32_t)a)/65535.f;
296 void precache_release(struct precache_output *p);
297 qcms_bool set_rgb_colorants(qcms_profile *profile, qcms_CIE_xyY white_point, qcms_CIE_xyYTRIPLE primaries);
299 void qcms_transform_data_rgb_out_lut_sse2(qcms_transform *transform,
300 unsigned char *src,
301 unsigned char *dest,
302 size_t length,
303 qcms_format_type output_format);
304 void qcms_transform_data_rgba_out_lut_sse2(qcms_transform *transform,
305 unsigned char *src,
306 unsigned char *dest,
307 size_t length,
308 qcms_format_type output_format);
309 void qcms_transform_data_tetra_clut_rgba_sse2(qcms_transform* transform,
310 unsigned char* src,
311 unsigned char* dest,
312 size_t length,
313 qcms_format_type output_format);
315 extern qcms_bool qcms_supports_iccv4;
318 #ifdef _MSC_VER
320 long __cdecl _InterlockedIncrement(long volatile *);
321 long __cdecl _InterlockedDecrement(long volatile *);
322 #pragma intrinsic(_InterlockedIncrement)
323 #pragma intrinsic(_InterlockedDecrement)
325 #define qcms_atomic_increment(x) _InterlockedIncrement((long volatile *)&x)
326 #define qcms_atomic_decrement(x) _InterlockedDecrement((long volatile*)&x)
328 #else
330 #define qcms_atomic_increment(x) __sync_add_and_fetch(&x, 1)
331 #define qcms_atomic_decrement(x) __sync_sub_and_fetch(&x, 1)
333 #endif