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

Side by Side Diff: third_party/qcms/src/tests/qcms_test_tetra_clut_rgba.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: Fix README 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 "qcmsint.h" 6 #include "qcms_test_util.h"
7 #include "qcmstypes.h"
8 #include "timing.h" 7 #include "timing.h"
9 8
10 #include <math.h> 9 #include <math.h>
11 #include <stdio.h> 10 #include <stdio.h>
12 #include <stdlib.h> 11 #include <stdlib.h>
13 #include <string.h> 12 #include <string.h>
14 13
15 // External qcms tetra clut interpolators. 14 // External qcms tetra clut interpolators.
16 15
17 extern void qcms_transform_data_tetra_clut_rgba(qcms_transform *transform, 16 extern void qcms_transform_data_tetra_clut_rgba(qcms_transform *transform,
18 unsigned char *src, 17 unsigned char *src,
19 unsigned char *dest, 18 unsigned char *dest,
20 size_t length, 19 size_t length,
21 qcms_format_type output_format); 20 qcms_format_type output_format);
22 21
23 extern void qcms_transform_data_tetra_clut_rgba_sse2(qcms_transform *transform, 22 extern void qcms_transform_data_tetra_clut_rgba_sse2(qcms_transform *transform,
24 unsigned char *src, 23 unsigned char *src,
25 unsigned char *dest, 24 unsigned char *dest,
26 size_t length, 25 size_t length,
27 qcms_format_type output_for mat); 26 qcms_format_type output_for mat);
28 27
29 #define PIXEL_SIZE 4
30
31 static void generate_source(unsigned char *src, size_t length)
32 {
33 size_t bytes = length * PIXEL_SIZE;
34 size_t i;
35
36 for (i = 0; i < bytes; ++i) {
37 *src++ = rand() & 255;
38 }
39 }
40
41 static float *create_lut(size_t lutSize) 28 static float *create_lut(size_t lutSize)
42 { 29 {
43 float *lut = malloc(lutSize * sizeof(float)); 30 float *lut = malloc(lutSize * sizeof(float));
44 size_t i; 31 size_t i;
45 32
46 for (i = 0; i < lutSize; ++i) { 33 for (i = 0; i < lutSize; ++i) {
47 lut[i] = (rand() & 255) * (1.0f / 255.0f); 34 lut[i] = (rand() & 255) * (1.0f / 255.0f);
48 } 35 }
49 36
50 return lut; 37 return lut;
51 } 38 }
52 39
53 static int diffs; 40 static int diffs;
54 41 static int validate(unsigned char *dst0, unsigned char *dst1, size_t length, int limit, const size_t pixel_size)
Noel Gordon 2015/10/07 14:03:06 Space before this line.
radu.velea 2015/10/07 14:43:43 Done.
55 static int validate(unsigned char *dst0, unsigned char *dst1, size_t length, int limit)
56 { 42 {
57 size_t bytes = length * PIXEL_SIZE; 43 size_t bytes = length * pixel_size;
58 size_t i; 44 size_t i;
59 45
60 // Compare dst0/dst0 byte-by-byte, allowing for minor differences due 46 // Compare dst0/dst0 byte-by-byte, allowing for minor differences due
61 // to SSE rounding modes (controlled by the limit argument). 47 // to SSE rounding modes (controlled by the limit argument).
62 48
63 if (limit < 0) 49 if (limit < 0)
64 limit = 255; // Ignore all differences. 50 limit = 255; // Ignore all differences.
65 51
66 for (diffs = 0, i = 0; i < bytes; ++i) { 52 for (diffs = 0, i = 0; i < bytes; ++i) {
67 if (abs((int)dst0[i] - (int)dst1[i]) > limit) { 53 if (abs((int)dst0[i] - (int)dst1[i]) > limit) {
68 ++diffs; 54 ++diffs;
69 } 55 }
70 } 56 }
71 57
72 return !diffs; 58 return !diffs;
73 } 59 }
74 60
75 int main(int argc, const char **argv) 61 static int qcms_test_tetra_clut_rgba(size_t width,
62 size_t height,
63 int iterations,
64 const char *in_profile,
65 const char *out_profile,
66 const int force_software)
76 { 67 {
77 qcms_transform transform0, transform1; 68 qcms_transform transform0, transform1;
78 qcms_format_type format = {2, 0}; 69 qcms_format_type format = {2, 0};
79 uint16_t samples = 33; 70 uint16_t samples = 33;
80 size_t lutSize; 71 size_t lutSize;
81 float *lut0, *lut1; 72 float *lut0, *lut1;
82 73
83 int iterations = 1; 74 const size_t length = width * height;
84 size_t height = 2000; 75 const size_t pixel_size = 4;
85 size_t width = 2000;
86 size_t length;
87 76
88 double time0, time1; 77 double time0, time1;
89 int i; 78 int i;
90 79
91 while (argc > 1) {
92 if (strcmp(argv[1], "-i") == 0)
93 iterations = abs(atoi(argv[2]));
94 else if (strcmp(argv[1], "-w") == 0)
95 width = (size_t) abs(atoi(argv[2]));
96 else if (strcmp(argv[1], "-h") == 0)
97 height = (size_t) abs(atoi(argv[2]));
98 (--argc, ++argv);
99 }
100
101 printf("Test qcms clut transforms for %d iterations\n", iterations); 80 printf("Test qcms clut transforms for %d iterations\n", iterations);
102 printf("Test image size %u x %u pixels\n", (unsigned) width, (unsigned) heig ht); 81 printf("Test image size %u x %u pixels\n", (unsigned) width, (unsigned) heig ht);
103 length = width * height;
104 fflush(stdout); 82 fflush(stdout);
105 83
106 srand(0); 84 srand(0);
107 seconds(); 85 seconds();
108 86
109 memset(&transform0, 0, sizeof(transform0)); 87 memset(&transform0, 0, sizeof(transform0));
110 memset(&transform1, 0, sizeof(transform1)); 88 memset(&transform1, 0, sizeof(transform1));
111 89
112 transform0.grid_size = samples; 90 transform0.grid_size = samples;
113 transform1.grid_size = samples; 91 transform1.grid_size = samples;
(...skipping 14 matching lines...) Expand all
128 transform1.g_clut = &lut1[1]; 106 transform1.g_clut = &lut1[1];
129 transform1.b_clut = &lut1[2]; 107 transform1.b_clut = &lut1[2];
130 108
131 // Re-generate and use different data sources during the iteration loop 109 // Re-generate and use different data sources during the iteration loop
132 // to avoid compiler / cache optimizations that may affect performance. 110 // to avoid compiler / cache optimizations that may affect performance.
133 111
134 time0 = 0.0; 112 time0 = 0.0;
135 time1 = 0.0; 113 time1 = 0.0;
136 114
137 for (i = 0; i < iterations; ++i) { 115 for (i = 0; i < iterations; ++i) {
138 unsigned char *src0 = (unsigned char *)calloc(length, PIXEL_SIZE); 116 unsigned char *src0 = (unsigned char *)calloc(length, pixel_size);
139 unsigned char *src1 = (unsigned char *)calloc(length, PIXEL_SIZE); 117 unsigned char *src1 = (unsigned char *)calloc(length, pixel_size);
140 unsigned char *dst0 = (unsigned char *)calloc(length, PIXEL_SIZE); 118 unsigned char *dst0 = (unsigned char *)calloc(length, pixel_size);
141 unsigned char *dst1 = (unsigned char *)calloc(length, PIXEL_SIZE); 119 unsigned char *dst1 = (unsigned char *)calloc(length, pixel_size);
142 120
143 generate_source(src0, length); 121 generate_source_uint8_t(src0, length, pixel_size);
144 memcpy(src1, src0, length * PIXEL_SIZE); 122 memcpy(src1, src0, length * pixel_size);
145 123
146 #define TRANSFORM_TEST0 qcms_transform_data_tetra_clut_rgba 124 #define TRANSFORM_TEST0 qcms_transform_data_tetra_clut_rgba
147 #define TRANSFORM_TEST1 qcms_transform_data_tetra_clut_rgba_sse2 125 #define TRANSFORM_TEST1 qcms_transform_data_tetra_clut_rgba_sse2
148 126
149 TIME(TRANSFORM_TEST0(&transform0, src0, dst0, length, format), &time0); 127 TIME(TRANSFORM_TEST0(&transform0, src0, dst0, length, format), &time0);
150 TIME(TRANSFORM_TEST1(&transform1, src1, dst1, length, format), &time1); 128 TIME(TRANSFORM_TEST1(&transform1, src1, dst1, length, format), &time1);
151 129
152 if (!validate(dst0, dst1, length, 0)) { 130 if (!validate(dst0, dst1, length, 0, pixel_size)) {
153 fprintf(stderr, "Invalid transform output: %d diffs\n", diffs); 131 fprintf(stderr, "Invalid transform output: %d diffs\n", diffs);
154 } 132 }
155 133
156 free(src0); 134 free(src0);
157 free(src1); 135 free(src1);
158 free(dst0); 136 free(dst0);
159 free(dst1); 137 free(dst1);
160 } 138 }
161 139
162 #define STRINGIZE(s) #s 140 #define STRINGIZE(s) #s
163 #define STRING(s) STRINGIZE(s) 141 #define STRING(s) STRINGIZE(s)
164 142
165 printf("%.6lf (avg %.6lf) seconds " STRING(TRANSFORM_TEST0) "\n", 143 printf("%.6lf (avg %.6lf) seconds " STRING(TRANSFORM_TEST0) "\n",
166 time0, time0 / iterations); 144 time0, time0 / iterations);
167 printf("%.6lf (avg %.6lf) seconds " STRING(TRANSFORM_TEST1) "\n", 145 printf("%.6lf (avg %.6lf) seconds " STRING(TRANSFORM_TEST1) "\n",
168 time1, time1 / iterations); 146 time1, time1 / iterations);
169 printf("%.6lf speedup after %d iterations\n\n", 147 printf("%.6lf speedup after %d iterations\n\n",
170 time0 / time1, iterations); 148 time0 / time1, iterations);
171 149
172 free(lut0); 150 free(lut0);
173 free(lut1); 151 free(lut1);
174 152
175 return EXIT_SUCCESS; 153 return diffs;
176 } 154 }
155
156 struct qcms_test_case qcms_test_tetra_clut_rgba_info = {
157 "qcms_test_tetra_clut_rgba",
158 qcms_test_tetra_clut_rgba,
159 QCMS_TEST_DISABLED
160 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698