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

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

Issue 2014023003: Add exact version of qcms used by Chrome for testing and comparison (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 6 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 2015 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 <string.h>
12 #include <time.h>
13
14 struct color_checker_chart {
15 char* name;
16 unsigned char r;
17 unsigned char g;
18 unsigned char b;
19 unsigned char a;
20 };
21
22 struct color_checker_chart adobe_munsell[24] = {
23 { "Dark Skin", 106, 81, 67, 255 },
24 { "Light Skin", 182, 149, 130, 255 },
25 { "Blue Sky", 103, 122, 154, 255 },
26 { "Foliage", 95, 108, 69, 255 },
27 { "Blue Flower", 129, 128, 174, 255 },
28 { "Bluish Green", 133, 189, 170, 255 },
29 { "Orange", 194, 121, 48, 255 },
30 { "Purplish Blue", 79, 91, 162, 255 },
31 { "Moderate Red", 170, 85, 97, 255 },
32 { "Purple", 84, 62, 105, 255 },
33 { "Yellow Green", 167, 186, 73, 255 },
34 { "Orange Yellow", 213, 162, 57, 255 },
35 { "Blue", 54, 62, 149, 255 },
36 { "Green", 101, 148, 76, 255 },
37 { "Red", 152, 48, 58, 255 },
38 { "Yellow", 228, 199, 55, 255 },
39 { "Magenta", 164, 83, 144, 255 },
40 { "Cyan", 63, 134, 163, 255 },
41 { "White", 242, 241, 236, 255 },
42 { "Neutral 8", 200, 200, 199, 255 },
43 { "Neutral 6.5", 159, 160, 159, 255 },
44 { "Neutral 5", 122, 121, 120, 255 },
45 { "Neutral 3.5", 84, 84, 84, 255 },
46 { "Black", 53, 53, 53, 255 },
47 };
48
49 struct color_checker_chart srgb_munsell[24] = {
50 { "Dark Skin", 115, 80, 64, 255 },
51 { "Light Skin", 195, 151, 130, 255 },
52 { "Blue Sky", 94, 123, 156, 255 },
53 { "Foliage", 88, 108, 65, 255 },
54 { "Blue Flower", 130, 129, 177, 255 },
55 { "Bluish Green", 100, 190, 171, 255 },
56 { "Orange", 217, 122, 37, 255 },
57 { "Purplish Blue", 72, 91, 165, 255 },
58 { "Moderate Red", 194, 84, 98, 255 },
59 { "Purple", 91, 59, 107, 255 },
60 { "Yellow Green", 160, 188, 60, 255 },
61 { "Orange Yellow", 230, 163, 42, 255 },
62 { "Blue", 46, 60, 153, 255 },
63 { "Green", 71, 150, 69, 255 },
64 { "Red", 177, 44, 56, 255 },
65 { "Yellow", 238, 200, 27, 255 },
66 { "Magenta", 187, 82, 148, 255 },
67 { "Cyan", /* -49 */ 0, 135, 166, 255 },
68 { "White", 243, 242, 237, 255 },
69 { "Neutral 8",201, 201, 201, 255 },
70 { "Neutral 6.5", 161, 161, 161, 255 },
71 { "Neutral 5",122, 122, 121, 255 },
72 { "Neutral 3.5", 83, 83, 83, 255 },
73 { "Black", 50, 49, 50, 255 },
74 };
75
76 extern void qcms_transform_data_rgba_out_lut_precache(qcms_transform *transform,
77 unsigned char *src,
78 unsigned char *dest,
79 size_t length,
80 qcms_format_type output_format);
81
82 static qcms_bool invalid_rgb_color_profile(qcms_profile *profile)
83 {
84 return rgbData != qcms_profile_get_color_space(profile) || qcms_profile_is_b ogus(profile);
85 }
86
87 static int color_error(struct color_checker_chart cx, struct color_checker_chart cy)
88 {
89 int dr = cx.r - cy.r;
90 int dg = cx.g - cy.g;
91 int db = cx.b - cy.b;
92
93 return round(sqrt((dr * dr) + (dg * dg) + (db * db)));
94 }
95
96 static qcms_profile* open_profile_from_path(const char *path)
97 {
98 if (strcmp(path, "internal-srgb") != 0)
99 return qcms_profile_from_path(path);
100 return qcms_profile_sRGB();
101 }
102
103 static int qcms_test_munsell(size_t width,
104 size_t height,
105 int iterations,
106 const char *in_path,
107 const char *out_path,
108 const int force_software)
109 {
110 qcms_profile *in_profile = NULL;
111 qcms_profile *out_profile = NULL;
112 qcms_format_type format = {0, 2}; // RGBA
113 qcms_transform *transform;
114
115 struct color_checker_chart *source_munsell = NULL;
116 struct color_checker_chart *reference_munsell = NULL;
117 struct color_checker_chart destination_munsell[24];
118
119 char file_name[256];
120 FILE *output;
121 int dE[24];
122 float rmse;
123
124 int i;
125
126 printf("Test qcms data transform accuracy using Munsell colors\n");
127 fflush(stdout);
128
129 if (in_path == NULL || out_path == NULL) {
130 fprintf(stderr, "%s: please provide valid ICC profiles via -i/o options\ n", __FUNCTION__);
131 return EXIT_FAILURE;
132 }
133
134 in_profile = open_profile_from_path(in_path);
135 if (!in_profile || invalid_rgb_color_profile(in_profile)) {
136 fprintf(stderr, "Invalid input profile\n");
137 return EXIT_FAILURE;
138 }
139
140 source_munsell = srgb_munsell;
141 if (strstr(in_profile->description, "Adobe") != NULL) {
142 source_munsell = adobe_munsell;
143 }
144
145 printf("Input profile %s\n", in_profile->description);
146
147 out_profile = open_profile_from_path(out_path);
148 if (!out_profile || invalid_rgb_color_profile(out_profile)) {
149 fprintf(stderr, "Invalid output profile\n");
150 return EXIT_FAILURE;
151 }
152
153 reference_munsell = srgb_munsell;
154 if (strstr(out_profile->description, "Adobe") != NULL) {
155 reference_munsell = adobe_munsell;
156 }
157
158 printf("Output profile %s (using qcms precache)\n", out_profile->description );
159 qcms_profile_precache_output_transform(out_profile);
160
161 transform = qcms_transform_create(in_profile, QCMS_DATA_RGBA_8, out_profile, QCMS_DATA_RGBA_8, QCMS_INTENT_DEFAULT);
162 if (!transform) {
163 fprintf(stderr, "Failed to create color transform\n");
164 return EXIT_FAILURE;
165 } else if (force_software) {
166 transform->transform_fn = qcms_transform_data_rgba_out_lut_precache;
167 }
168
169 if (qcms_profile_match(in_profile, out_profile)) {
170 printf("Note: input / output profiles match\n");
171 }
172
173 rmse = 0.0f;
174
175 for (i = 0; i < 24; i++) {
176 transform->transform_fn(transform, &source_munsell[i].r, &destination_mu nsell[i].r, 1, format);
177 dE[i] = color_error(reference_munsell[i], destination_munsell[i]);
178 rmse += dE[i] * dE[i];
179 }
180
181 rmse = sqrt(rmse / 24);
182 printf("RMS color error %.2f\n", rmse);
183
184 // Name and open test result file.
185 sprintf(file_name, "qcms-test-%ld-munsell-%s-to-%s-rms-%.3f.csv", (long int) time(NULL), in_profile->description, out_profile->description, rmse);
186 // FIXME: remove spaces from the file name?
187 output = fopen(file_name, "w");
188
189 // Print headers.
190 if (force_software)
191 fprintf(output, "Report for: qcms_transform_data_rgba_out_lut_precache\n \n");
192 else
193 fprintf(output, "Report for: qcms_transform_data_rgba_out_lut_sse2\n\n") ;
194
195 fprintf(output, "%14s,\t%s,\t%s,\t%s\n\n", "Color,", "Actual,,", "Expected," , "dE");
196
197 // Print results.
198 for (i = 0; i < 24; i++) {
199 fprintf(output, "%14s,\t%d,%d,%d,\t%d,%d,%d,\t%d\n",
200 source_munsell[i].name,
201 destination_munsell[i].r, destination_munsell[i].g, destination_ munsell[i].b,
202 reference_munsell[i].r, reference_munsell[i].g, reference_munsel l[i].b,
203 dE[i]);
204 }
205
206 fprintf(output, "\nRMS color error = %.2f\n", rmse);
207 fclose(output);
208
209 printf("Output written to %s\n", file_name);
210 return rmse > 0.000001f;
211 }
212
213 struct qcms_test_case qcms_test_munsell_info = {
214 "qcms_test_munsell",
215 qcms_test_munsell,
216 QCMS_TEST_DISABLED
217 };
OLDNEW
« no previous file with comments | « third_party/qcms/src/tests/qcms_test_main.c ('k') | third_party/qcms/src/tests/qcms_test_ntsc_gamut.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698