1 // Copyright 2023 Google LLC
2 // SPDX-License-Identifier: BSD-2-Clause
3 
4 #include "avif/avif.h"
5 #include "aviftest_helpers.h"
6 #include "gtest/gtest.h"
7 
8 namespace avif {
9 namespace {
10 
11 // Used to pass the data folder path to the GoogleTest suites.
12 const char* data_path = nullptr;
13 
TEST(AvifDecodeTest,AlphaNoIspe)14 TEST(AvifDecodeTest, AlphaNoIspe) {
15   if (!testutil::Av1DecoderAvailable()) {
16     GTEST_SKIP() << "AV1 Codec unavailable, skip test.";
17   }
18   // See https://github.com/AOMediaCodec/libavif/pull/745.
19   const char* file_name = "alpha_noispe.avif";
20   DecoderPtr decoder(avifDecoderCreate());
21   ASSERT_NE(decoder, nullptr);
22   ASSERT_EQ(avifDecoderSetIOFile(decoder.get(),
23                                  (std::string(data_path) + file_name).c_str()),
24             AVIF_RESULT_OK);
25   // By default, loose files are refused. Cast to avoid C4389 Windows warning.
26   EXPECT_EQ(decoder->strictFlags, (avifStrictFlags)AVIF_STRICT_ENABLED);
27   ASSERT_EQ(avifDecoderParse(decoder.get()), AVIF_RESULT_BMFF_PARSE_FAILED);
28   // Allow this kind of file specifically.
29   decoder->strictFlags = (avifStrictFlags)AVIF_STRICT_ENABLED &
30                          ~(avifStrictFlags)AVIF_STRICT_ALPHA_ISPE_REQUIRED;
31   ASSERT_EQ(avifDecoderParse(decoder.get()), AVIF_RESULT_OK);
32   EXPECT_EQ(decoder->compressionFormat, COMPRESSION_FORMAT_AVIF);
33   EXPECT_EQ(decoder->alphaPresent, AVIF_TRUE);
34   EXPECT_EQ(avifDecoderNextImage(decoder.get()), AVIF_RESULT_OK);
35   EXPECT_NE(decoder->image->alphaPlane, nullptr);
36   EXPECT_GT(decoder->image->alphaRowBytes, 0u);
37 }
38 
39 }  // namespace
40 }  // namespace avif
41 
main(int argc,char ** argv)42 int main(int argc, char** argv) {
43   ::testing::InitGoogleTest(&argc, argv);
44   if (argc != 2) {
45     std::cerr << "There must be exactly one argument containing the path to "
46                  "the test data folder"
47               << std::endl;
48     return 1;
49   }
50   avif::data_path = argv[1];
51   return RUN_ALL_TESTS();
52 }
53