Skip to content

Commit

Permalink
Bug 1736752 - Update libjxl r=tnikkel
Browse files Browse the repository at this point in the history
  • Loading branch information
saschanaz committed Oct 28, 2021
1 parent d381066 commit f192c39
Show file tree
Hide file tree
Showing 148 changed files with 3,593 additions and 3,492 deletions.
3 changes: 2 additions & 1 deletion media/libjxl/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ SOURCES += [
"/third_party/jpeg-xl/lib/jxl/aux_out.cc",
"/third_party/jpeg-xl/lib/jxl/base/cache_aligned.cc",
"/third_party/jpeg-xl/lib/jxl/base/data_parallel.cc",
"/third_party/jpeg-xl/lib/jxl/base/descriptive_statistics.cc",
"/third_party/jpeg-xl/lib/jxl/base/padded_bytes.cc",
"/third_party/jpeg-xl/lib/jxl/base/random.cc",
"/third_party/jpeg-xl/lib/jxl/base/status.cc",
"/third_party/jpeg-xl/lib/jxl/blending.cc",
"/third_party/jpeg-xl/lib/jxl/box_content_decoder.cc",
"/third_party/jpeg-xl/lib/jxl/chroma_from_luma.cc",
"/third_party/jpeg-xl/lib/jxl/coeff_order.cc",
"/third_party/jpeg-xl/lib/jxl/color_encoding_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 @@ -20,12 +20,12 @@ origin:

# Human-readable identifier for this version/release
# Generally "version NNN", "tag SSS", "bookmark SSS"
release: commit 702cd54420513b754edb60e33b9a4438f7e9ca00 (2021-09-28T08:19:14Z).
release: commit 0eff04c3a04e72e78d35f0965f17f54a98d61830 (2021-10-20T17:45:50Z).

# Revision to pull in
# Must be a long or short commit SHA (long preferred)
# NOTE(krosylight): Update highway together when updating this!
revision: 702cd54420513b754edb60e33b9a4438f7e9ca00
revision: 0eff04c3a04e72e78d35f0965f17f54a98d61830

# The package's license, where possible using the mnemonic from
# https://spdx.org/licenses/
Expand Down
3 changes: 3 additions & 0 deletions third_party/jpeg-xl/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ xiota
Ziemowit Zabawa <[email protected]>
Andrius Lukas Narbutas <[email protected]>
Misaki Kasumi <[email protected]>
Samuel Leong <[email protected]>
Alex Xu (Hello71) <[email protected]>
Vincent Torri <[email protected]>
2 changes: 1 addition & 1 deletion third_party/jpeg-xl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.6] - Unreleased
## [0.6] - 2021-10-04
### Added
- API: New functions to decode extra channels:
`JxlDecoderExtraChannelBufferSize` and `JxlDecoderSetExtraChannelBuffer`.
Expand Down
5 changes: 5 additions & 0 deletions third_party/jpeg-xl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ message(STATUS "CMAKE_SYSTEM_PROCESSOR is ${CMAKE_SYSTEM_PROCESSOR}")
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-fsanitize=fuzzer-no-link" CXX_FUZZERS_SUPPORTED)
check_cxx_compiler_flag("-Xclang -mconstructor-aliases" CXX_CONSTRUCTOR_ALIASES_SUPPORTED)
check_cxx_compiler_flag("-fmacro-prefix-map=OLD=NEW" CXX_MACRO_PREFIX_MAP)

# Enabled PIE binaries by default if supported.
include(CheckPIESupported OPTIONAL RESULT_VARIABLE CHECK_PIE_SUPPORTED)
Expand Down Expand Up @@ -206,6 +207,10 @@ if(JPEGXL_STATIC)
endif()
endif() # JPEGXL_STATIC

if ("${CXX_MACRO_PREFIX_MAP}")
add_compile_options(-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=.)
endif()

if (MSVC)
# TODO(janwas): add flags
else ()
Expand Down
11 changes: 11 additions & 0 deletions third_party/jpeg-xl/bash_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ test_copyright() {
return ${ret}
}

# Check that we don't use "%zu" or "%zd" in format string for size_t.
test_printf_size_t() {
if grep -n -E '%[0-9]*z[udx]' \
$(git ls-files | grep -E '(\.c|\.cc|\.cpp|\.h)$'); then
echo "Don't use '%zu' or '%zd' in a format string, instead use " \
"'%\" PRIuS \"' or '%\" PRIdS \"'." >&2
return 1
fi
return 0
}

# Check that "dec_" code doesn't depend on "enc_" headers.
test_dec_enc_deps() {
local ret=0
Expand Down
2 changes: 1 addition & 1 deletion third_party/jpeg-xl/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ cmd_coverage_report() {
# is not part of the code under test.
--filter '.*jxl/.*'
--exclude '.*_test.cc'
--exclude '.*_test-only..*'
--exclude '.*_testonly..*'
--exclude '.*test_utils..*'
--object-directory "${real_build_dir}"
)
Expand Down
2 changes: 1 addition & 1 deletion third_party/jpeg-xl/deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ MYDIR=$(dirname $(realpath "$0"))
# Git revisions we use for the given submodules. Update these whenever you
# update a git submodule.
THIRD_PARTY_HIGHWAY="e2397743fe092df68b760d358253773699a16c93"
THIRD_PARTY_LODEPNG="48e5364ef48ec2408f44c727657ac1b6703185f8"
THIRD_PARTY_LODEPNG="8c6a9e30576f07bf470ad6f09458a2dcd7a6a84a"
THIRD_PARTY_SKCMS="64374756e03700d649f897dbd98c95e78c30c7da"
THIRD_PARTY_SJPEG="868ab558fad70fcbe8863ba4e85179eeb81cc840"

Expand Down
15 changes: 11 additions & 4 deletions third_party/jpeg-xl/examples/decode_exif_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ bool DecodeJpegXlExif(const uint8_t* jxl, size_t size,
fprintf(stderr, "JxlDecoderSubscribeEvents failed\n");
return false;
}
bool support_decompression = true;
if (JXL_DEC_SUCCESS != JxlDecoderSetDecompressBoxes(dec.get(), JXL_TRUE)) {
fprintf(stderr, "JxlDecoderSetDecompressBoxes failed\n");
return false;
fprintf(stderr,
"NOTE: decompressing brob boxes not supported with the currently "
"used jxl library.\n");
support_decompression = false;
}

JxlDecoderSetInput(dec.get(), jxl, size);
Expand All @@ -39,7 +42,6 @@ bool DecodeJpegXlExif(const uint8_t* jxl, size_t size,

for (;;) {
JxlDecoderStatus status = JxlDecoderProcessInput(dec.get());

if (status == JXL_DEC_ERROR) {
fprintf(stderr, "Decoder error\n");
return false;
Expand All @@ -54,8 +56,10 @@ bool DecodeJpegXlExif(const uint8_t* jxl, size_t size,
return true;
}
JxlBoxType type;
if (!JxlDecoderGetBoxType(dec.get(), &type, JXL_TRUE)) {
if (JXL_DEC_SUCCESS !=
JxlDecoderGetBoxType(dec.get(), type, support_decompression)) {
fprintf(stderr, "Error, failed to get box type\n");
return false;
}
if (!memcmp(type, "Exif", 4)) {
exif->resize(kChunkSize);
Expand Down Expand Up @@ -155,6 +159,9 @@ int main(int argc, char* argv[]) {
if (exif.empty()) {
printf("No exif data present in this image\n");
} else {
// TODO(lode): the exif box data contains the 4-byte TIFF header at the
// beginning, check whether this is desired to be part of the output, or
// should be removed.
if (!WriteFile(exif_filename, exif.data(), exif.size())) {
fprintf(stderr, "Error while writing the exif file\n");
return 1;
Expand Down
6 changes: 4 additions & 2 deletions third_party/jpeg-xl/examples/decode_oneshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// available at once). The example outputs the pixels and color information to a
// floating point image and an ICC profile on disk.

#include <inttypes.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
Expand Down Expand Up @@ -96,8 +97,9 @@ bool DecodeJpegXlOneShot(const uint8_t* jxl, size_t size,
return false;
}
if (buffer_size != *xsize * *ysize * 16) {
fprintf(stderr, "Invalid out buffer size %zu %zu\n", buffer_size,
*xsize * *ysize * 16);
fprintf(stderr, "Invalid out buffer size %" PRIu64 " %" PRIu64 "\n",
static_cast<uint64_t>(buffer_size),
static_cast<uint64_t>(*xsize * *ysize * 16));
return false;
}
pixels->resize(*xsize * *ysize * 4);
Expand Down
20 changes: 13 additions & 7 deletions third_party/jpeg-xl/examples/jxlinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

// This example prints information from the main codestream header.

#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -25,9 +27,9 @@ int PrintBasicInfo(FILE* file) {

JxlDecoderSetKeepOrientation(dec, 1);

if (JXL_DEC_SUCCESS !=
JxlDecoderSubscribeEvents(
dec, JXL_DEC_BASIC_INFO | JXL_DEC_COLOR_ENCODING | JXL_DEC_FRAME)) {
if (JXL_DEC_SUCCESS != JxlDecoderSubscribeEvents(
dec, JXL_DEC_BASIC_INFO | JXL_DEC_COLOR_ENCODING |
JXL_DEC_FRAME | JXL_DEC_BOX)) {
fprintf(stderr, "JxlDecoderSubscribeEvents failed\n");
JxlDecoderDestroy(dec);
return 0;
Expand Down Expand Up @@ -232,7 +234,7 @@ int PrintBasicInfo(FILE* file) {
fprintf(stderr, "JxlDecoderGetICCProfileSize failed\n");
continue;
}
printf(" ICC profile size: %zu\n", profile_size);
printf(" ICC profile size: %" PRIu64 "\n", (uint64_t)profile_size);
if (profile_size < 132) {
fprintf(stderr, "ICC profile too small\n");
continue;
Expand All @@ -251,7 +253,6 @@ int PrintBasicInfo(FILE* file) {
printf(" rendering intent: %d\n", (int)profile[67]);
free(profile);
}

} else if (status == JXL_DEC_FRAME) {
if (JXL_DEC_SUCCESS != JxlDecoderGetFrameHeader(dec, &frame_header)) {
fprintf(stderr, "JxlDecoderGetFrameHeader failed\n");
Expand Down Expand Up @@ -280,8 +281,13 @@ int PrintBasicInfo(FILE* file) {
if (!frame_header.name_length && !info.have_animation) {
printf(" still frame, unnamed\n");
}

// This is the last expected event, no need to read the rest of the file.
} else if (status == JXL_DEC_BOX) {
JxlBoxType type;
uint64_t size;
JxlDecoderGetBoxType(dec, type, JXL_FALSE);
JxlDecoderGetBoxSizeRaw(dec, &size);
printf("box: type: \"%c%c%c%c\" size: %" PRIu64 "\n", type[0], type[1],
type[2], type[3], (uint64_t)size);
} else {
fprintf(stderr, "Unexpected decoder status\n");
break;
Expand Down
33 changes: 24 additions & 9 deletions third_party/jpeg-xl/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,19 @@ set(JPEGXL_PATCH_VERSION 0)
set(JPEGXL_LIBRARY_VERSION
"${JPEGXL_MAJOR_VERSION}.${JPEGXL_MINOR_VERSION}.${JPEGXL_PATCH_VERSION}")

# This the library API compatibility version.
# This is the library API/ABI compatibility version. Changing this value makes
# the shared library incompatible with previous version. A program linked
# against this shared library SOVERSION will not run with an older SOVERSION.
# It is important to update this value when making incompatible API/ABI changes
# so that programs that depend on libjxl can update their dependencies. Semantic
# versioning allows 0.y.z to have incompatible changes in minor versions.
set(JPEGXL_SO_MINOR_VERSION 6)
if (JPEGXL_MAJOR_VERSION EQUAL 0)
set(JPEGXL_LIBRARY_SOVERSION
"${JPEGXL_MAJOR_VERSION}.${JPEGXL_SO_MINOR_VERSION}")
else()
set(JPEGXL_LIBRARY_SOVERSION "${JPEGXL_MAJOR_VERSION}")
endif()


# List of warning and feature flags for our library and tests.
Expand Down Expand Up @@ -70,22 +81,26 @@ endif() # Clang

if (WIN32)
list(APPEND JPEGXL_INTERNAL_FLAGS
-Wno-c++98-compat-pedantic
-Wno-cast-align
-Wno-double-promotion
-Wno-float-equal
-Wno-format-nonliteral
-Wno-global-constructors
-Wno-language-extension-token
-Wno-missing-prototypes
-Wno-shadow
-Wno-shadow-field-in-constructor
-Wno-sign-conversion
-Wno-unused-member-function
-Wno-unused-template
-Wno-used-but-marked-unused
-Wno-zero-as-null-pointer-constant
)

if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
list(APPEND JPEGXL_INTERNAL_FLAGS
-Wno-used-but-marked-unused
-Wno-unused-template
-Wno-unused-member-function
-Wno-shadow-field-in-constructor
-Wno-language-extension-token
-Wno-global-constructors
-Wno-c++98-compat-pedantic
)
endif() # Clang
else() # WIN32
list(APPEND JPEGXL_INTERNAL_FLAGS
-fsized-deallocation
Expand Down
35 changes: 25 additions & 10 deletions third_party/jpeg-xl/lib/extras/codec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "lib/extras/codec_png.h"
#include "lib/extras/codec_pnm.h"
#include "lib/extras/codec_psd.h"
#include "lib/extras/packed_image_convert.h"
#include "lib/jxl/image_bundle.h"

namespace jxl {
Expand Down Expand Up @@ -89,40 +90,51 @@ Status SetFromBytes(const Span<const uint8_t> bytes,
ThreadPool* pool, Codec* orig_codec) {
if (bytes.size() < kMinBytes) return JXL_FAILURE("Too few bytes");

io->metadata.m.bit_depth.bits_per_sample = 0; // (For is-set check below)
extras::PackedPixelFile ppf;
// Default values when not set by decoders.
ppf.info.uses_original_profile = true;
ppf.info.orientation = JXL_ORIENT_IDENTITY;

Codec codec;
if (extras::DecodeImagePNG(bytes, color_hints, pool, io)) {
bool skip_ppf_conversion = false;
if (extras::DecodeImagePNG(bytes, color_hints, io->constraints, &ppf)) {
codec = Codec::kPNG;
}
#if JPEGXL_ENABLE_APNG
else if (extras::DecodeImageAPNG(bytes, color_hints, pool, io)) {
else if (extras::DecodeImageAPNG(bytes, color_hints, io->constraints, &ppf)) {
codec = Codec::kPNG;
}
#endif
else if (extras::DecodeImagePGX(bytes, color_hints, pool, io)) {
else if (extras::DecodeImagePGX(bytes, color_hints, io->constraints, &ppf)) {
codec = Codec::kPGX;
} else if (extras::DecodeImagePNM(bytes, color_hints, pool, io)) {
} else if (extras::DecodeImagePNM(bytes, color_hints, io->constraints,
&ppf)) {
codec = Codec::kPNM;
}
#if JPEGXL_ENABLE_GIF
else if (extras::DecodeImageGIF(bytes, color_hints, pool, io)) {
else if (extras::DecodeImageGIF(bytes, color_hints, io->constraints, &ppf)) {
codec = Codec::kGIF;
}
#endif
else if (io->dec_target == DecodeTarget::kQuantizedCoeffs &&
extras::DecodeImageJPGCoefficients(bytes, io)) {
// TODO(deymo): In this case the tools should use a different API to
// transcode the input JPEG to JXL.
// transcode the input JPEG to JXL instead of expressing it as a
// PackedPixelFile.
codec = Codec::kJPG;
skip_ppf_conversion = true;
} else if (io->dec_target == DecodeTarget::kPixels &&
extras::DecodeImageJPG(bytes, color_hints, pool, io)) {
extras::DecodeImageJPG(bytes, color_hints, io->constraints,
&ppf)) {
codec = Codec::kJPG;
} else if (extras::DecodeImagePSD(bytes, color_hints, pool, io)) {
// TODO(deymo): Migrate PSD codec too.
codec = Codec::kPSD;
skip_ppf_conversion = true;
}
#if JPEGXL_ENABLE_EXR
else if (extras::DecodeImageEXR(bytes, color_hints, pool, io)) {
else if (extras::DecodeImageEXR(bytes, color_hints, io->constraints,
io->target_nits, pool, &ppf)) {
codec = Codec::kEXR;
}
#endif
Expand All @@ -131,7 +143,10 @@ Status SetFromBytes(const Span<const uint8_t> bytes,
}
if (orig_codec) *orig_codec = codec;

io->CheckMetadata();
if (!skip_ppf_conversion) {
JXL_RETURN_IF_ERROR(ConvertPackedPixelFileToCodecInOut(ppf, pool, io));
}

return true;
}

Expand Down
Loading

0 comments on commit f192c39

Please sign in to comment.