-
Notifications
You must be signed in to change notification settings - Fork 15
/
qcmsint.h
190 lines (162 loc) · 5.72 KB
/
qcmsint.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// qcms
// Copyright (C) 2009 Mozilla Foundation
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the Software
// is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "qcms.h"
#include "qcmstypes.h"
/* used as a lookup table for the output transformation.
* we refcount them so we only need to have one around per output
* profile, instead of duplicating them per transform */
struct precache_output
{
int ref_count;
/* We previously used a count of 65536 here but that seems like more
* precision than we actually need. By reducing the size we can
* improve startup performance and reduce memory usage. ColorSync on
* 10.5 uses 4097 which is perhaps because they use a fixed point
* representation where 1. is represented by 0x1000. */
#define PRECACHE_OUTPUT_SIZE 8192
#define PRECACHE_OUTPUT_MAX (PRECACHE_OUTPUT_SIZE-1)
uint8_t data[PRECACHE_OUTPUT_SIZE];
};
#ifdef _MSC_VER
#define ALIGN __declspec(align(16))
#else
#define ALIGN __attribute__(( aligned (16) ))
#endif
struct _qcms_transform {
float ALIGN matrix[3][4];
float *input_gamma_table_r;
float *input_gamma_table_g;
float *input_gamma_table_b;
float *input_gamma_table_gray;
float out_gamma_r;
float out_gamma_g;
float out_gamma_b;
float out_gamma_gray;
uint16_t *output_gamma_lut_r;
uint16_t *output_gamma_lut_g;
uint16_t *output_gamma_lut_b;
uint16_t *output_gamma_lut_gray;
size_t output_gamma_lut_r_length;
size_t output_gamma_lut_g_length;
size_t output_gamma_lut_b_length;
size_t output_gamma_lut_gray_length;
struct precache_output *output_table_r;
struct precache_output *output_table_g;
struct precache_output *output_table_b;
void (*transform_fn)(struct _qcms_transform *transform, unsigned char *src, unsigned char *dest, size_t length);
};
typedef int32_t s15Fixed16Number;
typedef uint16_t uInt16Number;
struct XYZNumber {
s15Fixed16Number X;
s15Fixed16Number Y;
s15Fixed16Number Z;
};
struct curveType {
uint32_t count;
uInt16Number data[];
};
struct lutType {
uint8_t num_input_channels;
uint8_t num_output_channels;
uint8_t num_clut_grid_points;
s15Fixed16Number e00;
s15Fixed16Number e01;
s15Fixed16Number e02;
s15Fixed16Number e10;
s15Fixed16Number e11;
s15Fixed16Number e12;
s15Fixed16Number e20;
s15Fixed16Number e21;
s15Fixed16Number e22;
uint16_t num_input_table_entries;
uint16_t num_output_table_entries;
uint16_t *input_table;
uint16_t *clut_table;
uint16_t *output_table;
};
#if 0
/* this is from an intial idea of having the struct correspond to the data in
* the file. I decided that it wasn't a good idea.
*/
struct tag_value {
uint32_t type;
union {
struct {
uint32_t reserved;
struct {
s15Fixed16Number X;
s15Fixed16Number Y;
s15Fixed16Number Z;
} XYZNumber;
} XYZType;
};
}; // I guess we need to pack this?
#endif
#define RGB_SIGNATURE 0x52474220
#define GRAY_SIGNATURE 0x47524159
struct _qcms_profile {
uint32_t class;
uint32_t color_space;
qcms_intent rendering_intent;
struct XYZNumber redColorant;
struct XYZNumber blueColorant;
struct XYZNumber greenColorant;
struct curveType *redTRC;
struct curveType *blueTRC;
struct curveType *greenTRC;
struct curveType *grayTRC;
struct lutType *A2B0;
struct precache_output *output_table_r;
struct precache_output *output_table_g;
struct precache_output *output_table_b;
};
#ifdef _MSC_VER
#define inline _inline
#endif
/* produces the nearest float to 'a' with a maximum error
* of 1/1024 which happens for large values like 0x40000040 */
static inline float s15Fixed16Number_to_float(s15Fixed16Number a)
{
return ((int32_t)a)/65536.f;
}
static inline s15Fixed16Number double_to_s15Fixed16Number(double v)
{
return (int32_t)(v*65536);
}
void precache_release(struct precache_output *p);
qcms_bool set_rgb_colorants(qcms_profile *profile, qcms_CIE_xyY white_point, qcms_CIE_xyYTRIPLE primaries);
void qcms_transform_data_rgb_out_lut_sse2(qcms_transform *transform,
unsigned char *src,
unsigned char *dest,
size_t length);
void qcms_transform_data_rgba_out_lut_sse2(qcms_transform *transform,
unsigned char *src,
unsigned char *dest,
size_t length);
void qcms_transform_data_rgb_out_lut_sse1(qcms_transform *transform,
unsigned char *src,
unsigned char *dest,
size_t length);
void qcms_transform_data_rgba_out_lut_sse1(qcms_transform *transform,
unsigned char *src,
unsigned char *dest,
size_t length);