Skip to content

Commit

Permalink
Bug 1880922 - Update libjxl to ab47708dcf002fae0164555b370aa36487df0f…
Browse files Browse the repository at this point in the history
…5d r=saschanaz

Differential Revision: https://phabricator.services.mozilla.com/D202184
  • Loading branch information
updatebot-ci committed Feb 20, 2024
1 parent a7fea0f commit c265adb
Show file tree
Hide file tree
Showing 192 changed files with 3,549 additions and 2,851 deletions.
1 change: 1 addition & 0 deletions media/libjxl/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ SOURCES += [
"/third_party/jpeg-xl/lib/jxl/image.cc",
"/third_party/jpeg-xl/lib/jxl/image_bundle.cc",
"/third_party/jpeg-xl/lib/jxl/image_metadata.cc",
"/third_party/jpeg-xl/lib/jxl/image_ops.cc",
"/third_party/jpeg-xl/lib/jxl/loop_filter.cc",
"/third_party/jpeg-xl/lib/jxl/luminance.cc",
"/third_party/jpeg-xl/lib/jxl/memory_manager_internal.cc",
Expand Down
4 changes: 2 additions & 2 deletions media/libjxl/moz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ origin:

url: https://github.com/libjxl/libjxl

release: 07203da045f6b41f9b3b5b86023fd70b075137f6 (2024-01-29T17:41:05Z).
release: ab47708dcf002fae0164555b370aa36487df0f5d (2024-02-19T19:38:30Z).

revision: 07203da045f6b41f9b3b5b86023fd70b075137f6
revision: ab47708dcf002fae0164555b370aa36487df0f5d

license: Apache-2.0

Expand Down
3 changes: 2 additions & 1 deletion third_party/jpeg-xl/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Zoltan Szabadka <[email protected]>
# Individuals:
a-shvedov
Aditya Patadia <[email protected]>
Ahmad Amsyar Asyadiq Bin Syaiful Bahri <[email protected]>
Alex Xu (Hello71) <[email protected]>
Alexander Sago <[email protected]>
Alistair Barrow
Expand Down Expand Up @@ -74,6 +75,7 @@ Misaki Kasumi <[email protected]>
Moonchild Straver <[email protected]>
Nicholas Hayes <[email protected]>
Nigel Tao <[email protected]>
oupson <[email protected]>
Petr Diblík
Pieter Wuille
roland-rollo
Expand All @@ -93,4 +95,3 @@ xiota
Yonatan Nebenzhal <[email protected]>
Ziemowit Zabawa <[email protected]>
源文雨 <[email protected]>
oupson <[email protected]>
26 changes: 25 additions & 1 deletion third_party/jpeg-xl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased

### Added

- decoder API: added `JxlDecoderGetBoxSizeContents` for getting the size of the
content of a box without the headers.
### Removed

### Changed / clarified

## [0.9.2] - 2024-02-07

### Fixed
- bugs in the gdk-pixbuf plugin
- some build issues

## [0.9.1] - 2024-01-08

### Fixed
- multiple build issues

## [0.9.0] - 2023-12-22

### Added
Expand Down Expand Up @@ -57,6 +69,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- fixed how large boxes are decoded (#2958)
- fixed encoding files with unreadable patches (#3042, #3046)

## [0.8.2] - 2023-06-14

### Changed
- Security: Fix an integer underflow bug in patch decoding (#2551- CVE-2023-35790).

## [0.8.1] - 2023-02-03

### Changed
- Allow fast-lossless for 16-bit float input (#2093)
- Fix bug in palette (#2120)
- Security: Fix OOB read in exif.h (#2101 - [CVE-2023-0645](https://www.cve.org/cverecord?id=CVE-2023-0645))

## [0.8.0] - 2023-01-18

### Added
Expand Down
2 changes: 1 addition & 1 deletion third_party/jpeg-xl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ set(JPEGXL_ENABLE_AVX512_SPR false CACHE BOOL
set(JPEGXL_ENABLE_AVX512_ZEN4 false CACHE BOOL
"Build with Zen4-optimized AVX512 support (faster on CPUs that support it, but larger binary size).")
set(JPEGXL_ENABLE_WASM_TRHEADS true CACHE BOOL
"Builds WASM modules with threads suppurt")
"Builds WASM modules with threads support")

# Force system dependencies.
set(JPEGXL_FORCE_SYSTEM_BROTLI false CACHE BOOL
Expand Down
1 change: 0 additions & 1 deletion third_party/jpeg-xl/debian/libjxl-gdk-pixbuf.install
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
usr/lib/*/gdk-pixbuf-*/*/loaders/*
usr/share/mime/packages/image-jxl.xml
usr/share/thumbnailers/jxl.thumbnailer
2 changes: 1 addition & 1 deletion third_party/jpeg-xl/deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ MYDIR=$(dirname $(realpath "$0"))
# update a git submodule.
TESTDATA="873045a9c42ed60721756e26e2a6b32e17415205"
THIRD_PARTY_BROTLI="36533a866ed1ca4b75cf049f4521e4ec5fe24727"
THIRD_PARTY_HIGHWAY="ba0900a4957b929390ab73827235557959234fea"
THIRD_PARTY_HIGHWAY="58b52a717469e62b2d9b8eaa2f5dddb44d4a4cbf"
THIRD_PARTY_SKCMS="42030a771244ba67f86b1c1c76a6493f873c5f91"
THIRD_PARTY_SJPEG="e5ab13008bb214deb66d5f3e17ca2f8dbff150bf"
THIRD_PARTY_ZLIB="51b7f2abdade71cd9bb0e7a373ef2610ec6f9daf" # v1.3.1
Expand Down
10 changes: 4 additions & 6 deletions third_party/jpeg-xl/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ project(SAMPLE_LIBJXL LANGUAGES C CXX)

# Use pkg-config to find libjxl.
find_package(PkgConfig)
pkg_check_modules(Jxl REQUIRED IMPORTED_TARGET libjxl)
pkg_check_modules(JxlCms REQUIRED IMPORTED_TARGET libjxl_cms)
pkg_check_modules(JxlThreads REQUIRED IMPORTED_TARGET libjxl_threads)
pkg_check_modules(Jxl REQUIRED IMPORTED_TARGET libjxl libjxl_cms libjxl_threads)

# Build the example encoder/decoder binaries using the default shared libraries
# installed.
add_executable(decode_oneshot decode_oneshot.cc)
target_link_libraries(decode_oneshot PkgConfig::Jxl PkgConfig::JxlCms PkgConfig::JxlThreads)
target_link_libraries(decode_oneshot PkgConfig::Jxl)

add_executable(decode_progressive decode_progressive.cc)
target_link_libraries(decode_progressive PkgConfig::Jxl PkgConfig::JxlCms PkgConfig::JxlThreads)
target_link_libraries(decode_progressive PkgConfig::Jxl)

add_executable(encode_oneshot encode_oneshot.cc)
target_link_libraries(encode_oneshot PkgConfig::Jxl PkgConfig::JxlCms PkgConfig::JxlThreads)
target_link_libraries(encode_oneshot PkgConfig::Jxl)
10 changes: 10 additions & 0 deletions third_party/jpeg-xl/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ else()
set(PKGCONFIG_TARGET_LIBS "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
endif()

include(CheckCXXSymbolExists)
set(PKGCONFIG_CXX_LIB "")
check_cxx_symbol_exists(__GLIBCXX__ iostream LIBSTDCXX)
check_cxx_symbol_exists(_LIBCPP_VERSION iostream LIBCXX)
if(LIBSTDCXX)
set(PKGCONFIG_CXX_LIB "-lstdc++")
elseif(LIBCXX)
set(PKGCONFIG_CXX_LIB "-lc++")
endif()

# The jxl_cms library definition.
include(jxl_cms.cmake)
# The jxl library definition.
Expand Down
3 changes: 3 additions & 0 deletions third_party/jpeg-xl/lib/extras/dec/apng.cc
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,8 @@ Status DecodeImageAPNG(const Span<const uint8_t> bytes,
have_cicp = true;
have_color = true;
ppf->icc.clear();
ppf->primary_color_representation =
PackedPixelFile::kColorEncodingIsPrimary;
}
} else if (!have_cicp && id == kId_iCCP) {
if (processing_data(png_ptr, info_ptr, chunk.data(), chunk.size())) {
Expand All @@ -830,6 +832,7 @@ Status DecodeImageAPNG(const Span<const uint8_t> bytes,
&profile, &proflen);
if (ok && proflen) {
ppf->icc.assign(profile, profile + proflen);
ppf->primary_color_representation = PackedPixelFile::kIccIsPrimary;
have_color = true;
have_iccp = true;
} else {
Expand Down
9 changes: 5 additions & 4 deletions third_party/jpeg-xl/lib/extras/dec/color_hints.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,21 @@ Status ApplyColorHints(const ColorHints& color_hints,
} else if (key == "icc") {
const uint8_t* data = reinterpret_cast<const uint8_t*>(value.data());
std::vector<uint8_t> icc(data, data + value.size());
ppf->icc.swap(icc);
ppf->icc = std::move(icc);
ppf->primary_color_representation = PackedPixelFile::kIccIsPrimary;
got_color_space = true;
} else if (key == "exif") {
const uint8_t* data = reinterpret_cast<const uint8_t*>(value.data());
std::vector<uint8_t> blob(data, data + value.size());
ppf->metadata.exif.swap(blob);
ppf->metadata.exif = std::move(blob);
} else if (key == "xmp") {
const uint8_t* data = reinterpret_cast<const uint8_t*>(value.data());
std::vector<uint8_t> blob(data, data + value.size());
ppf->metadata.xmp.swap(blob);
ppf->metadata.xmp = std::move(blob);
} else if (key == "jumbf") {
const uint8_t* data = reinterpret_cast<const uint8_t*>(value.data());
std::vector<uint8_t> blob(data, data + value.size());
ppf->metadata.jumbf.swap(blob);
ppf->metadata.jumbf = std::move(blob);
} else {
JXL_WARNING("Ignoring %s hint", key.c_str());
}
Expand Down
8 changes: 6 additions & 2 deletions third_party/jpeg-xl/lib/extras/dec/jpegli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ Status DecodeJpeg(const std::vector<uint8_t>& compressed,
} else if (dparams.force_grayscale) {
cinfo.out_color_space = JCS_GRAYSCALE;
}
if (!ReadICCProfile(&cinfo, &ppf->icc)) {
if (ReadICCProfile(&cinfo, &ppf->icc)) {
ppf->primary_color_representation = PackedPixelFile::kIccIsPrimary;
} else {
ppf->primary_color_representation =
PackedPixelFile::kColorEncodingIsPrimary;
ppf->icc.clear();
// Default to SRGB
ppf->color_encoding.color_space =
Expand Down Expand Up @@ -227,7 +231,7 @@ Status DecodeJpeg(const std::vector<uint8_t>& compressed,
if (dparams.num_colors > 0) {
cinfo.quantize_colors = TRUE;
cinfo.desired_number_of_colors = dparams.num_colors;
cinfo.two_pass_quantize = dparams.two_pass_quant;
cinfo.two_pass_quantize = static_cast<boolean>(dparams.two_pass_quant);
cinfo.dither_mode = (J_DITHER_MODE)dparams.dither_mode;
}

Expand Down
8 changes: 6 additions & 2 deletions third_party/jpeg-xl/lib/extras/dec/jpg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,11 @@ Status DecodeImageJPG(const Span<const uint8_t> bytes,
if (nbcomp != 1 && nbcomp != 3) {
return failure("unsupported number of components in JPEG");
}
if (!ReadICCProfile(&cinfo, &ppf->icc)) {
if (ReadICCProfile(&cinfo, &ppf->icc)) {
ppf->primary_color_representation = PackedPixelFile::kIccIsPrimary;
} else {
ppf->primary_color_representation =
PackedPixelFile::kColorEncodingIsPrimary;
ppf->icc.clear();
// Default to SRGB
// Actually, (cinfo.output_components == nbcomp) will be checked after
Expand Down Expand Up @@ -278,7 +282,7 @@ Status DecodeImageJPG(const Span<const uint8_t> bytes,
if (dparams && dparams->num_colors > 0) {
cinfo.quantize_colors = TRUE;
cinfo.desired_number_of_colors = dparams->num_colors;
cinfo.two_pass_quantize = dparams->two_pass_quant;
cinfo.two_pass_quantize = static_cast<boolean>(dparams->two_pass_quant);
cinfo.dither_mode = (J_DITHER_MODE)dparams->dither_mode;
}

Expand Down
34 changes: 18 additions & 16 deletions third_party/jpeg-xl/lib/extras/dec/jxl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -351,24 +351,26 @@ bool DecodeImageJXL(const uint8_t* bytes, size_t bytes_size,
}
size_t icc_size = 0;
JxlColorProfileTarget target = JXL_COLOR_PROFILE_TARGET_DATA;
ppf->color_encoding.color_space = JXL_COLOR_SPACE_UNKNOWN;
if (JXL_DEC_SUCCESS != JxlDecoderGetColorAsEncodedProfile(
dec, target, &ppf->color_encoding) ||
dparams.need_icc) {
// only get ICC if it is not an Enum color encoding
if (JXL_DEC_SUCCESS !=
JxlDecoderGetICCProfileSize(dec, target, &icc_size)) {
fprintf(stderr, "JxlDecoderGetICCProfileSize failed\n");
}
if (icc_size != 0) {
ppf->icc.resize(icc_size);
if (JXL_DEC_SUCCESS != JxlDecoderGetColorAsICCProfile(
dec, target, ppf->icc.data(), icc_size)) {
fprintf(stderr, "JxlDecoderGetColorAsICCProfile failed\n");
return false;
}
if (JXL_DEC_SUCCESS !=
JxlDecoderGetICCProfileSize(dec, target, &icc_size)) {
fprintf(stderr, "JxlDecoderGetICCProfileSize failed\n");
}
if (icc_size != 0) {
ppf->primary_color_representation = PackedPixelFile::kIccIsPrimary;
ppf->icc.resize(icc_size);
if (JXL_DEC_SUCCESS != JxlDecoderGetColorAsICCProfile(
dec, target, ppf->icc.data(), icc_size)) {
fprintf(stderr, "JxlDecoderGetColorAsICCProfile failed\n");
return false;
}
}
if (JXL_DEC_SUCCESS == JxlDecoderGetColorAsEncodedProfile(
dec, target, &ppf->color_encoding)) {
ppf->primary_color_representation =
PackedPixelFile::kColorEncodingIsPrimary;
} else {
ppf->color_encoding.color_space = JXL_COLOR_SPACE_UNKNOWN;
}
icc_size = 0;
target = JXL_COLOR_PROFILE_TARGET_ORIGINAL;
if (JXL_DEC_SUCCESS !=
Expand Down
4 changes: 0 additions & 4 deletions third_party/jpeg-xl/lib/extras/dec/jxl.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ struct JXLDecompressParams {
// Whether truncated input should be treated as an error.
bool allow_partial_input = false;

// Set to true if an ICC profile has to be synthesized for Enum color
// encodings
bool need_icc = false;

// How many passes to decode at most. By default, decode everything.
uint32_t max_passes = std::numeric_limits<uint32_t>::max();

Expand Down
10 changes: 6 additions & 4 deletions third_party/jpeg-xl/lib/extras/enc/apng.cc
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,13 @@ Status APNGEncoder::EncodePackedPixelFileToAPNG(
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
PNG_FILTER_TYPE_BASE);
if (count == 0) {
if (!ppf.icc.empty()) {
png_set_benign_errors(png_ptr, 1);
png_set_iCCP(png_ptr, info_ptr, "1", 0, ppf.icc.data(), ppf.icc.size());
} else if (!MaybeAddSRGB(ppf.color_encoding, png_ptr, info_ptr)) {
if (!MaybeAddSRGB(ppf.color_encoding, png_ptr, info_ptr)) {
MaybeAddCICP(ppf.color_encoding, png_ptr, info_ptr);
if (!ppf.icc.empty()) {
png_set_benign_errors(png_ptr, 1);
png_set_iCCP(png_ptr, info_ptr, "1", 0, ppf.icc.data(),
ppf.icc.size());
}
MaybeAddCHRM(ppf.color_encoding, png_ptr, info_ptr);
MaybeAddGAMA(ppf.color_encoding, png_ptr, info_ptr);
}
Expand Down
7 changes: 4 additions & 3 deletions third_party/jpeg-xl/lib/extras/enc/jpegli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "lib/jxl/color_encoding_internal.h"
#include "lib/jxl/enc_xyb.h"
#include "lib/jxl/image.h"
#include "lib/jxl/simd_util.h"

namespace jxl {
namespace extras {
Expand Down Expand Up @@ -71,7 +72,7 @@ Status VerifyInput(const PackedPixelFile& ppf) {

Status GetColorEncoding(const PackedPixelFile& ppf,
ColorEncoding* color_encoding) {
if (!ppf.icc.empty()) {
if (ppf.primary_color_representation == PackedPixelFile::kIccIsPrimary) {
IccBytes icc = ppf.icc;
JXL_RETURN_IF_ERROR(
color_encoding->SetICC(std::move(icc), JxlGetDefaultCms()));
Expand Down Expand Up @@ -374,11 +375,11 @@ Status EncodeJpeg(const PackedPixelFile& ppf, const JpegSettings& jpeg_settings,
unsigned char* output_buffer = nullptr;
unsigned long output_size = 0;
std::vector<uint8_t> row_bytes;
size_t rowlen = RoundUpTo(ppf.info.xsize, VectorSize());
size_t rowlen = RoundUpTo(ppf.info.xsize, MaxVectorSize());
hwy::AlignedFreeUniquePtr<float[]> xyb_tmp =
hwy::AllocateAligned<float>(6 * rowlen);
hwy::AlignedFreeUniquePtr<float[]> premul_absorb =
hwy::AllocateAligned<float>(VectorSize() * 12);
hwy::AllocateAligned<float>(MaxVectorSize() * 12);
ComputePremulAbsorb(255.0f, premul_absorb.get());

jpeg_compress_struct cinfo;
Expand Down
2 changes: 1 addition & 1 deletion third_party/jpeg-xl/lib/extras/enc/jpg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ Status EncodeWithLibJpeg(const PackedImage& image, const JxlBasicInfo& info,
cinfo.input_components = info.num_color_channels;
cinfo.in_color_space = info.num_color_channels == 1 ? JCS_GRAYSCALE : JCS_RGB;
jpeg_set_defaults(&cinfo);
cinfo.optimize_coding = params.optimize_coding;
cinfo.optimize_coding = static_cast<boolean>(params.optimize_coding);
if (cinfo.input_components == 3) {
JXL_RETURN_IF_ERROR(
SetChromaSubsampling(params.chroma_subsampling, &cinfo));
Expand Down
12 changes: 11 additions & 1 deletion third_party/jpeg-xl/lib/extras/enc/jxl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ bool EncodeImageJXL(const JXLCompressParams& params, const PackedPixelFile& ppf,
fprintf(stderr, "Storing JPEG metadata failed.\n");
return false;
}
if (params.jpeg_store_metadata && params.jpeg_strip_exif) {
fprintf(stderr,
"Cannot store metadata and strip exif at the same time.\n");
return false;
}
if (params.jpeg_store_metadata && params.jpeg_strip_xmp) {
fprintf(stderr,
"Cannot store metadata and strip xmp at the same time.\n");
return false;
}
if (!params.jpeg_store_metadata && params.jpeg_strip_exif) {
JxlEncoderFrameSettingsSetOption(settings,
JXL_ENC_FRAME_SETTING_JPEG_KEEP_EXIF, 0);
Expand Down Expand Up @@ -248,7 +258,7 @@ bool EncodeImageJXL(const JXLCompressParams& params, const PackedPixelFile& ppf,
fprintf(stderr, "JxlEncoderSetFrameLossless() failed.\n");
return false;
}
if (!ppf.icc.empty()) {
if (ppf.primary_color_representation == PackedPixelFile::kIccIsPrimary) {
if (JXL_ENC_SUCCESS !=
JxlEncoderSetICCProfile(enc, ppf.icc.data(), ppf.icc.size())) {
fprintf(stderr, "JxlEncoderSetICCProfile() failed.\n");
Expand Down
2 changes: 1 addition & 1 deletion third_party/jpeg-xl/lib/extras/enc/jxl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct JXLCompressParams {
std::vector<JXLOption> options;
// Target butteraugli distance, 0.0 means lossless.
float distance = 1.0f;
float alpha_distance = 1.0f;
float alpha_distance = 0.0f;
// If set to true, forces container mode.
bool use_container = false;
// Whether to enable/disable byte-exact jpeg reconstruction for jpeg inputs.
Expand Down
5 changes: 4 additions & 1 deletion third_party/jpeg-xl/lib/extras/mmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

#include "lib/jxl/base/common.h"

#if __unix__
#if defined(__unix__) || defined(__unix) || \
defined(__APPLE__) && defined(__MACH__)
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
Expand Down Expand Up @@ -97,6 +98,8 @@ struct MemoryMappedFileImpl {
return f;
}

~MemoryMappedFileImpl() { UnmapViewOfFile(ptr); }

const uint8_t* data() const { return reinterpret_cast<const uint8_t*>(ptr); }
size_t size() const { return fsize.QuadPart; }

Expand Down
Loading

0 comments on commit c265adb

Please sign in to comment.