libjxl

FORK: libjxl patches used on blog
git clone https://git.neptards.moe/blog/libjxl.git
Log | Files | Refs | Submodules | README | LICENSE

blending_test.cc (2050B)


      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/types.h>
      7 
      8 #include <cstdint>
      9 #include <sstream>
     10 #include <utility>
     11 #include <vector>
     12 
     13 #include "lib/extras/dec/decode.h"
     14 #include "lib/extras/dec/jxl.h"
     15 #include "lib/extras/packed_image.h"
     16 #include "lib/jxl/base/span.h"
     17 #include "lib/jxl/test_utils.h"
     18 #include "lib/jxl/testing.h"
     19 
     20 namespace jxl {
     21 namespace {
     22 
     23 using ::testing::SizeIs;
     24 
     25 TEST(BlendingTest, Crops) {
     26   const std::vector<uint8_t> compressed =
     27       jxl::test::ReadTestData("jxl/blending/cropped_traffic_light.jxl");
     28   extras::JXLDecompressParams dparams;
     29   dparams.accepted_formats = {{3, JXL_TYPE_UINT16, JXL_LITTLE_ENDIAN, 0}};
     30   extras::PackedPixelFile decoded;
     31   ASSERT_TRUE(DecodeImageJXL(compressed.data(), compressed.size(), dparams,
     32                              /*decoded_bytes=*/nullptr, &decoded));
     33   ASSERT_THAT(decoded.frames, SizeIs(4));
     34 
     35   int i = 0;
     36   for (auto&& decoded_frame : decoded.frames) {
     37     std::ostringstream filename;
     38     filename << "jxl/blending/cropped_traffic_light_frame-" << i << ".png";
     39     const std::vector<uint8_t> compressed_frame =
     40         jxl::test::ReadTestData(filename.str());
     41     extras::PackedPixelFile decoded_frame_ppf;
     42     decoded_frame_ppf.info = decoded.info;
     43     decoded_frame_ppf.primary_color_representation =
     44         decoded.primary_color_representation;
     45     decoded_frame_ppf.color_encoding = decoded.color_encoding;
     46     decoded_frame_ppf.icc = decoded.icc;
     47     decoded_frame_ppf.extra_channels_info = decoded.extra_channels_info;
     48     decoded_frame_ppf.frames.emplace_back(std::move(decoded_frame));
     49     extras::PackedPixelFile expected_frame_ppf;
     50     ASSERT_TRUE(extras::DecodeBytes(Bytes(compressed_frame),
     51                                     extras::ColorHints(), &expected_frame_ppf));
     52     EXPECT_EQ(0.0f,
     53               test::ComputeDistance2(decoded_frame_ppf, expected_frame_ppf));
     54     ++i;
     55   }
     56 }
     57 
     58 }  // namespace
     59 }  // namespace jxl