xref: /aosp_15_r20/external/libaom/test/rd_test.cc (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker  * Copyright (c) 2021, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker  *
4*77c1e3ccSAndroid Build Coastguard Worker  * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker  * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker  * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker  */
11*77c1e3ccSAndroid Build Coastguard Worker 
12*77c1e3ccSAndroid Build Coastguard Worker #include <math.h>
13*77c1e3ccSAndroid Build Coastguard Worker #include <vector>
14*77c1e3ccSAndroid Build Coastguard Worker 
15*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/quant_common.h"
16*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/rd.h"
17*77c1e3ccSAndroid Build Coastguard Worker #include "aom/aom_codec.h"
18*77c1e3ccSAndroid Build Coastguard Worker #include "gtest/gtest.h"
19*77c1e3ccSAndroid Build Coastguard Worker 
20*77c1e3ccSAndroid Build Coastguard Worker namespace {
21*77c1e3ccSAndroid Build Coastguard Worker 
TEST(RdTest,GetDeltaqOffsetValueTest1)22*77c1e3ccSAndroid Build Coastguard Worker TEST(RdTest, GetDeltaqOffsetValueTest1) {
23*77c1e3ccSAndroid Build Coastguard Worker   aom_bit_depth_t bit_depth = AOM_BITS_8;
24*77c1e3ccSAndroid Build Coastguard Worker   double beta = 4;
25*77c1e3ccSAndroid Build Coastguard Worker   int q_index = 29;
26*77c1e3ccSAndroid Build Coastguard Worker   int dc_q_step =
27*77c1e3ccSAndroid Build Coastguard Worker       av1_dc_quant_QTX(q_index, 0, static_cast<aom_bit_depth_t>(bit_depth));
28*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(dc_q_step, 32);
29*77c1e3ccSAndroid Build Coastguard Worker 
30*77c1e3ccSAndroid Build Coastguard Worker   int ref_new_dc_q_step = static_cast<int>(round(dc_q_step / sqrt(beta)));
31*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(ref_new_dc_q_step, 16);
32*77c1e3ccSAndroid Build Coastguard Worker 
33*77c1e3ccSAndroid Build Coastguard Worker   int delta_q = av1_get_deltaq_offset(bit_depth, q_index, beta);
34*77c1e3ccSAndroid Build Coastguard Worker   int new_dc_q_step = av1_dc_quant_QTX(q_index, delta_q,
35*77c1e3ccSAndroid Build Coastguard Worker                                        static_cast<aom_bit_depth_t>(bit_depth));
36*77c1e3ccSAndroid Build Coastguard Worker 
37*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(new_dc_q_step, ref_new_dc_q_step);
38*77c1e3ccSAndroid Build Coastguard Worker }
39*77c1e3ccSAndroid Build Coastguard Worker 
TEST(RdTest,GetDeltaqOffsetValueTest2)40*77c1e3ccSAndroid Build Coastguard Worker TEST(RdTest, GetDeltaqOffsetValueTest2) {
41*77c1e3ccSAndroid Build Coastguard Worker   aom_bit_depth_t bit_depth = AOM_BITS_8;
42*77c1e3ccSAndroid Build Coastguard Worker   double beta = 1.0 / 4.0;
43*77c1e3ccSAndroid Build Coastguard Worker   int q_index = 29;
44*77c1e3ccSAndroid Build Coastguard Worker   int dc_q_step =
45*77c1e3ccSAndroid Build Coastguard Worker       av1_dc_quant_QTX(q_index, 0, static_cast<aom_bit_depth_t>(bit_depth));
46*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(dc_q_step, 32);
47*77c1e3ccSAndroid Build Coastguard Worker 
48*77c1e3ccSAndroid Build Coastguard Worker   int ref_new_dc_q_step = static_cast<int>(round(dc_q_step / sqrt(beta)));
49*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(ref_new_dc_q_step, 64);
50*77c1e3ccSAndroid Build Coastguard Worker 
51*77c1e3ccSAndroid Build Coastguard Worker   int delta_q = av1_get_deltaq_offset(bit_depth, q_index, beta);
52*77c1e3ccSAndroid Build Coastguard Worker   int new_dc_q_step = av1_dc_quant_QTX(q_index, delta_q,
53*77c1e3ccSAndroid Build Coastguard Worker                                        static_cast<aom_bit_depth_t>(bit_depth));
54*77c1e3ccSAndroid Build Coastguard Worker 
55*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(new_dc_q_step, ref_new_dc_q_step);
56*77c1e3ccSAndroid Build Coastguard Worker }
57*77c1e3ccSAndroid Build Coastguard Worker 
TEST(RdTest,GetDeltaqOffsetBoundaryTest1)58*77c1e3ccSAndroid Build Coastguard Worker TEST(RdTest, GetDeltaqOffsetBoundaryTest1) {
59*77c1e3ccSAndroid Build Coastguard Worker   aom_bit_depth_t bit_depth = AOM_BITS_8;
60*77c1e3ccSAndroid Build Coastguard Worker   double beta = 0.000000001;
61*77c1e3ccSAndroid Build Coastguard Worker   std::vector<int> q_index_ls = { 254, 255 };
62*77c1e3ccSAndroid Build Coastguard Worker   for (auto q_index : q_index_ls) {
63*77c1e3ccSAndroid Build Coastguard Worker     int delta_q = av1_get_deltaq_offset(bit_depth, q_index, beta);
64*77c1e3ccSAndroid Build Coastguard Worker     EXPECT_EQ(q_index + delta_q, 255);
65*77c1e3ccSAndroid Build Coastguard Worker   }
66*77c1e3ccSAndroid Build Coastguard Worker }
67*77c1e3ccSAndroid Build Coastguard Worker 
TEST(RdTest,GetDeltaqOffsetBoundaryTest2)68*77c1e3ccSAndroid Build Coastguard Worker TEST(RdTest, GetDeltaqOffsetBoundaryTest2) {
69*77c1e3ccSAndroid Build Coastguard Worker   aom_bit_depth_t bit_depth = AOM_BITS_8;
70*77c1e3ccSAndroid Build Coastguard Worker   double beta = 100;
71*77c1e3ccSAndroid Build Coastguard Worker   std::vector<int> q_index_ls = { 1, 0 };
72*77c1e3ccSAndroid Build Coastguard Worker   for (auto q_index : q_index_ls) {
73*77c1e3ccSAndroid Build Coastguard Worker     int delta_q = av1_get_deltaq_offset(bit_depth, q_index, beta);
74*77c1e3ccSAndroid Build Coastguard Worker     EXPECT_EQ(q_index + delta_q, 0);
75*77c1e3ccSAndroid Build Coastguard Worker   }
76*77c1e3ccSAndroid Build Coastguard Worker }
77*77c1e3ccSAndroid Build Coastguard Worker 
TEST(RdTest,GetDeltaqOffsetUnitaryTest1)78*77c1e3ccSAndroid Build Coastguard Worker TEST(RdTest, GetDeltaqOffsetUnitaryTest1) {
79*77c1e3ccSAndroid Build Coastguard Worker   aom_bit_depth_t bit_depth = AOM_BITS_8;
80*77c1e3ccSAndroid Build Coastguard Worker   double beta = 1;
81*77c1e3ccSAndroid Build Coastguard Worker   for (int q_index = 0; q_index < 255; ++q_index) {
82*77c1e3ccSAndroid Build Coastguard Worker     int delta_q = av1_get_deltaq_offset(bit_depth, q_index, beta);
83*77c1e3ccSAndroid Build Coastguard Worker     EXPECT_EQ(delta_q, 0);
84*77c1e3ccSAndroid Build Coastguard Worker   }
85*77c1e3ccSAndroid Build Coastguard Worker }
86*77c1e3ccSAndroid Build Coastguard Worker 
87*77c1e3ccSAndroid Build Coastguard Worker }  // namespace
88