Bug 1771985 [wpt PR 34266] - [FedCM] Move set_cookie into the helper file to share...
[gecko.git] / third_party / aom / test / scan_test.cc
blobdee2ab5a6978ee0620845db7bbd35b42a6224411
1 /*
2 * Copyright (c) 2018, Alliance for Open Media. All rights reserved
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.
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 #include "test/av1_txfm_test.h"
17 static int scan_test(const int16_t *scan, const int16_t *iscan, int si, int r,
18 int c, int w) {
19 if (iscan[r * w + c] != si || scan[si] != r * w + c) {
20 printf("r %d c %d ref_iscan %d iscan %d ref_scan %d scan %d\n", r, c, si,
21 iscan[r * w + c], r * w + c, scan[si]);
22 return 1;
23 } else {
24 return 0;
28 int scan_order_test(const SCAN_ORDER *scan_order, int w, int h,
29 SCAN_MODE mode) {
30 const int16_t *scan = scan_order->scan;
31 const int16_t *iscan = scan_order->iscan;
32 int dim = w + h - 1;
33 if (mode == SCAN_MODE_ZIG_ZAG) {
34 int si = 0;
35 for (int i = 0; i < dim; ++i) {
36 if (i % 2 == 0) {
37 for (int c = 0; c < w; ++c) {
38 int r = i - c;
39 if (r >= 0 && r < h) {
40 if (scan_test(scan, iscan, si, r, c, w)) return 1;
41 ++si;
44 } else {
45 for (int r = 0; r < h; ++r) {
46 int c = i - r;
47 if (c >= 0 && c < w) {
48 if (scan_test(scan, iscan, si, r, c, w)) return 1;
49 ++si;
54 } else if (mode == SCAN_MODE_COL_DIAG) {
55 int si = 0;
56 for (int i = 0; i < dim; ++i) {
57 for (int c = 0; c < w; ++c) {
58 int r = i - c;
59 if (r >= 0 && r < h) {
60 if (scan_test(scan, iscan, si, r, c, w)) return 1;
61 ++si;
65 } else if (mode == SCAN_MODE_ROW_DIAG) {
66 int si = 0;
67 for (int i = 0; i < dim; ++i) {
68 for (int r = 0; r < h; ++r) {
69 int c = i - r;
70 if (c >= 0 && c < w) {
71 if (scan_test(scan, iscan, si, r, c, w)) return 1;
72 ++si;
76 } else if (mode == SCAN_MODE_ROW_1D) {
77 int si = 0;
78 for (int r = 0; r < h; ++r) {
79 for (int c = 0; c < w; ++c) {
80 if (scan_test(scan, iscan, si, r, c, w)) return 1;
81 ++si;
84 } else {
85 assert(mode == SCAN_MODE_COL_1D);
86 int si = 0;
87 for (int c = 0; c < w; ++c) {
88 for (int r = 0; r < h; ++r) {
89 if (scan_test(scan, iscan, si, r, c, w)) return 1;
90 ++si;
94 return 0;
97 TEST(Av1ScanTest, Dependency) {
98 for (int tx_size = TX_4X4; tx_size < TX_SIZES_ALL; ++tx_size) {
99 const int org_rows = tx_size_high[(TX_SIZE)tx_size];
100 const int org_cols = tx_size_wide[(TX_SIZE)tx_size];
101 const int rows = get_txb_high((TX_SIZE)tx_size);
102 const int cols = get_txb_wide((TX_SIZE)tx_size);
103 for (int tx_type = 0; tx_type < TX_TYPES; ++tx_type) {
104 if (libaom_test::IsTxSizeTypeValid(static_cast<TX_SIZE>(tx_size),
105 static_cast<TX_TYPE>(tx_type)) ==
106 false) {
107 continue;
109 SCAN_MODE scan_mode;
110 TX_CLASS tx_class = tx_type_to_class[(TX_TYPE)tx_type];
111 if (tx_class == TX_CLASS_2D) {
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;
119 } else if (tx_class == TX_CLASS_VERT) {
120 scan_mode = SCAN_MODE_ROW_1D;
121 } else {
122 assert(tx_class == TX_CLASS_HORIZ);
123 scan_mode = SCAN_MODE_COL_1D;
125 const SCAN_ORDER *scan_order =
126 get_default_scan((TX_SIZE)tx_size, (TX_TYPE)tx_type);
127 ASSERT_EQ(scan_order_test(scan_order, cols, rows, scan_mode), 0)
128 << "scan mismatch tx_class " << tx_class << " tx_type " << tx_type
129 << " tx_w " << org_cols << " tx_h " << org_rows << " scan_mode "
130 << scan_mode << "\n";