Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the Chromium LICENSE file. | 3 // found in the Chromium LICENSE file. |
| 4 | 4 |
| 5 #include "qcms.h" | 5 #include "qcms.h" |
| 6 #include "qcms_test_util.h" | 6 #include "qcms_test_util.h" |
| 7 | 7 |
| 8 #include <assert.h> | 8 #include <assert.h> |
| 9 #include <math.h> | 9 #include <math.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 sRGB = qcms_profile_sRGB(); | 32 sRGB = qcms_profile_sRGB(); |
| 33 | 33 |
| 34 transform = qcms_transform_create(sRGB, QCMS_DATA_RGBA_8, target, QCMS_DATA_ RGBA_8, QCMS_INTENT_DEFAULT); | 34 transform = qcms_transform_create(sRGB, QCMS_DATA_RGBA_8, target, QCMS_DATA_ RGBA_8, QCMS_INTENT_DEFAULT); |
| 35 if (!transform) { | 35 if (!transform) { |
| 36 fprintf(stderr, "Failed to create colour transform\n"); | 36 fprintf(stderr, "Failed to create colour transform\n"); |
| 37 qcms_profile_release(sRGB); | 37 qcms_profile_release(sRGB); |
| 38 qcms_profile_release(target); | 38 qcms_profile_release(target); |
| 39 return EXIT_FAILURE; | 39 return EXIT_FAILURE; |
| 40 } | 40 } |
| 41 | 41 |
| 42 *size = qcms_transform_get_output_trc_rgba(transform, target, QCMS_TRC_USHOR T, NULL); | 42 *size = qcms_transform_get_output_trc_rgba(transform, target, QCMS_TRC_USHOR T, NULL); |
|
Noel Gordon
2016/04/28 07:30:27
Good, now optional: should we assert(*size >= 256)
radu.velea
2016/04/28 08:17:25
I guess it couldn't hurt.
| |
| 43 assert(*size == 256); | |
| 44 | 43 |
| 45 *table = malloc(*size * sizeof(uint16_t) * 4); | 44 *table = malloc(*size * sizeof(uint16_t) * 4); |
| 46 qcms_transform_get_output_trc_rgba(transform, target, QCMS_TRC_USHORT, *tabl e); | 45 qcms_transform_get_output_trc_rgba(transform, target, QCMS_TRC_USHORT, *tabl e); |
| 47 | 46 |
| 48 qcms_transform_release(transform); | 47 qcms_transform_release(transform); |
| 49 qcms_profile_release(sRGB); | 48 qcms_profile_release(sRGB); |
| 50 qcms_profile_release(target); | 49 qcms_profile_release(target); |
| 51 | 50 |
| 52 return 0; | 51 return 0; |
| 53 } | 52 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 67 sRGB = qcms_profile_sRGB(); | 66 sRGB = qcms_profile_sRGB(); |
| 68 | 67 |
| 69 transform = qcms_transform_create(source, QCMS_DATA_RGBA_8, sRGB, QCMS_DATA_ RGBA_8, QCMS_INTENT_DEFAULT); | 68 transform = qcms_transform_create(source, QCMS_DATA_RGBA_8, sRGB, QCMS_DATA_ RGBA_8, QCMS_INTENT_DEFAULT); |
| 70 if (!transform) { | 69 if (!transform) { |
| 71 fprintf(stderr, "Failed to create colour transform\n"); | 70 fprintf(stderr, "Failed to create colour transform\n"); |
| 72 qcms_profile_release(sRGB); | 71 qcms_profile_release(sRGB); |
| 73 qcms_profile_release(source); | 72 qcms_profile_release(source); |
| 74 return EXIT_FAILURE; | 73 return EXIT_FAILURE; |
| 75 } | 74 } |
| 76 | 75 |
| 77 *size = qcms_transform_get_input_trc_rgba(transform, source, QCMS_TRC_USHORT , NULL); | 76 *size = qcms_transform_get_input_trc_rgba(transform, source, QCMS_TRC_USHORT , NULL); |
|
Noel Gordon
2016/04/28 07:30:27
Good, now optional: should we assert(*size >= 256)
radu.velea
2016/04/28 08:17:25
Done.
| |
| 78 assert(*size == 256); | |
| 79 | 77 |
| 80 *table = calloc(*size, sizeof(uint16_t) * 4); | 78 *table = calloc(*size, sizeof(uint16_t) * 4); |
| 81 qcms_transform_get_input_trc_rgba(transform, source, QCMS_TRC_USHORT, *table ); | 79 qcms_transform_get_input_trc_rgba(transform, source, QCMS_TRC_USHORT, *table ); |
| 82 | 80 |
| 83 qcms_transform_release(transform); | 81 qcms_transform_release(transform); |
| 84 qcms_profile_release(sRGB); | 82 qcms_profile_release(sRGB); |
| 85 qcms_profile_release(source); | 83 qcms_profile_release(source); |
| 86 | 84 |
| 87 return 0; | 85 return 0; |
| 88 } | 86 } |
| 89 | 87 |
| 90 static int qcms_test_output_trc(size_t width, | 88 static int qcms_test_output_trc(size_t width, |
| 91 size_t height, | 89 size_t height, |
| 92 int iterations, | 90 int iterations, |
| 93 const char *in_path, | 91 const char *in_path, |
| 94 const char *out_path, | 92 const char *out_path, |
| 95 const int force_software) | 93 const int force_software) |
| 96 { | 94 { |
| 97 qcms_profile *profile; | 95 qcms_profile *profile; |
| 98 uint16_t *gamma_table_out; | 96 uint16_t *gamma_table_out; |
| 99 size_t gamma_table_size; | 97 size_t output_size; |
| 100 size_t i; | 98 size_t i; |
| 101 | 99 |
| 102 printf("Test qcms output gamma curve table integrity.\n"); | 100 printf("Test qcms output gamma curve table integrity.\n"); |
| 103 | 101 |
| 104 if (!in_path) { | 102 if (!in_path) { |
| 105 fprintf(stderr, "%s: please provide valid ICC profiles via -i option\n", __FUNCTION__); | 103 fprintf(stderr, "%s: please provide valid ICC profiles via -i option\n", __FUNCTION__); |
| 106 return EXIT_FAILURE; | 104 return EXIT_FAILURE; |
| 107 } | 105 } |
| 108 | 106 |
| 109 // Create profiles and transforms, get table and then free resources to make sure none | 107 // Create profiles and transforms, get table and then free resources to make sure none |
| 110 // of the internal tables are initialized by previous calls. | 108 // of the internal tables are initialized by previous calls. |
| 111 gamma_table_out = NULL; | 109 gamma_table_out = NULL; |
| 112 gamma_table_size = 0; | 110 output_size = 0; |
| 113 if (get_output_gamma_table(in_path, &gamma_table_out, &gamma_table_size) != 0) { | 111 if (get_output_gamma_table(in_path, &gamma_table_out, &output_size) != 0) { |
| 114 fprintf(stderr, "Unable to extract output gamma table\n"); | 112 fprintf(stderr, "Unable to extract output gamma table\n"); |
| 115 return EXIT_FAILURE; | 113 return EXIT_FAILURE; |
| 116 } | 114 } |
| 117 | 115 |
| 118 printf("LUT size = %zu\n", gamma_table_size); | 116 printf("LUT size = %zu\n", output_size); |
| 119 | 117 |
| 120 profile = qcms_profile_from_path(in_path); | 118 profile = qcms_profile_from_path(in_path); |
| 121 if (!profile) { | 119 if (!profile) { |
| 122 fprintf(stderr, "Invalid input profile\n"); | 120 fprintf(stderr, "Invalid input profile\n"); |
| 123 free(gamma_table_out); | 121 free(gamma_table_out); |
| 124 return EXIT_FAILURE; | 122 return EXIT_FAILURE; |
| 125 } | 123 } |
| 126 | 124 |
| 127 // Check only for red curve for now. | 125 // Check only for red curve for now. |
| 128 if (profile->redTRC->type == PARAMETRIC_CURVE_TYPE) { | 126 if (profile->redTRC->type == PARAMETRIC_CURVE_TYPE) { |
| 129 int type = - (int)(profile->redTRC->count + 1); | 127 int type = - (int)(profile->redTRC->count + 1); |
| 128 uint16_t *gamma_table_in = NULL; | |
| 129 size_t input_size = 0; | |
| 130 float scale_factor; | |
| 130 FILE *gamma_file; | 131 FILE *gamma_file; |
|
Noel Gordon
2016/04/28 07:30:27
gamma_file -> output_file.
radu.velea
2016/04/28 08:17:25
Done.
| |
| 131 uint16_t *gamma_table_in = NULL; | 132 char output_file_name[256] = {0,}; |
|
Noel Gordon
2016/04/28 07:30:27
char output_file_name[1024];
radu.velea
2016/04/28 08:17:25
Done.
| |
| 132 uint16_t *p_table_out, *p_table_in; | 133 long int time_stamp = (long int)time(NULL); |
| 133 char file_name[256] = {0,}; | |
| 134 size_t input_size = 0; | |
| 135 | 134 |
| 136 printf("Detected parametric curve type = %d\n", profile->redTRC->count); | 135 printf("Detected parametric curve type = %d\n", profile->redTRC->count); |
| 137 | 136 |
| 138 sprintf(file_name, "qcms-test-%ld-parametric-gamma-%s.csv", (long int)ti me(NULL), profile->description); | 137 sprintf(output_file_name, "qcms-test-%ld-parametric-gamma-output-%s.csv" , time_stamp, profile->description); |
| 139 printf("Writing input and output gamma tables to %s\n", file_name); | 138 printf("Writing output gamma tables to %s\n", output_file_name); |
| 140 | 139 |
| 141 printf("gamma = %.6f, a = %.6f, b = %.6f, c = %.6f, d = %.6f, e = %.6f, f = %.6f\n", | 140 printf("gamma = %.6f, a = %.6f, b = %.6f, c = %.6f, d = %.6f, e = %.6f, f = %.6f\n", |
| 142 profile->redTRC->parameter[0], profile->redTRC->parameter[1], pr ofile->redTRC->parameter[2], | 141 profile->redTRC->parameter[0], profile->redTRC->parameter[1], pr ofile->redTRC->parameter[2], |
| 143 profile->redTRC->parameter[3], profile->redTRC->parameter[4], pr ofile->redTRC->parameter[5], | 142 profile->redTRC->parameter[3], profile->redTRC->parameter[4], pr ofile->redTRC->parameter[5], |
| 144 profile->redTRC->parameter[6]); | 143 profile->redTRC->parameter[6]); |
| 145 | 144 |
| 146 // Write output to stdout and tables into a csv file. | 145 // Write output to stdout and tables into a csv file. |
| 147 gamma_file = fopen(file_name, "w"); | 146 gamma_file = fopen(output_file_name, "w"); |
| 148 fprintf(gamma_file, "Parametric gamma values for %s\n", profile->descrip tion); | 147 fprintf(gamma_file, "Parametric gamma values for %s\n", profile->descrip tion); |
| 149 fprintf(gamma_file, "gamma, a, b, c, d, e, f\n"); | 148 fprintf(gamma_file, "gamma, a, b, c, d, e, f\n"); |
| 150 fprintf(gamma_file, "%.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f\n", | 149 fprintf(gamma_file, "%.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f\n", |
| 151 profile->redTRC->parameter[0], profile->redTRC->parameter[1], pr ofile->redTRC->parameter[2], | 150 profile->redTRC->parameter[0], profile->redTRC->parameter[1], pr ofile->redTRC->parameter[2], |
| 152 profile->redTRC->parameter[3], profile->redTRC->parameter[4], pr ofile->redTRC->parameter[5], | 151 profile->redTRC->parameter[3], profile->redTRC->parameter[4], pr ofile->redTRC->parameter[5], |
| 153 profile->redTRC->parameter[6]); | 152 profile->redTRC->parameter[6]); |
| 154 | 153 |
| 155 get_input_gamma_table(in_path, &gamma_table_in, &input_size); | 154 get_input_gamma_table(in_path, &gamma_table_in, &input_size); |
| 156 assert(input_size == gamma_table_size); | |
| 157 if (!gamma_table_in) { | 155 if (!gamma_table_in) { |
| 158 fprintf(stderr, "Unable to compute input trc. Aborting\n"); | 156 fprintf(stderr, "Unable to compute input trc. Aborting\n"); |
| 159 fclose(gamma_file); | 157 fclose(gamma_file); |
| 160 qcms_profile_release(profile); | 158 qcms_profile_release(profile); |
| 161 free(gamma_table_out); | 159 free(gamma_table_out); |
| 162 return EXIT_FAILURE; | 160 return EXIT_FAILURE; |
| 163 } | 161 } |
| 164 | 162 |
| 163 scale_factor = (float)(output_size - 1) / (input_size - 1); | |
| 164 | |
| 165 fprintf(gamma_file, "\nInput curve size: %zu\nOutput curve size: %zu\n", input_size, output_size); | |
| 165 fprintf(gamma_file, "\n\nInput gamma, Output gamma, LCMS Output gamma, O utput gamma error\n"); | 166 fprintf(gamma_file, "\n\nInput gamma, Output gamma, LCMS Output gamma, O utput gamma error\n"); |
| 166 | 167 |
| 167 p_table_out = gamma_table_out; | 168 for (i = 0; i < input_size; ++i) { |
| 168 p_table_in = gamma_table_in; | 169 float input = gamma_table_in[i * 4] * inverse65535; |
| 170 size_t out_index = (size_t)floor( i * scale_factor + 0.5); | |
| 171 float p = out_index / (output_size * 1.0); | |
|
Noel Gordon
2016/04/28 07:30:27
What is the maximum value of |out_index| (assume c
radu.velea
2016/04/28 08:17:25
4095 / 4096 * 1.0, which comes short of 1.0 (which
| |
| 172 float reference_out = clamp_float(evaluate_parametric_curve(type, pr ofile->redTRC->parameter, p)); | |
|
Noel Gordon
2016/04/28 07:30:27
the "_out"'s are maybe not needed, perhaps use
ef
radu.velea
2016/04/28 08:17:25
Done.
| |
| 173 float actual_out = gamma_table_out[out_index * 4] * inverse65535; | |
|
Noel Gordon
2016/04/28 07:30:27
actual_out -> actual
radu.velea
2016/04/28 08:17:25
Done.
| |
| 174 float error_out = fabs(actual_out - reference_out); | |
|
Noel Gordon
2016/04/28 07:30:27
error_out -> difference
radu.velea
2016/04/28 08:17:25
Done.
| |
| 169 | 175 |
| 170 for (i = 0; i < gamma_table_size; ++i) { | 176 fprintf(gamma_file, "%.6f, %.6f, %6f, %6f\n", input, actual_out, ref erence_out, error_out); |
| 171 float p = i / (gamma_table_size * 1.0); | |
| 172 float reference_out = clamp_float(evaluate_parametric_curve(type, pr ofile->redTRC->parameter, p)); | |
| 173 float actual_out = *p_table_out * inverse65535; | |
| 174 float error_out = fabs(actual_out - reference_out); | |
| 175 float input = *p_table_in * inverse65535; | |
| 176 | |
| 177 fprintf(gamma_file, "%.6f, %.6f, %6f, %6f\n",input, actual_out, refe rence_out, error_out); | |
| 178 | |
| 179 p_table_out += 4; // Skip other channels. | |
| 180 p_table_in += 4; // Skip other channels. | |
| 181 } | 177 } |
| 182 | 178 |
| 179 fprintf(gamma_file, "\nNote: the output curves we down sampled by a fact or of %zu / %zu\n", | |
| 180 output_size, input_size); | |
| 181 | |
| 182 fclose(gamma_file); | |
| 183 free(gamma_table_in); | 183 free(gamma_table_in); |
| 184 fclose(gamma_file); | |
| 185 } | 184 } |
| 186 | 185 |
| 187 qcms_profile_release(profile); | 186 qcms_profile_release(profile); |
| 188 free(gamma_table_out); | 187 free(gamma_table_out); |
| 189 | 188 |
| 190 return 0; | 189 return 0; |
| 191 } | 190 } |
| 192 | 191 |
| 193 struct qcms_test_case qcms_test_output_trc_info = { | 192 struct qcms_test_case qcms_test_output_trc_info = { |
| 194 "qcms_test_output_trc", | 193 "qcms_test_output_trc", |
| 195 qcms_test_output_trc, | 194 qcms_test_output_trc, |
| 196 QCMS_TEST_DISABLED | 195 QCMS_TEST_DISABLED |
| 197 }; | 196 }; |
| OLD | NEW |