Angie Chiang | 937dcfb | 2018-02-12 14:32:50 -0800 | [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 | |
| 12 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
| 13 | #include "av1/common/scan.h" |
| 14 | #include "av1/common/txb_common.h" |
| 15 | |
Angie Chiang | 937dcfb | 2018-02-12 14:32:50 -0800 | [diff] [blame] | 16 | static int scan_test(const int16_t *scan, const int16_t *iscan, int si, int r, |
| 17 | int c, int w) { |
| 18 | if (iscan[r * w + c] != si || scan[si] != r * w + c) { |
| 19 | printf("r %d c %d ref_iscan %d iscan %d ref_scan %d scan %d\n", r, c, si, |
| 20 | iscan[r * w + c], r * w + c, scan[si]); |
| 21 | return 1; |
| 22 | } else { |
| 23 | return 0; |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | int scan_order_test(const SCAN_ORDER *scan_order, int w, int h, |
| 28 | SCAN_MODE mode) { |
| 29 | const int16_t *scan = scan_order->scan; |
| 30 | const int16_t *iscan = scan_order->iscan; |
| 31 | int dim = w + h - 1; |
| 32 | if (mode == SCAN_MODE_ZIG_ZAG) { |
| 33 | int si = 0; |
| 34 | for (int i = 0; i < dim; ++i) { |
| 35 | if (i % 2 == 0) { |
| 36 | for (int c = 0; c < w; ++c) { |
| 37 | int r = i - c; |
| 38 | if (r >= 0 && r < h) { |
| 39 | if (scan_test(scan, iscan, si, r, c, w)) return 1; |
| 40 | ++si; |
| 41 | } |
| 42 | } |
| 43 | } else { |
| 44 | for (int r = 0; r < h; ++r) { |
| 45 | int c = i - r; |
| 46 | if (c >= 0 && c < w) { |
| 47 | if (scan_test(scan, iscan, si, r, c, w)) return 1; |
| 48 | ++si; |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | } else if (mode == SCAN_MODE_COL_DIAG) { |
| 54 | int si = 0; |
| 55 | for (int i = 0; i < dim; ++i) { |
| 56 | for (int c = 0; c < w; ++c) { |
| 57 | int r = i - c; |
| 58 | if (r >= 0 && r < h) { |
| 59 | if (scan_test(scan, iscan, si, r, c, w)) return 1; |
| 60 | ++si; |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | } else if (mode == SCAN_MODE_ROW_DIAG) { |
| 65 | int si = 0; |
| 66 | for (int i = 0; i < dim; ++i) { |
| 67 | for (int r = 0; r < h; ++r) { |
| 68 | int c = i - r; |
| 69 | if (c >= 0 && c < w) { |
| 70 | if (scan_test(scan, iscan, si, r, c, w)) return 1; |
| 71 | ++si; |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | } else if (mode == SCAN_MODE_ROW_1D) { |
| 76 | int si = 0; |
| 77 | for (int r = 0; r < h; ++r) { |
| 78 | for (int c = 0; c < w; ++c) { |
| 79 | if (scan_test(scan, iscan, si, r, c, w)) return 1; |
| 80 | ++si; |
| 81 | } |
| 82 | } |
| 83 | } else { |
| 84 | assert(mode == SCAN_MODE_COL_1D); |
| 85 | int si = 0; |
| 86 | for (int c = 0; c < w; ++c) { |
| 87 | for (int r = 0; r < h; ++r) { |
| 88 | if (scan_test(scan, iscan, si, r, c, w)) return 1; |
| 89 | ++si; |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | TEST(Av1ScanTest, Dependency) { |
| 97 | for (int tx_size = TX_4X4; tx_size < TX_SIZES_ALL; ++tx_size) { |
| 98 | const int org_rows = tx_size_high[(TX_SIZE)tx_size]; |
| 99 | const int org_cols = tx_size_wide[(TX_SIZE)tx_size]; |
| 100 | const int rows = get_txb_high((TX_SIZE)tx_size); |
| 101 | const int cols = get_txb_wide((TX_SIZE)tx_size); |
| 102 | for (int tx_type = 0; tx_type < TX_TYPES; ++tx_type) { |
| 103 | if ((rows >= 32 || cols >= 32) && tx_type != DCT_DCT && tx_type != IDTX && |
| 104 | tx_type != V_DCT && tx_type != H_DCT) { |
| 105 | // No ADST for large size transforms. |
| 106 | continue; |
| 107 | } |
| 108 | SCAN_MODE scan_mode; |
| 109 | TX_CLASS tx_class = tx_type_to_class[(TX_TYPE)tx_type]; |
| 110 | if ((tx_class == TX_CLASS_2D && tx_type != IDTX) || org_rows == 64 || |
| 111 | org_cols == 64) { |
| 112 | if (rows == cols) { |
| 113 | scan_mode = SCAN_MODE_ZIG_ZAG; |
| 114 | } else if (rows > cols) { |
| 115 | scan_mode = SCAN_MODE_ROW_DIAG; |
| 116 | } else { |
| 117 | scan_mode = SCAN_MODE_COL_DIAG; |
| 118 | } |
| 119 | } else if (tx_type == IDTX) { |
| 120 | scan_mode = SCAN_MODE_ROW_1D; |
| 121 | } else if (tx_class == TX_CLASS_VERT) { |
| 122 | scan_mode = SCAN_MODE_ROW_1D; |
| 123 | } else { |
| 124 | assert(tx_class == TX_CLASS_HORIZ); |
| 125 | scan_mode = SCAN_MODE_COL_1D; |
| 126 | } |
Angie Chiang | 937dcfb | 2018-02-12 14:32:50 -0800 | [diff] [blame] | 127 | const SCAN_ORDER *scan_order = |
Yaowu Xu | f1e1293 | 2018-02-26 15:50:09 -0800 | [diff] [blame] | 128 | get_default_scan((TX_SIZE)tx_size, (TX_TYPE)tx_type); |
Angie Chiang | 937dcfb | 2018-02-12 14:32:50 -0800 | [diff] [blame] | 129 | ASSERT_EQ(scan_order_test(scan_order, cols, rows, scan_mode), 0) |
| 130 | << "scan mismatch tx_class " << tx_class << " tx_type " << tx_type |
| 131 | << " tx_w " << org_cols << " tx_h " << org_rows << " scan_mode " |
| 132 | << scan_mode << "\n"; |
| 133 | } |
| 134 | } |
| 135 | } |