Skip to content

Commit

Permalink
Merge branch 'main' into fix-cms-assert
Browse files Browse the repository at this point in the history
  • Loading branch information
sboukortt committed Mar 5, 2024
2 parents 1854129 + 1d6e167 commit 23bdc80
Show file tree
Hide file tree
Showing 112 changed files with 699 additions and 653 deletions.
19 changes: 11 additions & 8 deletions .clang-tidy
Expand Up @@ -39,6 +39,7 @@ Checks: >-
-modernize-use-trailing-return-type,
-modernize-use-using,
-performance-enum-size,
-readability-avoid-nested-conditional-operator,
-readability-else-after-return,
-readability-function-cognitive-complexity,
-readability-identifier-length,
Expand Down Expand Up @@ -71,11 +72,13 @@ WarningsAsErrors: >-
HeaderFilterRegex: '^.*/(lib|tools)/.*\.h$'

CheckOptions:
- key: readability-braces-around-statements.ShortStatementLines
value: '2'
- key: google-readability-braces-around-statements.ShortStatementLines
value: '2'
- key: readability-implicit-bool-conversion.AllowPointerConditions
value: '1'
- key: readability-implicit-bool-conversion.AllowIntegerConditions
value: '1'
- key: readability-braces-around-statements.ShortStatementLines
value: '2'
- key: google-readability-braces-around-statements.ShortStatementLines
value: '2'
- key: readability-implicit-bool-conversion.AllowPointerConditions
value: '1'
- key: readability-implicit-bool-conversion.AllowIntegerConditions
value: '1'
- key: bugprone-signed-char-misuse.CharTypdefsToIgnore
value: 'int8_t'
5 changes: 3 additions & 2 deletions examples/decode_exif_metadata.cc
Expand Up @@ -56,8 +56,9 @@ bool DecodeJpegXlExif(const uint8_t* jxl, size_t size,
return true;
}
JxlBoxType type;
if (JXL_DEC_SUCCESS !=
JxlDecoderGetBoxType(dec.get(), type, support_decompression)) {
status = JxlDecoderGetBoxType(dec.get(), type,
TO_JXL_BOOL(support_decompression));
if (JXL_DEC_SUCCESS != status) {
fprintf(stderr, "Error, failed to get box type\n");
return false;
}
Expand Down
11 changes: 3 additions & 8 deletions examples/decode_oneshot.cc
Expand Up @@ -7,11 +7,6 @@
// available at once). The example outputs the pixels and color information to a
// floating point image and an ICC profile on disk.

#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif

#include <inttypes.h>
#include <jxl/codestream_header.h>
#include <jxl/decode.h>
#include <jxl/decode_cxx.h>
Expand Down Expand Up @@ -102,9 +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 %" PRIu64 " %" PRIu64 "\n",
static_cast<uint64_t>(buffer_size),
static_cast<uint64_t>(*xsize * *ysize * 16));
fprintf(stderr, "Invalid out buffer size %d %d\n",
static_cast<int>(buffer_size),
static_cast<int>(*xsize * *ysize * 16));
return false;
}
pixels->resize(*xsize * *ysize * 4);
Expand Down
9 changes: 2 additions & 7 deletions examples/decode_progressive.cc
Expand Up @@ -6,10 +6,6 @@
// This C++ example decodes a JPEG XL image progressively (input bytes are
// passed in chunks). The example outputs the intermediate steps to PAM files.

#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif

#include <inttypes.h>
#include <jxl/decode.h>
#include <jxl/decode_cxx.h>
Expand All @@ -29,10 +25,9 @@ bool WritePAM(const char* filename, const uint8_t* buffer, size_t w, size_t h) {
return false;
}
fprintf(fp,
"P7\nWIDTH %" PRIu64 "\nHEIGHT %" PRIu64
"\nDEPTH 4\nMAXVAL 255\nTUPLTYPE "
"P7\nWIDTH %d\nHEIGHT %d\nDEPTH 4\nMAXVAL 255\nTUPLTYPE "
"RGB_ALPHA\nENDHDR\n",
static_cast<uint64_t>(w), static_cast<uint64_t>(h));
static_cast<int>(w), static_cast<int>(h));
size_t num_bytes = w * h * 4;
if (fwrite(buffer, 1, num_bytes, fp) != num_bytes) {
fclose(fp);
Expand Down
11 changes: 6 additions & 5 deletions examples/encode_oneshot.cc
Expand Up @@ -39,8 +39,9 @@ bool ReadPFM(const char* filename, std::vector<float>* pixels, uint32_t* xsize,
return false;
}
uint32_t endian_test = 1;
uint8_t little_endian[4];
memcpy(little_endian, &endian_test, 4);
uint8_t little_endian_check[4];
memcpy(little_endian_check, &endian_test, 4);
bool little_endian = (little_endian_check[0] == 1);

if (fseek(file, 0, SEEK_END) != 0) {
fclose(file);
Expand Down Expand Up @@ -122,7 +123,7 @@ bool ReadPFM(const char* filename, std::vector<float>* pixels, uint32_t* xsize,
return false;
}

if (!!little_endian[0] != input_little_endian) {
if (little_endian != input_little_endian) {
fprintf(stderr,
"%s has a different endianness than we do, conversion is not "
"supported.\n",
Expand Down Expand Up @@ -181,8 +182,8 @@ bool EncodeJxlOneshot(const std::vector<float>& pixels, const uint32_t xsize,
}

JxlColorEncoding color_encoding = {};
JxlColorEncodingSetToSRGB(&color_encoding,
/*is_gray=*/pixel_format.num_channels < 3);
JXL_BOOL is_gray = TO_JXL_BOOL(pixel_format.num_channels < 3);
JxlColorEncodingSetToSRGB(&color_encoding, is_gray);
if (JXL_ENC_SUCCESS !=
JxlEncoderSetColorEncoding(enc.get(), &color_encoding)) {
fprintf(stderr, "JxlEncoderSetColorEncoding failed\n");
Expand Down
2 changes: 1 addition & 1 deletion lib/extras/codec_test.cc
Expand Up @@ -227,7 +227,7 @@ void CreateTestImage(const TestImageParams& params, PackedPixelFile* ppf) {
ppf->info.exponent_bits_per_sample = params.bits_per_sample == 32 ? 8 : 0;
ppf->info.num_color_channels = params.is_gray ? 1 : 3;
ppf->info.alpha_bits = params.add_alpha ? params.bits_per_sample : 0;
ppf->info.alpha_premultiplied = (params.codec == Codec::kEXR);
ppf->info.alpha_premultiplied = TO_JXL_BOOL(params.codec == Codec::kEXR);

JxlColorEncoding color_encoding = CreateTestColorEncoding(params.is_gray);
ppf->icc = GenerateICC(color_encoding);
Expand Down
11 changes: 5 additions & 6 deletions lib/extras/dec/apng.cc
Expand Up @@ -518,9 +518,8 @@ int processing_start(png_structp& png_ptr, png_infop& info_ptr, void* frame_ptr,
png_process_data(png_ptr, info_ptr, chunkIHDR.data(), chunkIHDR.size());

if (hasInfo) {
for (unsigned int i = 0; i < chunksInfo.size(); i++) {
png_process_data(png_ptr, info_ptr, chunksInfo[i].data(),
chunksInfo[i].size());
for (auto& chunk : chunksInfo) {
png_process_data(png_ptr, info_ptr, chunk.data(), chunk.size());
}
}
return 0;
Expand Down Expand Up @@ -603,7 +602,7 @@ Status DecodeImageAPNG(const Span<const uint8_t> bytes,

// Make sure png memory is released in any case.
auto scope_guard = MakeScopeGuard([&]() {
png_destroy_read_struct(&png_ptr, &info_ptr, 0);
png_destroy_read_struct(&png_ptr, &info_ptr, nullptr);
// Just in case. Not all versions on libpng wipe-out the pointers.
png_ptr = nullptr;
info_ptr = nullptr;
Expand Down Expand Up @@ -660,7 +659,7 @@ Status DecodeImageAPNG(const Span<const uint8_t> bytes,

if (id == kId_acTL && !hasInfo && !isAnimated) {
isAnimated = true;
ppf->info.have_animation = true;
ppf->info.have_animation = JXL_TRUE;
ppf->info.animation.tps_numerator = 1000;
ppf->info.animation.tps_denominator = 1;
} else if (id == kId_IEND ||
Expand Down Expand Up @@ -992,7 +991,7 @@ Status DecodeImageAPNG(const Span<const uint8_t> bytes,
has_nontrivial_background && frame.dispose_op == DISPOSE_OP_BACKGROUND;
}
if (ppf->frames.empty()) return JXL_FAILURE("No frames decoded");
ppf->frames.back().frame_info.is_last = true;
ppf->frames.back().frame_info.is_last = JXL_TRUE;

return true;
#else
Expand Down
2 changes: 1 addition & 1 deletion lib/extras/dec/decode.cc
Expand Up @@ -99,7 +99,7 @@ Status DecodeBytes(const Span<const uint8_t> bytes,
*ppf = extras::PackedPixelFile();

// Default values when not set by decoders.
ppf->info.uses_original_profile = true;
ppf->info.uses_original_profile = JXL_TRUE;
ppf->info.orientation = JXL_ORIENT_IDENTITY;

const auto choose_codec = [&]() -> Codec {
Expand Down
2 changes: 1 addition & 1 deletion lib/extras/dec/exr.cc
Expand Up @@ -188,7 +188,7 @@ Status DecodeImageEXR(Span<const uint8_t> bytes, const ColorHints& color_hints,
if (has_alpha) {
ppf->info.alpha_bits = kExrAlphaBits;
ppf->info.alpha_exponent_bits = ppf->info.exponent_bits_per_sample;
ppf->info.alpha_premultiplied = true;
ppf->info.alpha_premultiplied = JXL_TRUE;
}
ppf->info.intensity_target = intensity_target;
return true;
Expand Down
2 changes: 1 addition & 1 deletion lib/extras/dec/gif.cc
Expand Up @@ -136,7 +136,7 @@ Status DecodeImageGIF(Span<const uint8_t> bytes, const ColorHints& color_hints,
}

if (gif->ImageCount > 1) {
ppf->info.have_animation = true;
ppf->info.have_animation = JXL_TRUE;
// Delays in GIF are specified in 100ths of a second.
ppf->info.animation.tps_numerator = 100;
ppf->info.animation.tps_denominator = 1;
Expand Down
2 changes: 1 addition & 1 deletion lib/extras/dec/jpegli.cc
Expand Up @@ -218,7 +218,7 @@ Status DecodeJpeg(const std::vector<uint8_t>& compressed,
} else {
return failure("unsupported data type");
}
ppf->info.uses_original_profile = true;
ppf->info.uses_original_profile = JXL_TRUE;

// No alpha in JPG
ppf->info.alpha_bits = 0;
Expand Down
11 changes: 6 additions & 5 deletions lib/extras/dec/jpg.cc
Expand Up @@ -270,7 +270,7 @@ Status DecodeImageJPG(const Span<const uint8_t> bytes,
ppf->info.bits_per_sample = BITS_IN_JSAMPLE;
JXL_ASSERT(BITS_IN_JSAMPLE == 8 || BITS_IN_JSAMPLE == 16);
ppf->info.exponent_bits_per_sample = 0;
ppf->info.uses_original_profile = true;
ppf->info.uses_original_profile = JXL_TRUE;

// No alpha in JPG
ppf->info.alpha_bits = 0;
Expand Down Expand Up @@ -306,12 +306,13 @@ Status DecodeImageJPG(const Span<const uint8_t> bytes,
frame.color.stride);

if (cinfo.quantize_colors) {
jxl::msan::UnpoisonMemory(cinfo.colormap, cinfo.out_color_components *
sizeof(cinfo.colormap[0]));
JSAMPLE** colormap = cinfo.colormap;
jxl::msan::UnpoisonMemory(reinterpret_cast<void*>(colormap),
cinfo.out_color_components * sizeof(JSAMPLE*));
for (int c = 0; c < cinfo.out_color_components; ++c) {
jxl::msan::UnpoisonMemory(
cinfo.colormap[c],
cinfo.actual_number_of_colors * sizeof(cinfo.colormap[c][0]));
reinterpret_cast<void*>(colormap[c]),
cinfo.actual_number_of_colors * sizeof(JSAMPLE));
}
}
for (size_t y = 0; y < cinfo.image_height; ++y) {
Expand Down
14 changes: 7 additions & 7 deletions lib/extras/dec/jxl.cc
Expand Up @@ -180,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;
}
Expand Down Expand Up @@ -313,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;
Expand Down
2 changes: 1 addition & 1 deletion lib/extras/dec/pgx.cc
Expand Up @@ -165,7 +165,7 @@ Status DecodeImagePGX(const Span<const uint8_t> bytes,
// Original data is uint, so exponent_bits_per_sample = 0.
ppf->info.bits_per_sample = header.bits_per_sample;
ppf->info.exponent_bits_per_sample = 0;
ppf->info.uses_original_profile = true;
ppf->info.uses_original_profile = JXL_TRUE;

// No alpha in PGX
ppf->info.alpha_bits = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/extras/enc/exr.cc
Expand Up @@ -84,7 +84,7 @@ Status EncodeImageEXR(const PackedImage& image, const JxlBasicInfo& info,
const size_t xsize = info.xsize;
const size_t ysize = info.ysize;
const bool has_alpha = info.alpha_bits > 0;
const bool alpha_is_premultiplied = info.alpha_premultiplied;
const bool alpha_is_premultiplied = FROM_JXL_BOOL(info.alpha_premultiplied);

if (info.num_color_channels != 3 ||
c_enc.color_space != JXL_COLOR_SPACE_RGB ||
Expand Down
8 changes: 4 additions & 4 deletions lib/extras/enc/jpegli.cc
Expand Up @@ -437,7 +437,7 @@ Status EncodeJpeg(const PackedPixelFile& ppf, const JpegSettings& jpeg_settings,
}
}
jpegli_enable_adaptive_quantization(
&cinfo, jpeg_settings.use_adaptive_quantization);
&cinfo, TO_JXL_BOOL(jpeg_settings.use_adaptive_quantization));
if (jpeg_settings.psnr_target > 0.0) {
jpegli_set_psnr(&cinfo, jpeg_settings.psnr_target,
jpeg_settings.search_tolerance,
Expand All @@ -449,11 +449,11 @@ Status EncodeJpeg(const PackedPixelFile& ppf, const JpegSettings& jpeg_settings,
jpegli_set_distance(&cinfo, jpeg_settings.distance, TRUE);
}
jpegli_set_progressive_level(&cinfo, jpeg_settings.progressive_level);
cinfo.optimize_coding = jpeg_settings.optimize_coding;
cinfo.optimize_coding = TO_JXL_BOOL(jpeg_settings.optimize_coding);
if (!jpeg_settings.app_data.empty()) {
// Make sure jpegli_start_compress() does not write any APP markers.
cinfo.write_JFIF_header = false;
cinfo.write_Adobe_marker = false;
cinfo.write_JFIF_header = JXL_FALSE;
cinfo.write_Adobe_marker = JXL_FALSE;
}
const PackedImage& image = ppf.frames[0].color;
if (jpeg_settings.xyb) {
Expand Down
4 changes: 2 additions & 2 deletions lib/extras/enc/jpg.cc
Expand Up @@ -216,8 +216,8 @@ void WriteExif(jpeg_compress_struct* const cinfo,
for (const unsigned char c : kExifSignature) {
jpeg_write_m_byte(cinfo, c);
}
for (size_t i = 0; i < exif.size(); ++i) {
jpeg_write_m_byte(cinfo, exif[i]);
for (uint8_t c : exif) {
jpeg_write_m_byte(cinfo, c);
}
}

Expand Down
29 changes: 16 additions & 13 deletions lib/extras/enc/jxl.cc
Expand Up @@ -7,6 +7,7 @@

#include <jxl/encode.h>
#include <jxl/encode_cxx.h>
#include <jxl/types.h>

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

Expand Down Expand Up @@ -150,18 +151,19 @@ 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))) {
fprintf(stderr, "JxlEncoderUseContainer failed.\n");
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");
Expand Down Expand Up @@ -220,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 =
Expand Down Expand Up @@ -294,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);
Expand Down Expand Up @@ -346,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;
Expand Down

0 comments on commit 23bdc80

Please sign in to comment.