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