Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: third_party/qcms/src/tests/qcms_test_output_trc.c

Issue 1862053002: Reland: [qcms] Fix build_output_lut to return correct data for parametric curves (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed gamma estimator Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 <math.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <time.h>
12
13 #define PARAMETRIC_CURVE_TYPE 0x70617261 // 'para'
14 #define MAX_FLOAT_ERROR 0.000001f
Noel Gordon 2016/04/26 02:46:39 MAX_FLOAT_ERROR is no longer used, right?
radu.velea 2016/04/26 10:23:18 Done.
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, bool precache)
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 if (precache) {
33 qcms_profile_precache_output_transform(target);
34 }
35
36 sRGB = qcms_profile_sRGB();
37
38 transform = qcms_transform_create(sRGB, QCMS_DATA_RGBA_8, target, QCMS_DATA_ RGBA_8, QCMS_INTENT_DEFAULT);
39 if (!transform) {
40 fprintf(stderr, "Failed to create colour transform\n");
41 qcms_profile_release(sRGB);
42 qcms_profile_release(target);
43 return EXIT_FAILURE;
44 }
45
46 *size = qcms_transform_get_output_trc_rgba(transform, target, QCMS_TRC_USHOR T, NULL);
Noel Gordon 2016/04/26 02:46:39 As suggested for the input table, how about we ass
radu.velea 2016/04/26 10:23:19 Done.
47 *table = malloc(*size * sizeof(uint16_t) * 4);
48 qcms_transform_get_output_trc_rgba(transform, target, QCMS_TRC_USHORT, *tabl e);
49
50 qcms_transform_release(transform);
51
Noel Gordon 2016/04/26 02:46:39 Remove this line, close up the space.
radu.velea 2016/04/26 10:23:18 Done.
52 qcms_profile_release(sRGB);
53 qcms_profile_release(target);
54
55 return 0;
56 }
57
58 static int get_input_gamma_table(const char *profile_path, uint16_t **table, siz e_t expected_size)
59 {
60 qcms_transform *transform;
61 qcms_profile *source;
62 qcms_profile *sRGB;
63 size_t size;
64
65 source = qcms_profile_from_path(profile_path);
66 if (!source) {
67 fprintf(stderr, "Invalid input profile\n");
68 return EXIT_FAILURE;
69 }
70
71 sRGB = qcms_profile_sRGB();
72
73 transform = qcms_transform_create(source, QCMS_DATA_RGBA_8, sRGB, QCMS_DATA_ RGBA_8, QCMS_INTENT_DEFAULT);
74 if (!transform) {
75 fprintf(stderr, "Failed to create colour transform\n");
76 qcms_profile_release(sRGB);
77 qcms_profile_release(source);
78 return EXIT_FAILURE;
79 }
80
81 // For now the size of input gamma table for parametric curves is hardcoded to 256.
82 // See compute_curve_gamma_table_type_parametric for details.
83 // Future implementations might decide to return an arbitrary-sized table.
84 size = qcms_transform_get_input_trc_rgba(transform, source, QCMS_TRC_USHORT, NULL);
Noel Gordon 2016/04/26 02:46:39 This comment also applies to the output gamma tabl
radu.velea 2016/04/26 10:23:19 Done.
85 if (size != expected_size) {
86 fprintf(stderr, "Expected input table size (%zu) to match output size (% zu)\n", size, expected_size);
Noel Gordon 2016/04/26 02:46:39 How about we assert(size == 256);
radu.velea 2016/04/26 10:23:18 Done.
87 size = size > expected_size ? size : expected_size;
88 }
89
90 *table = calloc(size, sizeof(uint16_t) * 4);
91 qcms_transform_get_input_trc_rgba(transform, source, QCMS_TRC_USHORT, *table );
92
93 qcms_transform_release(transform);
94
Noel Gordon 2016/04/26 02:46:39 Remove this line, close up the space.
radu.velea 2016/04/26 10:23:18 Done.
95 qcms_profile_release(sRGB);
96 qcms_profile_release(source);
97
98 return 0;
99 }
100
101 static int qcms_test_output_trc(size_t width,
102 size_t height,
103 int iterations,
104 const char *in_path,
105 const char *out_path,
106 const int force_software)
107 {
108 int err = 0;
109 qcms_profile *profile;
110 uint16_t *gamma_table_out, *gamma_table_out_precache;
111 size_t gamma_table_size, gamma_table_size_precache;
112 int i;
113
114 printf("Test qcms output gamma curve integrity with and without precached ta bles.\n");
115
116 if (!in_path) {
117 fprintf(stderr, "%s: please provide valid ICC profiles via -i option\n", __FUNCTION__);
118 return EXIT_FAILURE;
119 }
120
121 // Create profiles and transforms, get table and then free resources to make sure none
122 // of the internal tables are initialized by previous calls.
123 gamma_table_out = NULL;
124 gamma_table_size = 0;
125 if (get_output_gamma_table(in_path, &gamma_table_out, &gamma_table_size, tru e) != 0) {
126 fprintf(stderr, "Unable to extract output gamma table\n");
127 return EXIT_FAILURE;
128 }
129
130 gamma_table_out_precache = NULL;
131 gamma_table_size_precache = 0;
132 if (get_output_gamma_table(in_path, &gamma_table_out_precache, &gamma_table_ size_precache, false) != 0) {
133 fprintf(stderr, "Unable to extract precached output gamma table\n");
134 return EXIT_FAILURE;
135 }
136
137 // Check if precached and non-precached tables match in size and contents.
138 if (gamma_table_size != gamma_table_size_precache) {
139 fprintf(stderr, "Size mismatch between output table sizes.\n"
140 "Output gamma size = %zu, gamma size with precahce = %zu\n", gam ma_table_size, gamma_table_size_precache);
141 free(gamma_table_out);
142 free(gamma_table_out_precache);
143 return EXIT_FAILURE;
144 }
145
146 printf("LUT size = %zu, %zu\n", gamma_table_size, gamma_table_size_precache) ;
147
148 for (i = 0; i < 4 * gamma_table_size; ++i) {
149 err += abs(gamma_table_out[i] - gamma_table_out_precache[i]);
150 }
151
152 if (err != 0) {
153 fprintf(stderr, "Gamma output total error = %d\n.Aborting.", err);
154 free(gamma_table_out);
155 free(gamma_table_out_precache);
156 return EXIT_FAILURE;
157 }
158
159 profile = qcms_profile_from_path(in_path);
160 if (!profile) {
161 fprintf(stderr, "Invalid input profile\n");
162 free(gamma_table_out);
163 free(gamma_table_out_precache);
164 return EXIT_FAILURE;
165 }
166
167 // Check only for red curve for now.
168 if (profile->redTRC->type == PARAMETRIC_CURVE_TYPE) {
169 int type = - (profile->redTRC->count + 1);
170 FILE *gamma_file;
171 uint16_t *gamma_table_in = NULL;
172 uint16_t *p_table_out, *p_table_in;
173 char file_name[256] = {0,};
174
175 printf("Detected parametric curve type = %d\n", profile->redTRC->count);
176
177 sprintf(file_name, "qcms-test-%ld-parametric-gamma-%s.csv", (long int)ti me(NULL), profile->description);
178 printf("Writing input and output gamma tables to %s\n", file_name);
179
180 printf("gamma = %.6f, a = %.6f, b = %.6f, c = %.6f, d = %.6f, e = %.6f, f = %.6f\n",
181 profile->redTRC->parameter[0], profile->redTRC->parameter[1], pr ofile->redTRC->parameter[2],
182 profile->redTRC->parameter[3], profile->redTRC->parameter[4], pr ofile->redTRC->parameter[5],
183 profile->redTRC->parameter[6]);
184
185 // Write output to stdout and tables into a csv file.
186 gamma_file = fopen(file_name, "w");
187 fprintf(gamma_file, "Parametric gamma values for %s\n", profile->descrip tion);
188 fprintf(gamma_file, "gamma, a, b, c, d, e, f\n");
189 fprintf(gamma_file, "%.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f\n",
190 profile->redTRC->parameter[0], profile->redTRC->parameter[1], pr ofile->redTRC->parameter[2],
191 profile->redTRC->parameter[3], profile->redTRC->parameter[4], pr ofile->redTRC->parameter[5],
192 profile->redTRC->parameter[6]);
193
194 get_input_gamma_table(in_path, &gamma_table_in, gamma_table_size);
195 if (!gamma_table_in) {
196 fprintf(stderr, "Unable to compute input trc. Aborting\n");
197 fclose(gamma_file);
198 qcms_profile_release(profile);
199 free(gamma_table_out);
200 free(gamma_table_out_precache);
201 return EXIT_FAILURE;
202 }
203
204 fprintf(gamma_file, "\n\nInput gamma, Output gamma, LCMS Output gamma, O utput gamma error\n");
205
206 p_table_out = gamma_table_out;
207 p_table_in = gamma_table_in;
208
209 for (i = 0; i < gamma_table_size; ++i) {
210 float p = i / (gamma_table_size * 1.0);
211 float reference_out = clamp_float(evaluate_parametric_curve(type, pr ofile->redTRC->parameter, p));
212 float actual_out = *p_table_out * inverse65535;
213 float error_out = fabs(actual_out - reference_out);
214 float input = *p_table_in * inverse65535;
215
216 fprintf(gamma_file, "%.6f, %.6f, %6f, %6f\n",input, actual_out, refe rence_out, error_out);
217
218 p_table_out += 4; // Skip other channels.
219 p_table_in += 4; // Skip other channels.
220 }
221
222 free(gamma_table_in);
223 fclose(gamma_file);
224 }
225
226 qcms_profile_release(profile);
227
228 free(gamma_table_out);
229 free(gamma_table_out_precache);
230
231 return err;
232 }
233
234 struct qcms_test_case qcms_test_output_trc_info = {
235 "qcms_test_output_trc",
236 qcms_test_output_trc,
237 QCMS_TEST_DISABLED
238 };
OLDNEW
« no previous file with comments | « third_party/qcms/src/tests/qcms_test_main.c ('k') | third_party/qcms/src/tests/qcms_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698