tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

av1_get_qmlevel_test.cc (5008B)


      1 /*
      2 * Copyright (c) 2024, 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 #include "gtest/gtest.h"
     12 
     13 #include "av1/common/quant_common.h"
     14 
     15 namespace {
     16 
     17 TEST(GetQmLevelTest, Regular) {
     18  // Get some QM levels from representative qindex values.
     19  int qindex_1_qmlevel = aom_get_qmlevel(1, DEFAULT_QM_FIRST, DEFAULT_QM_LAST);
     20  int qindex_60_qmlevel =
     21      aom_get_qmlevel(60, DEFAULT_QM_FIRST, DEFAULT_QM_LAST);
     22  int qindex_120_qmlevel =
     23      aom_get_qmlevel(120, DEFAULT_QM_FIRST, DEFAULT_QM_LAST);
     24  int qindex_180_qmlevel =
     25      aom_get_qmlevel(180, DEFAULT_QM_FIRST, DEFAULT_QM_LAST);
     26  int qindex_255_qmlevel =
     27      aom_get_qmlevel(255, DEFAULT_QM_FIRST, DEFAULT_QM_LAST);
     28 
     29  // Extreme qindex values should also result in extreme QM levels.
     30  EXPECT_EQ(qindex_1_qmlevel, DEFAULT_QM_FIRST);
     31  EXPECT_EQ(qindex_255_qmlevel, DEFAULT_QM_LAST);
     32 
     33  // aom_get_qmlevel() QMs become steeper (i.e. QM levels become lower) the
     34  // lower the qindex.
     35  EXPECT_GE(qindex_255_qmlevel, qindex_180_qmlevel);
     36  EXPECT_GE(qindex_180_qmlevel, qindex_120_qmlevel);
     37  EXPECT_GE(qindex_120_qmlevel, qindex_60_qmlevel);
     38  EXPECT_GE(qindex_60_qmlevel, qindex_1_qmlevel);
     39  EXPECT_GT(qindex_255_qmlevel, qindex_1_qmlevel);
     40 
     41  // Set min and max QM levels to be lower than DEFAULT_QM_FIRST.
     42  int qindex_1_qmlevel_belowfirst = aom_get_qmlevel(1, 1, DEFAULT_QM_FIRST - 1);
     43  int qindex_255_qmlevel_belowfirst =
     44      aom_get_qmlevel(255, 1, DEFAULT_QM_FIRST - 1);
     45 
     46  // Formula should always respect QM level boundaries, even when they're below
     47  // DEFAULT_QM_FIRST.
     48  EXPECT_LT(qindex_1_qmlevel_belowfirst, DEFAULT_QM_FIRST);
     49  EXPECT_LT(qindex_255_qmlevel_belowfirst, DEFAULT_QM_FIRST);
     50 
     51  // Set min and max QM levels to be higher than DEFAULT_QM_LAST.
     52  int qindex_1_qmlevel_abovelast = aom_get_qmlevel(1, DEFAULT_QM_LAST + 1, 15);
     53  int qindex_255_qmlevel_abovelast =
     54      aom_get_qmlevel(255, DEFAULT_QM_LAST + 1, 15);
     55 
     56  // Formula should always respect QM level boundaries, even when they're above
     57  // DEFAULT_QM_LAST.
     58  EXPECT_GT(qindex_1_qmlevel_abovelast, DEFAULT_QM_LAST);
     59  EXPECT_GT(qindex_255_qmlevel_abovelast, DEFAULT_QM_LAST);
     60 }
     61 
     62 TEST(GetQmLevelTest, AllIntra) {
     63  // Get some QM levels from representative qindex values.
     64  int qindex_1_qmlevel = aom_get_qmlevel_allintra(1, DEFAULT_QM_FIRST_ALLINTRA,
     65                                                  DEFAULT_QM_LAST_ALLINTRA);
     66  int qindex_60_qmlevel = aom_get_qmlevel_allintra(
     67      60, DEFAULT_QM_FIRST_ALLINTRA, DEFAULT_QM_LAST_ALLINTRA);
     68  int qindex_120_qmlevel = aom_get_qmlevel_allintra(
     69      120, DEFAULT_QM_FIRST_ALLINTRA, DEFAULT_QM_LAST_ALLINTRA);
     70  int qindex_180_qmlevel = aom_get_qmlevel_allintra(
     71      180, DEFAULT_QM_FIRST_ALLINTRA, DEFAULT_QM_LAST_ALLINTRA);
     72  int qindex_255_qmlevel = aom_get_qmlevel_allintra(
     73      255, DEFAULT_QM_FIRST_ALLINTRA, DEFAULT_QM_LAST_ALLINTRA);
     74 
     75  // Extreme qindex values should also result in extreme QM levels.
     76  EXPECT_EQ(qindex_1_qmlevel, DEFAULT_QM_LAST_ALLINTRA);
     77  EXPECT_EQ(qindex_255_qmlevel, DEFAULT_QM_FIRST_ALLINTRA);
     78 
     79  // Unlike with aom_get_qmlevel(), aom_get_qmlevel_allintra() QMs become
     80  // flatter (i.e. QM levels become higher) the lower the qindex.
     81  EXPECT_LE(qindex_255_qmlevel, qindex_180_qmlevel);
     82  EXPECT_LE(qindex_180_qmlevel, qindex_120_qmlevel);
     83  EXPECT_LE(qindex_120_qmlevel, qindex_60_qmlevel);
     84  EXPECT_LE(qindex_60_qmlevel, qindex_1_qmlevel);
     85  EXPECT_LT(qindex_255_qmlevel, qindex_1_qmlevel);
     86 
     87  // Set min and max QM levels to be lower than DEFAULT_QM_FIRST_ALLINTRA.
     88  int qindex_1_qmlevel_belowfirst =
     89      aom_get_qmlevel_allintra(1, 1, DEFAULT_QM_FIRST_ALLINTRA - 1);
     90  int qindex_255_qmlevel_belowfirst =
     91      aom_get_qmlevel_allintra(255, 1, DEFAULT_QM_FIRST_ALLINTRA - 1);
     92 
     93  // Formula should always respect QM level boundaries, even when they're below
     94  // DEFAULT_QM_FIRST_ALLINTRA.
     95  EXPECT_EQ(qindex_1_qmlevel_belowfirst, DEFAULT_QM_FIRST_ALLINTRA - 1);
     96  EXPECT_EQ(qindex_255_qmlevel_belowfirst, DEFAULT_QM_FIRST_ALLINTRA - 1);
     97 
     98  // Set min and max QM levels to be higher than DEFAULT_QM_LAST_ALLINTRA.
     99  int qindex_1_qmlevel_abovelast =
    100      aom_get_qmlevel_allintra(1, DEFAULT_QM_LAST_ALLINTRA + 1, 15);
    101  int qindex_255_qmlevel_abovelast =
    102      aom_get_qmlevel_allintra(255, DEFAULT_QM_LAST_ALLINTRA + 1, 15);
    103 
    104  // Formula should always respect QM level boundaries, even when they're above
    105  // DEFAULT_QM_LAST_ALLINTRA.
    106  EXPECT_EQ(qindex_1_qmlevel_abovelast, DEFAULT_QM_LAST_ALLINTRA + 1);
    107  EXPECT_EQ(qindex_255_qmlevel_abovelast, DEFAULT_QM_LAST_ALLINTRA + 1);
    108 }
    109 
    110 }  // namespace