Chromium Code Reviews| 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 results[24] = {0,}, 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\n"); | |
|
Noel Gordon
2015/10/08 03:12:49
printf("Test qcms data transforms accuracy using M
radu.velea
2015/10/08 09:39:13
Done.
| |
| 104 printf("Test image size 1 x 1 pixels (using Munsell colors)\n"); | |
|
Noel Gordon
2015/10/08 03:12:49
Delete this printf.
radu.velea
2015/10/08 09:39:13
Done.
| |
| 105 fflush(stdout); | |
| 106 | |
| 107 seconds(); | |
| 108 | |
| 109 if (in_path == NULL || out_path == NULL) { | |
| 110 fprintf(stderr, "%s:Please provide valid icc profiles via -i/o option\n" , __FUNCTION__); | |
| 111 return -1; | |
| 112 } | |
| 113 | |
| 114 in_profile = qcms_profile_from_path(in_path); | |
| 115 if (!in_profile || qcms_profile_is_bogus(in_profile)) { | |
| 116 fprintf(stderr, "Invalid input profile\n"); | |
| 117 return -1; | |
| 118 } | |
| 119 | |
| 120 if (strstr(in_profile->description, "Adobe") != NULL) { | |
| 121 source_munsell = adobe_munsell; | |
| 122 } | |
| 123 | |
| 124 printf("Input profile %s\n", in_profile->description); | |
| 125 | |
| 126 out_profile = qcms_profile_from_path(out_path); | |
| 127 if (!out_profile || qcms_profile_is_bogus(out_profile)) { | |
| 128 fprintf(stderr, "Invalid output profile\n"); | |
| 129 return -1; | |
| 130 } | |
| 131 | |
| 132 if (strstr(out_profile->description, "Adobe") != NULL) { | |
| 133 reference_munsell = adobe_munsell; | |
| 134 } | |
| 135 | |
| 136 printf("Output profile %s\n", out_profile->description); | |
| 137 | |
| 138 qcms_profile_precache_output_transform(out_profile); | |
| 139 transform = qcms_transform_create(in_profile, QCMS_DATA_RGBA_8, out_profile, QCMS_DATA_RGBA_8, QCMS_INTENT_DEFAULT); | |
|
Noel Gordon
2015/10/08 03:12:49
Check if the transform is NULL and bail with an er
radu.velea
2015/10/08 09:39:13
Done.
| |
| 140 if (force_software) | |
| 141 transform->transform_fn = qcms_transform_data_rgba_out_lut_precache; | |
| 142 | |
| 143 for (i = 0; i < (sizeof(adobe_munsell) / sizeof(adobe_munsell[0])); i++) { | |
|
Noel Gordon
2015/10/08 03:12:49
(sizeof(adobe_munsell) / sizeof(adobe_munsell[0])
radu.velea
2015/10/08 09:39:13
Done.
| |
| 144 transform->transform_fn(transform, &source_munsell[i].r, &destination_mu nsell[i].r, 1, format); | |
| 145 int r_diff = reference_munsell[i].r - destination_munsell[i].r; | |
| 146 int g_diff = reference_munsell[i].g - destination_munsell[i].g; | |
| 147 int b_diff = reference_munsell[i].b - destination_munsell[i].b; | |
| 148 diff[i] = abs(r_diff) + abs(g_diff) + abs(b_diff); | |
| 149 results[i] = sqrt(r_diff * r_diff + g_diff * g_diff + b_diff * b_diff); | |
|
Noel Gordon
2015/10/08 03:12:49
results[i] is not used other than in this loop. S
radu.velea
2015/10/08 09:39:13
Done.
| |
| 150 rmse += results[i]; | |
| 151 } | |
| 152 | |
| 153 if (rmse != 0) { | |
|
Noel Gordon
2015/10/08 03:12:49
remove the if, always write the RMS error.
radu.velea
2015/10/08 09:39:13
Done.
| |
| 154 printf("Transform RMS %.3f\n", rmse / 24); | |
|
Noel Gordon
2015/10/08 03:12:49
rmse / 24 is computed multiple times below. Why n
radu.velea
2015/10/08 09:39:13
Done.
| |
| 155 } | |
| 156 | |
| 157 // Name and open file. | |
| 158 sprintf(file_name, "qcms_test_munsell_%lu_RMS_%.3f.csv", time(NULL), rmse / 24); | |
|
Noel Gordon
2015/10/08 03:12:49
Use "...munsell_%ld..." and cast the time(NULL) ar
radu.velea
2015/10/08 09:39:13
Done.
| |
| 159 output = fopen(file_name, "w"); | |
| 160 // Print header. | |
|
Noel Gordon
2015/10/08 03:12:49
Space before this line.
radu.velea
2015/10/08 09:39:13
Done.
| |
| 161 if (force_software) | |
| 162 fprintf(output, "Report for: qcms_transform_data_rgba_out_lut_precache\n \n"); | |
| 163 else | |
| 164 fprintf(output, "Report for: qcms_transform_data_rgba_out_lut_sse2\n\n") ; | |
| 165 | |
| 166 fprintf(output, "color name,Input %s[R],Input %s[G],Input %s[B]," | |
|
Noel Gordon
2015/10/08 03:12:49
Remove the input color "Input %s[R],Input %s[G],In
radu.velea
2015/10/08 09:39:13
Done.
| |
| 167 "Output %s[R],Output %s[G], Output %s[B]," | |
| 168 "Reference %s[R],Reference %s[G],Reference %s[B],diff\n", | |
| 169 in_profile->description, in_profile->description, in_profile->descri ption, | |
| 170 out_profile->description, out_profile->description, out_profile->des cription, | |
| 171 out_profile->description, out_profile->description, out_profile->des cription); | |
| 172 // Print results. | |
|
Noel Gordon
2015/10/08 03:12:49
Space before this line.
radu.velea
2015/10/08 09:39:13
Done.
| |
| 173 for (i = 0; i < (sizeof(adobe_munsell) / sizeof(adobe_munsell[0])); i++) { | |
|
Noel Gordon
2015/10/08 03:12:49
(sizeof(adobe_munsell) / sizeof(adobe_munsell[0])
radu.velea
2015/10/08 09:39:13
Done.
| |
| 174 fprintf(output, "%s,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n", | |
| 175 source_munsell[i].name, source_munsell[i].r, source_munsell[i].g , source_munsell[i].b, | |
| 176 destination_munsell[i].r, destination_munsell[i].g, destination_ munsell[i].b, | |
| 177 reference_munsell[i].r, reference_munsell[i].g, reference_munsel l[i].b, diff[i]); | |
| 178 } | |
| 179 fprintf(output, "\nRMSE = %.4f\n", rmse / 24); | |
| 180 fclose(output); | |
| 181 | |
| 182 printf("Output written to %s\n", file_name); | |
| 183 return (rmse / 24) > 0.000001f; | |
| 184 } | |
| 185 | |
| 186 struct qcms_test_case qcms_test_munsell_info = { | |
| 187 "qcms_test_munsell", | |
| 188 qcms_test_munsell, | |
| 189 QCMS_TEST_DISABLED | |
| 190 }; | |
| OLD | NEW |