summaryrefslogtreecommitdiffstats
path: root/third_party/jpeg-xl/lib/extras/enc/jxl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/jpeg-xl/lib/extras/enc/jxl.cc')
-rw-r--r--third_party/jpeg-xl/lib/extras/enc/jxl.cc45
1 files changed, 29 insertions, 16 deletions
diff --git a/third_party/jpeg-xl/lib/extras/enc/jxl.cc b/third_party/jpeg-xl/lib/extras/enc/jxl.cc
index 00adbb7dda..d563f298e6 100644
--- a/third_party/jpeg-xl/lib/extras/enc/jxl.cc
+++ b/third_party/jpeg-xl/lib/extras/enc/jxl.cc
@@ -7,6 +7,7 @@
#include <jxl/encode.h>
#include <jxl/encode_cxx.h>
+#include <jxl/types.h>
#include "lib/jxl/base/exif.h"
@@ -132,7 +133,7 @@ bool EncodeImageJXL(const JXLCompressParams& params, const PackedPixelFile& ppf,
return false;
}
- auto settings = JxlEncoderFrameSettingsCreate(enc, nullptr);
+ auto* settings = JxlEncoderFrameSettingsCreate(enc, nullptr);
size_t option_idx = 0;
if (!SetFrameOptions(params.options, 0, &option_idx, settings)) {
return false;
@@ -150,10 +151,11 @@ bool EncodeImageJXL(const JXLCompressParams& params, const PackedPixelFile& ppf,
JxlEncoderCollectStats(settings, params.stats);
}
+ bool has_jpeg_bytes = (jpeg_bytes != nullptr);
bool use_boxes = !ppf.metadata.exif.empty() || !ppf.metadata.xmp.empty() ||
!ppf.metadata.jumbf.empty() || !ppf.metadata.iptc.empty();
bool use_container = params.use_container || use_boxes ||
- (jpeg_bytes && params.jpeg_store_metadata);
+ (has_jpeg_bytes && params.jpeg_store_metadata);
if (JXL_ENC_SUCCESS !=
JxlEncoderUseContainer(enc, static_cast<int>(use_container))) {
@@ -161,12 +163,22 @@ bool EncodeImageJXL(const JXLCompressParams& params, const PackedPixelFile& ppf,
return false;
}
- if (jpeg_bytes) {
+ if (has_jpeg_bytes) {
if (params.jpeg_store_metadata &&
JXL_ENC_SUCCESS != JxlEncoderStoreJPEGMetadata(enc, JXL_TRUE)) {
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);
@@ -210,8 +222,8 @@ bool EncodeImageJXL(const JXLCompressParams& params, const PackedPixelFile& ppf,
basic_info.num_extra_channels =
std::max<uint32_t>(num_alpha_channels, ppf.info.num_extra_channels);
basic_info.num_color_channels = ppf.info.num_color_channels;
- const bool lossless = params.distance == 0;
- basic_info.uses_original_profile = lossless;
+ const bool lossless = (params.distance == 0);
+ basic_info.uses_original_profile = TO_JXL_BOOL(lossless);
if (params.override_bitdepth != 0) {
basic_info.bits_per_sample = params.override_bitdepth;
basic_info.exponent_bits_per_sample =
@@ -233,7 +245,7 @@ bool EncodeImageJXL(const JXLCompressParams& params, const PackedPixelFile& ppf,
return false;
}
if (JXL_ENC_SUCCESS !=
- JxlEncoderSetFrameBitDepth(settings, &params.input_bitdepth)) {
+ JxlEncoderSetFrameBitDepth(settings, &ppf.input_bitdepth)) {
fprintf(stderr, "JxlEncoderSetFrameBitDepth() failed.\n");
return false;
}
@@ -248,7 +260,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");
@@ -284,14 +296,15 @@ bool EncodeImageJXL(const JXLCompressParams& params, const PackedPixelFile& ppf,
{"jumb", ppf.metadata.jumbf},
{"xml ", ppf.metadata.iptc},
};
- for (size_t i = 0; i < sizeof boxes / sizeof *boxes; ++i) {
- const BoxInfo& box = boxes[i];
- if (!box.bytes.empty() &&
- JXL_ENC_SUCCESS != JxlEncoderAddBox(enc, box.type, box.bytes.data(),
- box.bytes.size(),
- params.compress_boxes)) {
- fprintf(stderr, "JxlEncoderAddBox() failed (%s).\n", box.type);
- return false;
+ for (auto box : boxes) {
+ if (!box.bytes.empty()) {
+ if (JXL_ENC_SUCCESS !=
+ JxlEncoderAddBox(enc, box.type, box.bytes.data(),
+ box.bytes.size(),
+ TO_JXL_BOOL(params.compress_boxes))) {
+ fprintf(stderr, "JxlEncoderAddBox() failed (%s).\n", box.type);
+ return false;
+ }
}
}
JxlEncoderCloseBoxes(enc);
@@ -336,7 +349,7 @@ bool EncodeImageJXL(const JXLCompressParams& params, const PackedPixelFile& ppf,
}
const bool last_frame = fi + 1 == ppf.chunked_frames.size();
if (JXL_ENC_SUCCESS !=
- JxlEncoderAddChunkedFrame(settings, last_frame,
+ JxlEncoderAddChunkedFrame(settings, TO_JXL_BOOL(last_frame),
chunked_frame.GetInputSource())) {
fprintf(stderr, "JxlEncoderAddChunkedFrame() failed.\n");
return false;