MCPcopy Create free account
hub / github.com/AOMediaCodec/libavif / ToneMapImageAndCompareToReference

Function ToneMapImageAndCompareToReference

tests/gtest/avifgainmaptest.cc:1001–1048  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

999};
1000
1001void ToneMapImageAndCompareToReference(
1002 const avifImage* base_image, const avifGainMap& gain_map,
1003 float hdr_headroom, int out_depth,
1004 avifTransferCharacteristics out_transfer_characteristics,
1005 avifRGBFormat out_rgb_format, const avifImage* reference_image,
1006 float min_psnr, float max_psnr, float* psnr_out = nullptr) {
1007 SCOPED_TRACE("hdr_headroom: " + std::to_string(hdr_headroom));
1008
1009 testutil::AvifRgbImage tone_mapped_rgb(base_image, out_depth, out_rgb_format);
1010 ImagePtr tone_mapped(
1011 avifImageCreate(tone_mapped_rgb.width, tone_mapped_rgb.height,
1012 tone_mapped_rgb.depth, AVIF_PIXEL_FORMAT_YUV444));
1013 tone_mapped->transferCharacteristics = out_transfer_characteristics;
1014 tone_mapped->colorPrimaries = reference_image
1015 ? reference_image->colorPrimaries
1016 : base_image->colorPrimaries;
1017 tone_mapped->matrixCoefficients = reference_image
1018 ? reference_image->matrixCoefficients
1019 : base_image->matrixCoefficients;
1020
1021 avifDiagnostics diag;
1022 avifResult result = avifImageApplyGainMap(
1023 base_image, &gain_map, hdr_headroom, tone_mapped->colorPrimaries,
1024 tone_mapped->transferCharacteristics, &tone_mapped_rgb,
1025 &tone_mapped->clli, &diag);
1026 ASSERT_EQ(result, AVIF_RESULT_OK)
1027 << avifResultToString(result) << " " << diag.error;
1028 ASSERT_EQ(avifImageRGBToYUV(tone_mapped.get(), &tone_mapped_rgb),
1029 AVIF_RESULT_OK);
1030 if (reference_image != nullptr) {
1031 EXPECT_EQ(out_depth, (int)reference_image->depth);
1032 const double psnr = testutil::GetPsnr(*reference_image, *tone_mapped);
1033 std::cout << "PSNR (tone mapped vs reference): " << psnr << "\n";
1034 EXPECT_GE(psnr, min_psnr);
1035 EXPECT_LE(psnr, max_psnr);
1036 if (psnr_out != nullptr) {
1037 *psnr_out = (float)psnr;
1038 }
1039 }
1040
1041 // Uncomment the following to save the encoded image as an AVIF file.
1042 // const testutil::AvifRwData encoded =
1043 // testutil::Encode(tone_mapped.get(), /*speed=*/9, /*quality=*/90);
1044 // ASSERT_GT(encoded.size, 0u);
1045 // std::ofstream("/tmp/tone_mapped_" + std::to_string(hdr_headroom) +
1046 // ".avif", std::ios::binary)
1047 // .write(reinterpret_cast<char*>(encoded.data), encoded.size);
1048}
1049
1050TEST_P(ToneMapTest, ToneMapImage) {
1051 const std::string source = std::get<0>(GetParam());

Callers 2

TEST_PFunction · 0.85
TESTFunction · 0.85

Calls 5

avifImageCreateFunction · 0.85
avifImageApplyGainMapFunction · 0.85
avifResultToStringFunction · 0.85
avifImageRGBToYUVFunction · 0.85
GetPsnrFunction · 0.70

Tested by

no test coverage detected