summaryrefslogtreecommitdiffstats
path: root/third_party/jpeg-xl/lib/extras/dec/jxl.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
commitfbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch)
tree4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /third_party/jpeg-xl/lib/extras/dec/jxl.cc
parentReleasing progress-linux version 124.0.1-1~progress7.99u1. (diff)
downloadfirefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz
firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/jpeg-xl/lib/extras/dec/jxl.cc')
-rw-r--r--third_party/jpeg-xl/lib/extras/dec/jxl.cc90
1 files changed, 58 insertions, 32 deletions
diff --git a/third_party/jpeg-xl/lib/extras/dec/jxl.cc b/third_party/jpeg-xl/lib/extras/dec/jxl.cc
index f3e62c970a..5b7fa03f02 100644
--- a/third_party/jpeg-xl/lib/extras/dec/jxl.cc
+++ b/third_party/jpeg-xl/lib/extras/dec/jxl.cc
@@ -16,20 +16,23 @@
#include "lib/extras/dec/color_description.h"
#include "lib/jxl/base/exif.h"
#include "lib/jxl/base/printf_macros.h"
+#include "lib/jxl/base/status.h"
namespace jxl {
namespace extras {
namespace {
struct BoxProcessor {
- BoxProcessor(JxlDecoder* dec) : dec_(dec) { Reset(); }
+ explicit BoxProcessor(JxlDecoder* dec) : dec_(dec) { Reset(); }
void InitializeOutput(std::vector<uint8_t>* out) {
+ JXL_ASSERT(out != nullptr);
box_data_ = out;
AddMoreOutput();
}
bool AddMoreOutput() {
+ JXL_ASSERT(box_data_ != nullptr);
Flush();
static const size_t kBoxOutputChunkSize = 1 << 16;
box_data_->resize(box_data_->size() + kBoxOutputChunkSize);
@@ -126,7 +129,7 @@ bool DecodeImageJXL(const uint8_t* bytes, size_t bytes_size,
return false;
}
- JxlPixelFormat format;
+ JxlPixelFormat format = {}; // Initialize to calm down clang-tidy.
std::vector<JxlPixelFormat> accepted_formats = dparams.accepted_formats;
JxlColorEncoding color_encoding;
@@ -177,18 +180,18 @@ bool DecodeImageJXL(const uint8_t* bytes, size_t bytes_size,
return false;
}
if (jpeg_bytes == nullptr) {
- if (JXL_DEC_SUCCESS !=
- JxlDecoderSetRenderSpotcolors(dec, dparams.render_spotcolors)) {
+ if (JXL_DEC_SUCCESS != JxlDecoderSetRenderSpotcolors(
+ dec, TO_JXL_BOOL(dparams.render_spotcolors))) {
fprintf(stderr, "JxlDecoderSetRenderSpotColors failed\n");
return false;
}
- if (JXL_DEC_SUCCESS !=
- JxlDecoderSetKeepOrientation(dec, dparams.keep_orientation)) {
+ if (JXL_DEC_SUCCESS != JxlDecoderSetKeepOrientation(
+ dec, TO_JXL_BOOL(dparams.keep_orientation))) {
fprintf(stderr, "JxlDecoderSetKeepOrientation failed\n");
return false;
}
- if (JXL_DEC_SUCCESS !=
- JxlDecoderSetUnpremultiplyAlpha(dec, dparams.unpremultiply_alpha)) {
+ if (JXL_DEC_SUCCESS != JxlDecoderSetUnpremultiplyAlpha(
+ dec, TO_JXL_BOOL(dparams.unpremultiply_alpha))) {
fprintf(stderr, "JxlDecoderSetUnpremultiplyAlpha failed\n");
return false;
}
@@ -267,6 +270,7 @@ bool DecodeImageJXL(const uint8_t* bytes, size_t bytes_size,
return false;
}
} else if (status == JXL_DEC_JPEG_NEED_MORE_OUTPUT) {
+ JXL_ASSERT(jpeg_bytes != nullptr); // Help clang-tidy.
// Decoded a chunk to JPEG.
size_t used_jpeg_output =
jpeg_data_chunk.size() - JxlDecoderReleaseJPEGBuffer(dec);
@@ -309,7 +313,7 @@ bool DecodeImageJXL(const uint8_t* bytes, size_t bytes_size,
} else {
if (dparams.unpremultiply_alpha) {
// Mark in the basic info that alpha was unpremultiplied.
- ppf->info.alpha_premultiplied = false;
+ ppf->info.alpha_premultiplied = JXL_FALSE;
}
}
bool alpha_found = false;
@@ -327,7 +331,8 @@ bool DecodeImageJXL(const uint8_t* bytes, size_t bytes_size,
}
std::string name(eci.name_length + 1, 0);
if (JXL_DEC_SUCCESS !=
- JxlDecoderGetExtraChannelName(dec, i, &name[0], name.size())) {
+ JxlDecoderGetExtraChannelName(
+ dec, i, const_cast<char*>(name.data()), name.size())) {
fprintf(stderr, "JxlDecoderGetExtraChannelName failed\n");
return false;
}
@@ -351,24 +356,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 !=
@@ -385,14 +392,21 @@ bool DecodeImageJXL(const uint8_t* bytes, size_t bytes_size,
}
}
} else if (status == JXL_DEC_FRAME) {
- jxl::extras::PackedFrame frame(ppf->info.xsize, ppf->info.ysize, format);
+ auto frame_or = jxl::extras::PackedFrame::Create(ppf->info.xsize,
+ ppf->info.ysize, format);
+ if (!frame_or.status()) {
+ fprintf(stderr, "Failed to create image frame.");
+ return false;
+ }
+ jxl::extras::PackedFrame frame = std::move(frame_or).value();
if (JXL_DEC_SUCCESS != JxlDecoderGetFrameHeader(dec, &frame.frame_info)) {
fprintf(stderr, "JxlDecoderGetFrameHeader failed\n");
return false;
}
frame.name.resize(frame.frame_info.name_length + 1, 0);
if (JXL_DEC_SUCCESS !=
- JxlDecoderGetFrameName(dec, &frame.name[0], frame.name.size())) {
+ JxlDecoderGetFrameName(dec, const_cast<char*>(frame.name.data()),
+ frame.name.size())) {
fprintf(stderr, "JxlDecoderGetFrameName failed\n");
return false;
}
@@ -423,9 +437,16 @@ bool DecodeImageJXL(const uint8_t* bytes, size_t bytes_size,
fprintf(stderr, "JxlDecoderPreviewOutBufferSize failed\n");
return false;
}
+ auto preview_image_or = jxl::extras::PackedImage::Create(
+ ppf->info.preview.xsize, ppf->info.preview.ysize, format);
+ if (!preview_image_or.status()) {
+ fprintf(stderr, "Failed to create preview image\n");
+ return false;
+ }
+ jxl::extras::PackedImage preview_image =
+ std::move(preview_image_or).value();
ppf->preview_frame = std::unique_ptr<jxl::extras::PackedFrame>(
- new jxl::extras::PackedFrame(ppf->info.preview.xsize,
- ppf->info.preview.ysize, format));
+ new jxl::extras::PackedFrame(std::move(preview_image)));
if (buffer_size != ppf->preview_frame->color.pixels_size) {
fprintf(stderr, "Invalid out buffer size %" PRIuS " %" PRIuS "\n",
buffer_size, ppf->preview_frame->color.pixels_size);
@@ -492,8 +513,13 @@ bool DecodeImageJXL(const uint8_t* bytes, size_t bytes_size,
JxlPixelFormat ec_format = format;
ec_format.num_channels = 1;
for (auto& eci : ppf->extra_channels_info) {
- frame.extra_channels.emplace_back(jxl::extras::PackedImage(
- ppf->info.xsize, ppf->info.ysize, ec_format));
+ auto image = jxl::extras::PackedImage::Create(
+ ppf->info.xsize, ppf->info.ysize, ec_format);
+ if (!image.status()) {
+ fprintf(stderr, "Failed to create extra channel image\n");
+ return false;
+ }
+ frame.extra_channels.emplace_back(std::move(image).value());
auto& ec = frame.extra_channels.back();
size_t buffer_size;
if (JXL_DEC_SUCCESS != JxlDecoderExtraChannelBufferSize(