elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, Alliance for Open Media. All rights reserved |
| 3 | * |
| 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
| 10 | */ |
| 11 | |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 12 | #include <stdbool.h> |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 13 | #include "aom_mem/aom_mem.h" |
| 14 | #include "av1/encoder/rdopt.h" |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 15 | #include "test/util.h" |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 16 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
| 17 | |
| 18 | namespace { |
| 19 | |
elliottk | 9be5922 | 2018-10-19 16:17:17 -0700 | [diff] [blame] | 20 | using ::testing::get; |
| 21 | using ::testing::tuple; |
| 22 | |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 23 | static int get_pix(uint8_t *buf, int i, bool high_bd) { |
| 24 | if (high_bd) { |
| 25 | return *CONVERT_TO_SHORTPTR(buf + i); |
| 26 | } else { |
| 27 | return buf[i]; |
| 28 | } |
| 29 | } |
| 30 | |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 31 | /** Get the (i, j) value from the input; if i or j is outside of the width |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 32 | * or height, the nearest pixel value is returned. |
| 33 | */ |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 34 | static int get_nearest_pix(const int *buf, int w, int h, int i, int j) { |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 35 | int offset = AOMMAX(AOMMIN(i, w - 1), 0) + w * AOMMAX(AOMMIN(j, h - 1), 0); |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 36 | return buf[offset]; |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | /** Given the image data, creates a new image with padded values, so an |
| 40 | * 8-tap filter can be convolved. The padded value is the same as the closest |
| 41 | * value in the image. Returns a pointer to the start of the image in the |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 42 | * padded data. Must be freed with free_pad_8tap. The output will be either |
| 43 | * 8-bit or 16-bit, depending on the high bit-depth (high_bd) field. |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 44 | */ |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 45 | static uint8_t *pad_8tap_convolve(const int *data, int w, int h, bool high_bd) { |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 46 | // SIMD optimizations require the width to be a multiple of 8 and the height |
| 47 | // to be multiples of 4. |
| 48 | assert(w % 8 == 0); |
| 49 | assert(h % 4 == 0); |
| 50 | // For an 8-tap filter, we need to pad with 3 lines on top and on the left, |
| 51 | // and 4 lines on the right and bottom, for 7 extra lines. |
| 52 | const int pad_w = w + 7; |
| 53 | const int pad_h = h + 7; |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 54 | |
| 55 | uint8_t *dst; |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 56 | if (high_bd) { |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 57 | dst = |
| 58 | CONVERT_TO_BYTEPTR(aom_memalign(32, sizeof(uint16_t) * pad_w * pad_h)); |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 59 | } else { |
| 60 | dst = (uint8_t *)aom_memalign(32, sizeof(uint8_t) * pad_w * pad_h); |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 61 | } |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 62 | for (int j = 0; j < pad_h; ++j) { |
| 63 | for (int i = 0; i < pad_w; ++i) { |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 64 | const int v = get_nearest_pix(data, w, h, i - 3, j - 3); |
| 65 | if (high_bd) { |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 66 | *CONVERT_TO_SHORTPTR(dst + i + j * pad_w) = v; |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 67 | } else { |
| 68 | dst[i + j * pad_w] = v; |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 69 | } |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | return dst + (w + 7) * 3 + 3; |
| 73 | } |
| 74 | |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 75 | static int stride_8tap(int width) { return width + 7; } |
| 76 | |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 77 | static void free_pad_8tap(uint8_t *padded, int width, bool high_bd) { |
| 78 | if (high_bd) { |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 79 | aom_free(CONVERT_TO_SHORTPTR(padded - (width + 7) * 3 - 3)); |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 80 | } else { |
| 81 | aom_free(padded - (width + 7) * 3 - 3); |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 82 | } |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 83 | } |
| 84 | |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 85 | static uint8_t *malloc_bd(int num_entries, bool high_bd) { |
| 86 | const int bytes_per_entry = high_bd ? sizeof(uint16_t) : sizeof(uint8_t); |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 87 | |
| 88 | uint8_t *buf = (uint8_t *)aom_memalign(32, bytes_per_entry * num_entries); |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 89 | if (high_bd) { |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 90 | return CONVERT_TO_BYTEPTR(buf); |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 91 | } else { |
| 92 | return buf; |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 96 | static void free_bd(uint8_t *p, bool high_bd) { |
| 97 | if (high_bd) { |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 98 | aom_free(CONVERT_TO_SHORTPTR(p)); |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 99 | } else { |
| 100 | aom_free(p); |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | |
| 104 | class EdgeDetectBrightnessTest : |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 105 | // Parameters are (brightness, width, height, high bit depth representation, |
| 106 | // bit depth). |
| 107 | public ::testing::TestWithParam<tuple<int, int, int, bool, int> > { |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 108 | protected: |
| 109 | void SetUp() override { |
| 110 | // Allocate a (width by height) array of luma values in orig_. |
| 111 | // padded_ will be filled by the pad() call, which adds a border around |
| 112 | // the orig_. The output_ array has enough space for the computation. |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 113 | const int brightness = GET_PARAM(0); |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 114 | const int width = GET_PARAM(1); |
| 115 | const int height = GET_PARAM(2); |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 116 | const bool high_bd = GET_PARAM(3); |
| 117 | |
| 118 | // Create the padded image of uniform brightness. |
| 119 | int *orig = (int *)malloc(width * height * sizeof(int)); |
| 120 | for (int i = 0; i < width * height; ++i) { |
| 121 | orig[i] = brightness; |
| 122 | } |
| 123 | input_ = pad_8tap_convolve(orig, width, height, high_bd); |
| 124 | free(orig); |
| 125 | output_ = malloc_bd(width * height, high_bd); |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | void TearDown() override { |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 129 | const int width = GET_PARAM(1); |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 130 | const bool high_bd = GET_PARAM(3); |
| 131 | free_pad_8tap(input_, width, high_bd); |
| 132 | free_bd(output_, high_bd); |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 133 | } |
| 134 | |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 135 | // Skip the tests where brightness exceeds the bit-depth; we run into this |
| 136 | // issue because of gtest's limitation on valid combinations of test |
| 137 | // parameters. Also skip the tests where bit depth is greater than 8, but |
| 138 | // high bit depth representation is not set. |
| 139 | bool should_skip() const { |
| 140 | const int brightness = GET_PARAM(0); |
| 141 | const int bd = GET_PARAM(4); |
| 142 | if (brightness >= (1 << bd)) { |
| 143 | return true; |
| 144 | } |
| 145 | const bool high_bd = GET_PARAM(3); |
| 146 | if (bd > 8 && !high_bd) { |
| 147 | return true; |
| 148 | } |
| 149 | return false; |
| 150 | } |
| 151 | |
| 152 | uint8_t *input_; |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 153 | uint8_t *output_; |
| 154 | }; |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 155 | |
| 156 | TEST_P(EdgeDetectBrightnessTest, BlurUniformBrightness) { |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 157 | // Some combination of parameters are non-sensical, due to limitations |
| 158 | // of the testing framework. Ignore these. |
| 159 | if (should_skip()) { |
| 160 | return; |
| 161 | } |
| 162 | |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 163 | // For varying levels of brightness, the algorithm should |
| 164 | // produce the same output. |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 165 | const int brightness = GET_PARAM(0); |
| 166 | const int width = GET_PARAM(1); |
| 167 | const int height = GET_PARAM(2); |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 168 | const bool high_bd = GET_PARAM(3); |
| 169 | const int bd = GET_PARAM(4); |
| 170 | |
| 171 | gaussian_blur(input_, stride_8tap(width), width, height, output_, high_bd, |
| 172 | bd); |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 173 | for (int i = 0; i < width * height; ++i) { |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 174 | ASSERT_EQ(brightness, get_pix(output_, i, high_bd)); |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 175 | } |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | // No edges on a uniformly bright image. |
| 179 | TEST_P(EdgeDetectBrightnessTest, DetectUniformBrightness) { |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 180 | if (should_skip()) { |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 181 | return; |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 182 | } |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 183 | const int width = GET_PARAM(1); |
| 184 | const int height = GET_PARAM(2); |
| 185 | const bool high_bd = GET_PARAM(3); |
| 186 | const int bd = GET_PARAM(4); |
| 187 | |
elliottk | 17dd3ea | 2019-02-01 11:59:57 -0800 | [diff] [blame] | 188 | ASSERT_EQ( |
| 189 | 0, av1_edge_exists(input_, stride_8tap(width), width, height, high_bd, bd) |
| 190 | .magnitude); |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | INSTANTIATE_TEST_CASE_P(ImageBrightnessTests, EdgeDetectBrightnessTest, |
| 194 | ::testing::Combine( |
| 195 | // Brightness |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 196 | ::testing::Values(0, 1, 2, 127, 128, 129, 254, 255, |
| 197 | 256, 511, 512, 1023, 1024, 2048, |
| 198 | 4095), |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 199 | // Width |
| 200 | ::testing::Values(8, 16, 32), |
| 201 | // Height |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 202 | ::testing::Values(4, 8, 12, 32), |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 203 | // High bit depth representation |
| 204 | ::testing::Bool(), |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 205 | // Bit depth |
| 206 | ::testing::Values(8, 10, 12))); |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 207 | |
| 208 | class EdgeDetectImageTest : |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 209 | // Parameters are (width, height, high bit depth representation, bit depth). |
| 210 | public ::testing::TestWithParam<tuple<int, int, bool, int> > { |
| 211 | protected: |
| 212 | // Skip the tests where bit depth is greater than 8, but high bit depth |
| 213 | // representation is not set (limitation of testing framework). |
| 214 | bool should_skip() const { |
| 215 | const bool high_bd = GET_PARAM(2); |
| 216 | const int bd = GET_PARAM(3); |
| 217 | return bd > 8 && !high_bd; |
| 218 | } |
| 219 | }; |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 220 | |
| 221 | // Generate images with black on one side and white on the other. |
| 222 | TEST_P(EdgeDetectImageTest, BlackWhite) { |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 223 | // Some combination of parameters are non-sensical, due to limitations |
| 224 | // of the testing framework. Ignore these. |
| 225 | if (should_skip()) { |
| 226 | return; |
| 227 | } |
| 228 | |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 229 | const int width = GET_PARAM(0); |
| 230 | const int height = GET_PARAM(1); |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 231 | const bool high_bd = GET_PARAM(2); |
| 232 | const int bd = GET_PARAM(3); |
| 233 | |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 234 | const int white = (1 << bd) - 1; |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 235 | int *orig = (int *)malloc(width * height * sizeof(int)); |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 236 | for (int j = 0; j < height; ++j) { |
| 237 | for (int i = 0; i < width; ++i) { |
| 238 | if (i < width / 2) { |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 239 | orig[i + j * width] = 0; |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 240 | } else { |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 241 | orig[i + j * width] = white; |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | } |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 245 | uint8_t *padded = pad_8tap_convolve(orig, width, height, high_bd); |
| 246 | free(orig); |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 247 | // Value should be between 556 and 560. |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 248 | ASSERT_LE(556, av1_edge_exists(padded, stride_8tap(width), width, height, |
elliottk | 17dd3ea | 2019-02-01 11:59:57 -0800 | [diff] [blame] | 249 | high_bd, bd) |
| 250 | .magnitude); |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 251 | ASSERT_GE(560, av1_edge_exists(padded, stride_8tap(width), width, height, |
elliottk | 17dd3ea | 2019-02-01 11:59:57 -0800 | [diff] [blame] | 252 | high_bd, bd) |
| 253 | .magnitude); |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 254 | |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 255 | free_pad_8tap(padded, width, high_bd); |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 256 | } |
| 257 | |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 258 | // Hardcoded blur tests. |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 259 | static const int luma[32] = { 241, 147, 7, 90, 184, 103, 28, 186, |
| 260 | 2, 248, 49, 242, 114, 146, 127, 22, |
| 261 | 121, 228, 167, 108, 158, 174, 41, 168, |
| 262 | 214, 99, 184, 109, 114, 247, 117, 119 }; |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 263 | static const uint8_t expected[] = { 161, 138, 119, 118, 123, 118, 113, 122, |
| 264 | 143, 140, 134, 133, 134, 126, 116, 114, |
| 265 | 147, 149, 145, 142, 143, 138, 126, 118, |
| 266 | 164, 156, 148, 144, 148, 148, 138, 126 }; |
| 267 | |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 268 | static void hardcoded_blur_test_aux(const bool high_bd) { |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 269 | const int w = 8; |
| 270 | const int h = 4; |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 271 | for (int bd = 8; bd <= 12; bd += 2) { |
| 272 | // Skip the tests where bit depth is greater than 8, but high bit depth |
| 273 | // representation is not set. |
| 274 | if (bd > 8 && !high_bd) { |
| 275 | break; |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 276 | } |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 277 | uint8_t *output = malloc_bd(w * h, high_bd); |
| 278 | uint8_t *padded = pad_8tap_convolve(luma, w, h, high_bd); |
| 279 | gaussian_blur(padded, stride_8tap(w), w, h, output, high_bd, bd); |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 280 | for (int i = 0; i < w * h; ++i) { |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 281 | ASSERT_EQ(expected[i], get_pix(output, i, high_bd)); |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 282 | } |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 283 | free_pad_8tap(padded, w, high_bd); |
| 284 | free_bd(output, high_bd); |
| 285 | |
| 286 | // If we multiply the inputs by a constant factor, the output should not |
| 287 | // vary more than 0.5 * factor. |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 288 | for (int c = 2; c < (1 << (bd - 8)); ++c) { |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 289 | int scaled_luma[32]; |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 290 | for (int i = 0; i < 32; ++i) { |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 291 | scaled_luma[i] = luma[i] * c; |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 292 | } |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 293 | uint8_t *output = malloc_bd(w * h, high_bd); |
| 294 | uint8_t *padded = pad_8tap_convolve(scaled_luma, w, h, high_bd); |
| 295 | gaussian_blur(padded, stride_8tap(w), w, h, output, high_bd, bd); |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 296 | for (int i = 0; i < w * h; ++i) { |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 297 | ASSERT_GE(c / 2, abs(expected[i] * c - get_pix(output, i, high_bd))); |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 298 | } |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 299 | free_pad_8tap(padded, w, high_bd); |
| 300 | free_bd(output, high_bd); |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | } |
| 304 | |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 305 | TEST(EdgeDetectImageTest, HardcodedBlurTest) { |
| 306 | hardcoded_blur_test_aux(false); |
| 307 | hardcoded_blur_test_aux(true); |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | TEST(EdgeDetectImageTest, SobelTest) { |
| 311 | // Randomly generated 3x3. Compute Sobel for middle value. |
| 312 | const uint8_t buf[9] = { 241, 147, 7, 90, 184, 103, 28, 186, 2 }; |
| 313 | const int stride = 3; |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 314 | bool high_bd = false; |
| 315 | sobel_xy result = sobel(buf, stride, 1, 1, high_bd); |
| 316 | ASSERT_EQ(234, result.x); |
| 317 | ASSERT_EQ(140, result.y); |
| 318 | |
| 319 | // Verify it works for 8-bit values in a high bit-depth buffer. |
| 320 | const uint16_t buf8_16[9] = { 241, 147, 7, 90, 184, 103, 28, 186, 2 }; |
| 321 | high_bd = true; |
| 322 | result = sobel(CONVERT_TO_BYTEPTR(buf8_16), stride, 1, 1, high_bd); |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 323 | ASSERT_EQ(234, result.x); |
| 324 | ASSERT_EQ(140, result.y); |
| 325 | |
| 326 | // Verify it works for high bit-depth values as well. |
| 327 | const uint16_t buf16[9] = { 241, 147, 7, 90, 184, 2003, 1028, 186, 2 }; |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 328 | result = sobel(CONVERT_TO_BYTEPTR(buf16), stride, 1, 1, high_bd); |
| 329 | ASSERT_EQ(-2566, result.x); |
| 330 | ASSERT_EQ(-860, result.y); |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | INSTANTIATE_TEST_CASE_P(EdgeDetectImages, EdgeDetectImageTest, |
| 334 | ::testing::Combine( |
| 335 | // Width |
| 336 | ::testing::Values(8, 16, 32), |
| 337 | // Height |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 338 | ::testing::Values(4, 8, 12, 32), |
elliottk | 1dbb8c1 | 2018-11-06 22:28:59 -0800 | [diff] [blame] | 339 | // High bit depth representation |
| 340 | ::testing::Bool(), |
elliottk | 84c6daf | 2018-11-01 17:39:08 -0700 | [diff] [blame] | 341 | // Bit depth |
| 342 | ::testing::Values(8, 10, 12))); |
elliottk | 35be78d | 2018-10-17 16:07:12 -0700 | [diff] [blame] | 343 | } // namespace |