Skip to content

Commit

Permalink
Support 16-bit images (#18)
Browse files Browse the repository at this point in the history
Only with JPEG XL for now.
  • Loading branch information
y-guyon authored Jan 2, 2025
1 parent ca8cf65 commit 82dcdc1
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v0.4.0

- Bump the version of libwebp2 in deps.sh.
- Support reading 16-bit images.

## v0.3.6

- Disable thread-unsafe CCSO tool in AVM.
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cmake_minimum_required(VERSION 3.20)
project(
codec-compare-gen
LANGUAGES CXX
VERSION 0.3.6)
VERSION 0.4.0)
set(CMAKE_CXX_STANDARD 17)

option(BUILD_SHARED_LIBS "Build the shared codec-compare-gen library" ON)
Expand Down
2 changes: 1 addition & 1 deletion deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pushd third_party

git clone https://chromium.googlesource.com/codecs/libwebp2
pushd libwebp2
git checkout 425411e8016acc4497d23999e168bf38970c3afb
git checkout b03ac3800bf6a4cfd45e1302770f385eb08b39c7
cmake -S . -B build \
-DCMAKE_PREFIX_PATH="../libwebp/src/;../libwebp/build/" \
-DWP2_BUILD_TESTS=OFF \
Expand Down
5 changes: 2 additions & 3 deletions src/distortion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,8 @@ StatusOr<bool> PixelEquality(const WP2::ArgbBuffer& a, const WP2::ArgbBuffer& b,
CHECK_OR_RETURN(a.format() == b.format(), quiet);
CHECK_OR_RETURN(a.width() == b.width() && a.height() == b.height(), quiet);
for (uint32_t y = 0; y < a.height(); ++y) {
if (!std::equal(a.GetRow8(y),
a.GetRow8(y) + a.width() * WP2FormatBpp(a.format()),
b.GetRow8(y))) {
if (std::memcmp(a.GetRow(y), b.GetRow(y),
a.width() * WP2FormatBpp(a.format())) != 0) {
return false;
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,14 @@ StatusOr<Image> ReadStillImageOrAnimation(const char* file_path,
bool is_last;
do {
uint32_t duration_ms;
const WP2Status status = reader.ReadFrame(&is_last, &duration_ms);
WP2Status status = reader.ReadFrame(&is_last, &duration_ms);
if (status == WP2_STATUS_INVALID_PARAMETER && image.empty()) {
// Maybe it is a 16-bit file and the ImageReaderPNG refused to read it
// into an 8-bit buffer. Try again with a 16-bit buffer.
CHECK_OR_RETURN(buffer.SetFormat(WP2_ARGB_64) == WP2_STATUS_OK, quiet);
reader = WP2::ImageReader(file_path, &buffer);
status = reader.ReadFrame(&is_last, &duration_ms);
}
CHECK_OR_RETURN(status == WP2_STATUS_OK, quiet)
<< "Got " << WP2GetStatusMessage(status) << " when reading frame "
<< image.size() << " of " << file_path;
Expand Down
4 changes: 2 additions & 2 deletions src/result_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Status TasksToJson(const std::string& batch_name, CodecSettings settings,
const std::string image_prefix =
GetImagePathCommonPrefix(tasks, /*get_encoded_path=*/false);
const std::string build_cmd =
"git clone -b v0.3.6 --depth 1"
"git clone -b v0.4.0 --depth 1"
" https://github.com/webmproject/codec-compare-gen.git &&"
" cd codec-compare-gen && ./deps.sh &&"
" cmake -S . -B build -DCMAKE_CXX_COMPILER=clang++ &&"
Expand All @@ -113,7 +113,7 @@ Status TasksToJson(const std::string& batch_name, CodecSettings settings,
if (settings.quality == kQualityLossless) {
encoding_cmd += " --lossless";
} else {
encoding_cmd += " --lossy --quality " + std::to_string(settings.quality);
encoding_cmd += " --lossy --quality ${quality}";
encoding_cmd += " --metric_binary_folder codec-compare-gen/third_party/";
}
encoding_cmd += " -- ${original_path}";
Expand Down
Binary file added tests/data/alpha31x32_16bits.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/data/gradient32x32_16bits.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 9 additions & 4 deletions tests/test_ccgen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ TEST(CodecCompareGenTest, Help) {
}

TEST(CodecCompareGenTest, Run) {
EXPECT_EQ(TestMain(data_path, "--lossless", "--codec", "webp", "444", "6"),
0);
EXPECT_EQ(TestMain(data_path, "--lossy", "--codec", "webp", "420", "4",
const std::string file_path = std::string(data_path) + "gradient32x32.png";
const char* const path = file_path.c_str();
EXPECT_EQ(TestMain(path, "--lossless", "--codec", "webp", "444", "6"), 0);
EXPECT_EQ(TestMain(path, "--lossy", "--codec", "webp", "420", "4",
"--metric_binary_folder", "no_metric_binary_for_testing"),
0);
}
Expand All @@ -66,7 +67,11 @@ void TestProgressFileLength(size_t expected_lines, Args... args) {
("progress" + std::to_string(expected_lines) + ".csv");
(void)std::filesystem::remove(progress_file_path);

EXPECT_EQ(TestMain(data_path, "--codec", "webp", "420", "4",
std::vector<std::string> paths = {"alpha1x17.png", "anim80x80.gif",
"anim80x80.webp", "gradient32x32.png"};
for (std::string& path : paths) path = data_path + path;
EXPECT_EQ(TestMain(paths[0].c_str(), paths[1].c_str(), paths[2].c_str(),
paths[3].c_str(), "--codec", "webp", "420", "4",
"--metric_binary_folder", "no_metric_binary_for_testing",
"--progress_file", progress_file_path.c_str(), args...),
0);
Expand Down
10 changes: 10 additions & 0 deletions tests/test_framework.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ TEST_F(FrameworkTest, AllChromaSubsamplings) {
Status::kOk);
}

TEST_F(FrameworkTest, AllCodecsSupporting16bits) {
ComparisonSettings settings;
settings.codec_settings.push_back(
{Codec::kJpegXl, Subsampling::kDefault, /*effort=*/1, /*quality=*/100});
EXPECT_EQ(Compare({std::string(data_path) + "alpha31x32_16bits.png",
std::string(data_path) + "gradient32x32_16bits.png"},
settings, TempPath("completed_tasks.csv"), TempPath()),
Status::kOk);
}

TEST_F(FrameworkTest, ExperimentalCodecs) {
ComparisonSettings settings;
settings.codec_settings.push_back(
Expand Down

0 comments on commit 82dcdc1

Please sign in to comment.