summaryrefslogtreecommitdiffstats
path: root/third_party/aom/test/scan_test.cc
blob: 571658ee0aad47a4f0858cbb738c619bce53fd42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
 * Copyright (c) 2018, Alliance for Open Media. All rights reserved
 *
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
 */

#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
#include "av1/common/scan.h"
#include "av1/common/txb_common.h"
#include "test/av1_txfm_test.h"

static int scan_test(const int16_t *scan, const int16_t *iscan, int si, int r,
                     int c, int h) {
  if (iscan[c * h + r] != si || scan[si] != c * h + r) {
    printf("r %d c %d ref_iscan %d iscan %d ref_scan %d scan %d\n", r, c, si,
           iscan[c * h + r], c * h + r, scan[si]);
    return 1;
  } else {
    return 0;
  }
}

int scan_order_test(const SCAN_ORDER *scan_order, int w, int h,
                    SCAN_MODE mode) {
  const int16_t *scan = scan_order->scan;
  const int16_t *iscan = scan_order->iscan;
  int dim = w + h - 1;
  if (mode == SCAN_MODE_ZIG_ZAG) {
    int si = 0;
    for (int i = 0; i < dim; ++i) {
      if (i % 2 == 0) {
        for (int c = 0; c < w; ++c) {
          int r = i - c;
          if (r >= 0 && r < h) {
            if (scan_test(scan, iscan, si, r, c, h)) return 1;
            ++si;
          }
        }
      } else {
        for (int r = 0; r < h; ++r) {
          int c = i - r;
          if (c >= 0 && c < w) {
            if (scan_test(scan, iscan, si, r, c, h)) return 1;
            ++si;
          }
        }
      }
    }
  } else if (mode == SCAN_MODE_COL_DIAG) {
    int si = 0;
    for (int i = 0; i < dim; ++i) {
      for (int c = 0; c < w; ++c) {
        int r = i - c;
        if (r >= 0 && r < h) {
          if (scan_test(scan, iscan, si, r, c, h)) return 1;
          ++si;
        }
      }
    }
  } else if (mode == SCAN_MODE_ROW_DIAG) {
    int si = 0;
    for (int i = 0; i < dim; ++i) {
      for (int r = 0; r < h; ++r) {
        int c = i - r;
        if (c >= 0 && c < w) {
          if (scan_test(scan, iscan, si, r, c, h)) return 1;
          ++si;
        }
      }
    }
  } else if (mode == SCAN_MODE_ROW_1D) {
    int si = 0;
    for (int r = 0; r < h; ++r) {
      for (int c = 0; c < w; ++c) {
        if (scan_test(scan, iscan, si, r, c, h)) return 1;
        ++si;
      }
    }
  } else {
    assert(mode == SCAN_MODE_COL_1D);
    int si = 0;
    for (int c = 0; c < w; ++c) {
      for (int r = 0; r < h; ++r) {
        if (scan_test(scan, iscan, si, r, c, h)) return 1;
        ++si;
      }
    }
  }
  return 0;
}

TEST(Av1ScanTest, Dependency) {
  for (int tx_size = TX_4X4; tx_size < TX_SIZES_ALL; ++tx_size) {
    const int org_rows = tx_size_high[(TX_SIZE)tx_size];
    const int org_cols = tx_size_wide[(TX_SIZE)tx_size];
    const int rows = get_txb_high((TX_SIZE)tx_size);
    const int cols = get_txb_wide((TX_SIZE)tx_size);
    for (int tx_type = 0; tx_type < TX_TYPES; ++tx_type) {
      if (libaom_test::IsTxSizeTypeValid(static_cast<TX_SIZE>(tx_size),
                                         static_cast<TX_TYPE>(tx_type)) ==
          false) {
        continue;
      }
      SCAN_MODE scan_mode;
      TX_CLASS tx_class = tx_type_to_class[(TX_TYPE)tx_type];
      if (tx_class == TX_CLASS_2D) {
        if (rows == cols) {
          scan_mode = SCAN_MODE_ZIG_ZAG;
        } else if (rows > cols) {
          scan_mode = SCAN_MODE_ROW_DIAG;
        } else {
          scan_mode = SCAN_MODE_COL_DIAG;
        }
      } else if (tx_class == TX_CLASS_VERT) {
        scan_mode = SCAN_MODE_ROW_1D;
      } else {
        assert(tx_class == TX_CLASS_HORIZ);
        scan_mode = SCAN_MODE_COL_1D;
      }
      const SCAN_ORDER *scan_order =
          get_default_scan((TX_SIZE)tx_size, (TX_TYPE)tx_type);
      ASSERT_EQ(scan_order_test(scan_order, cols, rows, scan_mode), 0)
          << "scan mismatch tx_class " << tx_class << " tx_type " << tx_type
          << " tx_w " << org_cols << " tx_h " << org_rows << " scan_mode "
          << scan_mode << "\n";
    }
  }
}