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

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 test size 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)
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 transform0.grid_size = samples; 87 transform0.grid_size = samples;
110 transform1.grid_size = samples; 88 transform1.grid_size = samples;
111 89
112 lutSize = 3 * samples * samples * samples; 90 lutSize = 3 * samples * samples * samples;
113 lut0 = create_lut(lutSize); 91 lut0 = create_lut(lutSize);
114 lut1 = (float *)malloc(lutSize * sizeof(float)); 92 lut1 = (float *)malloc(lutSize * sizeof(float));
115 memcpy(lut1, lut0, lutSize * sizeof(float)); 93 memcpy(lut1, lut0, lutSize * sizeof(float));
116 94
117 transform0.r_clut = &lut0[0]; 95 transform0.r_clut = &lut0[0];
118 transform0.g_clut = &lut0[1]; 96 transform0.g_clut = &lut0[1];
119 transform0.b_clut = &lut0[2]; 97 transform0.b_clut = &lut0[2];
120 98
121 transform1.r_clut = &lut1[0]; 99 transform1.r_clut = &lut1[0];
122 transform1.g_clut = &lut1[1]; 100 transform1.g_clut = &lut1[1];
123 transform1.b_clut = &lut1[2]; 101 transform1.b_clut = &lut1[2];
124 102
125 // Re-generate and use different data sources during the iteration loop 103 // Re-generate and use different data sources during the iteration loop
126 // to avoid compiler / cache optimizations that may affect performance. 104 // to avoid compiler / cache optimizations that may affect performance.
127 105
128 time0 = 0.0; 106 time0 = 0.0;
129 time1 = 0.0; 107 time1 = 0.0;
130 108
131 for (i = 0; i < iterations; ++i) { 109 for (i = 0; i < iterations; ++i) {
132 unsigned char *src0 = (unsigned char *)calloc(length, PIXEL_SIZE); 110 unsigned char *src0 = (unsigned char *)calloc(length, pixel_size);
133 unsigned char *src1 = (unsigned char *)calloc(length, PIXEL_SIZE); 111 unsigned char *src1 = (unsigned char *)calloc(length, pixel_size);
134 unsigned char *dst0 = (unsigned char *)calloc(length, PIXEL_SIZE); 112 unsigned char *dst0 = (unsigned char *)calloc(length, pixel_size);
135 unsigned char *dst1 = (unsigned char *)calloc(length, PIXEL_SIZE); 113 unsigned char *dst1 = (unsigned char *)calloc(length, pixel_size);
136 114
137 generate_source(src0, length); 115 generate_source_uint8_t(src0, length, pixel_size);
138 memcpy(src1, src0, length * PIXEL_SIZE); 116 memcpy(src1, src0, length * pixel_size);
139 117
140 #define TRANSFORM_TEST0 qcms_transform_data_tetra_clut_rgba 118 #define TRANSFORM_TEST0 qcms_transform_data_tetra_clut_rgba
141 #define TRANSFORM_TEST1 qcms_transform_data_tetra_clut_rgba_sse2 119 #define TRANSFORM_TEST1 qcms_transform_data_tetra_clut_rgba_sse2
142 120
143 TIME(TRANSFORM_TEST0(&transform0, src0, dst0, length, format), &time0); 121 TIME(TRANSFORM_TEST0(&transform0, src0, dst0, length, format), &time0);
144 TIME(TRANSFORM_TEST1(&transform1, src1, dst1, length, format), &time1); 122 TIME(TRANSFORM_TEST1(&transform1, src1, dst1, length, format), &time1);
145 123
146 if (!validate(dst0, dst1, length, 0)) { 124 if (!validate(dst0, dst1, length, 0, pixel_size)) {
147 fprintf(stderr, "Invalid transform output: %d diffs\n", diffs); 125 fprintf(stderr, "Invalid transform output: %d diffs\n", diffs);
148 } 126 }
149 127
150 free(src0); 128 free(src0);
151 free(src1); 129 free(src1);
152 free(dst0); 130 free(dst0);
153 free(dst1); 131 free(dst1);
154 } 132 }
155 133
156 #define STRINGIZE(s) #s 134 #define STRINGIZE(s) #s
157 #define STRING(s) STRINGIZE(s) 135 #define STRING(s) STRINGIZE(s)
158 136
159 printf("%.6lf (avg %.6lf) seconds " STRING(TRANSFORM_TEST0) "\n", 137 printf("%.6lf (avg %.6lf) seconds " STRING(TRANSFORM_TEST0) "\n",
160 time0, time0 / iterations); 138 time0, time0 / iterations);
161 printf("%.6lf (avg %.6lf) seconds " STRING(TRANSFORM_TEST1) "\n", 139 printf("%.6lf (avg %.6lf) seconds " STRING(TRANSFORM_TEST1) "\n",
162 time1, time1 / iterations); 140 time1, time1 / iterations);
163 printf("%.6lf speedup after %d iterations\n\n", 141 printf("%.6lf speedup after %d iterations\n\n",
164 time0 / time1, iterations); 142 time0 / time1, iterations);
165 143
166 free(lut0); 144 free(lut0);
167 free(lut1); 145 free(lut1);
168 146
169 return EXIT_SUCCESS; 147 return diffs;
170 } 148 }
149
150 struct qcms_test_case qcms_test_tetra_clut_rgba_info = {
151 "qcms_test_tetra_clut_rgba",
152 qcms_test_tetra_clut_rgba,
153 QCMS_TEST_DISABLED
154 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698