patch_dictionary_test.cc (1893B)
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 8 #include <cstddef> 9 #include <cstdint> 10 #include <vector> 11 12 #include "lib/extras/codec.h" 13 #include "lib/jxl/base/override.h" 14 #include "lib/jxl/base/span.h" 15 #include "lib/jxl/enc_params.h" 16 #include "lib/jxl/image_test_utils.h" 17 #include "lib/jxl/test_utils.h" 18 #include "lib/jxl/testing.h" 19 20 namespace jxl { 21 namespace { 22 23 using test::ButteraugliDistance; 24 using test::ReadTestData; 25 using test::Roundtrip; 26 27 TEST(PatchDictionaryTest, GrayscaleModular) { 28 const std::vector<uint8_t> orig = ReadTestData("jxl/grayscale_patches.png"); 29 CodecInOut io; 30 ASSERT_TRUE(SetFromBytes(Bytes(orig), &io)); 31 32 CompressParams cparams; 33 cparams.SetLossless(); 34 cparams.patches = jxl::Override::kOn; 35 36 CodecInOut io2; 37 // Without patches: ~25k 38 size_t compressed_size; 39 JXL_EXPECT_OK(Roundtrip(&io, cparams, {}, &io2, _, &compressed_size)); 40 EXPECT_LE(compressed_size, 8000u); 41 JXL_ASSERT_OK(VerifyRelativeError(*io.Main().color(), *io2.Main().color(), 42 1e-7f, 0, _)); 43 } 44 45 TEST(PatchDictionaryTest, GrayscaleVarDCT) { 46 const std::vector<uint8_t> orig = ReadTestData("jxl/grayscale_patches.png"); 47 CodecInOut io; 48 ASSERT_TRUE(SetFromBytes(Bytes(orig), &io)); 49 50 CompressParams cparams; 51 cparams.patches = jxl::Override::kOn; 52 53 CodecInOut io2; 54 // Without patches: ~47k 55 size_t compressed_size; 56 JXL_EXPECT_OK(Roundtrip(&io, cparams, {}, &io2, _, &compressed_size)); 57 EXPECT_LE(compressed_size, 14000u); 58 // Without patches: ~1.2 59 EXPECT_LE(ButteraugliDistance(io.frames, io2.frames, ButteraugliParams(), 60 *JxlGetDefaultCms(), 61 /*distmap=*/nullptr), 62 1.1); 63 } 64 65 } // namespace 66 } // namespace jxl