OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the Chromium LICENSE file. | |
4 | |
5 #include "qcms.h" | |
6 #include "qcms_test_util.h" | |
7 | |
8 #include <assert.h> | |
9 #include <math.h> | |
10 #include <stdio.h> | |
11 #include <stdlib.h> | |
12 #include <time.h> | |
13 | |
14 #define PARAMETRIC_CURVE_TYPE 0x70617261 // 'para' | |
15 | |
16 static const float inverse65535 = (float) (1.0 / 65535.0); | |
17 | |
18 extern float clamp_float(float a); | |
19 | |
20 static int get_output_gamma_table(const char *profile_path, uint16_t **table, si ze_t *size) | |
21 { | |
22 qcms_transform *transform; | |
23 qcms_profile *sRGB; | |
24 qcms_profile *target; | |
25 | |
26 target = qcms_profile_from_path(profile_path); | |
27 if (!target) { | |
28 fprintf(stderr, "Invalid input profile\n"); | |
29 return EXIT_FAILURE; | |
30 } | |
31 | |
32 sRGB = qcms_profile_sRGB(); | |
33 | |
34 transform = qcms_transform_create(sRGB, QCMS_DATA_RGBA_8, target, QCMS_DATA_ RGBA_8, QCMS_INTENT_DEFAULT); | |
35 if (!transform) { | |
36 fprintf(stderr, "Failed to create colour transform\n"); | |
37 qcms_profile_release(sRGB); | |
38 qcms_profile_release(target); | |
39 return EXIT_FAILURE; | |
40 } | |
41 | |
42 *size = qcms_transform_get_output_trc_rgba(transform, target, QCMS_TRC_USHOR T, NULL); | |
43 assert(*size == 256); | |
44 *table = malloc(*size * sizeof(uint16_t) * 4); | |
45 qcms_transform_get_output_trc_rgba(transform, target, QCMS_TRC_USHORT, *tabl e); | |
46 | |
47 qcms_transform_release(transform); | |
48 qcms_profile_release(sRGB); | |
49 qcms_profile_release(target); | |
50 | |
51 return 0; | |
52 } | |
53 | |
54 static int get_input_gamma_table(const char *profile_path, uint16_t **table, siz e_t *size) | |
55 { | |
56 qcms_transform *transform; | |
57 qcms_profile *source; | |
58 qcms_profile *sRGB; | |
59 | |
60 source = qcms_profile_from_path(profile_path); | |
61 if (!source) { | |
62 fprintf(stderr, "Invalid input profile\n"); | |
63 return EXIT_FAILURE; | |
64 } | |
65 | |
66 sRGB = qcms_profile_sRGB(); | |
67 | |
68 transform = qcms_transform_create(source, QCMS_DATA_RGBA_8, sRGB, QCMS_DATA_ RGBA_8, QCMS_INTENT_DEFAULT); | |
69 if (!transform) { | |
70 fprintf(stderr, "Failed to create colour transform\n"); | |
71 qcms_profile_release(sRGB); | |
72 qcms_profile_release(source); | |
73 return EXIT_FAILURE; | |
74 } | |
75 | |
76 // For now the size of input gamma table for parametric curves is hardcoded to 256. | |
77 // See compute_curve_gamma_table_type_parametric for details. | |
78 // Future implementations might decide to return an arbitrary-sized table. | |
79 *size = qcms_transform_get_input_trc_rgba(transform, source, QCMS_TRC_USHORT , NULL); | |
80 assert(*size == 256); | |
81 | |
82 *table = calloc(*size, sizeof(uint16_t) * 4); | |
83 qcms_transform_get_input_trc_rgba(transform, source, QCMS_TRC_USHORT, *table ); | |
84 | |
85 qcms_transform_release(transform); | |
86 qcms_profile_release(sRGB); | |
87 qcms_profile_release(source); | |
88 | |
89 return 0; | |
90 } | |
91 | |
92 static int qcms_test_output_trc(size_t width, | |
93 size_t height, | |
94 int iterations, | |
95 const char *in_path, | |
96 const char *out_path, | |
97 const int force_software) | |
98 { | |
99 int err = 0; | |
100 qcms_profile *profile; | |
101 uint16_t *gamma_table_out; | |
102 size_t gamma_table_size; | |
103 int i; | |
104 | |
105 printf("Test qcms output gamma curve integrity with and without precached ta bles.\n"); | |
106 | |
107 if (!in_path) { | |
108 fprintf(stderr, "%s: please provide valid ICC profiles via -i option\n", __FUNCTION__); | |
109 return EXIT_FAILURE; | |
110 } | |
111 | |
112 // Create profiles and transforms, get table and then free resources to make sure none | |
113 // of the internal tables are initialized by previous calls. | |
114 gamma_table_out = NULL; | |
115 gamma_table_size = 0; | |
116 if (get_output_gamma_table(in_path, &gamma_table_out, &gamma_table_size) != 0) { | |
117 fprintf(stderr, "Unable to extract output gamma table\n"); | |
118 return EXIT_FAILURE; | |
119 } | |
120 | |
121 printf("LUT size = %zu\n", gamma_table_size); | |
122 | |
123 if (err != 0) { | |
Noel Gordon
2016/04/26 10:32:15
You can remove this too I think, it's never anythi
radu.velea
2016/04/26 10:36:49
Done.
| |
124 fprintf(stderr, "Gamma output total error = %d\n.Aborting.", err); | |
125 free(gamma_table_out); | |
126 return EXIT_FAILURE; | |
127 } | |
128 | |
129 profile = qcms_profile_from_path(in_path); | |
130 if (!profile) { | |
131 fprintf(stderr, "Invalid input profile\n"); | |
132 free(gamma_table_out); | |
133 return EXIT_FAILURE; | |
134 } | |
135 | |
136 // Check only for red curve for now. | |
137 if (profile->redTRC->type == PARAMETRIC_CURVE_TYPE) { | |
138 int type = - (profile->redTRC->count + 1); | |
139 FILE *gamma_file; | |
140 uint16_t *gamma_table_in = NULL; | |
141 uint16_t *p_table_out, *p_table_in; | |
142 char file_name[256] = {0,}; | |
143 size_t input_size = 0; | |
144 | |
145 printf("Detected parametric curve type = %d\n", profile->redTRC->count); | |
146 | |
147 sprintf(file_name, "qcms-test-%ld-parametric-gamma-%s.csv", (long int)ti me(NULL), profile->description); | |
148 printf("Writing input and output gamma tables to %s\n", file_name); | |
149 | |
150 printf("gamma = %.6f, a = %.6f, b = %.6f, c = %.6f, d = %.6f, e = %.6f, f = %.6f\n", | |
151 profile->redTRC->parameter[0], profile->redTRC->parameter[1], pr ofile->redTRC->parameter[2], | |
152 profile->redTRC->parameter[3], profile->redTRC->parameter[4], pr ofile->redTRC->parameter[5], | |
153 profile->redTRC->parameter[6]); | |
154 | |
155 // Write output to stdout and tables into a csv file. | |
156 gamma_file = fopen(file_name, "w"); | |
157 fprintf(gamma_file, "Parametric gamma values for %s\n", profile->descrip tion); | |
158 fprintf(gamma_file, "gamma, a, b, c, d, e, f\n"); | |
159 fprintf(gamma_file, "%.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f\n", | |
160 profile->redTRC->parameter[0], profile->redTRC->parameter[1], pr ofile->redTRC->parameter[2], | |
161 profile->redTRC->parameter[3], profile->redTRC->parameter[4], pr ofile->redTRC->parameter[5], | |
162 profile->redTRC->parameter[6]); | |
163 | |
164 get_input_gamma_table(in_path, &gamma_table_in, &input_size); | |
165 assert(input_size == gamma_table_size); | |
166 if (!gamma_table_in) { | |
167 fprintf(stderr, "Unable to compute input trc. Aborting\n"); | |
168 fclose(gamma_file); | |
169 qcms_profile_release(profile); | |
170 free(gamma_table_out); | |
171 return EXIT_FAILURE; | |
172 } | |
173 | |
174 fprintf(gamma_file, "\n\nInput gamma, Output gamma, LCMS Output gamma, O utput gamma error\n"); | |
175 | |
176 p_table_out = gamma_table_out; | |
177 p_table_in = gamma_table_in; | |
178 | |
179 for (i = 0; i < gamma_table_size; ++i) { | |
180 float p = i / (gamma_table_size * 1.0); | |
181 float reference_out = clamp_float(evaluate_parametric_curve(type, pr ofile->redTRC->parameter, p)); | |
182 float actual_out = *p_table_out * inverse65535; | |
183 float error_out = fabs(actual_out - reference_out); | |
184 float input = *p_table_in * inverse65535; | |
185 | |
186 fprintf(gamma_file, "%.6f, %.6f, %6f, %6f\n",input, actual_out, refe rence_out, error_out); | |
187 | |
188 p_table_out += 4; // Skip other channels. | |
189 p_table_in += 4; // Skip other channels. | |
190 } | |
191 | |
192 free(gamma_table_in); | |
193 fclose(gamma_file); | |
194 } | |
195 | |
196 qcms_profile_release(profile); | |
197 | |
198 free(gamma_table_out); | |
199 | |
200 return err; | |
Noel Gordon
2016/04/26 10:32:15
return 0? here ?
radu.velea
2016/04/26 10:36:49
Done.
| |
201 } | |
202 | |
203 struct qcms_test_case qcms_test_output_trc_info = { | |
204 "qcms_test_output_trc", | |
205 qcms_test_output_trc, | |
206 QCMS_TEST_DISABLED | |
207 }; | |
OLD | NEW |