xref: /aosp_15_r20/external/libaom/test/rd_test.cc (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1 /*
2  * Copyright (c) 2021, 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 <math.h>
13 #include <vector>
14 
15 #include "av1/common/quant_common.h"
16 #include "av1/encoder/rd.h"
17 #include "aom/aom_codec.h"
18 #include "gtest/gtest.h"
19 
20 namespace {
21 
TEST(RdTest,GetDeltaqOffsetValueTest1)22 TEST(RdTest, GetDeltaqOffsetValueTest1) {
23   aom_bit_depth_t bit_depth = AOM_BITS_8;
24   double beta = 4;
25   int q_index = 29;
26   int dc_q_step =
27       av1_dc_quant_QTX(q_index, 0, static_cast<aom_bit_depth_t>(bit_depth));
28   EXPECT_EQ(dc_q_step, 32);
29 
30   int ref_new_dc_q_step = static_cast<int>(round(dc_q_step / sqrt(beta)));
31   EXPECT_EQ(ref_new_dc_q_step, 16);
32 
33   int delta_q = av1_get_deltaq_offset(bit_depth, q_index, beta);
34   int new_dc_q_step = av1_dc_quant_QTX(q_index, delta_q,
35                                        static_cast<aom_bit_depth_t>(bit_depth));
36 
37   EXPECT_EQ(new_dc_q_step, ref_new_dc_q_step);
38 }
39 
TEST(RdTest,GetDeltaqOffsetValueTest2)40 TEST(RdTest, GetDeltaqOffsetValueTest2) {
41   aom_bit_depth_t bit_depth = AOM_BITS_8;
42   double beta = 1.0 / 4.0;
43   int q_index = 29;
44   int dc_q_step =
45       av1_dc_quant_QTX(q_index, 0, static_cast<aom_bit_depth_t>(bit_depth));
46   EXPECT_EQ(dc_q_step, 32);
47 
48   int ref_new_dc_q_step = static_cast<int>(round(dc_q_step / sqrt(beta)));
49   EXPECT_EQ(ref_new_dc_q_step, 64);
50 
51   int delta_q = av1_get_deltaq_offset(bit_depth, q_index, beta);
52   int new_dc_q_step = av1_dc_quant_QTX(q_index, delta_q,
53                                        static_cast<aom_bit_depth_t>(bit_depth));
54 
55   EXPECT_EQ(new_dc_q_step, ref_new_dc_q_step);
56 }
57 
TEST(RdTest,GetDeltaqOffsetBoundaryTest1)58 TEST(RdTest, GetDeltaqOffsetBoundaryTest1) {
59   aom_bit_depth_t bit_depth = AOM_BITS_8;
60   double beta = 0.000000001;
61   std::vector<int> q_index_ls = { 254, 255 };
62   for (auto q_index : q_index_ls) {
63     int delta_q = av1_get_deltaq_offset(bit_depth, q_index, beta);
64     EXPECT_EQ(q_index + delta_q, 255);
65   }
66 }
67 
TEST(RdTest,GetDeltaqOffsetBoundaryTest2)68 TEST(RdTest, GetDeltaqOffsetBoundaryTest2) {
69   aom_bit_depth_t bit_depth = AOM_BITS_8;
70   double beta = 100;
71   std::vector<int> q_index_ls = { 1, 0 };
72   for (auto q_index : q_index_ls) {
73     int delta_q = av1_get_deltaq_offset(bit_depth, q_index, beta);
74     EXPECT_EQ(q_index + delta_q, 0);
75   }
76 }
77 
TEST(RdTest,GetDeltaqOffsetUnitaryTest1)78 TEST(RdTest, GetDeltaqOffsetUnitaryTest1) {
79   aom_bit_depth_t bit_depth = AOM_BITS_8;
80   double beta = 1;
81   for (int q_index = 0; q_index < 255; ++q_index) {
82     int delta_q = av1_get_deltaq_offset(bit_depth, q_index, beta);
83     EXPECT_EQ(delta_q, 0);
84   }
85 }
86 
87 }  // namespace
88