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

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

Issue 1923873002: [qcms] Make build_output_lut output 4096 points for parametric curves (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added asserts and renamed variables Created 4 years, 7 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
« no previous file with comments | « third_party/qcms/README.chromium ('k') | third_party/qcms/src/transform_util.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 22 matching lines...) Expand all
33 33
34 transform = qcms_transform_create(sRGB, QCMS_DATA_RGBA_8, target, QCMS_DATA_ RGBA_8, QCMS_INTENT_DEFAULT); 34 transform = qcms_transform_create(sRGB, QCMS_DATA_RGBA_8, target, QCMS_DATA_ RGBA_8, QCMS_INTENT_DEFAULT);
35 if (!transform) { 35 if (!transform) {
36 fprintf(stderr, "Failed to create colour transform\n"); 36 fprintf(stderr, "Failed to create colour transform\n");
37 qcms_profile_release(sRGB); 37 qcms_profile_release(sRGB);
38 qcms_profile_release(target); 38 qcms_profile_release(target);
39 return EXIT_FAILURE; 39 return EXIT_FAILURE;
40 } 40 }
41 41
42 *size = qcms_transform_get_output_trc_rgba(transform, target, QCMS_TRC_USHOR T, NULL); 42 *size = qcms_transform_get_output_trc_rgba(transform, target, QCMS_TRC_USHOR T, NULL);
43 assert(*size == 256); 43 assert(*size >= 256);
44 44
45 *table = malloc(*size * sizeof(uint16_t) * 4); 45 *table = malloc(*size * sizeof(uint16_t) * 4);
46 qcms_transform_get_output_trc_rgba(transform, target, QCMS_TRC_USHORT, *tabl e); 46 qcms_transform_get_output_trc_rgba(transform, target, QCMS_TRC_USHORT, *tabl e);
47 47
48 qcms_transform_release(transform); 48 qcms_transform_release(transform);
49 qcms_profile_release(sRGB); 49 qcms_profile_release(sRGB);
50 qcms_profile_release(target); 50 qcms_profile_release(target);
51 51
52 return 0; 52 return 0;
53 } 53 }
(...skipping 14 matching lines...) Expand all
68 68
69 transform = qcms_transform_create(source, QCMS_DATA_RGBA_8, sRGB, QCMS_DATA_ RGBA_8, QCMS_INTENT_DEFAULT); 69 transform = qcms_transform_create(source, QCMS_DATA_RGBA_8, sRGB, QCMS_DATA_ RGBA_8, QCMS_INTENT_DEFAULT);
70 if (!transform) { 70 if (!transform) {
71 fprintf(stderr, "Failed to create colour transform\n"); 71 fprintf(stderr, "Failed to create colour transform\n");
72 qcms_profile_release(sRGB); 72 qcms_profile_release(sRGB);
73 qcms_profile_release(source); 73 qcms_profile_release(source);
74 return EXIT_FAILURE; 74 return EXIT_FAILURE;
75 } 75 }
76 76
77 *size = qcms_transform_get_input_trc_rgba(transform, source, QCMS_TRC_USHORT , NULL); 77 *size = qcms_transform_get_input_trc_rgba(transform, source, QCMS_TRC_USHORT , NULL);
78 assert(*size == 256); 78 assert(*size >= 256);
79 79
80 *table = calloc(*size, sizeof(uint16_t) * 4); 80 *table = calloc(*size, sizeof(uint16_t) * 4);
81 qcms_transform_get_input_trc_rgba(transform, source, QCMS_TRC_USHORT, *table ); 81 qcms_transform_get_input_trc_rgba(transform, source, QCMS_TRC_USHORT, *table );
82 82
83 qcms_transform_release(transform); 83 qcms_transform_release(transform);
84 qcms_profile_release(sRGB); 84 qcms_profile_release(sRGB);
85 qcms_profile_release(source); 85 qcms_profile_release(source);
86 86
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 qcms_profile *profile; 97 qcms_profile *profile;
98 uint16_t *gamma_table_out; 98 uint16_t *gamma_table_out;
99 size_t gamma_table_size; 99 size_t output_size;
100 size_t i; 100 size_t i;
101 101
102 printf("Test qcms output gamma curve table integrity.\n"); 102 printf("Test qcms output gamma curve table integrity.\n");
103 103
104 if (!in_path) { 104 if (!in_path) {
105 fprintf(stderr, "%s: please provide valid ICC profiles via -i option\n", __FUNCTION__); 105 fprintf(stderr, "%s: please provide valid ICC profiles via -i option\n", __FUNCTION__);
106 return EXIT_FAILURE; 106 return EXIT_FAILURE;
107 } 107 }
108 108
109 // Create profiles and transforms, get table and then free resources to make sure none 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. 110 // of the internal tables are initialized by previous calls.
111 gamma_table_out = NULL; 111 gamma_table_out = NULL;
112 gamma_table_size = 0; 112 output_size = 0;
113 if (get_output_gamma_table(in_path, &gamma_table_out, &gamma_table_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("LUT size = %zu\n", gamma_table_size); 118 printf("LUT 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. 127 // Check only for red curve for now.
128 if (profile->redTRC->type == PARAMETRIC_CURVE_TYPE) { 128 if (profile->redTRC->type == PARAMETRIC_CURVE_TYPE) {
129 int type = - (int)(profile->redTRC->count + 1); 129 int type = - (int)(profile->redTRC->count + 1);
130 FILE *gamma_file;
131 uint16_t *gamma_table_in = NULL; 130 uint16_t *gamma_table_in = NULL;
132 uint16_t *p_table_out, *p_table_in;
133 char file_name[256] = {0,};
134 size_t input_size = 0; 131 size_t input_size = 0;
132 float scale_factor;
133 FILE *output_file;
134 char output_file_name[1024];
135 long int time_stamp = (long int)time(NULL);
135 136
136 printf("Detected parametric curve type = %d\n", profile->redTRC->count); 137 printf("Detected parametric curve type = %d\n", profile->redTRC->count);
137 138
138 sprintf(file_name, "qcms-test-%ld-parametric-gamma-%s.csv", (long int)ti me(NULL), profile->description); 139 sprintf(output_file_name, "qcms-test-%ld-parametric-gamma-output-%s.csv" , time_stamp, profile->description);
139 printf("Writing input and output gamma tables to %s\n", file_name); 140 printf("Writing output gamma tables to %s\n", output_file_name);
140 141
141 printf("gamma = %.6f, a = %.6f, b = %.6f, c = %.6f, d = %.6f, e = %.6f, f = %.6f\n", 142 printf("gamma = %.6f, a = %.6f, b = %.6f, c = %.6f, d = %.6f, e = %.6f, f = %.6f\n",
142 profile->redTRC->parameter[0], profile->redTRC->parameter[1], pr ofile->redTRC->parameter[2], 143 profile->redTRC->parameter[0], profile->redTRC->parameter[1], pr ofile->redTRC->parameter[2],
143 profile->redTRC->parameter[3], profile->redTRC->parameter[4], pr ofile->redTRC->parameter[5], 144 profile->redTRC->parameter[3], profile->redTRC->parameter[4], pr ofile->redTRC->parameter[5],
144 profile->redTRC->parameter[6]); 145 profile->redTRC->parameter[6]);
145 146
146 // Write output to stdout and tables into a csv file. 147 // Write output to stdout and tables into a csv file.
147 gamma_file = fopen(file_name, "w"); 148 output_file = fopen(output_file_name, "w");
148 fprintf(gamma_file, "Parametric gamma values for %s\n", profile->descrip tion); 149 fprintf(output_file, "Parametric gamma values for %s\n", profile->descri ption);
149 fprintf(gamma_file, "gamma, a, b, c, d, e, f\n"); 150 fprintf(output_file, "gamma, a, b, c, d, e, f\n");
150 fprintf(gamma_file, "%.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f\n", 151 fprintf(output_file, "%.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f\n",
151 profile->redTRC->parameter[0], profile->redTRC->parameter[1], pr ofile->redTRC->parameter[2], 152 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[3], profile->redTRC->parameter[4], pr ofile->redTRC->parameter[5],
153 profile->redTRC->parameter[6]); 154 profile->redTRC->parameter[6]);
154 155
155 get_input_gamma_table(in_path, &gamma_table_in, &input_size); 156 get_input_gamma_table(in_path, &gamma_table_in, &input_size);
156 assert(input_size == gamma_table_size);
157 if (!gamma_table_in) { 157 if (!gamma_table_in) {
158 fprintf(stderr, "Unable to compute input trc. Aborting\n"); 158 fprintf(stderr, "Unable to compute input trc. Aborting\n");
159 fclose(gamma_file); 159 fclose(output_file);
160 qcms_profile_release(profile); 160 qcms_profile_release(profile);
161 free(gamma_table_out); 161 free(gamma_table_out);
162 return EXIT_FAILURE; 162 return EXIT_FAILURE;
163 } 163 }
164 164
165 fprintf(gamma_file, "\n\nInput gamma, Output gamma, LCMS Output gamma, O utput gamma error\n"); 165 scale_factor = (float)(output_size - 1) / (input_size - 1);
166 166
167 p_table_out = gamma_table_out; 167 fprintf(output_file, "\nInput curve size: %zu\nOutput curve size: %zu\n" , input_size, output_size);
168 p_table_in = gamma_table_in; 168 fprintf(output_file, "\n\nInput gamma, Output gamma, LCMS Output gamma, Output gamma error\n");
169 169
170 for (i = 0; i < gamma_table_size; ++i) { 170 for (i = 0; i < input_size; ++i) {
171 float p = i / (gamma_table_size * 1.0); 171 float input = gamma_table_in[i * 4] * inverse65535;
172 float reference_out = clamp_float(evaluate_parametric_curve(type, pr ofile->redTRC->parameter, p)); 172 size_t out_index = (size_t)floor( i * scale_factor + 0.5);
Noel Gordon 2016/04/28 08:26:45 floor( i * -> floor(i *
radu.velea 2016/04/28 08:33:44 Done.
173 float actual_out = *p_table_out * inverse65535; 173 float p = out_index / ((output_size - 1) * 1.0);
Noel Gordon 2016/04/28 08:26:45 (output_size - 1.0); here? Please check locally t
radu.velea 2016/04/28 08:33:44 Done.
174 float error_out = fabs(actual_out - reference_out); 174 float reference = clamp_float(evaluate_parametric_curve(type, profil e->redTRC->parameter, p));
175 float input = *p_table_in * inverse65535; 175 float actual = gamma_table_out[out_index * 4] * inverse65535;
176 float difference = fabs(actual - reference);
176 177
177 fprintf(gamma_file, "%.6f, %.6f, %6f, %6f\n",input, actual_out, refe rence_out, error_out); 178 fprintf(output_file, "%.6f, %.6f, %6f, %6f\n", input, actual, refere nce, difference);
178
179 p_table_out += 4; // Skip other channels.
180 p_table_in += 4; // Skip other channels.
181 } 179 }
182 180
181 fprintf(output_file, "\nNote: the output curves we down sampled by a fac tor of %zu / %zu\n",
182 output_size, input_size);
183
184 fclose(output_file);
183 free(gamma_table_in); 185 free(gamma_table_in);
184 fclose(gamma_file);
185 } 186 }
186 187
187 qcms_profile_release(profile); 188 qcms_profile_release(profile);
188 free(gamma_table_out); 189 free(gamma_table_out);
189 190
190 return 0; 191 return 0;
191 } 192 }
192 193
193 struct qcms_test_case qcms_test_output_trc_info = { 194 struct qcms_test_case qcms_test_output_trc_info = {
194 "qcms_test_output_trc", 195 "qcms_test_output_trc",
195 qcms_test_output_trc, 196 qcms_test_output_trc,
196 QCMS_TEST_DISABLED 197 QCMS_TEST_DISABLED
197 }; 198 };
OLDNEW
« no previous file with comments | « third_party/qcms/README.chromium ('k') | third_party/qcms/src/transform_util.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698