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

Unified Diff: third_party/qcms/src/tests/qcms_test_munsell.c

Issue 1374953003: Expand QCMS tests. Add Munsell test for transform accuracy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: third_party/qcms/src/tests/qcms_test_munsell.c
diff --git a/third_party/qcms/src/tests/qcms_test_munsell.c b/third_party/qcms/src/tests/qcms_test_munsell.c
new file mode 100644
index 0000000000000000000000000000000000000000..8ecccdec977d748fe3b5725fdab3055e660962e4
--- /dev/null
+++ b/third_party/qcms/src/tests/qcms_test_munsell.c
@@ -0,0 +1,190 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the Chromium LICENSE file.
+
+#include "qcms.h"
+#include "qcms_test_util.h"
+#include "timing.h"
+
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+struct color_checker_chart {
+ char* name;
+ unsigned char r;
+ unsigned char g;
+ unsigned char b;
+ unsigned char a;
+};
+
+struct color_checker_chart adobe_munsell[24] = {
+ { "Dark Skin", 106, 81, 67, 255 },
+ { "Light Skin", 182, 149, 130, 255 },
+ { "Blue Sky", 103, 122, 154, 255 },
+ { "Foliage", 95, 108, 69, 255 },
+ { "Blue Flower", 129, 128, 174, 255 },
+ { "Bluish Green", 133, 189, 170, 255 },
+ { "Orange", 194, 121, 48, 255 },
+ { "Purplish Blue", 79, 91, 162, 255 },
+ { "Moderate Red", 170, 85, 97, 255 },
+ { "Purple", 84, 62, 105, 255 },
+ { "Yellow Green", 167, 186, 73, 255 },
+ { "Orange Yellow", 213, 162, 57, 255 },
+ { "Blue", 54, 62, 149, 255 },
+ { "Green", 101, 148, 76, 255 },
+ { "Red", 152, 48, 58, 255 },
+ { "Yellow", 228, 199, 55, 255 },
+ { "Magenta", 164, 83, 144, 255 },
+ { "Cyan", 63, 134, 163, 255 },
+ { "White", 242, 241, 236, 255 },
+ { "Neutral 8", 200, 200, 199, 255 },
+ { "Neutral 6.5", 159, 160, 159, 255 },
+ { "Neutral 5", 122, 121, 120, 255 },
+ { "Neutral 3.5", 84, 84, 84, 255 },
+ { "Black", 53, 53, 53, 255 },
+};
+
+struct color_checker_chart srgb_munsell[24] = {
+ { "Dark Skin", 115, 80, 64, 255 },
+ { "Light Skin", 195, 151, 130, 255 },
+ { "Blue Sky", 94, 123, 156, 255 },
+ { "Foliage", 88, 108, 65, 255 },
+ { "Blue Flower", 130, 129, 177, 255 },
+ { "Bluish Green", 100, 190, 171, 255 },
+ { "Orange", 217, 122, 37, 255 },
+ { "Purplish Blue", 72, 91, 165, 255 },
+ { "Moderate Red", 194, 84, 98, 255 },
+ { "Purple", 91, 59, 107, 255 },
+ { "Yellow Green", 160, 188, 60, 255 },
+ { "Orange Yellow", 230, 163, 42, 255 },
+ { "Blue", 46, 60, 153, 255 },
+ { "Green", 71, 150, 69, 255 },
+ { "Red", 177, 44, 56, 255 },
+ { "Yellow", 238, 200, 27, 255 },
+ { "Magenta", 187, 82, 148, 255 },
+ { "Cyan", /* -49 */ 0, 135, 166, 255 },
+ { "White", 243, 242, 237, 255 },
+ { "Neutral 8",201, 201, 201, 255 },
+ { "Neutral 6.5", 161, 161, 161, 255 },
+ { "Neutral 5",122, 122, 121, 255 },
+ { "Neutral 3.5", 83, 83, 83, 255 },
+ { "Black", 50, 49, 50, 255 },
+};
+
+extern void qcms_transform_data_rgba_out_lut_precache(qcms_transform *transform,
+ unsigned char *src,
+ unsigned char *dest,
+ size_t length,
+ qcms_format_type output_format);
+
+static int qcms_test_munsell(size_t width,
+ size_t height,
+ int iterations,
+ const char *in_path,
+ const char *out_path,
+ const int force_software)
+{
+ qcms_profile *in_profile = NULL, *out_profile = NULL;
+ qcms_transform *transform;
+ qcms_format_type format = {0, 2};
+ struct color_checker_chart *source_munsell = srgb_munsell;
+ struct color_checker_chart *reference_munsell = srgb_munsell;
+ float results[24] = {0,}, rmse = 0.0f;
+ int diff[24] = {0,};
+ struct color_checker_chart destination_munsell[24];
+ char file_name[256];
+
+ FILE *output;
+
+ int i;
+
+ 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.
+ 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.
+ fflush(stdout);
+
+ seconds();
+
+ if (in_path == NULL || out_path == NULL) {
+ fprintf(stderr, "%s:Please provide valid icc profiles via -i/o option\n", __FUNCTION__);
+ return -1;
+ }
+
+ in_profile = qcms_profile_from_path(in_path);
+ if (!in_profile || qcms_profile_is_bogus(in_profile)) {
+ fprintf(stderr, "Invalid input profile\n");
+ return -1;
+ }
+
+ if (strstr(in_profile->description, "Adobe") != NULL) {
+ source_munsell = adobe_munsell;
+ }
+
+ printf("Input profile %s\n", in_profile->description);
+
+ out_profile = qcms_profile_from_path(out_path);
+ if (!out_profile || qcms_profile_is_bogus(out_profile)) {
+ fprintf(stderr, "Invalid output profile\n");
+ return -1;
+ }
+
+ if (strstr(out_profile->description, "Adobe") != NULL) {
+ reference_munsell = adobe_munsell;
+ }
+
+ printf("Output profile %s\n", out_profile->description);
+
+ qcms_profile_precache_output_transform(out_profile);
+ 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.
+ if (force_software)
+ transform->transform_fn = qcms_transform_data_rgba_out_lut_precache;
+
+ 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.
+ transform->transform_fn(transform, &source_munsell[i].r, &destination_munsell[i].r, 1, format);
+ int r_diff = reference_munsell[i].r - destination_munsell[i].r;
+ int g_diff = reference_munsell[i].g - destination_munsell[i].g;
+ int b_diff = reference_munsell[i].b - destination_munsell[i].b;
+ diff[i] = abs(r_diff) + abs(g_diff) + abs(b_diff);
+ 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.
+ rmse += results[i];
+ }
+
+ 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.
+ 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.
+ }
+
+ // Name and open file.
+ 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.
+ output = fopen(file_name, "w");
+ // Print header.
Noel Gordon 2015/10/08 03:12:49 Space before this line.
radu.velea 2015/10/08 09:39:13 Done.
+ if (force_software)
+ fprintf(output, "Report for: qcms_transform_data_rgba_out_lut_precache\n\n");
+ else
+ fprintf(output, "Report for: qcms_transform_data_rgba_out_lut_sse2\n\n");
+
+ 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.
+ "Output %s[R],Output %s[G], Output %s[B],"
+ "Reference %s[R],Reference %s[G],Reference %s[B],diff\n",
+ in_profile->description, in_profile->description, in_profile->description,
+ out_profile->description, out_profile->description, out_profile->description,
+ out_profile->description, out_profile->description, out_profile->description);
+ // Print results.
Noel Gordon 2015/10/08 03:12:49 Space before this line.
radu.velea 2015/10/08 09:39:13 Done.
+ 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.
+ fprintf(output, "%s,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
+ source_munsell[i].name, source_munsell[i].r, source_munsell[i].g, source_munsell[i].b,
+ destination_munsell[i].r, destination_munsell[i].g, destination_munsell[i].b,
+ reference_munsell[i].r, reference_munsell[i].g, reference_munsell[i].b, diff[i]);
+ }
+ fprintf(output, "\nRMSE = %.4f\n", rmse / 24);
+ fclose(output);
+
+ printf("Output written to %s\n", file_name);
+ return (rmse / 24) > 0.000001f;
+}
+
+struct qcms_test_case qcms_test_munsell_info = {
+ "qcms_test_munsell",
+ qcms_test_munsell,
+ QCMS_TEST_DISABLED
+};

Powered by Google App Engine
This is Rietveld 408576698