blob: d74dd0f0149e6a4788c018335c6ccae314f16f92 [file] [log] [blame]
Elliott Karpilovsky5fb44032019-11-13 14:34:37 -08001/*
2 * Copyright (c) 2019, 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
12#include <stdbool.h>
13#include "test/util.h"
14#include "av1/common/reconinter.h"
15#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
16
17#if CONFIG_ILLUM_MCOMP
18
19namespace {
20
21// To instantiate a regular test.
22class IllumMcompTest : public ::testing::Test {};
23
24TEST_F(IllumMcompTest, ComputeDc) {
25 uint8_t pred[256];
26 // Averaging the same color, is always that color.
27 for (int i = 0; i < 256; ++i) {
28 for (int j = 0; j < 256; ++j) {
29 pred[j] = i;
30 }
31 // Try different shapes/sizes/strides. They should all
32 // produce the same value.
Elliott Karpilovsky2a28eb82020-03-02 15:37:45 -080033 ASSERT_EQ(i, illum_mcomp_compute_dc_lowbd(pred, 8, 8, 8));
34 ASSERT_EQ(i, illum_mcomp_compute_dc_lowbd(pred, 1, 1, 256));
35 ASSERT_EQ(i, illum_mcomp_compute_dc_lowbd(pred, 2, 1, 128));
36 ASSERT_EQ(i, illum_mcomp_compute_dc_lowbd(pred, 2, 2, 128));
Elliott Karpilovsky5fb44032019-11-13 14:34:37 -080037 }
38
39 // Try half black, half white. Average should be grey.
40 for (int j = 0; j < 256; ++j) {
41 pred[j] = (j < 128) ? 0 : 255;
42 }
Elliott Karpilovsky2a28eb82020-03-02 15:37:45 -080043 ASSERT_EQ(128, illum_mcomp_compute_dc_lowbd(pred, 16, 16, 16));
44 ASSERT_EQ(128, illum_mcomp_compute_dc_lowbd(pred, 1, 1, 256));
45 ASSERT_EQ(128, illum_mcomp_compute_dc_lowbd(pred, 2, 1, 128));
46 ASSERT_EQ(128, illum_mcomp_compute_dc_lowbd(pred, 2, 2, 128));
Elliott Karpilovsky5fb44032019-11-13 14:34:37 -080047}
48
49TEST_F(IllumMcompTest, ComputeDcHigh) {
50 uint16_t pred[256];
51 for (int i = 0; i < 1024; ++i) {
52 for (int j = 0; j < 256; ++j) {
53 pred[j] = i;
54 }
55 // Try different shapes/sizes/strides. They should all
56 // produce the same value.
Elliott Karpilovsky2a28eb82020-03-02 15:37:45 -080057 ASSERT_EQ(i, illum_mcomp_compute_dc_highbd(pred, 16, 16, 16));
58 ASSERT_EQ(i, illum_mcomp_compute_dc_highbd(pred, 1, 1, 256));
59 ASSERT_EQ(i, illum_mcomp_compute_dc_highbd(pred, 2, 1, 128));
60 ASSERT_EQ(i, illum_mcomp_compute_dc_highbd(pred, 2, 2, 128));
Elliott Karpilovsky5fb44032019-11-13 14:34:37 -080061 }
62
63 // Try half black, half white. Average should be grey.
64 for (int j = 0; j < 256; ++j) {
65 pred[j] = (j < 128) ? 0 : 1023;
66 }
Elliott Karpilovsky2a28eb82020-03-02 15:37:45 -080067 ASSERT_EQ(512, illum_mcomp_compute_dc_highbd(pred, 16, 16, 16));
68 ASSERT_EQ(512, illum_mcomp_compute_dc_highbd(pred, 1, 1, 256));
69 ASSERT_EQ(512, illum_mcomp_compute_dc_highbd(pred, 2, 1, 128));
70 ASSERT_EQ(512, illum_mcomp_compute_dc_highbd(pred, 2, 2, 128));
Elliott Karpilovsky5fb44032019-11-13 14:34:37 -080071}
72
73} // namespace
74
75#endif // CONFIG_ILLUM_MCOMP