blob: 22a6d85ecbdce4f71ee7eff2012d8edf85ea7d0a [file] [log] [blame]
Angie Chiang3f841992016-10-27 11:43:10 -07001/*
2 * Copyright (c) 2016, 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
Angie Chiang3f841992016-10-27 11:43:10 -070012#include "av1/common/scan.h"
Angie Chiang3f841992016-10-27 11:43:10 -070013#include "third_party/googletest/src/include/gtest/gtest.h"
14
Angie Chiang3f841992016-10-27 11:43:10 -070015namespace {
16
Angie Chiangec932242016-10-31 11:25:59 -070017TEST(ScanTest, av1_augment_prob) {
18 const int tx1d_size = 4;
Angie Chiang3f841992016-10-27 11:43:10 -070019 uint32_t prob[16] = { 8, 8, 7, 7, 8, 8, 4, 2, 3, 3, 2, 2, 2, 2, 2, 2 };
Angie Chiangec932242016-10-31 11:25:59 -070020 const uint32_t ref_prob[16] = {
21 8, 8, 7, 7, 8, 8, 4, 2, 3, 3, 2, 2, 2, 2, 2, 2
22 };
Angie Chiang3f841992016-10-27 11:43:10 -070023 av1_augment_prob(prob, tx1d_size, tx1d_size);
24 for (int r = 0; r < tx1d_size; ++r) {
25 for (int c = 0; c < tx1d_size; ++c) {
Angie Chiangec932242016-10-31 11:25:59 -070026 const int idx = r * tx1d_size + c;
Angie Chiang3f841992016-10-27 11:43:10 -070027 EXPECT_EQ(ref_prob[idx], prob[idx] >> 16);
28 }
29 }
30
Angie Chiangec932242016-10-31 11:25:59 -070031 const int mask = (1 << 10) - 1;
Angie Chiang3f841992016-10-27 11:43:10 -070032 for (int r = 0; r < tx1d_size; ++r) {
33 for (int c = 0; c < tx1d_size; ++c) {
Angie Chiangec932242016-10-31 11:25:59 -070034 const int idx = r * tx1d_size + c;
Angie Chiang3f841992016-10-27 11:43:10 -070035 EXPECT_EQ(idx, mask ^ (prob[r * tx1d_size + c] & mask));
36 }
37 }
38}
39
Angie Chiangec932242016-10-31 11:25:59 -070040TEST(ScanTest, av1_update_sort_order) {
41 const TX_SIZE tx_size = TX_4X4;
42 const uint32_t prob[16] = { 8, 8, 7, 7, 8, 8, 4, 2, 3, 3, 2, 2, 2, 2, 2, 2 };
43 const int16_t ref_sort_order[16] = { 0, 1, 4, 5, 2, 3, 6, 8,
44 9, 12, 7, 10, 13, 11, 14, 15 };
Angie Chiang3f841992016-10-27 11:43:10 -070045 int16_t sort_order[16];
46 av1_update_sort_order(tx_size, prob, sort_order);
47 for (int i = 0; i < 16; ++i) EXPECT_EQ(ref_sort_order[i], sort_order[i]);
48}
49
Angie Chiangec932242016-10-31 11:25:59 -070050TEST(ScanTest, av1_update_scan_order) {
Angie Chiang3f841992016-10-27 11:43:10 -070051 TX_SIZE tx_size = TX_4X4;
Angie Chiangec932242016-10-31 11:25:59 -070052 const uint32_t prob[16] = { 4, 5, 7, 4, 5, 6, 8, 2, 3, 3, 2, 2, 2, 2, 2, 2 };
Angie Chiang3f841992016-10-27 11:43:10 -070053 int16_t sort_order[16];
54 int16_t scan[16];
55 int16_t iscan[16];
Angie Chiangec932242016-10-31 11:25:59 -070056 const int16_t ref_iscan[16] = { 0, 1, 2, 6, 3, 4, 5, 10,
57 7, 8, 11, 13, 9, 12, 14, 15 };
Angie Chiang3f841992016-10-27 11:43:10 -070058
59 av1_update_sort_order(tx_size, prob, sort_order);
60 av1_update_scan_order(tx_size, sort_order, scan, iscan);
61
Angie Chiangec932242016-10-31 11:25:59 -070062 for (int i = 0; i < 16; ++i) {
63 EXPECT_EQ(ref_iscan[i], iscan[i]);
64 EXPECT_EQ(i, scan[ref_iscan[i]]);
65 }
Angie Chiang3f841992016-10-27 11:43:10 -070066}
67
Angie Chiangec932242016-10-31 11:25:59 -070068TEST(ScanTest, av1_update_neighbors) {
Angie Chiang3f841992016-10-27 11:43:10 -070069 TX_SIZE tx_size = TX_4X4;
70 // raster order
Angie Chiangec932242016-10-31 11:25:59 -070071 const int16_t scan[16] = { 0, 1, 2, 3, 4, 5, 6, 7,
72 8, 9, 10, 11, 12, 13, 14, 15 };
Angie Chiang3f841992016-10-27 11:43:10 -070073 int16_t nb[(16 + 1) * 2];
Angie Chiangec932242016-10-31 11:25:59 -070074 const int16_t ref_nb[(16 + 1) * 2] = { 0, 0, 0, 0, 1, 1, 2, 2, 0,
75 0, 4, 1, 5, 2, 6, 3, 4, 4,
76 8, 5, 9, 6, 10, 7, 8, 8, 12,
77 9, 13, 10, 14, 11, 0, 0 };
Angie Chiang3f841992016-10-27 11:43:10 -070078
79 // raster order's scan and iscan are the same
80 av1_update_neighbors(tx_size, scan, scan, nb);
81 for (int i = 0; i < (16 + 1) * 2; ++i) {
82 EXPECT_EQ(ref_nb[i], nb[i]);
83 }
84}
85
86} // namespace