OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the Chromium LICENSE file. | 3 // found in the Chromium LICENSE file. |
4 | 4 |
5 #include "qcms.h" | 5 #include "qcms.h" |
6 #include "qcms_test_util.h" | 6 #include "qcms_test_util.h" |
7 | 7 |
8 #include <assert.h> | 8 #include <assert.h> |
9 #include <math.h> | 9 #include <math.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 return 0; | 87 return 0; |
88 } | 88 } |
89 | 89 |
90 static int qcms_test_output_trc(size_t width, | 90 static int qcms_test_output_trc(size_t width, |
91 size_t height, | 91 size_t height, |
92 int iterations, | 92 int iterations, |
93 const char *in_path, | 93 const char *in_path, |
94 const char *out_path, | 94 const char *out_path, |
95 const int force_software) | 95 const int force_software) |
96 { | 96 { |
| 97 uint16_t *gamma_table_out = NULL; |
| 98 size_t output_size = 0; |
97 qcms_profile *profile; | 99 qcms_profile *profile; |
98 uint16_t *gamma_table_out; | 100 long time_stamp = (long)time(NULL); |
99 size_t output_size; | 101 char output_file_name[1024]; |
| 102 float scale_factor; |
100 size_t i; | 103 size_t i; |
101 | 104 |
102 if (!in_path) { | 105 if (!in_path) { |
103 fprintf(stderr, "%s: please provide valid ICC profiles via -i option\n",
__FUNCTION__); | 106 fprintf(stderr, "%s: please provide valid ICC profiles via -i option\n",
__FUNCTION__); |
104 return EXIT_FAILURE; | 107 return EXIT_FAILURE; |
105 } | 108 } |
106 | 109 |
107 printf("Test qcms output gamma curve table integrity.\n"); | 110 printf("Test color profile gamma curves\n"); |
| 111 fflush(stdout); |
108 | 112 |
109 // Create profiles and transforms, get table and then free resources to make
sure none | |
110 // of the internal tables are initialized by previous calls. | |
111 gamma_table_out = NULL; | |
112 output_size = 0; | |
113 if (get_output_gamma_table(in_path, &gamma_table_out, &output_size) != 0) { | 113 if (get_output_gamma_table(in_path, &gamma_table_out, &output_size) != 0) { |
114 fprintf(stderr, "Unable to extract output gamma table\n"); | 114 fprintf(stderr, "Unable to extract output gamma table\n"); |
115 return EXIT_FAILURE; | 115 return EXIT_FAILURE; |
116 } | 116 } |
117 | 117 |
118 printf("Output gamma table size = %zu\n", output_size); | 118 printf("Output gamma table size = %zu\n", output_size); |
119 | 119 |
120 profile = qcms_profile_from_path(in_path); | 120 profile = qcms_profile_from_path(in_path); |
121 if (!profile) { | 121 if (!profile) { |
122 fprintf(stderr, "Invalid input profile\n"); | 122 fprintf(stderr, "Invalid input profile\n"); |
123 free(gamma_table_out); | 123 free(gamma_table_out); |
124 return EXIT_FAILURE; | 124 return EXIT_FAILURE; |
125 } | 125 } |
126 | 126 |
127 // Check only for red curve for now. | |
128 if (profile->redTRC->type == PARAMETRIC_CURVE_TYPE) { | 127 if (profile->redTRC->type == PARAMETRIC_CURVE_TYPE) { |
| 128 // Check the red TRC curve only for now. |
129 int type = - (int)(profile->redTRC->count + 1); | 129 int type = - (int)(profile->redTRC->count + 1); |
130 uint16_t *gamma_table_in = NULL; | 130 uint16_t *gamma_table_in = NULL; |
131 size_t input_size = 0; | 131 size_t input_size = 0; |
132 float scale_factor; | |
133 FILE *output_file; | 132 FILE *output_file; |
134 char output_file_name[1024]; | |
135 long int time_stamp = (long int)time(NULL); | |
136 | 133 |
137 printf("Detected parametric curve type = %d\n", profile->redTRC->count); | 134 printf("Detected parametric curve type = %d\n", profile->redTRC->count); |
138 | 135 |
139 sprintf(output_file_name, "qcms-test-%ld-parametric-gamma-output-%s.csv"
, time_stamp, profile->description); | 136 if (get_input_gamma_table(in_path, &gamma_table_in, &input_size) != 0) { |
| 137 fprintf(stderr, "Failed to compute input gamma table\n"); |
| 138 qcms_profile_release(profile); |
| 139 free(gamma_table_out); |
| 140 return EXIT_FAILURE; |
| 141 } |
| 142 |
| 143 // Write output to stdout and tables into a csv file. |
| 144 sprintf(output_file_name, "qcms-test-%ld-parametric-gamma-output-%s.csv"
, |
| 145 time_stamp, profile->description); |
140 printf("Writing output gamma tables to %s\n", output_file_name); | 146 printf("Writing output gamma tables to %s\n", output_file_name); |
| 147 output_file = fopen(output_file_name, "w"); |
| 148 |
| 149 printf("Parametric gamma values for profile %s description [%s]\n", |
| 150 in_path, profile->description); |
| 151 fprintf(output_file, "Parametric gamma values for profile %s description
[%s]\n", |
| 152 in_path, profile->description); |
141 | 153 |
142 printf("gamma = %.6f, a = %.6f, b = %.6f, c = %.6f, d = %.6f, e = %.6f,
f = %.6f\n", | 154 printf("gamma = %.6f, a = %.6f, b = %.6f, c = %.6f, d = %.6f, e = %.6f,
f = %.6f\n", |
143 profile->redTRC->parameter[0], profile->redTRC->parameter[1], pr
ofile->redTRC->parameter[2], | 155 profile->redTRC->parameter[0], profile->redTRC->parameter[1], pr
ofile->redTRC->parameter[2], |
144 profile->redTRC->parameter[3], profile->redTRC->parameter[4], pr
ofile->redTRC->parameter[5], | 156 profile->redTRC->parameter[3], profile->redTRC->parameter[4], pr
ofile->redTRC->parameter[5], |
145 profile->redTRC->parameter[6]); | 157 profile->redTRC->parameter[6]); |
146 | 158 |
147 // Write output to stdout and tables into a csv file. | |
148 output_file = fopen(output_file_name, "w"); | |
149 fprintf(output_file, "Parametric gamma values for %s\n", profile->descri
ption); | |
150 fprintf(output_file, "gamma, a, b, c, d, e, f\n"); | 159 fprintf(output_file, "gamma, a, b, c, d, e, f\n"); |
151 fprintf(output_file, "%.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f\n", | 160 fprintf(output_file, "%.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f\n", |
152 profile->redTRC->parameter[0], profile->redTRC->parameter[1], pr
ofile->redTRC->parameter[2], | 161 profile->redTRC->parameter[0], profile->redTRC->parameter[1], pr
ofile->redTRC->parameter[2], |
153 profile->redTRC->parameter[3], profile->redTRC->parameter[4], pr
ofile->redTRC->parameter[5], | 162 profile->redTRC->parameter[3], profile->redTRC->parameter[4], pr
ofile->redTRC->parameter[5], |
154 profile->redTRC->parameter[6]); | 163 profile->redTRC->parameter[6]); |
155 | 164 |
156 get_input_gamma_table(in_path, &gamma_table_in, &input_size); | 165 fprintf(output_file, "\nInput curve size: %zu", input_size); |
157 if (!gamma_table_in) { | 166 fprintf(output_file, "\nOutput curve size: %zu", output_size); |
158 fprintf(stderr, "Unable to compute input trc. Aborting\n"); | 167 |
159 fclose(output_file); | 168 fprintf(output_file, "\n\nInput gamma, Output gamma, LCMS Output gamma,
Output gamma error\n"); |
| 169 // Output gamma curve down-sample factor. |
| 170 scale_factor = (float)(output_size - 1) / (input_size - 1); |
| 171 |
| 172 for (i = 0; i < input_size; ++i) { |
| 173 float input = gamma_table_in[i * 4] * inverse65535; |
| 174 size_t out_index = (size_t)floor(i * scale_factor + 0.5); |
| 175 float output = gamma_table_out[out_index * 4] * inverse65535; |
| 176 float x = out_index / (float)(output_size - 1); |
| 177 float reference = clamp_float(evaluate_parametric_curve(type, profil
e->redTRC->parameter, x)); |
| 178 float difference = fabs(output - reference); |
| 179 |
| 180 fprintf(output_file, "%.6f, %.6f, %6f, %6f\n", input, output, refere
nce, difference); |
| 181 } |
| 182 |
| 183 fprintf(output_file, "\nNote: the output gamma curves are down-sampled b
y a factor of %zu / %zu\n", |
| 184 output_size, input_size); |
| 185 |
| 186 fclose(output_file); |
| 187 free(gamma_table_in); |
| 188 } else { |
| 189 uint16_t *gamma_table_in = NULL; |
| 190 size_t input_size = 0; |
| 191 FILE *output_file; |
| 192 |
| 193 if (get_input_gamma_table(in_path, &gamma_table_in, &input_size) != 0) { |
| 194 fprintf(stderr, "Failed to compute input gamma table\n"); |
160 qcms_profile_release(profile); | 195 qcms_profile_release(profile); |
161 free(gamma_table_out); | 196 free(gamma_table_out); |
162 return EXIT_FAILURE; | 197 return EXIT_FAILURE; |
163 } | 198 } |
164 | 199 |
| 200 // Write output to stdout and tables into a csv file. |
| 201 sprintf(output_file_name, "qcms-test-%ld-gamma-output-%s.csv", |
| 202 time_stamp, profile->description); |
| 203 printf("Writing gamma tables to %s\n", output_file_name); |
| 204 output_file = fopen(output_file_name, "w"); |
| 205 |
| 206 printf("Gamma values for profile %s description [%s]\n", |
| 207 in_path, profile->description); |
| 208 fprintf(output_file, "Gamma values for profile %s description [%s]\n", |
| 209 in_path, profile->description); |
| 210 |
| 211 if (profile->redTRC->count == 0) { |
| 212 printf("Gamma LUT type 0: linear gamma\n"); |
| 213 fprintf(output_file, "Gamma LUT type 0: linear gamma\n"); |
| 214 } else if (profile->redTRC->count == 1) { |
| 215 float gamma = profile->redTRC->data[0] / 256.0f; |
| 216 printf("Gamma LUT type 1: gamma = %.6f\n", gamma); |
| 217 fprintf(output_file, "Gamma LUT type 1: gamma = %.6f\n", gamma); |
| 218 } else { |
| 219 printf("Gamma LUT table size = %u\n", profile->redTRC->count); |
| 220 fprintf(output_file, "Gamma LUT table size = %u\n", profile->redTRC-
>count); |
| 221 } |
| 222 |
165 fprintf(output_file, "\nInput curve size: %zu", input_size); | 223 fprintf(output_file, "\nInput curve size: %zu", input_size); |
166 fprintf(output_file, "\nOutput curve size: %zu", output_size); | 224 fprintf(output_file, "\nOutput curve size: %zu", output_size); |
167 | 225 |
| 226 fprintf(output_file, "\n\nInput gamma, Output gamma\n"); |
| 227 // Output gamma curve down-sample factor. |
168 scale_factor = (float)(output_size - 1) / (input_size - 1); | 228 scale_factor = (float)(output_size - 1) / (input_size - 1); |
169 | 229 |
170 fprintf(output_file, "\n\nInput gamma, Output gamma, LCMS Output gamma,
Output gamma error\n"); | |
171 | |
172 for (i = 0; i < input_size; ++i) { | 230 for (i = 0; i < input_size; ++i) { |
173 float input = gamma_table_in[i * 4] * inverse65535; | 231 float input = gamma_table_in[i * 4] * inverse65535; |
174 size_t out_index = (size_t)floor(i * scale_factor + 0.5); | 232 size_t out_index = (size_t)floor(i * scale_factor + 0.5); |
175 float p = out_index / (float)(output_size - 1); | 233 float output = gamma_table_out[out_index * 4] * inverse65535; |
176 float reference = clamp_float(evaluate_parametric_curve(type, profil
e->redTRC->parameter, p)); | |
177 float actual = gamma_table_out[out_index * 4] * inverse65535; | |
178 float difference = fabs(actual - reference); | |
179 | 234 |
180 fprintf(output_file, "%.6f, %.6f, %6f, %6f\n", input, actual, refere
nce, difference); | 235 fprintf(output_file, "%.6f, %.6f\n", input, output); |
181 } | 236 } |
182 | 237 |
183 fprintf(output_file, "\nNote: the output gamma curves are down-sampled b
y a factor of %zu / %zu\n", | 238 fprintf(output_file, "\nNote: the output gamma curves are down-sampled b
y a factor of %zu / %zu\n", |
184 output_size, input_size); | 239 output_size, input_size); |
185 | 240 |
186 fclose(output_file); | 241 fclose(output_file); |
187 free(gamma_table_in); | 242 free(gamma_table_in); |
188 } | 243 } |
189 | 244 |
190 qcms_profile_release(profile); | 245 qcms_profile_release(profile); |
191 free(gamma_table_out); | 246 free(gamma_table_out); |
192 | 247 |
193 return 0; | 248 return 0; |
194 } | 249 } |
195 | 250 |
196 struct qcms_test_case qcms_test_output_trc_info = { | 251 struct qcms_test_case qcms_test_output_trc_info = { |
197 "qcms_test_output_trc", | 252 "qcms_test_output_trc", |
198 qcms_test_output_trc, | 253 qcms_test_output_trc, |
199 QCMS_TEST_DISABLED | 254 QCMS_TEST_DISABLED |
200 }; | 255 }; |
OLD | NEW |