Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 577112177
Change-Id: Iea446d589ea083b4e3adbfab05a5fc9b558c7dff
  • Loading branch information
vrabaud authored and copybara-github committed Oct 27, 2023
1 parent 133ceca commit bdad388
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
39 changes: 39 additions & 0 deletions tensorstore/internal/image/avif_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,32 @@ void FillYUVImage(const ImageInfo& info,

if (info.num_components == 2) {
image->yuvFormat = AVIF_PIXEL_FORMAT_YUV400;
#if AVIF_VERSION_MAJOR >= 1
ABSL_CHECK_EQ(avifImageAllocatePlanes(image, AVIF_PLANES_ALL),
AVIF_RESULT_OK)
<< "Cannot allocate AVIF_PLANES_ALL";
#else
avifImageAllocatePlanes(image, AVIF_PLANES_ALL);
#endif
assert(image->alphaRowBytes > 0);
} else if (info.num_components == 3) {
image->yuvFormat = AVIF_PIXEL_FORMAT_YUV444;
#if AVIF_VERSION_MAJOR >= 1
ABSL_CHECK_EQ(avifImageAllocatePlanes(image, AVIF_PLANES_YUV),
AVIF_RESULT_OK)
<< "Cannot allocate AVIF_PLANES_YUV";
#else
avifImageAllocatePlanes(image, AVIF_PLANES_YUV);
#endif
} else if (info.num_components == 4) {
image->yuvFormat = AVIF_PIXEL_FORMAT_YUV444;
#if AVIF_VERSION_MAJOR >= 1
ABSL_CHECK_EQ(avifImageAllocatePlanes(image, AVIF_PLANES_ALL),
AVIF_RESULT_OK)
<< "Cannot allocate AVIF_PLANES_ALL";
#else
avifImageAllocatePlanes(image, AVIF_PLANES_ALL);
#endif
assert(image->alphaRowBytes > 0);
} else {
ABSL_LOG(FATAL) << "Wrong num_channels for FillYUVImage";
Expand Down Expand Up @@ -299,16 +317,37 @@ absl::Status AvifWriter::InitializeImpl(riegeli::Writer* writer,
/// Use the codec specific cq-level option rather than the global
/// quantizer setting for quality.
std::string quantizer = tensorstore::StrCat(options.quantizer);
#if AVIF_VERSION_MAJOR >= 1
if (avifEncoderSetCodecSpecificOption(encoder.get(), "cq-level",
quantizer.c_str()) != AVIF_RESULT_OK) {
return absl::InternalError("Failed to set cq-level option in AVIF");
}
#else
avifEncoderSetCodecSpecificOption(encoder.get(), "cq-level",
quantizer.c_str());
#endif

/// Set the rate control to constant-quality mode.
#if AVIF_VERSION_MAJOR >= 1
if (avifEncoderSetCodecSpecificOption(encoder.get(), "end-usage", "q") !=
AVIF_RESULT_OK) {
return absl::InternalError("Failed to set end-usage option in AVIF");
}
#else
avifEncoderSetCodecSpecificOption(encoder.get(), "end-usage", "q");
#endif

/// TODO: Experiment with the tune parameter: ssim vs psnr
#if 0
if (cq_level <= 32) {
#if AVIF_VERSION_MAJOR >= 1
if (avifEncoderSetCodecSpecificOption(encoder.get(), "tune", "ssim") !=
AVIF_RESULT_OK) {
return absl::InternalError("Failed to set tune option in AVIF");
}
#else
avifEncoderSetCodecSpecificOption(encoder.get(), "tune", "ssim");
#endif
}
#endif
encoder_ = std::move(encoder);
Expand Down
3 changes: 2 additions & 1 deletion third_party/org_aomedia_avif/libavif.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ cc_library(
],
# Exclude codecs that have not been configured/linked.
exclude = [
"src/codec_rav1e.c",
"src/codec_avm.c",
"src/codec_libgav1.c",
"src/codec_rav1e.c",
"src/codec_svt.c",
],
),
Expand Down
6 changes: 3 additions & 3 deletions third_party/org_aomedia_avif/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def repo():
third_party_http_archive,
name = "org_aomedia_avif",
urls = [
"https://storage.googleapis.com/tensorstore-bazel-mirror/github.com/AOMediaCodec/libavif/archive/88d98ec7a85d6eebbe6ee3630b0701d3d7fcff7b.tar.gz", # main(2022-11-01)
"https://storage.googleapis.com/tensorstore-bazel-mirror/github.com/AOMediaCodec/libavif/archive/d1c26facaf5a8a97919ceee06814d05d10e25622.tar.gz", # 1.0.1(2023-08-30)
],
sha256 = "7dc8c044b36d72c496eb6d48e9f03675505dbc7ae05b6b12d51a6f09fddaa0f3",
strip_prefix = "libavif-88d98ec7a85d6eebbe6ee3630b0701d3d7fcff7b",
sha256 = "ace07eede0af2960dbad3b46f66a2902cc622ccdf4c404ad92620e38050498ba",
strip_prefix = "libavif-d1c26facaf5a8a97919ceee06814d05d10e25622",
build_file = Label("//third_party:org_aomedia_avif/libavif.BUILD.bazel"),
system_build_file = Label("//third_party:org_aomedia_avif/system.BUILD.bazel"),
cmake_name = "AVIF",
Expand Down

0 comments on commit bdad388

Please sign in to comment.