| OLD | NEW |
| (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 #include "timing.h" |
| 8 |
| 9 #include <math.h> |
| 10 #include <stdio.h> |
| 11 #include <stdlib.h> |
| 12 #include <string.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 int qcms_test_munsell(size_t width, |
| 83 size_t height, |
| 84 int iterations, |
| 85 const char *in_path, |
| 86 const char *out_path, |
| 87 const int force_software) |
| 88 { |
| 89 qcms_profile *in_profile = NULL, *out_profile = NULL; |
| 90 qcms_transform *transform; |
| 91 qcms_format_type format = {0, 2}; |
| 92 struct color_checker_chart *source_munsell = srgb_munsell; |
| 93 struct color_checker_chart *reference_munsell = srgb_munsell; |
| 94 float rmse = 0.0f; |
| 95 int diff[24] = {0,}; |
| 96 struct color_checker_chart destination_munsell[24]; |
| 97 char file_name[256]; |
| 98 |
| 99 FILE *output; |
| 100 |
| 101 int i; |
| 102 |
| 103 printf("Test qcms data transforms accuracy using Munsell colours\n"); |
| 104 fflush(stdout); |
| 105 |
| 106 seconds(); |
| 107 |
| 108 if (in_path == NULL || out_path == NULL) { |
| 109 fprintf(stderr, "%s:Please provide valid icc profiles via -i/o option\n"
, __FUNCTION__); |
| 110 return EXIT_FAILURE; |
| 111 } |
| 112 |
| 113 in_profile = qcms_profile_from_path(in_path); |
| 114 if (!in_profile || qcms_profile_is_bogus(in_profile)) { |
| 115 fprintf(stderr, "Invalid input profile\n"); |
| 116 return EXIT_FAILURE; |
| 117 } |
| 118 |
| 119 if (strstr(in_profile->description, "Adobe") != NULL) { |
| 120 source_munsell = adobe_munsell; |
| 121 } |
| 122 |
| 123 printf("Input profile %s\n", in_profile->description); |
| 124 |
| 125 out_profile = qcms_profile_from_path(out_path); |
| 126 if (!out_profile || qcms_profile_is_bogus(out_profile)) { |
| 127 fprintf(stderr, "Invalid output profile\n"); |
| 128 return EXIT_FAILURE; |
| 129 } |
| 130 |
| 131 if (strstr(out_profile->description, "Adobe") != NULL) { |
| 132 reference_munsell = adobe_munsell; |
| 133 } |
| 134 |
| 135 printf("Output profile %s\n", out_profile->description); |
| 136 |
| 137 qcms_profile_precache_output_transform(out_profile); |
| 138 transform = qcms_transform_create(in_profile, QCMS_DATA_RGBA_8, out_profile,
QCMS_DATA_RGBA_8, QCMS_INTENT_DEFAULT); |
| 139 if (!transform) { |
| 140 fprintf(stderr, "Unable to create transform\n"); |
| 141 return EXIT_FAILURE; |
| 142 } |
| 143 |
| 144 if (force_software) |
| 145 transform->transform_fn = qcms_transform_data_rgba_out_lut_precache; |
| 146 |
| 147 for (i = 0; i < 24; i++) { |
| 148 transform->transform_fn(transform, &source_munsell[i].r, &destination_mu
nsell[i].r, 1, format); |
| 149 int r_diff = reference_munsell[i].r - destination_munsell[i].r; |
| 150 int g_diff = reference_munsell[i].g - destination_munsell[i].g; |
| 151 int b_diff = reference_munsell[i].b - destination_munsell[i].b; |
| 152 diff[i] = abs(r_diff) + abs(g_diff) + abs(b_diff); |
| 153 rmse += sqrt(r_diff * r_diff + g_diff * g_diff + b_diff * b_diff); |
| 154 } |
| 155 |
| 156 rmse = rmse / 24; |
| 157 printf("Transform RMSE %.3f\n", rmse); |
| 158 |
| 159 // Name and open file. |
| 160 sprintf(file_name, "qcms_test_munsell_%ld_RMS_%.3f.csv", (long int)time(NULL
), rmse); |
| 161 output = fopen(file_name, "w"); |
| 162 |
| 163 // Print header. |
| 164 if (force_software) |
| 165 fprintf(output, "Report for: qcms_transform_data_rgba_out_lut_precache\n
\n"); |
| 166 else |
| 167 fprintf(output, "Report for: qcms_transform_data_rgba_out_lut_sse2\n\n")
; |
| 168 |
| 169 fprintf(output, "color name," |
| 170 "Output %s[R],Output %s[G], Output %s[B]," |
| 171 "Reference %s[R],Reference %s[G],Reference %s[B],diff\n", |
| 172 out_profile->description, out_profile->description, out_profile->des
cription, |
| 173 out_profile->description, out_profile->description, out_profile->des
cription); |
| 174 |
| 175 // Print results. |
| 176 for (i = 0; i < 24; i++) { |
| 177 fprintf(output, "%s,%d,%d,%d,%d,%d,%d,%d\n", |
| 178 source_munsell[i].name, |
| 179 destination_munsell[i].r, destination_munsell[i].g, destination_
munsell[i].b, |
| 180 reference_munsell[i].r, reference_munsell[i].g, reference_munsel
l[i].b, diff[i]); |
| 181 } |
| 182 fprintf(output, "\nRMSE = %.4f\n", rmse); |
| 183 fclose(output); |
| 184 |
| 185 printf("Output written to %s\n", file_name); |
| 186 return rmse > 0.000001f; |
| 187 } |
| 188 |
| 189 struct qcms_test_case qcms_test_munsell_info = { |
| 190 "qcms_test_munsell", |
| 191 qcms_test_munsell, |
| 192 QCMS_TEST_DISABLED |
| 193 }; |
| OLD | NEW |