screen_content_detection_mode_2_test.cc (2495B)
1 /* 2 * Copyright (c) 2025, 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/encoder/encoder.h" 14 15 namespace { 16 17 /* clang-format off */ 18 // Test the example taken from av1_dilate_block() 19 constexpr uint8_t kSource[] = { 0, 0, 1, 2, 255, 3, 4, 0, 0, 20 0, 5, 6, 255, 255, 255, 7, 8, 0, 21 0, 255, 255, 255, 255, 255, 255, 255, 0, 22 0, 255, 255, 255, 255, 255, 255, 255, 0, 23 0, 9, 10, 255, 255, 255, 11, 12, 0, 24 0, 0, 13, 14, 255, 15, 16, 0, 0}; 25 26 constexpr uint8_t kExpected[] = { 0, 0, 255, 255, 255, 255, 255, 0, 0, 27 255, 255, 255, 255, 255, 255, 255, 255, 255, 28 255, 255, 255, 255, 255, 255, 255, 255, 255, 29 255, 255, 255, 255, 255, 255, 255, 255, 255, 30 255, 255, 255, 255, 255, 255, 255, 255, 255, 31 0, 0, 255, 255, 255, 255, 255, 0, 0}; 32 /* clang-format on */ 33 34 constexpr int kWidth = 9; 35 constexpr int kHeight = 6; 36 37 TEST(ScreenContentDetectionMode2, FindDominantValue) { 38 // Find the dominant value of kSource[], which should be 255, 39 // as it appears 22 times. This is in contrast to 0 (16 times). 40 EXPECT_EQ(av1_find_dominant_value(kSource, kWidth, /*rows=*/kHeight, 41 /*cols=*/kWidth), 42 255); 43 } 44 45 TEST(ScreenContentDetectionMode2, DilateBlock) { 46 uint8_t dilated[kWidth * kHeight] = { 0 }; 47 48 av1_dilate_block(kSource, kWidth, dilated, kWidth, /*rows=*/kHeight, 49 /*cols=*/kWidth); 50 51 // Compare values coming from av1_dilate_block() against the expected values 52 for (int r = 0; r < kHeight; ++r) { 53 for (int c = 0; c < kWidth; ++c) { 54 EXPECT_EQ(kExpected[r * kHeight + c], dilated[r * kHeight + c]); 55 } 56 } 57 } 58 59 } // namespace