diff options
Diffstat (limited to 'third_party/qcms/src/tests')
-rw-r--r-- | third_party/qcms/src/tests/Makefile | 16 | ||||
-rw-r--r-- | third_party/qcms/src/tests/qcms_test_internal_srgb.c | 155 | ||||
-rw-r--r-- | third_party/qcms/src/tests/qcms_test_main.c | 131 | ||||
-rw-r--r-- | third_party/qcms/src/tests/qcms_test_munsell.c | 217 | ||||
-rw-r--r-- | third_party/qcms/src/tests/qcms_test_ntsc_gamut.c | 74 | ||||
-rw-r--r-- | third_party/qcms/src/tests/qcms_test_output_trc.c | 255 | ||||
-rw-r--r-- | third_party/qcms/src/tests/qcms_test_tetra_clut_rgba.c | 180 | ||||
-rw-r--r-- | third_party/qcms/src/tests/qcms_test_util.c | 280 | ||||
-rw-r--r-- | third_party/qcms/src/tests/qcms_test_util.h | 27 | ||||
-rw-r--r-- | third_party/qcms/src/tests/timing.h | 51 |
10 files changed, 0 insertions, 1386 deletions
diff --git a/third_party/qcms/src/tests/Makefile b/third_party/qcms/src/tests/Makefile deleted file mode 100644 index 4adb7e217f..0000000000 --- a/third_party/qcms/src/tests/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -CC=gcc -INCLUDE=-I../ -WALL=-Wall -CFLAGS=-O2 -msse2 $(WALL) -DSSE2_ENABLE -LDFLAGS=-lm - -QCMS=../transform.c ../transform-sse2.c ../transform_util.c ../matrix.c ../iccread.c ../chain.c ../qcms_util.c -OBJS=$(QCMS:.c=.o) - -all: qcms_tests - -qcms_tests: qcms_test_*.c $(OBJS) - $(CC) $(CFLAGS) $(INCLUDE) $^ -o $@ $(LDFLAGS) - -clean: - rm -rf qcms_tests *.o $(OBJS) diff --git a/third_party/qcms/src/tests/qcms_test_internal_srgb.c b/third_party/qcms/src/tests/qcms_test_internal_srgb.c deleted file mode 100644 index dac55f339f..0000000000 --- a/third_party/qcms/src/tests/qcms_test_internal_srgb.c +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright 2016 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 <assert.h> -#include <math.h> // sqrt -#include <stdio.h> -#include <stdint.h> -#include <stdlib.h> - -#ifndef DISPLAY_DEVICE_PROFILE -#define DISPLAY_DEVICE_PROFILE 0x6d6e7472 // 'mntr' -#endif - -// D50 adapted color primaries of the internal sRGB color profile. -static s15Fixed16Number sRGB_reference[3][3] = { - { 0x06fa0, 0x06296, 0x024a0 }, // ( 0.436035, 0.385101, 0.143066 ) - { 0x038f2, 0x0b789, 0x00f85 }, // ( 0.222443, 0.716934, 0.060623 ) - { 0x0038f, 0x018da, 0x0b6c4 }, // ( 0.013901, 0.097076, 0.713928 ) -}; - -// Reference media white point of the sRGB IEC61966-2.1 color profile. -static struct XYZNumber D65 = { - 0xf351, 0x10000, 0x116cc // ( 0.950455, 1.000000, 1.089050 ) -}; - -static void check_profile_description(qcms_profile *profile) -{ - printf("Test profile description:\n"); - - const char* description = qcms_profile_get_description(profile); - printf("description=[%s]\n\n", description); -} - -static void check_profile_pcs_white_point(const qcms_profile *profile) -{ - float rX = s15Fixed16Number_to_float(profile->redColorant.X); - float gX = s15Fixed16Number_to_float(profile->greenColorant.X); - float bX = s15Fixed16Number_to_float(profile->blueColorant.X); - float rY = s15Fixed16Number_to_float(profile->redColorant.Y); - float gY = s15Fixed16Number_to_float(profile->greenColorant.Y); - float bY = s15Fixed16Number_to_float(profile->blueColorant.Y); - float rZ = s15Fixed16Number_to_float(profile->redColorant.Z); - float gZ = s15Fixed16Number_to_float(profile->greenColorant.Z); - float bZ = s15Fixed16Number_to_float(profile->blueColorant.Z); - - printf("Test PCS white point against expected D50 XYZ values\n"); - - float X = rX + gX + bX; - float Y = rY + gY + bY; - float Z = rZ + gZ + bZ; - - float x = X / (X + Y + Z); - float y = Y / (X + Y + Z); - - printf("Computed profile D50 White point xyY = [%.6f %.6f %.6f]\n", x, y, Y); - - float xerr = x - 0.345702915; // Compute error to ICC spec D50 xyY. - float yerr = y - 0.358538597; - float Yerr = Y - 1.000000000; - - printf("D50 white point error = %.6f\n\n", (float) - sqrt((xerr * xerr) + (yerr * yerr) + (Yerr * Yerr))); -} - -static void check_profile_media_white_point(const qcms_profile *profile) -{ - int errX = profile->mediaWhitePoint.X - D65.X; - int errY = profile->mediaWhitePoint.Y - D65.Y; - int errZ = profile->mediaWhitePoint.Z - D65.Z; - - printf("Test media white point against expected D65 XYZ values\n"); - printf("Internal profile D65 values = [0x%X, 0x%X, 0x%X]\n", - profile->mediaWhitePoint.X, profile->mediaWhitePoint.Y, profile->mediaWhitePoint.Z); - printf("D65 media white point error = [%d, %d, %d]\n\n", errX, errY, errZ); -} - -static s15Fixed16Number check_profile_primaries(const qcms_profile *profile) -{ - s15Fixed16Number sRGB_internal[3][3]; - s15Fixed16Number primary_error; - int i, j; - - printf("Test qcms internal sRGB color primaries\n"); - - sRGB_internal[0][0] = profile->redColorant.X; - sRGB_internal[1][0] = profile->redColorant.Y; - sRGB_internal[2][0] = profile->redColorant.Z; - sRGB_internal[0][1] = profile->greenColorant.X; - sRGB_internal[1][1] = profile->greenColorant.Y; - sRGB_internal[2][1] = profile->greenColorant.Z; - sRGB_internal[0][2] = profile->blueColorant.X; - sRGB_internal[1][2] = profile->blueColorant.Y; - sRGB_internal[2][2] = profile->blueColorant.Z; - - primary_error = 0; - for (i = 0; i < 3; i++) { - for (j = 0; j < 3; j++) { - s15Fixed16Number tmp = sRGB_internal[i][j] - sRGB_reference[i][j]; - printf(" %d", tmp); - primary_error += abs(tmp); - } - printf("\n"); - } - - return primary_error; -} - -static int qcms_test_internal_srgb(size_t width, - size_t height, - int iterations, - const char *in_path, - const char *out_path, - const int force_software) -{ - s15Fixed16Number primary_error; - - qcms_profile *profile = qcms_profile_sRGB(); - - assert(profile->class == DISPLAY_DEVICE_PROFILE); - assert(profile->rendering_intent == QCMS_INTENT_PERCEPTUAL); - assert(profile->color_space == RGB_SIGNATURE); - assert(profile->pcs == XYZ_SIGNATURE); - - if (qcms_profile_is_bogus(profile)) { - fprintf(stderr, "Failure: the internal sRGB profile failed the bogus profile check\n"); - qcms_profile_release(profile); - return -1; - } - - // Compute tristimulus matrix error. - primary_error = check_profile_primaries(profile); - printf("Total primary error = 0x%x [%.6f]\n\n", primary_error, primary_error / 65536.0); - - // Verify media white point correctness. - check_profile_media_white_point(profile); - - // Verify PCS white point correctness. - check_profile_pcs_white_point(profile); - - // Output profile description. - check_profile_description(profile); - - qcms_profile_release(profile); - return primary_error; -} - -struct qcms_test_case qcms_test_internal_srgb_info = { - "qcms_test_internal_srgb", - qcms_test_internal_srgb, - QCMS_TEST_DISABLED -}; diff --git a/third_party/qcms/src/tests/qcms_test_main.c b/third_party/qcms/src/tests/qcms_test_main.c deleted file mode 100644 index 455d17b4ab..0000000000 --- a/third_party/qcms/src/tests/qcms_test_main.c +++ /dev/null @@ -1,131 +0,0 @@ -// 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> - -// Manually update the items below to add more tests. -extern struct qcms_test_case qcms_test_tetra_clut_rgba_info; -extern struct qcms_test_case qcms_test_munsell_info; -extern struct qcms_test_case qcms_test_internal_srgb_info; -extern struct qcms_test_case qcms_test_ntsc_gamut_info; -extern struct qcms_test_case qcms_test_output_trc_info; - -struct qcms_test_case qcms_test[5]; -#define TEST_CASES (sizeof(qcms_test) / sizeof(qcms_test[0])) - -static void initialize_tests() -{ - qcms_test[0] = qcms_test_tetra_clut_rgba_info; - qcms_test[1] = qcms_test_munsell_info; - qcms_test[2] = qcms_test_internal_srgb_info; - qcms_test[3] = qcms_test_ntsc_gamut_info; - qcms_test[4] = qcms_test_output_trc_info; -} - -static void list_tests() -{ - int i; - printf("Available qcms tests:\n"); - - for (i = 0; i < TEST_CASES; ++i) { - printf("\t%s\n", qcms_test[i].test_name); - } - - exit(EXIT_FAILURE); -} - -static void print_usage() -{ - printf("Usage:\n\tqcms_test -w WIDTH -h HEIGHT -n ITERATIONS -t TEST\n"); - printf("\t-w INT\t\ttest image width\n"); - printf("\t-h INT\t\ttest image height\n"); - printf("\t-n INT\t\tnumber of iterations for each test\n"); - printf("\t-a\t\trun all tests\n"); - printf("\t-l\t\tlist available tests\n"); - printf("\t-s \t\tforce software(non-sse) transform function, where available\n"); - printf("\t-i STRING\tspecify input icc color profile\n"); - printf("\t-o STRING\tspecify output icc color profile\n"); - printf("\t-t STRING\trun specific test - use \"-l\" to list possible values\n"); - printf("\n"); - exit(1); -} - -int enable_test(const char *args) -{ - int i; - - if (!args) - return 0; - - for (i = 0; i < TEST_CASES; ++i) { - if (strcmp(qcms_test[i].test_name, args) == 0) { - qcms_test[i].status = QCMS_TEST_ENABLED; - return 1; - } - } - - return 0; -} - -int main(int argc, const char **argv) -{ - int iterations = 1; - size_t height = 2000; - size_t width = 2000; - int run_all = 0; - const char *in = NULL, *out = NULL; - int force_software = 0; - int exit_status; - int enabled_tests = 0; - int i; - - initialize_tests(); - seconds(); - - if (argc == 1) { - print_usage(); - } - - while (argc > 1) { - if (strcmp(argv[1], "-n") == 0) - iterations = abs(atoi(argv[2])); - else if (strcmp(argv[1], "-w") == 0) - width = (size_t) abs(atoi(argv[2])); - else if (strcmp(argv[1], "-h") == 0) - height = (size_t) abs(atoi(argv[2])); - else if (strcmp(argv[1], "-l") == 0) - list_tests(); - else if (strcmp(argv[1], "-t") == 0) - enabled_tests += enable_test(argv[2]); - else if (strcmp(argv[1], "-a") == 0) - run_all = 1; - else if (strcmp(argv[1], "-i") == 0) - in = argv[2]; - else if (strcmp(argv[1], "-o") == 0) - out = argv[2]; - else if (strcmp(argv[1], "-s") == 0) - force_software = 1; - (--argc, ++argv); - } - - if (!run_all && !enabled_tests) { - print_usage(); - } - - exit_status = 0; - - for (i = 0; i < TEST_CASES; ++i) { - if (run_all || QCMS_TEST_ENABLED == qcms_test[i].status) - exit_status += qcms_test[i].test_fn(width, height, iterations, in, out, force_software); - } - - return exit_status; -} diff --git a/third_party/qcms/src/tests/qcms_test_munsell.c b/third_party/qcms/src/tests/qcms_test_munsell.c deleted file mode 100644 index 8df3570eb0..0000000000 --- a/third_party/qcms/src/tests/qcms_test_munsell.c +++ /dev/null @@ -1,217 +0,0 @@ -// 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 <math.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.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 qcms_bool invalid_rgb_color_profile(qcms_profile *profile) -{ - return rgbData != qcms_profile_get_color_space(profile) || qcms_profile_is_bogus(profile); -} - -static int color_error(struct color_checker_chart cx, struct color_checker_chart cy) -{ - int dr = cx.r - cy.r; - int dg = cx.g - cy.g; - int db = cx.b - cy.b; - - return round(sqrt((dr * dr) + (dg * dg) + (db * db))); -} - -static qcms_profile* open_profile_from_path(const char *path) -{ - if (strcmp(path, "internal-srgb") != 0) - return qcms_profile_from_path(path); - return qcms_profile_sRGB(); -} - -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; - qcms_profile *out_profile = NULL; - qcms_format_type format = {0, 2}; // RGBA - qcms_transform *transform; - - struct color_checker_chart *source_munsell = NULL; - struct color_checker_chart *reference_munsell = NULL; - struct color_checker_chart destination_munsell[24]; - - char file_name[256]; - FILE *output; - int dE[24]; - float rmse; - - int i; - - printf("Test qcms data transform accuracy using Munsell colors\n"); - fflush(stdout); - - if (in_path == NULL || out_path == NULL) { - fprintf(stderr, "%s: please provide valid ICC profiles via -i/o options\n", __FUNCTION__); - return EXIT_FAILURE; - } - - in_profile = open_profile_from_path(in_path); - if (!in_profile || invalid_rgb_color_profile(in_profile)) { - fprintf(stderr, "Invalid input profile\n"); - return EXIT_FAILURE; - } - - source_munsell = srgb_munsell; - if (strstr(in_profile->description, "Adobe") != NULL) { - source_munsell = adobe_munsell; - } - - printf("Input profile %s\n", in_profile->description); - - out_profile = open_profile_from_path(out_path); - if (!out_profile || invalid_rgb_color_profile(out_profile)) { - fprintf(stderr, "Invalid output profile\n"); - return EXIT_FAILURE; - } - - reference_munsell = srgb_munsell; - if (strstr(out_profile->description, "Adobe") != NULL) { - reference_munsell = adobe_munsell; - } - - printf("Output profile %s (using qcms precache)\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); - if (!transform) { - fprintf(stderr, "Failed to create color transform\n"); - return EXIT_FAILURE; - } else if (force_software) { - transform->transform_fn = qcms_transform_data_rgba_out_lut_precache; - } - - if (qcms_profile_match(in_profile, out_profile)) { - printf("Note: input / output profiles match\n"); - } - - rmse = 0.0f; - - for (i = 0; i < 24; i++) { - transform->transform_fn(transform, &source_munsell[i].r, &destination_munsell[i].r, 1, format); - dE[i] = color_error(reference_munsell[i], destination_munsell[i]); - rmse += dE[i] * dE[i]; - } - - rmse = sqrt(rmse / 24); - printf("RMS color error %.2f\n", rmse); - - // Name and open test result file. - sprintf(file_name, "qcms-test-%ld-munsell-%s-to-%s-rms-%.3f.csv", (long int)time(NULL), in_profile->description, out_profile->description, rmse); - // FIXME: remove spaces from the file name? - output = fopen(file_name, "w"); - - // Print headers. - 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, "%14s,\t%s,\t%s,\t%s\n\n", "Color,", "Actual,,", "Expected,", "dE"); - - // Print results. - for (i = 0; i < 24; i++) { - fprintf(output, "%14s,\t%d,%d,%d,\t%d,%d,%d,\t%d\n", - source_munsell[i].name, - destination_munsell[i].r, destination_munsell[i].g, destination_munsell[i].b, - reference_munsell[i].r, reference_munsell[i].g, reference_munsell[i].b, - dE[i]); - } - - fprintf(output, "\nRMS color error = %.2f\n", rmse); - fclose(output); - - printf("Output written to %s\n", file_name); - return rmse > 0.000001f; -} - -struct qcms_test_case qcms_test_munsell_info = { - "qcms_test_munsell", - qcms_test_munsell, - QCMS_TEST_DISABLED -}; diff --git a/third_party/qcms/src/tests/qcms_test_ntsc_gamut.c b/third_party/qcms/src/tests/qcms_test_ntsc_gamut.c deleted file mode 100644 index 22a702b04b..0000000000 --- a/third_party/qcms/src/tests/qcms_test_ntsc_gamut.c +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2016 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_test_util.h" - -#include <stdio.h> -#include <stdlib.h> -#include <time.h> - -static qcms_bool invalid_rgb_color_profile(qcms_profile *profile) -{ - return rgbData != qcms_profile_get_color_space(profile) || qcms_profile_is_bogus(profile); -} - -static int qcms_test_ntsc_gamut(size_t width, - size_t height, - int iterations, - const char *input_path, - const char *referece_path, - const int force_software) -{ - qcms_profile *input_profile; - qcms_profile *reference_profile = qcms_profile_sRGB(); - qcms_transform *transform; - float input_gamut_metric, reference_gamut_metric; - - if (!input_path) { - fprintf(stderr, "%s: please provide valid ICC profiles via -i/o options\n", __FUNCTION__); - return EXIT_FAILURE; - } - - input_profile = qcms_profile_from_path(input_path); - if (!input_profile || invalid_rgb_color_profile(input_profile)) { - fprintf(stderr, "Invalid input profile\n"); - return EXIT_FAILURE; - } - - transform = qcms_transform_create(input_profile, QCMS_DATA_RGBA_8, reference_profile, QCMS_DATA_RGBA_8, QCMS_INTENT_DEFAULT); - if (!transform) { - fprintf(stderr, "Could not create transform\n"); - return EXIT_FAILURE; - } - - if (!(transform->transform_flags & TRANSFORM_FLAG_MATRIX)) { - fprintf(stderr, "Transform is not matrix\n"); - qcms_transform_release(transform); - qcms_profile_release(input_profile); - qcms_profile_release(reference_profile); - return EXIT_FAILURE; - } - - printf("NTSC 1953 relative gamut area test\n"); - - input_gamut_metric = qcms_profile_ntsc_relative_gamut_size(input_profile); - printf("Input profile\n\tDescription: %s\n\tNTSC relative gamut area: %.3f %%\n", - input_profile->description, input_gamut_metric); - - reference_gamut_metric = qcms_profile_ntsc_relative_gamut_size(reference_profile); - printf("Internal reference profile\n\tDescription: %s\n\tNTSC relative gamut area: %.3f %%\n", - reference_profile->description, reference_gamut_metric); - - qcms_transform_release(transform); - qcms_profile_release(input_profile); - qcms_profile_release(reference_profile); - - return 0; -} - -struct qcms_test_case qcms_test_ntsc_gamut_info = { - "qcms_test_ntsc_gamut", - qcms_test_ntsc_gamut, - QCMS_TEST_DISABLED -}; diff --git a/third_party/qcms/src/tests/qcms_test_output_trc.c b/third_party/qcms/src/tests/qcms_test_output_trc.c deleted file mode 100644 index 049141b634..0000000000 --- a/third_party/qcms/src/tests/qcms_test_output_trc.c +++ /dev/null @@ -1,255 +0,0 @@ -// Copyright 2016 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 <assert.h> -#include <math.h> -#include <stdio.h> -#include <stdlib.h> -#include <time.h> - -#define PARAMETRIC_CURVE_TYPE 0x70617261 // 'para' - -static const float inverse65535 = (float) (1.0 / 65535.0); - -extern float clamp_float(float a); - -static int get_output_gamma_table(const char *profile_path, uint16_t **table, size_t *size) -{ - qcms_transform *transform; - qcms_profile *sRGB; - qcms_profile *target; - - target = qcms_profile_from_path(profile_path); - if (!target) { - fprintf(stderr, "Invalid input profile\n"); - return EXIT_FAILURE; - } - - sRGB = qcms_profile_sRGB(); - - transform = qcms_transform_create(sRGB, QCMS_DATA_RGBA_8, target, QCMS_DATA_RGBA_8, QCMS_INTENT_DEFAULT); - if (!transform) { - fprintf(stderr, "Failed to create colour transform\n"); - qcms_profile_release(sRGB); - qcms_profile_release(target); - return EXIT_FAILURE; - } - - *size = qcms_transform_get_output_trc_rgba(transform, target, QCMS_TRC_USHORT, NULL); - assert(*size >= 256); - - *table = malloc(*size * sizeof(uint16_t) * 4); - qcms_transform_get_output_trc_rgba(transform, target, QCMS_TRC_USHORT, *table); - - qcms_transform_release(transform); - qcms_profile_release(sRGB); - qcms_profile_release(target); - - return 0; -} - -static int get_input_gamma_table(const char *profile_path, uint16_t **table, size_t *size) -{ - qcms_transform *transform; - qcms_profile *source; - qcms_profile *sRGB; - - source = qcms_profile_from_path(profile_path); - if (!source) { - fprintf(stderr, "Invalid input profile\n"); - return EXIT_FAILURE; - } - - sRGB = qcms_profile_sRGB(); - - transform = qcms_transform_create(source, QCMS_DATA_RGBA_8, sRGB, QCMS_DATA_RGBA_8, QCMS_INTENT_DEFAULT); - if (!transform) { - fprintf(stderr, "Failed to create colour transform\n"); - qcms_profile_release(sRGB); - qcms_profile_release(source); - return EXIT_FAILURE; - } - - *size = qcms_transform_get_input_trc_rgba(transform, source, QCMS_TRC_USHORT, NULL); - assert(*size >= 256); - - *table = calloc(*size, sizeof(uint16_t) * 4); - qcms_transform_get_input_trc_rgba(transform, source, QCMS_TRC_USHORT, *table); - - qcms_transform_release(transform); - qcms_profile_release(sRGB); - qcms_profile_release(source); - - return 0; -} - -static int qcms_test_output_trc(size_t width, - size_t height, - int iterations, - const char *in_path, - const char *out_path, - const int force_software) -{ - uint16_t *gamma_table_out = NULL; - size_t output_size = 0; - qcms_profile *profile; - long time_stamp = (long)time(NULL); - char output_file_name[1024]; - float scale_factor; - size_t i; - - if (!in_path) { - fprintf(stderr, "%s: please provide valid ICC profiles via -i option\n", __FUNCTION__); - return EXIT_FAILURE; - } - - printf("Test color profile gamma curves\n"); - fflush(stdout); - - if (get_output_gamma_table(in_path, &gamma_table_out, &output_size) != 0) { - fprintf(stderr, "Unable to extract output gamma table\n"); - return EXIT_FAILURE; - } - - printf("Output gamma table size = %zu\n", output_size); - - profile = qcms_profile_from_path(in_path); - if (!profile) { - fprintf(stderr, "Invalid input profile\n"); - free(gamma_table_out); - return EXIT_FAILURE; - } - - if (profile->redTRC->type == PARAMETRIC_CURVE_TYPE) { - // Check the red TRC curve only for now. - int type = - (int)(profile->redTRC->count + 1); - uint16_t *gamma_table_in = NULL; - size_t input_size = 0; - FILE *output_file; - - printf("Detected parametric curve type = %d\n", profile->redTRC->count); - - if (get_input_gamma_table(in_path, &gamma_table_in, &input_size) != 0) { - fprintf(stderr, "Failed to compute input gamma table\n"); - qcms_profile_release(profile); - free(gamma_table_out); - return EXIT_FAILURE; - } - - // Write output to stdout and tables into a csv file. - sprintf(output_file_name, "qcms-test-%ld-parametric-gamma-output-%s.csv", - time_stamp, profile->description); - printf("Writing output gamma tables to %s\n", output_file_name); - output_file = fopen(output_file_name, "w"); - - printf("Parametric gamma values for profile %s description [%s]\n", - in_path, profile->description); - fprintf(output_file, "Parametric gamma values for profile %s description [%s]\n", - in_path, profile->description); - - printf("gamma = %.6f, a = %.6f, b = %.6f, c = %.6f, d = %.6f, e = %.6f, f = %.6f\n", - profile->redTRC->parameter[0], profile->redTRC->parameter[1], profile->redTRC->parameter[2], - profile->redTRC->parameter[3], profile->redTRC->parameter[4], profile->redTRC->parameter[5], - profile->redTRC->parameter[6]); - - fprintf(output_file, "gamma, a, b, c, d, e, f\n"); - fprintf(output_file, "%.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f\n", - profile->redTRC->parameter[0], profile->redTRC->parameter[1], profile->redTRC->parameter[2], - profile->redTRC->parameter[3], profile->redTRC->parameter[4], profile->redTRC->parameter[5], - profile->redTRC->parameter[6]); - - fprintf(output_file, "\nInput curve size: %zu", input_size); - fprintf(output_file, "\nOutput curve size: %zu", output_size); - - fprintf(output_file, "\n\nInput gamma, Output gamma, LCMS Output gamma, Output gamma error\n"); - // Output gamma curve down-sample factor. - scale_factor = (float)(output_size - 1) / (input_size - 1); - - for (i = 0; i < input_size; ++i) { - float input = gamma_table_in[i * 4] * inverse65535; - size_t out_index = (size_t)floor(i * scale_factor + 0.5); - float output = gamma_table_out[out_index * 4] * inverse65535; - float x = out_index / (float)(output_size - 1); - float reference = clamp_float(evaluate_parametric_curve(type, profile->redTRC->parameter, x)); - float difference = fabs(output - reference); - - fprintf(output_file, "%.6f, %.6f, %6f, %6f\n", input, output, reference, difference); - } - - fprintf(output_file, "\nNote: the output gamma curves are down-sampled by a factor of %zu / %zu\n", - output_size, input_size); - - fclose(output_file); - free(gamma_table_in); - } else { - uint16_t *gamma_table_in = NULL; - size_t input_size = 0; - FILE *output_file; - - if (get_input_gamma_table(in_path, &gamma_table_in, &input_size) != 0) { - fprintf(stderr, "Failed to compute input gamma table\n"); - qcms_profile_release(profile); - free(gamma_table_out); - return EXIT_FAILURE; - } - - // Write output to stdout and tables into a csv file. - sprintf(output_file_name, "qcms-test-%ld-gamma-output-%s.csv", - time_stamp, profile->description); - printf("Writing gamma tables to %s\n", output_file_name); - output_file = fopen(output_file_name, "w"); - - printf("Gamma values for profile %s description [%s]\n", - in_path, profile->description); - fprintf(output_file, "Gamma values for profile %s description [%s]\n", - in_path, profile->description); - - if (profile->redTRC->count == 0) { - printf("Gamma LUT type 0: linear gamma\n"); - fprintf(output_file, "Gamma LUT type 0: linear gamma\n"); - } else if (profile->redTRC->count == 1) { - float gamma = profile->redTRC->data[0] / 256.0f; - printf("Gamma LUT type 1: gamma = %.6f\n", gamma); - fprintf(output_file, "Gamma LUT type 1: gamma = %.6f\n", gamma); - } else { - printf("Gamma LUT table size = %u\n", profile->redTRC->count); - fprintf(output_file, "Gamma LUT table size = %u\n", profile->redTRC->count); - } - - fprintf(output_file, "\nInput curve size: %zu", input_size); - fprintf(output_file, "\nOutput curve size: %zu", output_size); - - fprintf(output_file, "\n\nInput gamma, Output gamma\n"); - // Output gamma curve down-sample factor. - scale_factor = (float)(output_size - 1) / (input_size - 1); - - for (i = 0; i < input_size; ++i) { - float input = gamma_table_in[i * 4] * inverse65535; - size_t out_index = (size_t)floor(i * scale_factor + 0.5); - float output = gamma_table_out[out_index * 4] * inverse65535; - - fprintf(output_file, "%.6f, %.6f\n", input, output); - } - - fprintf(output_file, "\nNote: the output gamma curves are down-sampled by a factor of %zu / %zu\n", - output_size, input_size); - - fclose(output_file); - free(gamma_table_in); - } - - qcms_profile_release(profile); - free(gamma_table_out); - - return 0; -} - -struct qcms_test_case qcms_test_output_trc_info = { - "qcms_test_output_trc", - qcms_test_output_trc, - QCMS_TEST_DISABLED -}; diff --git a/third_party/qcms/src/tests/qcms_test_tetra_clut_rgba.c b/third_party/qcms/src/tests/qcms_test_tetra_clut_rgba.c deleted file mode 100644 index 81b6ee3287..0000000000 --- a/third_party/qcms/src/tests/qcms_test_tetra_clut_rgba.c +++ /dev/null @@ -1,180 +0,0 @@ -// 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> - -// External qcms tetra clut interpolators. - -extern void qcms_transform_data_tetra_clut_rgba(qcms_transform *transform, - unsigned char *src, - unsigned char *dest, - size_t length, - qcms_format_type output_format); - -#ifdef SSE2_ENABLE -extern void qcms_transform_data_tetra_clut_rgba_sse2(qcms_transform *transform, - unsigned char *src, - unsigned char *dest, - size_t length, - qcms_format_type output_format); -#else -void qcms_transform_data_tetra_clut_rgba_dummy(qcms_transform *transform, - unsigned char *src, - unsigned char *dest, - size_t length, - qcms_format_type output_format) -{ - (void)(transform); - (void)(src); - (void)(dest); - (void)(length); - (void)(output_format); -} -#endif - -static float *create_lut(size_t lutSize) -{ - float *lut = malloc(lutSize * sizeof(float)); - size_t i; - - for (i = 0; i < lutSize; ++i) { - lut[i] = (rand() & 255) * (1.0f / 255.0f); - } - - return lut; -} - -static int diffs; - -static int validate(unsigned char *dst0, unsigned char *dst1, size_t length, int limit, const size_t pixel_size) -{ - size_t bytes = length * pixel_size; - size_t i; - - // Compare dst0/dst0 byte-by-byte, allowing for minor differences due - // to SSE rounding modes (controlled by the limit argument). - - if (limit < 0) - limit = 255; // Ignore all differences. - - for (diffs = 0, i = 0; i < bytes; ++i) { - if (abs((int)dst0[i] - (int)dst1[i]) > limit) { - ++diffs; - } - } - - return !diffs; -} - -static int qcms_test_tetra_clut_rgba(size_t width, - size_t height, - int iterations, - const char *in_profile, - const char *out_profile, - const int force_software) -{ - qcms_transform transform0, transform1; - qcms_format_type format = {2, 0}; - uint16_t samples = 33; - size_t lutSize; - float *lut0, *lut1; - - const size_t length = width * height; - const size_t pixel_size = 4; - - double time0, time1; - int i; - - printf("Test qcms clut transforms for %d iterations\n", iterations); - printf("Test image size %u x %u pixels\n", (unsigned) width, (unsigned) height); - fflush(stdout); - - srand(0); - seconds(); - - memset(&transform0, 0, sizeof(transform0)); - memset(&transform1, 0, sizeof(transform1)); - - transform0.grid_size = samples; - transform1.grid_size = samples; - - transform0.transform_flags = 0; - transform1.transform_flags = 0; - - lutSize = 3 * samples * samples * samples; - lut0 = create_lut(lutSize); - lut1 = (float *)malloc(lutSize * sizeof(float)); - memcpy(lut1, lut0, lutSize * sizeof(float)); - - transform0.r_clut = &lut0[0]; - transform0.g_clut = &lut0[1]; - transform0.b_clut = &lut0[2]; - - transform1.r_clut = &lut1[0]; - transform1.g_clut = &lut1[1]; - transform1.b_clut = &lut1[2]; - - // Re-generate and use different data sources during the iteration loop - // to avoid compiler / cache optimizations that may affect performance. - - time0 = 0.0; - time1 = 0.0; - - for (i = 0; i < iterations; ++i) { - unsigned char *src0 = (unsigned char *)calloc(length, pixel_size); - unsigned char *src1 = (unsigned char *)calloc(length, pixel_size); - unsigned char *dst0 = (unsigned char *)calloc(length, pixel_size); - unsigned char *dst1 = (unsigned char *)calloc(length, pixel_size); - - generate_source_uint8_t(src0, length, pixel_size); - memcpy(src1, src0, length * pixel_size); - -#define TRANSFORM_TEST0 qcms_transform_data_tetra_clut_rgba -#ifdef SSE2_ENABLE -#define TRANSFORM_TEST1 qcms_transform_data_tetra_clut_rgba_sse2 -#else -#define TRANSFORM_TEST1 qcms_transform_data_tetra_clut_rgba_dummy -#endif - - TIME(TRANSFORM_TEST0(&transform0, src0, dst0, length, format), &time0); - TIME(TRANSFORM_TEST1(&transform1, src1, dst1, length, format), &time1); - - if (!validate(dst0, dst1, length, 0, pixel_size)) { - fprintf(stderr, "Invalid transform output: %d diffs\n", diffs); - } - - free(src0); - free(src1); - free(dst0); - free(dst1); - } - -#define STRINGIZE(s) #s -#define STRING(s) STRINGIZE(s) - - printf("%.6lf (avg %.6lf) seconds " STRING(TRANSFORM_TEST0) "\n", - time0, time0 / iterations); - printf("%.6lf (avg %.6lf) seconds " STRING(TRANSFORM_TEST1) "\n", - time1, time1 / iterations); - printf("%.6lf speedup after %d iterations\n\n", - time0 / time1, iterations); - - free(lut0); - free(lut1); - - return diffs; -} - -struct qcms_test_case qcms_test_tetra_clut_rgba_info = { - "qcms_test_tetra_clut_rgba", - qcms_test_tetra_clut_rgba, - QCMS_TEST_DISABLED -}; diff --git a/third_party/qcms/src/tests/qcms_test_util.c b/third_party/qcms/src/tests/qcms_test_util.c deleted file mode 100644 index e0ecff3af4..0000000000 --- a/third_party/qcms/src/tests/qcms_test_util.c +++ /dev/null @@ -1,280 +0,0 @@ -// Copyright 2016 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_test_util.h" - -#include <math.h> -#include <stdlib.h> - -#define MAX_FLOAT_ERROR 0.000001f - -// Store random pixel data in the source. -void generate_source_uint8_t(unsigned char *src, const size_t length, const size_t pixel_size) -{ - size_t bytes = length * pixel_size; - size_t i; - - for (i = 0; i < bytes; ++i) { - *src++ = rand() & 255; - } -} - -// Parametric Fn using floating point <from lcms/src/cmsgamma.c>: DefaultEvalParametricFn -float evaluate_parametric_curve(int type, const float params[], float r) -{ - float e, val, disc; - - switch (type) { - - // X = Y ^ Gamma - case 1: - if (r < 0) { - - if (fabs(params[0] - 1.0) < MAX_FLOAT_ERROR) - val = r; - else - val = 0; - } - else - val = pow(r, params[0]); - break; - - // Type 1 Reversed: X = Y ^1/gamma - case -1: - if (r < 0) { - - if (fabs(params[0] - 1.0) < MAX_FLOAT_ERROR) - val = r; - else - val = 0; - } - else - val = pow(r, 1/params[0]); - break; - - // CIE 122-1966 - // Y = (aX + b)^Gamma | X >= -b/a - // Y = 0 | else - case 2: - disc = -params[2] / params[1]; - - if (r >= disc ) { - - e = params[1]*r + params[2]; - - if (e > 0) - val = pow(e, params[0]); - else - val = 0; - } - else - val = 0; - break; - - // Type 2 Reversed - // X = (Y ^1/g - b) / a - case -2: - if (r < 0) - val = 0; - else - val = (pow(r, 1.0/params[0]) - params[2]) / params[1]; - - if (val < 0) - val = 0; - break; - - - // IEC 61966-3 - // Y = (aX + b)^Gamma | X <= -b/a - // Y = c | else - case 3: - disc = -params[2] / params[1]; - if (disc < 0) - disc = 0; - - if (r >= disc) { - - e = params[1]*r + params[2]; - - if (e > 0) - val = pow(e, params[0]) + params[3]; - else - val = 0; - } - else - val = params[3]; - break; - - - // Type 3 reversed - // X=((Y-c)^1/g - b)/a | (Y>=c) - // X=-b/a | (Y<c) - case -3: - if (r >= params[3]) { - - e = r - params[3]; - - if (e > 0) - val = (pow(e, 1/params[0]) - params[2]) / params[1]; - else - val = 0; - } - else { - val = -params[2] / params[1]; - } - break; - - - // IEC 61966-2.1 (sRGB) - // Y = (aX + b)^Gamma | X >= d - // Y = cX | X < d - case 4: - if (r >= params[4]) { - - e = params[1]*r + params[2]; - - if (e > 0) - val = pow(e, params[0]); - else - val = 0; - } - else - val = r * params[3]; - break; - - // Type 4 reversed - // X=((Y^1/g-b)/a) | Y >= (ad+b)^g - // X=Y/c | Y< (ad+b)^g - case -4: - e = params[1] * params[4] + params[2]; - if (e < 0) - disc = 0; - else - disc = pow(e, params[0]); - - if (r >= disc) { - - val = (pow(r, 1.0/params[0]) - params[2]) / params[1]; - } - else { - val = r / params[3]; - } - break; - - - // Y = (aX + b)^Gamma + e | X >= d - // Y = cX + f | X < d - case 5: - if (r >= params[4]) { - - e = params[1]*r + params[2]; - - if (e > 0) - val = pow(e, params[0]) + params[5]; - else - val = params[5]; - } - else - val = r*params[3] + params[6]; - break; - - - // Reversed type 5 - // X=((Y-e)1/g-b)/a | Y >=(ad+b)^g+e), cd+f - // X=(Y-f)/c | else - case -5: - - disc = params[3] * params[4] + params[6]; - if (r >= disc) { - - e = r - params[5]; - if (e < 0) - val = 0; - else - val = (pow(e, 1.0/params[0]) - params[2]) / params[1]; - } - else { - val = (r - params[6]) / params[3]; - } - break; - - - // Types 6,7,8 comes from segmented curves as described in ICCSpecRevision_02_11_06_Float.pdf - // Type 6 is basically identical to type 5 without d - - // Y = (a * X + b) ^ Gamma + c - case 6: - e = params[1]*r + params[2]; - - if (e < 0) - val = params[3]; - else - val = pow(e, params[0]) + params[3]; - break; - - // ((Y - c) ^1/Gamma - b) / a - case -6: - e = r - params[3]; - if (e < 0) - val = 0; - else - val = (pow(e, 1.0/params[0]) - params[2]) / params[1]; - break; - - - // Y = a * log (b * X^Gamma + c) + d - case 7: - - e = params[2] * pow(r, params[0]) + params[3]; - if (e <= 0) - val = params[4]; - else - val = params[1]*log10(e) + params[4]; - break; - - // (Y - d) / a = log(b * X ^Gamma + c) - // pow(10, (Y-d) / a) = b * X ^Gamma + c - // pow((pow(10, (Y-d) / a) - c) / b, 1/g) = X - case -7: - val = pow((pow(10.0, (r-params[4]) / params[1]) - params[3]) / params[2], 1.0 / params[0]); - break; - - - //Y = a * b^(c*X+d) + e - case 8: - val = (params[0] * pow(params[1], params[2] * r + params[3]) + params[4]); - break; - - - // Y = (log((y-e) / a) / log(b) - d ) / c - // a=0, b=1, c=2, d=3, e=4, - case -8: - - disc = r - params[4]; - if (disc < 0) val = 0; - else - val = (log(disc / params[0]) / log(params[1]) - params[3]) / params[2]; - break; - - // S-Shaped: (1 - (1-x)^1/g)^1/g - case 108: - val = pow(1.0 - pow(1 - r, 1/params[0]), 1/params[0]); - break; - - // y = (1 - (1-x)^1/g)^1/g - // y^g = (1 - (1-x)^1/g) - // 1 - y^g = (1-x)^1/g - // (1 - y^g)^g = 1 - x - // 1 - (1 - y^g)^g - case -108: - val = 1 - pow(1 - pow(r, params[0]), params[0]); - break; - - default: - // Unsupported parametric curve. Should never reach here - return 0; - } - - return val; -} diff --git a/third_party/qcms/src/tests/qcms_test_util.h b/third_party/qcms/src/tests/qcms_test_util.h deleted file mode 100644 index d8286e6028..0000000000 --- a/third_party/qcms/src/tests/qcms_test_util.h +++ /dev/null @@ -1,27 +0,0 @@ -// 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 "qcmsint.h" -#include "qcmstypes.h" - -typedef int (*qcms_test_function)(size_t width, - size_t height, - int iterations, - const char *in_profile, - const char *out_profile, - const int force_software); - -enum QCMS_TEST_STATUS { - QCMS_TEST_DISABLED = 0, - QCMS_TEST_ENABLED = 1, -}; - -struct qcms_test_case { - char test_name[256]; - qcms_test_function test_fn; - enum QCMS_TEST_STATUS status; -}; - -void generate_source_uint8_t(unsigned char *src, const size_t length, const size_t pixel_size); -float evaluate_parametric_curve(int type, const float params[], float r); diff --git a/third_party/qcms/src/tests/timing.h b/third_party/qcms/src/tests/timing.h deleted file mode 100644 index 83f1bbdf0c..0000000000 --- a/third_party/qcms/src/tests/timing.h +++ /dev/null @@ -1,51 +0,0 @@ -// 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. - -#ifndef TESTS_TIMING_H -#define TESTS_TIMING_H - -#include <assert.h> -#if defined(_WIN32) -#include <windows.h> -#else -#include <sys/time.h> -#endif -#include <time.h> - -#if defined(_WIN32) - -static double seconds() -{ - static double clock_frequency; - static bool have_frequency; - - LARGE_INTEGER qpc; - QueryPerformanceCounter(&qpc); - if (have_frequency) - return qpc.QuadPart * clock_frequency; - - have_frequency = true; - QueryPerformanceFrequency(&qpc); - clock_frequency = 1.0 / (double) qpc.QuadPart; - return seconds(); -} - -#else - -static double seconds() -{ - struct timeval now; - gettimeofday(&now, 0); - return now.tv_sec + now.tv_usec * (1.0 / 1000000.0); -} - -#endif - -#define TIME(function, time) do { \ - double start = seconds(); \ - (function); \ - *time += seconds() - start; \ -} while (0) - -#endif // TESTS_TIMING_H |