diff options
author | Jiyong <jiyong.min@samsung.com> | 2023-12-26 17:33:03 +0900 |
---|---|---|
committer | Jiyong <jiyong.min@samsung.com> | 2023-12-27 08:25:11 +0900 |
commit | a6d06c38e46e552195648836052eb909925fe5ff (patch) | |
tree | 5b34f3947c8331dc618a5166974e4d9757f8e782 /lib/jxl/modular_test.cc | |
parent | f3e519be675ef7922a6c1c3a682232302b55496d (diff) | |
parent | 3b773d382e34fcfc7c8995d8bd681a6ef0529b02 (diff) | |
download | libjxl-accepted/tizen_unified_riscv.tar.gz libjxl-accepted/tizen_unified_riscv.tar.bz2 libjxl-accepted/tizen_unified_riscv.zip |
Merge branch 'upstream' into tizenaccepted/tizen/unified/riscv/20240103.054630accepted/tizen/unified/20231228.165749accepted/tizen_unified_riscv
Change-Id: I13b4d2c94ada4853484630800e2a8a5ae90d34c1
Diffstat (limited to 'lib/jxl/modular_test.cc')
-rw-r--r-- | lib/jxl/modular_test.cc | 160 |
1 files changed, 77 insertions, 83 deletions
diff --git a/lib/jxl/modular_test.cc b/lib/jxl/modular_test.cc index c87be68..cdff03f 100644 --- a/lib/jxl/modular_test.cc +++ b/lib/jxl/modular_test.cc @@ -3,31 +3,27 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include <stdint.h> -#include <stdio.h> +#include <jxl/cms.h> #include <array> +#include <cstdint> #include <string> #include <utility> #include <vector> -#include "gtest/gtest.h" #include "lib/extras/codec.h" #include "lib/extras/dec/jxl.h" -#include "lib/jxl/aux_out.h" +#include "lib/extras/metrics.h" #include "lib/jxl/base/compiler_specific.h" #include "lib/jxl/base/data_parallel.h" #include "lib/jxl/base/override.h" -#include "lib/jxl/base/padded_bytes.h" -#include "lib/jxl/base/thread_pool_internal.h" +#include "lib/jxl/base/span.h" #include "lib/jxl/codec_in_out.h" #include "lib/jxl/color_encoding_internal.h" -#include "lib/jxl/color_management.h" +#include "lib/jxl/enc_aux_out.h" #include "lib/jxl/enc_butteraugli_comparator.h" -#include "lib/jxl/enc_butteraugli_pnorm.h" #include "lib/jxl/enc_cache.h" -#include "lib/jxl/enc_color_management.h" -#include "lib/jxl/enc_file.h" +#include "lib/jxl/enc_fields.h" #include "lib/jxl/enc_params.h" #include "lib/jxl/enc_toc.h" #include "lib/jxl/image.h" @@ -37,32 +33,32 @@ #include "lib/jxl/modular/encoding/enc_encoding.h" #include "lib/jxl/modular/encoding/encoding.h" #include "lib/jxl/modular/encoding/ma_common.h" +#include "lib/jxl/padded_bytes.h" #include "lib/jxl/test_utils.h" -#include "lib/jxl/testdata.h" +#include "lib/jxl/testing.h" namespace jxl { namespace { + +using test::ReadTestData; using test::Roundtrip; void TestLosslessGroups(size_t group_size_shift) { - ThreadPool* pool = nullptr; - const PaddedBytes orig = ReadTestData("jxl/flower/flower.png"); + const std::vector<uint8_t> orig = ReadTestData("jxl/flower/flower.png"); CompressParams cparams; cparams.SetLossless(); cparams.modular_group_size_shift = group_size_shift; CodecInOut io_out; - size_t compressed_size; CodecInOut io; - ASSERT_TRUE(SetFromBytes(Span<const uint8_t>(orig), &io, pool)); + ASSERT_TRUE(SetFromBytes(Bytes(orig), &io)); io.ShrinkTo(io.xsize() / 4, io.ysize() / 4); - compressed_size = Roundtrip(&io, cparams, {}, pool, &io_out); + size_t compressed_size; + JXL_EXPECT_OK(Roundtrip(&io, cparams, {}, &io_out, _, &compressed_size)); EXPECT_LE(compressed_size, 280000u); - EXPECT_LE(ButteraugliDistance(io, io_out, cparams.ba_params, GetJxlCms(), - /*distmap=*/nullptr, pool), - 0.0); + JXL_EXPECT_OK(SamePixels(*io.Main().color(), *io_out.Main().color(), _)); } TEST(ModularTest, RoundtripLosslessGroups128) { TestLosslessGroups(0); } @@ -76,8 +72,7 @@ TEST(ModularTest, JXL_TSAN_SLOW_TEST(RoundtripLosslessGroups1024)) { } TEST(ModularTest, RoundtripLosslessCustomWP_PermuteRCT) { - ThreadPool* pool = nullptr; - const PaddedBytes orig = + const std::vector<uint8_t> orig = ReadTestData("external/wesaturate/500px/u76c0g_bliznaca_srgb8.png"); CompressParams cparams; cparams.SetLossless(); @@ -88,22 +83,19 @@ TEST(ModularTest, RoundtripLosslessCustomWP_PermuteRCT) { cparams.options.predictor = {Predictor::Weighted}; CodecInOut io_out; - size_t compressed_size; CodecInOut io; - ASSERT_TRUE(SetFromBytes(Span<const uint8_t>(orig), &io, pool)); + ASSERT_TRUE(SetFromBytes(Bytes(orig), &io)); io.ShrinkTo(100, 100); - compressed_size = Roundtrip(&io, cparams, {}, pool, &io_out); - EXPECT_LE(compressed_size, 10150u); - EXPECT_LE(ButteraugliDistance(io, io_out, cparams.ba_params, GetJxlCms(), - /*distmap=*/nullptr, pool), - 0.0); + size_t compressed_size; + JXL_EXPECT_OK(Roundtrip(&io, cparams, {}, &io_out, _, &compressed_size)); + EXPECT_LE(compressed_size, 10169u); + JXL_EXPECT_OK(SamePixels(*io.Main().color(), *io_out.Main().color(), _)); } TEST(ModularTest, RoundtripLossyDeltaPalette) { - ThreadPool* pool = nullptr; - const PaddedBytes orig = + const std::vector<uint8_t> orig = ReadTestData("external/wesaturate/500px/u76c0g_bliznaca_srgb8.png"); CompressParams cparams; cparams.modular_mode = true; @@ -112,22 +104,21 @@ TEST(ModularTest, RoundtripLossyDeltaPalette) { cparams.palette_colors = 0; CodecInOut io_out; - size_t compressed_size; CodecInOut io; - ASSERT_TRUE(SetFromBytes(Span<const uint8_t>(orig), &io, pool)); + ASSERT_TRUE(SetFromBytes(Bytes(orig), &io)); io.ShrinkTo(300, 100); - compressed_size = Roundtrip(&io, cparams, {}, pool, &io_out); + size_t compressed_size; + JXL_EXPECT_OK(Roundtrip(&io, cparams, {}, &io_out, _, &compressed_size)); EXPECT_LE(compressed_size, 6800u); - cparams.ba_params.intensity_target = 80.0f; - EXPECT_THAT(ButteraugliDistance(io, io_out, cparams.ba_params, GetJxlCms(), - /*distmap=*/nullptr, pool), + EXPECT_THAT(ButteraugliDistance(io.frames, io_out.frames, ButteraugliParams(), + *JxlGetDefaultCms(), + /*distmap=*/nullptr), IsSlightlyBelow(1.5)); } TEST(ModularTest, RoundtripLossyDeltaPaletteWP) { - ThreadPool* pool = nullptr; - const PaddedBytes orig = + const std::vector<uint8_t> orig = ReadTestData("external/wesaturate/500px/u76c0g_bliznaca_srgb8.png"); CompressParams cparams; cparams.SetLossless(); @@ -136,63 +127,65 @@ TEST(ModularTest, RoundtripLossyDeltaPaletteWP) { cparams.options.predictor = jxl::Predictor::Weighted; CodecInOut io_out; - size_t compressed_size; CodecInOut io; - ASSERT_TRUE(SetFromBytes(Span<const uint8_t>(orig), &io, pool)); + ASSERT_TRUE(SetFromBytes(Bytes(orig), &io)); io.ShrinkTo(300, 100); - compressed_size = Roundtrip(&io, cparams, {}, pool, &io_out); + size_t compressed_size; + JXL_EXPECT_OK(Roundtrip(&io, cparams, {}, &io_out, _, &compressed_size)); EXPECT_LE(compressed_size, 7000u); - cparams.ba_params.intensity_target = 80.0f; - EXPECT_THAT(ButteraugliDistance(io, io_out, cparams.ba_params, GetJxlCms(), - /*distmap=*/nullptr, pool), - IsSlightlyBelow(10.0)); + EXPECT_THAT(ButteraugliDistance(io.frames, io_out.frames, ButteraugliParams(), + *JxlGetDefaultCms(), + /*distmap=*/nullptr), + IsSlightlyBelow(10.1)); } TEST(ModularTest, RoundtripLossy) { - ThreadPool* pool = nullptr; - const PaddedBytes orig = + const std::vector<uint8_t> orig = ReadTestData("external/wesaturate/500px/u76c0g_bliznaca_srgb8.png"); CompressParams cparams; cparams.modular_mode = true; cparams.butteraugli_distance = 2.f; + cparams.SetCms(*JxlGetDefaultCms()); CodecInOut io_out; - size_t compressed_size; CodecInOut io; - ASSERT_TRUE(SetFromBytes(Span<const uint8_t>(orig), &io, pool)); + ASSERT_TRUE(SetFromBytes(Bytes(orig), &io)); - compressed_size = Roundtrip(&io, cparams, {}, pool, &io_out); + size_t compressed_size; + JXL_EXPECT_OK(Roundtrip(&io, cparams, {}, &io_out, _, &compressed_size)); EXPECT_LE(compressed_size, 30000u); - cparams.ba_params.intensity_target = 80.0f; - EXPECT_THAT(ButteraugliDistance(io, io_out, cparams.ba_params, GetJxlCms(), - /*distmap=*/nullptr, pool), + EXPECT_THAT(ButteraugliDistance(io.frames, io_out.frames, ButteraugliParams(), + *JxlGetDefaultCms(), + /*distmap=*/nullptr), IsSlightlyBelow(2.3)); } TEST(ModularTest, RoundtripLossy16) { - ThreadPool* pool = nullptr; - const PaddedBytes orig = + const std::vector<uint8_t> orig = ReadTestData("external/raw.pixls/DJI-FC6310-16bit_709_v4_krita.png"); CompressParams cparams; cparams.modular_mode = true; cparams.butteraugli_distance = 2.f; CodecInOut io_out; - size_t compressed_size; CodecInOut io; - ASSERT_TRUE(SetFromBytes(Span<const uint8_t>(orig), &io, pool)); - JXL_CHECK(io.TransformTo(ColorEncoding::SRGB(), GetJxlCms(), pool)); + ASSERT_TRUE(SetFromBytes(Bytes(orig), &io)); + JXL_CHECK(!io.metadata.m.have_preview); + JXL_CHECK(io.frames.size() == 1); + JXL_CHECK( + io.frames[0].TransformTo(ColorEncoding::SRGB(), *JxlGetDefaultCms())); io.metadata.m.color_encoding = ColorEncoding::SRGB(); - compressed_size = Roundtrip(&io, cparams, {}, pool, &io_out); + size_t compressed_size; + JXL_EXPECT_OK(Roundtrip(&io, cparams, {}, &io_out, _, &compressed_size)); EXPECT_LE(compressed_size, 300u); - cparams.ba_params.intensity_target = 80.0f; - EXPECT_THAT(ButteraugliDistance(io, io_out, cparams.ba_params, GetJxlCms(), - /*distmap=*/nullptr, pool), + EXPECT_THAT(ButteraugliDistance(io.frames, io_out.frames, ButteraugliParams(), + *JxlGetDefaultCms(), + /*distmap=*/nullptr), IsSlightlyBelow(1.6)); } @@ -239,11 +232,10 @@ TEST(ModularTest, RoundtripExtraProperties) { } TEST(ModularTest, RoundtripLosslessCustomSqueeze) { - ThreadPool* pool = nullptr; - const PaddedBytes orig = + const std::vector<uint8_t> orig = ReadTestData("external/wesaturate/500px/tmshre_riaphotographs_srgb8.png"); CodecInOut io; - ASSERT_TRUE(SetFromBytes(Span<const uint8_t>(orig), &io, pool)); + ASSERT_TRUE(SetFromBytes(Bytes(orig), &io)); CompressParams cparams; cparams.modular_mode = true; @@ -265,9 +257,10 @@ TEST(ModularTest, RoundtripLosslessCustomSqueeze) { cparams.squeezes.push_back(p); CodecInOut io2; - EXPECT_LE(Roundtrip(&io, cparams, {}, pool, &io2), 265000u); - EXPECT_EQ(0.0, ButteraugliDistance(io, io2, cparams.ba_params, GetJxlCms(), - /*distmap=*/nullptr, pool)); + size_t compressed_size; + JXL_EXPECT_OK(Roundtrip(&io, cparams, {}, &io2, _, &compressed_size)); + EXPECT_LE(compressed_size, 265000u); + JXL_EXPECT_OK(SamePixels(*io.Main().color(), *io2.Main().color(), _)); } struct RoundtripLosslessConfig { @@ -306,10 +299,10 @@ TEST_P(ModularTestParam, RoundtripLossless) { ThreadPool* pool = nullptr; Rng generator(123); - const PaddedBytes orig = + const std::vector<uint8_t> orig = ReadTestData("external/wesaturate/500px/u76c0g_bliznaca_srgb8.png"); CodecInOut io1; - ASSERT_TRUE(SetFromBytes(Span<const uint8_t>(orig), &io1, pool)); + ASSERT_TRUE(SetFromBytes(Bytes(orig), &io1, pool)); // vary the dimensions a bit, in case of bugs related to // even vs odd width or height. @@ -349,9 +342,10 @@ TEST_P(ModularTestParam, RoundtripLossless) { cparams.speed_tier = SpeedTier::kThunder; cparams.responsive = responsive; CodecInOut io2; - EXPECT_LE(Roundtrip(&io, cparams, {}, pool, &io2), - bitdepth * xsize * ysize / 3); - EXPECT_LE(0, ComputeDistance2(io.Main(), io2.Main(), GetJxlCms())); + size_t compressed_size; + JXL_EXPECT_OK(Roundtrip(&io, cparams, {}, &io2, _, &compressed_size)); + EXPECT_LE(compressed_size, bitdepth * xsize * ysize / 3); + EXPECT_LE(0, ComputeDistance2(io.Main(), io2.Main(), *JxlGetDefaultCms())); size_t different = 0; for (size_t c = 0; c < 3; c++) { for (size_t y = 0; y < ysize; y++) { @@ -369,7 +363,6 @@ TEST_P(ModularTestParam, RoundtripLossless) { } TEST(ModularTest, RoundtripLosslessCustomFloat) { - ThreadPool* pool = nullptr; CodecInOut io; size_t xsize = 100, ysize = 300; io.SetSize(xsize, ysize); @@ -378,7 +371,7 @@ TEST(ModularTest, RoundtripLosslessCustomFloat) { io.metadata.m.bit_depth.floating_point_sample = true; io.metadata.m.modular_16_bit_buffer_sufficient = false; ColorEncoding color_encoding; - color_encoding.tf.SetTransferFunction(TransferFunction::kLinear); + color_encoding.Tf().SetTransferFunction(TransferFunction::kLinear); color_encoding.SetColorSpace(ColorSpace::kRGB); Image3F testimage(xsize, ysize); float factor = 1.f / (1 << 14); @@ -403,16 +396,17 @@ TEST(ModularTest, RoundtripLosslessCustomFloat) { cparams.decoding_speed_tier = 2; CodecInOut io2; - EXPECT_LE(Roundtrip(&io, cparams, {}, pool, &io2), 23000u); - EXPECT_EQ(0.0, ButteraugliDistance(io, io2, cparams.ba_params, GetJxlCms(), - /*distmap=*/nullptr, pool)); + size_t compressed_size; + JXL_EXPECT_OK(Roundtrip(&io, cparams, {}, &io2, _, &compressed_size)); + EXPECT_LE(compressed_size, 23000u); + JXL_EXPECT_OK(SamePixels(*io.Main().color(), *io2.Main().color(), _)); } void WriteHeaders(BitWriter* writer, size_t xsize, size_t ysize) { BitWriter::Allotment allotment(writer, 16); writer->Write(8, 0xFF); writer->Write(8, kCodestreamMarker); - ReclaimAndCharge(writer, &allotment, 0, nullptr); + allotment.ReclaimAndCharge(writer, 0, nullptr); CodecMetadata metadata; EXPECT_TRUE(metadata.size.Set(xsize, ysize)); EXPECT_TRUE(WriteSizeHeader(metadata.size, writer, 0, nullptr)); @@ -473,7 +467,7 @@ TEST(ModularTest, PredictorIntegerOverflow) { bw->Write(8, 119); bw->Write(28, 0xfffffff); bw->ZeroPadToByte(); - ReclaimAndCharge(bw, &allotment, 0, nullptr); + allotment.ReclaimAndCharge(bw, 0, nullptr); } EXPECT_TRUE(WriteGroupOffsets(group_codes, nullptr, &writer, nullptr)); writer.AppendByteAligned(group_codes); @@ -481,7 +475,7 @@ TEST(ModularTest, PredictorIntegerOverflow) { PaddedBytes compressed = std::move(writer).TakeBytes(); extras::PackedPixelFile ppf; extras::JXLDecompressParams params; - params.accepted_formats.push_back({1, JXL_TYPE_FLOAT, JXL_LITTLE_ENDIAN, 0}); + params.accepted_formats.push_back({1, JXL_TYPE_FLOAT, JXL_NATIVE_ENDIAN, 0}); EXPECT_TRUE(DecodeImageJXL(compressed.data(), compressed.size(), params, nullptr, &ppf)); ASSERT_EQ(1, ppf.frames.size()); @@ -521,7 +515,7 @@ TEST(ModularTest, UnsqueezeIntegerOverflow) { bw->Write(28, 0xffffffe); } bw->ZeroPadToByte(); - ReclaimAndCharge(bw, &allotment, 0, nullptr); + allotment.ReclaimAndCharge(bw, 0, nullptr); } EXPECT_TRUE(WriteGroupOffsets(group_codes, nullptr, &writer, nullptr)); writer.AppendByteAligned(group_codes); @@ -529,7 +523,7 @@ TEST(ModularTest, UnsqueezeIntegerOverflow) { PaddedBytes compressed = std::move(writer).TakeBytes(); extras::PackedPixelFile ppf; extras::JXLDecompressParams params; - params.accepted_formats.push_back({1, JXL_TYPE_FLOAT, JXL_LITTLE_ENDIAN, 0}); + params.accepted_formats.push_back({1, JXL_TYPE_FLOAT, JXL_NATIVE_ENDIAN, 0}); EXPECT_TRUE(DecodeImageJXL(compressed.data(), compressed.size(), params, nullptr, &ppf)); ASSERT_EQ(1, ppf.frames.size()); |