xref: /aosp_15_r20/external/libaom/test/scan_test.cc (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
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 "av1/common/scan.h"
13 #include "av1/common/txb_common.h"
14 #include "gtest/gtest.h"
15 #include "test/av1_txfm_test.h"
16 
scan_test(const int16_t * scan,const int16_t * iscan,int si,int r,int c,int h)17 static int scan_test(const int16_t *scan, const int16_t *iscan, int si, int r,
18                      int c, int h) {
19   if (iscan[c * h + r] != si || scan[si] != c * h + r) {
20     printf("r %d c %d ref_iscan %d iscan %d ref_scan %d scan %d\n", r, c, si,
21            iscan[c * h + r], c * h + r, scan[si]);
22     return 1;
23   } else {
24     return 0;
25   }
26 }
27 
scan_order_test(const SCAN_ORDER * scan_order,int w,int h,SCAN_MODE mode)28 static 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, h)) return 1;
41             ++si;
42           }
43         }
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, h)) return 1;
49             ++si;
50           }
51         }
52       }
53     }
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, h)) return 1;
61           ++si;
62         }
63       }
64     }
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, h)) return 1;
72           ++si;
73         }
74       }
75     }
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, h)) return 1;
81         ++si;
82       }
83     }
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, h)) return 1;
90         ++si;
91       }
92     }
93   }
94   return 0;
95 }
96 
TEST(Av1ScanTest,Dependency)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;
108       }
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;
118         }
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;
124       }
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";
131     }
132   }
133 }
134