Angie Chiang | 3f84199 | 2016-10-27 11:43:10 -0700 | [diff] [blame] | 1 | /* |
| 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 Chiang | 3f84199 | 2016-10-27 11:43:10 -0700 | [diff] [blame] | 12 | #include "av1/common/scan.h" |
Angie Chiang | 3f84199 | 2016-10-27 11:43:10 -0700 | [diff] [blame] | 13 | #include "third_party/googletest/src/include/gtest/gtest.h" |
| 14 | |
Angie Chiang | 3f84199 | 2016-10-27 11:43:10 -0700 | [diff] [blame] | 15 | namespace { |
| 16 | |
Angie Chiang | ec93224 | 2016-10-31 11:25:59 -0700 | [diff] [blame] | 17 | TEST(ScanTest, av1_augment_prob) { |
| 18 | const int tx1d_size = 4; |
Angie Chiang | 3f84199 | 2016-10-27 11:43:10 -0700 | [diff] [blame] | 19 | uint32_t prob[16] = { 8, 8, 7, 7, 8, 8, 4, 2, 3, 3, 2, 2, 2, 2, 2, 2 }; |
Angie Chiang | ec93224 | 2016-10-31 11:25:59 -0700 | [diff] [blame] | 20 | 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 Chiang | 3f84199 | 2016-10-27 11:43:10 -0700 | [diff] [blame] | 23 | 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 Chiang | ec93224 | 2016-10-31 11:25:59 -0700 | [diff] [blame] | 26 | const int idx = r * tx1d_size + c; |
Angie Chiang | 3f84199 | 2016-10-27 11:43:10 -0700 | [diff] [blame] | 27 | EXPECT_EQ(ref_prob[idx], prob[idx] >> 16); |
| 28 | } |
| 29 | } |
| 30 | |
Angie Chiang | ec93224 | 2016-10-31 11:25:59 -0700 | [diff] [blame] | 31 | const int mask = (1 << 10) - 1; |
Angie Chiang | 3f84199 | 2016-10-27 11:43:10 -0700 | [diff] [blame] | 32 | for (int r = 0; r < tx1d_size; ++r) { |
| 33 | for (int c = 0; c < tx1d_size; ++c) { |
Angie Chiang | ec93224 | 2016-10-31 11:25:59 -0700 | [diff] [blame] | 34 | const int idx = r * tx1d_size + c; |
Angie Chiang | 3f84199 | 2016-10-27 11:43:10 -0700 | [diff] [blame] | 35 | EXPECT_EQ(idx, mask ^ (prob[r * tx1d_size + c] & mask)); |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
Angie Chiang | ec93224 | 2016-10-31 11:25:59 -0700 | [diff] [blame] | 40 | TEST(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 Chiang | 3f84199 | 2016-10-27 11:43:10 -0700 | [diff] [blame] | 45 | 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 Chiang | ec93224 | 2016-10-31 11:25:59 -0700 | [diff] [blame] | 50 | TEST(ScanTest, av1_update_scan_order) { |
Angie Chiang | 3f84199 | 2016-10-27 11:43:10 -0700 | [diff] [blame] | 51 | TX_SIZE tx_size = TX_4X4; |
Angie Chiang | ec93224 | 2016-10-31 11:25:59 -0700 | [diff] [blame] | 52 | const uint32_t prob[16] = { 4, 5, 7, 4, 5, 6, 8, 2, 3, 3, 2, 2, 2, 2, 2, 2 }; |
Angie Chiang | 3f84199 | 2016-10-27 11:43:10 -0700 | [diff] [blame] | 53 | int16_t sort_order[16]; |
| 54 | int16_t scan[16]; |
| 55 | int16_t iscan[16]; |
Angie Chiang | ec93224 | 2016-10-31 11:25:59 -0700 | [diff] [blame] | 56 | const int16_t ref_iscan[16] = { 0, 1, 2, 6, 3, 4, 5, 10, |
| 57 | 7, 8, 11, 13, 9, 12, 14, 15 }; |
Angie Chiang | 3f84199 | 2016-10-27 11:43:10 -0700 | [diff] [blame] | 58 | |
| 59 | av1_update_sort_order(tx_size, prob, sort_order); |
| 60 | av1_update_scan_order(tx_size, sort_order, scan, iscan); |
| 61 | |
Angie Chiang | ec93224 | 2016-10-31 11:25:59 -0700 | [diff] [blame] | 62 | 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 Chiang | 3f84199 | 2016-10-27 11:43:10 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Angie Chiang | ec93224 | 2016-10-31 11:25:59 -0700 | [diff] [blame] | 68 | TEST(ScanTest, av1_update_neighbors) { |
Angie Chiang | 3f84199 | 2016-10-27 11:43:10 -0700 | [diff] [blame] | 69 | TX_SIZE tx_size = TX_4X4; |
| 70 | // raster order |
Angie Chiang | ec93224 | 2016-10-31 11:25:59 -0700 | [diff] [blame] | 71 | const int16_t scan[16] = { 0, 1, 2, 3, 4, 5, 6, 7, |
| 72 | 8, 9, 10, 11, 12, 13, 14, 15 }; |
Angie Chiang | 3f84199 | 2016-10-27 11:43:10 -0700 | [diff] [blame] | 73 | int16_t nb[(16 + 1) * 2]; |
Angie Chiang | ec93224 | 2016-10-31 11:25:59 -0700 | [diff] [blame] | 74 | 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 Chiang | 3f84199 | 2016-10-27 11:43:10 -0700 | [diff] [blame] | 78 | |
| 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 |