diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /third_party/jpeg-xl/lib/jxl/modular_test.cc | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/jpeg-xl/lib/jxl/modular_test.cc')
-rw-r--r-- | third_party/jpeg-xl/lib/jxl/modular_test.cc | 67 |
1 files changed, 38 insertions, 29 deletions
diff --git a/third_party/jpeg-xl/lib/jxl/modular_test.cc b/third_party/jpeg-xl/lib/jxl/modular_test.cc index 689063ce95..bd1a947493 100644 --- a/third_party/jpeg-xl/lib/jxl/modular_test.cc +++ b/third_party/jpeg-xl/lib/jxl/modular_test.cc @@ -7,6 +7,7 @@ #include <jxl/encode.h> #include <jxl/types.h> +#include <cmath> #include <cstddef> #include <cstdint> #include <sstream> @@ -29,7 +30,6 @@ #include "lib/jxl/dec_bit_reader.h" #include "lib/jxl/enc_aux_out.h" #include "lib/jxl/enc_bit_writer.h" -#include "lib/jxl/enc_butteraugli_comparator.h" #include "lib/jxl/enc_fields.h" #include "lib/jxl/enc_params.h" #include "lib/jxl/enc_toc.h" @@ -54,6 +54,7 @@ namespace jxl { namespace { +using test::ButteraugliDistance; using test::ReadTestData; using test::Roundtrip; using test::TestImage; @@ -130,10 +131,11 @@ TEST(ModularTest, RoundtripLossyDeltaPalette) { size_t compressed_size; JXL_EXPECT_OK(Roundtrip(&io, cparams, {}, &io_out, _, &compressed_size)); EXPECT_LE(compressed_size, 6800u); - EXPECT_THAT(ButteraugliDistance(io.frames, io_out.frames, ButteraugliParams(), - *JxlGetDefaultCms(), - /*distmap=*/nullptr), - IsSlightlyBelow(1.5)); + EXPECT_SLIGHTLY_BELOW( + ButteraugliDistance(io.frames, io_out.frames, ButteraugliParams(), + *JxlGetDefaultCms(), + /*distmap=*/nullptr), + 1.5); } TEST(ModularTest, RoundtripLossyDeltaPaletteWP) { const std::vector<uint8_t> orig = @@ -153,10 +155,11 @@ TEST(ModularTest, RoundtripLossyDeltaPaletteWP) { size_t compressed_size; JXL_EXPECT_OK(Roundtrip(&io, cparams, {}, &io_out, _, &compressed_size)); EXPECT_LE(compressed_size, 7000u); - EXPECT_THAT(ButteraugliDistance(io.frames, io_out.frames, ButteraugliParams(), - *JxlGetDefaultCms(), - /*distmap=*/nullptr), - IsSlightlyBelow(10.1)); + EXPECT_SLIGHTLY_BELOW( + ButteraugliDistance(io.frames, io_out.frames, ButteraugliParams(), + *JxlGetDefaultCms(), + /*distmap=*/nullptr), + 10.1); } TEST(ModularTest, RoundtripLossy) { @@ -175,10 +178,11 @@ TEST(ModularTest, RoundtripLossy) { size_t compressed_size; JXL_EXPECT_OK(Roundtrip(&io, cparams, {}, &io_out, _, &compressed_size)); EXPECT_LE(compressed_size, 30000u); - EXPECT_THAT(ButteraugliDistance(io.frames, io_out.frames, ButteraugliParams(), - *JxlGetDefaultCms(), - /*distmap=*/nullptr), - IsSlightlyBelow(2.3)); + EXPECT_SLIGHTLY_BELOW( + ButteraugliDistance(io.frames, io_out.frames, ButteraugliParams(), + *JxlGetDefaultCms(), + /*distmap=*/nullptr), + 2.3); } TEST(ModularTest, RoundtripLossy16) { @@ -201,15 +205,17 @@ TEST(ModularTest, RoundtripLossy16) { size_t compressed_size; JXL_EXPECT_OK(Roundtrip(&io, cparams, {}, &io_out, _, &compressed_size)); EXPECT_LE(compressed_size, 300u); - EXPECT_THAT(ButteraugliDistance(io.frames, io_out.frames, ButteraugliParams(), - *JxlGetDefaultCms(), - /*distmap=*/nullptr), - IsSlightlyBelow(1.6)); + EXPECT_SLIGHTLY_BELOW( + ButteraugliDistance(io.frames, io_out.frames, ButteraugliParams(), + *JxlGetDefaultCms(), + /*distmap=*/nullptr), + 1.6); } TEST(ModularTest, RoundtripExtraProperties) { constexpr size_t kSize = 250; - Image image(kSize, kSize, /*bitdepth=*/8, 3); + JXL_ASSIGN_OR_DIE(Image image, + Image::Create(kSize, kSize, /*bitdepth=*/8, 3)); ModularOptions options; options.max_properties = 4; options.predictor = Predictor::Zero; @@ -224,10 +230,12 @@ TEST(ModularTest, RoundtripExtraProperties) { BitWriter writer; ASSERT_TRUE(ModularGenericCompress(image, options, &writer)); writer.ZeroPadToByte(); - Image decoded(kSize, kSize, /*bitdepth=*/8, image.channel.size()); + JXL_ASSIGN_OR_DIE(Image decoded, Image::Create(kSize, kSize, /*bitdepth=*/8, + image.channel.size())); for (size_t i = 0; i < image.channel.size(); i++) { const Channel& ch = image.channel[i]; - decoded.channel[i] = Channel(ch.w, ch.h, ch.hshift, ch.vshift); + JXL_ASSIGN_OR_DIE(decoded.channel[i], + Channel::Create(ch.w, ch.h, ch.hshift, ch.vshift)); } Status status = true; { @@ -302,7 +310,7 @@ TEST_P(ModularTestParam, RoundtripLossless) { double factor = ((1lu << bitdepth) - 1lu); double ifactor = 1.0 / factor; - Image3F noise_added(xsize, ysize); + JXL_ASSIGN_OR_DIE(Image3F noise_added, Image3F::Create(xsize, ysize)); for (size_t c = 0; c < 3; c++) { for (size_t y = 0; y < ysize; y++) { @@ -313,7 +321,7 @@ TEST_P(ModularTestParam, RoundtripLossless) { float f = in[x] + generator.UniformF(0.0f, 1.f / 255.f); if (f > 1.f) f = 1.f; // quantize to the bitdepth we're testing - unsigned int u = f * factor + 0.5; + unsigned int u = static_cast<unsigned int>(std::lround(f * factor)); out[x] = u * ifactor; } } @@ -330,7 +338,7 @@ TEST_P(ModularTestParam, RoundtripLossless) { CodecInOut io2; size_t compressed_size; JXL_EXPECT_OK(Roundtrip(&io, cparams, {}, &io2, _, &compressed_size)); - EXPECT_LE(compressed_size, bitdepth * xsize * ysize / 3); + EXPECT_LE(compressed_size, bitdepth * xsize * ysize / 3.0 * 1.1); EXPECT_LE(0, ComputeDistance2(io.Main(), io2.Main(), *JxlGetDefaultCms())); size_t different = 0; for (size_t c = 0; c < 3; c++) { @@ -350,7 +358,8 @@ TEST_P(ModularTestParam, RoundtripLossless) { TEST(ModularTest, RoundtripLosslessCustomFloat) { CodecInOut io; - size_t xsize = 100, ysize = 300; + size_t xsize = 100; + size_t ysize = 300; io.SetSize(xsize, ysize); io.metadata.m.bit_depth.bits_per_sample = 18; io.metadata.m.bit_depth.exponent_bits_per_sample = 6; @@ -359,7 +368,7 @@ TEST(ModularTest, RoundtripLosslessCustomFloat) { ColorEncoding color_encoding; color_encoding.Tf().SetTransferFunction(TransferFunction::kLinear); color_encoding.SetColorSpace(ColorSpace::kRGB); - Image3F testimage(xsize, ysize); + JXL_ASSIGN_OR_DIE(Image3F testimage, Image3F::Create(xsize, ysize)); float factor = 1.f / (1 << 14); for (size_t c = 0; c < 3; c++) { for (size_t y = 0; y < ysize; y++) { @@ -442,7 +451,7 @@ TEST(ModularTest, PredictorIntegerOverflow) { WriteHeaders(&writer, xsize, ysize); std::vector<BitWriter> group_codes(1); { - BitWriter* bw = &group_codes[0]; + BitWriter* bw = group_codes.data(); BitWriter::Allotment allotment(bw, 1 << 20); WriteHistograms(bw); GroupHeader header; @@ -466,7 +475,7 @@ TEST(ModularTest, PredictorIntegerOverflow) { nullptr, &ppf)); ASSERT_EQ(1, ppf.frames.size()); const auto& img = ppf.frames[0].color; - const auto pixels = reinterpret_cast<const float*>(img.pixels()); + const auto* pixels = reinterpret_cast<const float*>(img.pixels()); EXPECT_EQ(-1.0f, pixels[0]); } @@ -478,7 +487,7 @@ TEST(ModularTest, UnsqueezeIntegerOverflow) { WriteHeaders(&writer, xsize, ysize); std::vector<BitWriter> group_codes(1); { - BitWriter* bw = &group_codes[0]; + BitWriter* bw = group_codes.data(); BitWriter::Allotment allotment(bw, 1 << 20); WriteHistograms(bw); GroupHeader header; @@ -514,7 +523,7 @@ TEST(ModularTest, UnsqueezeIntegerOverflow) { nullptr, &ppf)); ASSERT_EQ(1, ppf.frames.size()); const auto& img = ppf.frames[0].color; - const auto pixels = reinterpret_cast<const float*>(img.pixels()); + const float* pixels = reinterpret_cast<const float*>(img.pixels()); for (size_t x = 0; x < xsize; ++x) { EXPECT_NEAR(-0.5f, pixels[x], 1e-10); EXPECT_NEAR(0.5f, pixels[xsize + x], 1e-10); |