Skip to content

Commit

Permalink
Remove some usages of CodecInOut (libjxl#3857)
Browse files Browse the repository at this point in the history
* remove CodecInOut from JPEGFrameTest

* removed unused CodecInOut in TestJPEGReconstruction

* partially remove CodecInOut from RoundtripLossless

* format

(cherry picked from commit 6455966)
  • Loading branch information
mo271 committed Nov 26, 2024
1 parent 9bb285b commit d97cb51
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
21 changes: 9 additions & 12 deletions lib/jxl/encode_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1488,17 +1488,16 @@ JXL_GTEST_INSTANTIATE_TEST_SUITE_P(

JXL_TRANSCODE_JPEG_TEST(EncodeTest, JPEGFrameTest) {
TEST_LIBJPEG_SUPPORT();
JxlMemoryManager* memory_manager = jxl::test::MemoryManager();
for (int skip_basic_info = 0; skip_basic_info < 2; skip_basic_info++) {
for (int skip_color_encoding = 0; skip_color_encoding < 2;
skip_color_encoding++) {
// cannot set color encoding if basic info is not set
if (skip_basic_info && !skip_color_encoding) continue;
const std::string jpeg_path = "jxl/flower/flower_cropped.jpg";
const std::vector<uint8_t> orig = jxl::test::ReadTestData(jpeg_path);
jxl::CodecInOut orig_io{memory_manager};
ASSERT_TRUE(SetFromBytes(jxl::Bytes(orig), &orig_io,
/*pool=*/nullptr));
jxl::extras::PackedPixelFile orig_ppf;
ASSERT_TRUE(
DecodeBytes(jxl::Bytes(orig), jxl::extras::ColorHints(), &orig_ppf));

JxlEncoderPtr enc = JxlEncoderMake(nullptr);
JxlEncoderFrameSettings* frame_settings =
Expand All @@ -1508,8 +1507,8 @@ JXL_TRANSCODE_JPEG_TEST(EncodeTest, JPEGFrameTest) {
if (!skip_basic_info) {
JxlBasicInfo basic_info;
JxlEncoderInitBasicInfo(&basic_info);
basic_info.xsize = orig_io.xsize();
basic_info.ysize = orig_io.ysize();
basic_info.xsize = orig_ppf.xsize();
basic_info.ysize = orig_ppf.ysize();
basic_info.uses_original_profile = JXL_TRUE;
EXPECT_EQ(JXL_ENC_SUCCESS,
JxlEncoderSetBasicInfo(enc.get(), &basic_info));
Expand Down Expand Up @@ -1541,13 +1540,11 @@ JXL_TRANSCODE_JPEG_TEST(EncodeTest, JPEGFrameTest) {
compressed.resize(next_out - compressed.data());
EXPECT_EQ(JXL_ENC_SUCCESS, process_result);

jxl::CodecInOut decoded_io{memory_manager};
EXPECT_TRUE(jxl::test::DecodeFile(
{}, jxl::Bytes(compressed.data(), compressed.size()), &decoded_io));
jxl::extras::PackedPixelFile decoded_ppf;
EXPECT_TRUE(DecodeBytes(jxl::Bytes(compressed.data(), compressed.size()),
jxl::extras::ColorHints(), &decoded_ppf));

EXPECT_LE(ComputeDistance2(orig_io.Main(), decoded_io.Main(),
*JxlGetDefaultCms()),
3.5);
EXPECT_LE(jxl::test::ComputeDistance2(orig_ppf, decoded_ppf), 3.5);
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions lib/jxl/modular_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,11 @@ TEST_P(ModularTestParam, RoundtripLossless) {
int bitdepth = config.bitdepth;
int responsive = config.responsive;

ThreadPool* pool = nullptr;
Rng generator(123);
const std::vector<uint8_t> orig =
ReadTestData("external/wesaturate/500px/u76c0g_bliznaca_srgb8.png");
CodecInOut io1{memory_manager};
ASSERT_TRUE(SetFromBytes(Bytes(orig), &io1, pool));
extras::PackedPixelFile ppf1;
ASSERT_TRUE(DecodeBytes(Bytes(orig), extras::ColorHints(), &ppf1));

// vary the dimensions a bit, in case of bugs related to
// even vs odd width or height.
Expand All @@ -332,11 +331,11 @@ TEST_P(ModularTestParam, RoundtripLossless) {

for (size_t c = 0; c < 3; c++) {
for (size_t y = 0; y < ysize; y++) {
const float* in = io1.Main().color()->PlaneRow(c, y);
float* out = noise_added.PlaneRow(c, y);
for (size_t x = 0; x < xsize; x++) {
// make the least significant bits random
float f = in[x] + generator.UniformF(0.0f, 1.f / 255.f);
float f = *ppf1.frames[0].color.const_pixels(y, x, c) +
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 = static_cast<unsigned int>(std::lround(f * factor));
Expand Down
2 changes: 0 additions & 2 deletions lib/jxl/roundtrip_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,6 @@ JXL_TRANSCODE_JPEG_TEST(RoundtripTest, TestJPEGReconstruction) {
TEST_LIBJPEG_SUPPORT();
const std::string jpeg_path = "jxl/flower/flower.png.im_q85_420.jpg";
const std::vector<uint8_t> orig = jxl::test::ReadTestData(jpeg_path);
jxl::CodecInOut orig_io{jxl::test::MemoryManager()};
ASSERT_TRUE(SetFromBytes(jxl::Bytes(orig), &orig_io, /*pool=*/nullptr));

JxlEncoderPtr enc = JxlEncoderMake(nullptr);
JxlEncoderFrameSettings* frame_settings =
Expand Down

0 comments on commit d97cb51

Please sign in to comment.