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); | |
Noel Gordon
2016/04/26 10:44:19
Add a line before this to match what you did in ge
radu.velea
2016/04/26 10:49:15
Done.
| |
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 *size = qcms_transform_get_input_trc_rgba(transform, source, QCMS_TRC_USHORT , NULL); | |
77 assert(*size == 256); | |
78 | |
79 *table = calloc(*size, sizeof(uint16_t) * 4); | |
80 qcms_transform_get_input_trc_rgba(transform, source, QCMS_TRC_USHORT, *table ); | |
81 | |
82 qcms_transform_release(transform); | |
83 qcms_profile_release(sRGB); | |
84 qcms_profile_release(source); | |
85 | |
86 return 0; | |
87 } | |
88 | |
89 static int qcms_test_output_trc(size_t width, | |
90 size_t height, | |
91 int iterations, | |
92 const char *in_path, | |
93 const char *out_path, | |
94 const int force_software) | |
95 { | |
96 qcms_profile *profile; | |
97 uint16_t *gamma_table_out; | |
98 size_t gamma_table_size; | |
99 int i; | |
100 | |
101 printf("Test qcms output gamma curve integrity with and without precached ta bles.\n"); | |
102 | |
103 if (!in_path) { | |
104 fprintf(stderr, "%s: please provide valid ICC profiles via -i option\n", __FUNCTION__); | |
105 return EXIT_FAILURE; | |
106 } | |
107 | |
108 // Create profiles and transforms, get table and then free resources to make sure none | |
109 // of the internal tables are initialized by previous calls. | |
110 gamma_table_out = NULL; | |
111 gamma_table_size = 0; | |
112 if (get_output_gamma_table(in_path, &gamma_table_out, &gamma_table_size) != 0) { | |
113 fprintf(stderr, "Unable to extract output gamma table\n"); | |
114 return EXIT_FAILURE; | |
115 } | |
116 | |
117 printf("LUT size = %zu\n", gamma_table_size); | |
118 | |
119 profile = qcms_profile_from_path(in_path); | |
120 if (!profile) { | |
121 fprintf(stderr, "Invalid input profile\n"); | |
122 free(gamma_table_out); | |
123 return EXIT_FAILURE; | |
124 } | |
125 | |
126 // Check only for red curve for now. | |
127 if (profile->redTRC->type == PARAMETRIC_CURVE_TYPE) { | |
128 int type = - (profile->redTRC->count + 1); | |
129 FILE *gamma_file; | |
130 uint16_t *gamma_table_in = NULL; | |
131 uint16_t *p_table_out, *p_table_in; | |
132 char file_name[256] = {0,}; | |
133 size_t input_size = 0; | |
134 | |
135 printf("Detected parametric curve type = %d\n", profile->redTRC->count); | |
136 | |
137 sprintf(file_name, "qcms-test-%ld-parametric-gamma-%s.csv", (long int)ti me(NULL), profile->description); | |
138 printf("Writing input and output gamma tables to %s\n", file_name); | |
139 | |
140 printf("gamma = %.6f, a = %.6f, b = %.6f, c = %.6f, d = %.6f, e = %.6f, f = %.6f\n", | |
141 profile->redTRC->parameter[0], profile->redTRC->parameter[1], pr ofile->redTRC->parameter[2], | |
142 profile->redTRC->parameter[3], profile->redTRC->parameter[4], pr ofile->redTRC->parameter[5], | |
143 profile->redTRC->parameter[6]); | |
144 | |
145 // Write output to stdout and tables into a csv file. | |
146 gamma_file = fopen(file_name, "w"); | |
147 fprintf(gamma_file, "Parametric gamma values for %s\n", profile->descrip tion); | |
148 fprintf(gamma_file, "gamma, a, b, c, d, e, f\n"); | |
149 fprintf(gamma_file, "%.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f\n", | |
150 profile->redTRC->parameter[0], profile->redTRC->parameter[1], pr ofile->redTRC->parameter[2], | |
151 profile->redTRC->parameter[3], profile->redTRC->parameter[4], pr ofile->redTRC->parameter[5], | |
152 profile->redTRC->parameter[6]); | |
153 | |
154 get_input_gamma_table(in_path, &gamma_table_in, &input_size); | |
155 assert(input_size == gamma_table_size); | |
156 if (!gamma_table_in) { | |
157 fprintf(stderr, "Unable to compute input trc. Aborting\n"); | |
158 fclose(gamma_file); | |
159 qcms_profile_release(profile); | |
160 free(gamma_table_out); | |
161 return EXIT_FAILURE; | |
162 } | |
163 | |
164 fprintf(gamma_file, "\n\nInput gamma, Output gamma, LCMS Output gamma, O utput gamma error\n"); | |
165 | |
166 p_table_out = gamma_table_out; | |
167 p_table_in = gamma_table_in; | |
168 | |
169 for (i = 0; i < gamma_table_size; ++i) { | |
170 float p = i / (gamma_table_size * 1.0); | |
171 float reference_out = clamp_float(evaluate_parametric_curve(type, pr ofile->redTRC->parameter, p)); | |
172 float actual_out = *p_table_out * inverse65535; | |
173 float error_out = fabs(actual_out - reference_out); | |
174 float input = *p_table_in * inverse65535; | |
175 | |
176 fprintf(gamma_file, "%.6f, %.6f, %6f, %6f\n",input, actual_out, refe rence_out, error_out); | |
177 | |
178 p_table_out += 4; // Skip other channels. | |
179 p_table_in += 4; // Skip other channels. | |
180 } | |
181 | |
182 free(gamma_table_in); | |
183 fclose(gamma_file); | |
184 } | |
185 | |
186 qcms_profile_release(profile); | |
187 | |
Noel Gordon
2016/04/26 10:44:19
Nit: remove this line.
radu.velea
2016/04/26 10:49:15
Done.
| |
188 free(gamma_table_out); | |
189 | |
190 return 0; | |
191 } | |
192 | |
193 struct qcms_test_case qcms_test_output_trc_info = { | |
194 "qcms_test_output_trc", | |
195 qcms_test_output_trc, | |
196 QCMS_TEST_DISABLED | |
197 }; | |
OLD | NEW |