patch_dictionary_test.cc (2044B)
1 // Copyright (c) the JPEG XL Project Authors. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 #include <jxl/cms.h> 7 #include <jxl/memory_manager.h> 8 9 #include <cstddef> 10 #include <cstdint> 11 #include <vector> 12 13 #include "lib/extras/codec.h" 14 #include "lib/jxl/base/override.h" 15 #include "lib/jxl/base/span.h" 16 #include "lib/jxl/enc_params.h" 17 #include "lib/jxl/image_test_utils.h" 18 #include "lib/jxl/test_memory_manager.h" 19 #include "lib/jxl/test_utils.h" 20 #include "lib/jxl/testing.h" 21 22 namespace jxl { 23 namespace { 24 25 using ::jxl::test::ButteraugliDistance; 26 using ::jxl::test::GetImage; 27 using ::jxl::test::ReadTestData; 28 using ::jxl::test::Roundtrip; 29 30 TEST(PatchDictionaryTest, GrayscaleModular) { 31 const std::vector<uint8_t> orig = ReadTestData("jxl/grayscale_patches.png"); 32 extras::PackedPixelFile ppf; 33 ASSERT_TRUE(DecodeBytes(Bytes(orig), jxl::extras::ColorHints(), &ppf)); 34 35 extras::JXLCompressParams cparams = jxl::test::CompressParamsForLossless(); 36 cparams.AddOption(JXL_ENC_FRAME_SETTING_PATCHES, 1); 37 38 extras::PackedPixelFile ppf2; 39 // Without patches: ~25k 40 size_t compressed_size = Roundtrip(ppf, cparams, {}, nullptr, &ppf2); 41 EXPECT_LE(compressed_size, 8000u); 42 JXL_TEST_ASSIGN_OR_DIE(ImageF image, GetImage(ppf)); 43 JXL_TEST_ASSIGN_OR_DIE(ImageF image2, GetImage(ppf2)); 44 JXL_TEST_ASSERT_OK(VerifyRelativeError(image, image2, 1e-7f, 0, _)); 45 } 46 47 TEST(PatchDictionaryTest, GrayscaleVarDCT) { 48 const std::vector<uint8_t> orig = ReadTestData("jxl/grayscale_patches.png"); 49 extras::PackedPixelFile ppf; 50 ASSERT_TRUE(DecodeBytes(Bytes(orig), jxl::extras::ColorHints(), &ppf)); 51 52 extras::JXLCompressParams cparams; 53 cparams.AddOption(JXL_ENC_FRAME_SETTING_PATCHES, 1); 54 55 extras::PackedPixelFile ppf2; 56 // Without patches: ~47k 57 size_t compressed_size = Roundtrip(ppf, cparams, {}, nullptr, &ppf2); 58 EXPECT_LE(compressed_size, 14000u); 59 // Without patches: ~1.2 60 EXPECT_LE(ButteraugliDistance(ppf, ppf2), 1.1); 61 } 62 63 } // namespace 64 } // namespace jxl