summaryrefslogtreecommitdiffstats
path: root/third_party/jpeg-xl/lib/jpegli
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/jpeg-xl/lib/jpegli')
-rw-r--r--third_party/jpeg-xl/lib/jpegli/adaptive_quantization.cc19
-rw-r--r--third_party/jpeg-xl/lib/jpegli/bitstream.cc7
-rw-r--r--third_party/jpeg-xl/lib/jpegli/bitstream.h5
-rw-r--r--third_party/jpeg-xl/lib/jpegli/color_quantize.cc40
-rw-r--r--third_party/jpeg-xl/lib/jpegli/color_quantize.h2
-rw-r--r--third_party/jpeg-xl/lib/jpegli/dct-inl.h10
-rw-r--r--third_party/jpeg-xl/lib/jpegli/decode.cc39
-rw-r--r--third_party/jpeg-xl/lib/jpegli/decode_api_test.cc35
-rw-r--r--third_party/jpeg-xl/lib/jpegli/decode_internal.h17
-rw-r--r--third_party/jpeg-xl/lib/jpegli/decode_marker.cc63
-rw-r--r--third_party/jpeg-xl/lib/jpegli/decode_marker.h4
-rw-r--r--third_party/jpeg-xl/lib/jpegli/decode_scan.cc9
-rw-r--r--third_party/jpeg-xl/lib/jpegli/decode_scan.h4
-rw-r--r--third_party/jpeg-xl/lib/jpegli/destination_manager.cc16
-rw-r--r--third_party/jpeg-xl/lib/jpegli/downsample.cc8
-rw-r--r--third_party/jpeg-xl/lib/jpegli/encode.cc33
-rw-r--r--third_party/jpeg-xl/lib/jpegli/encode_api_test.cc24
-rw-r--r--third_party/jpeg-xl/lib/jpegli/encode_finish.cc2
-rw-r--r--third_party/jpeg-xl/lib/jpegli/entropy_coding.cc58
-rw-r--r--third_party/jpeg-xl/lib/jpegli/error.h5
-rw-r--r--third_party/jpeg-xl/lib/jpegli/error_handling_test.cc21
-rw-r--r--third_party/jpeg-xl/lib/jpegli/huffman.cc5
-rw-r--r--third_party/jpeg-xl/lib/jpegli/idct.cc5
-rw-r--r--third_party/jpeg-xl/lib/jpegli/input.cc18
-rw-r--r--third_party/jpeg-xl/lib/jpegli/input_suspension_test.cc30
-rw-r--r--third_party/jpeg-xl/lib/jpegli/libjpeg_test_util.cc15
-rw-r--r--third_party/jpeg-xl/lib/jpegli/libjpeg_wrapper.cc4
-rw-r--r--third_party/jpeg-xl/lib/jpegli/memory_manager.h3
-rw-r--r--third_party/jpeg-xl/lib/jpegli/output_suspension_test.cc12
-rw-r--r--third_party/jpeg-xl/lib/jpegli/quant.cc18
-rw-r--r--third_party/jpeg-xl/lib/jpegli/render.cc31
-rw-r--r--third_party/jpeg-xl/lib/jpegli/source_manager.cc4
-rw-r--r--third_party/jpeg-xl/lib/jpegli/source_manager_test.cc4
-rw-r--r--third_party/jpeg-xl/lib/jpegli/streaming_test.cc18
-rw-r--r--third_party/jpeg-xl/lib/jpegli/test_utils-inl.h40
-rw-r--r--third_party/jpeg-xl/lib/jpegli/test_utils.cc81
-rw-r--r--third_party/jpeg-xl/lib/jpegli/testing.h20
-rw-r--r--third_party/jpeg-xl/lib/jpegli/transpose-inl.h8
-rw-r--r--third_party/jpeg-xl/lib/jpegli/upsample.cc6
39 files changed, 387 insertions, 356 deletions
diff --git a/third_party/jpeg-xl/lib/jpegli/adaptive_quantization.cc b/third_party/jpeg-xl/lib/jpegli/adaptive_quantization.cc
index 6a8c4d3128..2039326cbd 100644
--- a/third_party/jpeg-xl/lib/jpegli/adaptive_quantization.cc
+++ b/third_party/jpeg-xl/lib/jpegli/adaptive_quantization.cc
@@ -5,6 +5,7 @@
#include "lib/jpegli/adaptive_quantization.h"
+#include <jxl/types.h>
#include <stddef.h>
#include <stdlib.h>
@@ -46,7 +47,7 @@ using hwy::HWY_NAMESPACE::Sqrt;
using hwy::HWY_NAMESPACE::Sub;
using hwy::HWY_NAMESPACE::ZeroIfNegative;
-static constexpr float kInputScaling = 1.0f / 255.0f;
+constexpr float kInputScaling = 1.0f / 255.0f;
// Primary template: default to actual division.
template <typename T, class V>
@@ -65,7 +66,7 @@ struct FastDivision<float, V> {
}
V operator()(const V n, const V d) const {
-#if 1 // Faster on SKX
+#if JXL_TRUE // Faster on SKX
return Div(n, d);
#else
return n * ReciprocalNR(d);
@@ -191,12 +192,12 @@ V ComputeMask(const D d, const V out_val) {
}
// mul and mul2 represent a scaling difference between jxl and butteraugli.
-static const float kSGmul = 226.0480446705883f;
-static const float kSGmul2 = 1.0f / 73.377132366608819f;
-static const float kLog2 = 0.693147181f;
+const float kSGmul = 226.0480446705883f;
+const float kSGmul2 = 1.0f / 73.377132366608819f;
+const float kLog2 = 0.693147181f;
// Includes correction factor for std::log -> log2.
-static const float kSGRetMul = kSGmul2 * 18.6580932135f * kLog2;
-static const float kSGVOffset = 7.14672470003f;
+const float kSGRetMul = kSGmul2 * 18.6580932135f * kLog2;
+const float kSGVOffset = 7.14672470003f;
template <bool invert, typename D, typename V>
V RatioOfDerivativesOfCubicRootToSimpleGamma(const D d, V v) {
@@ -226,7 +227,7 @@ V RatioOfDerivativesOfCubicRootToSimpleGamma(const D d, V v) {
}
template <bool invert = false>
-static float RatioOfDerivativesOfCubicRootToSimpleGamma(float v) {
+float RatioOfDerivativesOfCubicRootToSimpleGamma(float v) {
using DScalar = HWY_CAPPED(float, 1);
auto vscalar = Load(DScalar(), &v);
return GetLane(
@@ -503,7 +504,7 @@ HWY_EXPORT(PerBlockModulations);
namespace {
-static constexpr int kPreErosionBorder = 1;
+constexpr int kPreErosionBorder = 1;
} // namespace
diff --git a/third_party/jpeg-xl/lib/jpegli/bitstream.cc b/third_party/jpeg-xl/lib/jpegli/bitstream.cc
index 3448367dde..4dbeb738bb 100644
--- a/third_party/jpeg-xl/lib/jpegli/bitstream.cc
+++ b/third_party/jpeg-xl/lib/jpegli/bitstream.cc
@@ -90,8 +90,8 @@ bool EncodeDQT(j_compress_ptr cinfo, bool write_all_tables) {
JPEGLI_ERROR("Missing quant table %d", i);
}
int precision = 0;
- for (size_t k = 0; k < DCTSIZE2; ++k) {
- if (quant_table->quantval[k] > 255) {
+ for (UINT16 q : quant_table->quantval) {
+ if (q > 255) {
precision = 1;
is_baseline = false;
}
@@ -123,7 +123,6 @@ bool EncodeDQT(j_compress_ptr cinfo, bool write_all_tables) {
void EncodeSOF(j_compress_ptr cinfo, bool is_baseline) {
if (cinfo->data_precision != kJpegPrecision) {
- is_baseline = false;
JPEGLI_ERROR("Unsupported data precision %d", cinfo->data_precision);
}
const uint8_t marker = cinfo->progressive_mode ? 0xc2
@@ -302,7 +301,7 @@ void WriteBlock(const int32_t* JXL_RESTRICT symbols,
namespace {
-static JXL_INLINE void EmitMarker(JpegBitWriter* bw, int marker) {
+JXL_INLINE void EmitMarker(JpegBitWriter* bw, int marker) {
bw->data[bw->pos++] = 0xFF;
bw->data[bw->pos++] = marker;
}
diff --git a/third_party/jpeg-xl/lib/jpegli/bitstream.h b/third_party/jpeg-xl/lib/jpegli/bitstream.h
index aa54c73d7e..bed441aefe 100644
--- a/third_party/jpeg-xl/lib/jpegli/bitstream.h
+++ b/third_party/jpeg-xl/lib/jpegli/bitstream.h
@@ -32,9 +32,8 @@ void EncodeSOS(j_compress_ptr cinfo, int scan_index);
void WriteScanHeader(j_compress_ptr cinfo, int scan_index);
void WriteBlock(const int32_t* JXL_RESTRICT symbols,
- const int32_t* JXL_RESTRICT extra_bits, const int num_nonzeros,
- const bool emit_eob,
- const HuffmanCodeTable* JXL_RESTRICT dc_code,
+ const int32_t* JXL_RESTRICT extra_bits, int num_nonzeros,
+ bool emit_eob, const HuffmanCodeTable* JXL_RESTRICT dc_code,
const HuffmanCodeTable* JXL_RESTRICT ac_code,
JpegBitWriter* JXL_RESTRICT bw);
void WriteScanData(j_compress_ptr cinfo, int scan_index);
diff --git a/third_party/jpeg-xl/lib/jpegli/color_quantize.cc b/third_party/jpeg-xl/lib/jpegli/color_quantize.cc
index e8357e2160..c4f32bf439 100644
--- a/third_party/jpeg-xl/lib/jpegli/color_quantize.cc
+++ b/third_party/jpeg-xl/lib/jpegli/color_quantize.cc
@@ -11,13 +11,14 @@
#include "lib/jpegli/decode_internal.h"
#include "lib/jpegli/error.h"
+#include "lib/jxl/base/status.h"
namespace jpegli {
namespace {
-static constexpr int kNumColorCellBits[kMaxComponents] = {3, 4, 3, 3};
-static constexpr int kCompW[kMaxComponents] = {2, 3, 1, 1};
+constexpr int kNumColorCellBits[kMaxComponents] = {3, 4, 3, 3};
+constexpr int kCompW[kMaxComponents] = {2, 3, 1, 1};
int Pow(int a, int b) {
int r = 1;
@@ -102,8 +103,8 @@ namespace {
// 2^13 priority levels for the PQ seems to be a good compromise between
// accuracy, running time and stack space usage.
-static const int kMaxPriority = 1 << 13;
-static const int kMaxLevel = 3;
+const int kMaxPriority = 1 << 13;
+const int kMaxLevel = 3;
// This function is used in the multi-resolution grid to be able to compute
// the keys for the different resolutions by just shifting the first key.
@@ -153,7 +154,7 @@ inline int ColorIntQuadDistanceRGB(uint8_t r1, uint8_t g1, uint8_t b1,
}
inline int ScaleQuadDistanceRGB(int d) {
- return static_cast<int>(sqrt(d * 0.25) + 0.5);
+ return static_cast<int>(std::lround(sqrt(d * 0.25)));
}
// The function updates the minimal distances, the clustering and the
@@ -216,9 +217,9 @@ struct WangHasher {
// to a unique integer index assigned to the different colors in order of
// appearance in the image. Return the number of unique colors found.
// The colors are pre-quantized to 3 * 6 bits precision.
-static int BuildRGBColorIndex(const uint8_t* const image, int const num_pixels,
- int* const count, uint8_t* const red,
- uint8_t* const green, uint8_t* const blue) {
+int BuildRGBColorIndex(const uint8_t* const image, int const num_pixels,
+ int* const count, uint8_t* const red,
+ uint8_t* const green, uint8_t* const blue) {
// Impossible because rgb are in the low 24 bits, and the upper 8 bits is 0.
const uint32_t impossible_pixel_value = 0x10000000;
std::unordered_map<uint32_t, int, RGBPixelHasher> index_map(1 << 12);
@@ -264,7 +265,7 @@ void ChooseColorMap2Pass(j_decompress_ptr cinfo) {
std::unique_ptr<uint8_t[]> blue(new uint8_t[max_color_count]);
std::vector<int> count(max_color_count, 0);
// number of colors
- int n = BuildRGBColorIndex(m->pixels_, num_pixels, &count[0], &red[0],
+ int n = BuildRGBColorIndex(m->pixels_, num_pixels, count.data(), &red[0],
&green[0], &blue[0]);
std::vector<int> dist(n, std::numeric_limits<int>::max());
@@ -285,14 +286,14 @@ void ChooseColorMap2Pass(j_decompress_ptr cinfo) {
winner = i;
}
if (!in_palette[i] && count[i] > count_threshold) {
- AddToRGBPalette(&red[0], &green[0], &blue[0], &count[0], i, k++, n,
- &dist[0], &cluster[0], &center[0], &error);
+ AddToRGBPalette(&red[0], &green[0], &blue[0], count.data(), i, k++, n,
+ dist.data(), cluster.data(), &center[0], &error);
in_palette[i] = true;
}
}
if (k == 0) {
- AddToRGBPalette(&red[0], &green[0], &blue[0], &count[0], winner, k++, n,
- &dist[0], &cluster[0], &center[0], &error);
+ AddToRGBPalette(&red[0], &green[0], &blue[0], count.data(), winner, k++, n,
+ dist.data(), cluster.data(), &center[0], &error);
in_palette[winner] = true;
}
@@ -365,8 +366,8 @@ void ChooseColorMap2Pass(j_decompress_ptr cinfo) {
if (priority < top_priority) {
bucket_array[priority].push_back(i);
} else {
- AddToRGBPalette(&red[0], &green[0], &blue[0], &count[0], i, k++, n,
- &dist[0], &cluster[0], &center[0], &error);
+ AddToRGBPalette(&red[0], &green[0], &blue[0], count.data(), i, k++, n,
+ dist.data(), cluster.data(), &center[0], &error);
}
bucket_array[top_priority].pop_back();
while (top_priority >= 0 && bucket_array[top_priority].empty()) {
@@ -387,7 +388,7 @@ void ChooseColorMap2Pass(j_decompress_ptr cinfo) {
namespace {
-void FindCandidatesForCell(j_decompress_ptr cinfo, int ncomp, int cell[],
+void FindCandidatesForCell(j_decompress_ptr cinfo, int ncomp, const int cell[],
std::vector<uint8_t>* candidates) {
int cell_min[kMaxComponents];
int cell_max[kMaxComponents];
@@ -404,7 +405,8 @@ void FindCandidatesForCell(j_decompress_ptr cinfo, int ncomp, int cell[],
int dmax = 0;
for (int c = 0; c < ncomp; ++c) {
int palette_c = cinfo->colormap[c][i];
- int dminc = 0, dmaxc;
+ int dminc = 0;
+ int dmaxc;
if (palette_c < cell_min[c]) {
dminc = cell_min[c] - palette_c;
dmaxc = cell_max[c] - palette_c;
@@ -436,6 +438,8 @@ void FindCandidatesForCell(j_decompress_ptr cinfo, int ncomp, int cell[],
void CreateInverseColorMap(j_decompress_ptr cinfo) {
jpeg_decomp_master* m = cinfo->master;
int ncomp = cinfo->out_color_components;
+ JXL_ASSERT(ncomp > 0);
+ JXL_ASSERT(ncomp <= kMaxComponents);
int num_cells = 1;
for (int c = 0; c < ncomp; ++c) {
num_cells *= (1 << kNumColorCellBits[c]);
@@ -455,7 +459,7 @@ void CreateInverseColorMap(j_decompress_ptr cinfo) {
m->regenerate_inverse_colormap_ = false;
}
-int LookupColorIndex(j_decompress_ptr cinfo, JSAMPLE* pixel) {
+int LookupColorIndex(j_decompress_ptr cinfo, const JSAMPLE* pixel) {
jpeg_decomp_master* m = cinfo->master;
int num_channels = cinfo->out_color_components;
int index = 0;
diff --git a/third_party/jpeg-xl/lib/jpegli/color_quantize.h b/third_party/jpeg-xl/lib/jpegli/color_quantize.h
index 3dda1d8713..92b922f756 100644
--- a/third_party/jpeg-xl/lib/jpegli/color_quantize.h
+++ b/third_party/jpeg-xl/lib/jpegli/color_quantize.h
@@ -20,7 +20,7 @@ void CreateOrderedDitherTables(j_decompress_ptr cinfo);
void InitFSDitherState(j_decompress_ptr cinfo);
-int LookupColorIndex(j_decompress_ptr cinfo, JSAMPLE* pixel);
+int LookupColorIndex(j_decompress_ptr cinfo, const JSAMPLE* pixel);
} // namespace jpegli
diff --git a/third_party/jpeg-xl/lib/jpegli/dct-inl.h b/third_party/jpeg-xl/lib/jpegli/dct-inl.h
index 1cbe704002..66cc3b6b53 100644
--- a/third_party/jpeg-xl/lib/jpegli/dct-inl.h
+++ b/third_party/jpeg-xl/lib/jpegli/dct-inl.h
@@ -187,7 +187,7 @@ void DCT1D(const float* JXL_RESTRICT pixels, size_t pixels_stride,
}
}
-static JXL_INLINE JXL_MAYBE_UNUSED void TransformFromPixels(
+JXL_INLINE JXL_MAYBE_UNUSED void TransformFromPixels(
const float* JXL_RESTRICT pixels, size_t pixels_stride,
float* JXL_RESTRICT coefficients, float* JXL_RESTRICT scratch_space) {
DCT1D(pixels, pixels_stride, scratch_space);
@@ -196,14 +196,14 @@ static JXL_INLINE JXL_MAYBE_UNUSED void TransformFromPixels(
Transpose8x8Block(scratch_space, coefficients);
}
-static JXL_INLINE JXL_MAYBE_UNUSED void StoreQuantizedValue(const Vec<DI>& ival,
- int16_t* out) {
+JXL_INLINE JXL_MAYBE_UNUSED void StoreQuantizedValue(const Vec<DI>& ival,
+ int16_t* out) {
Rebind<int16_t, DI> di16;
Store(DemoteTo(di16, ival), di16, out);
}
-static JXL_INLINE JXL_MAYBE_UNUSED void StoreQuantizedValue(const Vec<DI>& ival,
- int32_t* out) {
+JXL_INLINE JXL_MAYBE_UNUSED void StoreQuantizedValue(const Vec<DI>& ival,
+ int32_t* out) {
DI di;
Store(ival, di, out);
}
diff --git a/third_party/jpeg-xl/lib/jpegli/decode.cc b/third_party/jpeg-xl/lib/jpegli/decode.cc
index 758babeb5e..9fdf68dd18 100644
--- a/third_party/jpeg-xl/lib/jpegli/decode.cc
+++ b/third_party/jpeg-xl/lib/jpegli/decode.cc
@@ -115,8 +115,10 @@ void InitProgressMonitor(j_decompress_ptr cinfo, bool coef_only) {
cinfo->progress->total_passes = 1;
} else {
int input_passes = !cinfo->buffered_image && m->is_multiscan_ ? 1 : 0;
- bool two_pass_quant = cinfo->quantize_colors && !cinfo->colormap &&
- cinfo->two_pass_quantize && cinfo->enable_2pass_quant;
+ bool two_pass_quant = FROM_JXL_BOOL(cinfo->quantize_colors) &&
+ (cinfo->colormap != nullptr) &&
+ FROM_JXL_BOOL(cinfo->two_pass_quantize) &&
+ FROM_JXL_BOOL(cinfo->enable_2pass_quant);
cinfo->progress->total_passes = input_passes + (two_pass_quant ? 2 : 1);
}
cinfo->progress->completed_passes = 0;
@@ -175,7 +177,7 @@ void BuildHuffmanLookupTable(j_decompress_ptr cinfo, JHUFF_TBL* table,
for (int i = 0; i < total_count; ++i) {
int value = table->huffval[i];
if (values_seen[value]) {
- return JPEGLI_ERROR("Duplicate Huffman code value %d", value);
+ JPEGLI_ERROR("Duplicate Huffman code value %d", value);
}
values_seen[value] = 1;
values[i] = value;
@@ -223,7 +225,7 @@ void PrepareForScan(j_decompress_ptr cinfo) {
HuffmanTableEntry* huff_lut =
&m->dc_huff_lut_[dc_tbl_idx * kJpegHuffmanLutSize];
if (!table) {
- return JPEGLI_ERROR("DC Huffman table %d not found", dc_tbl_idx);
+ JPEGLI_ERROR("DC Huffman table %d not found", dc_tbl_idx);
}
BuildHuffmanLookupTable(cinfo, table, huff_lut);
}
@@ -233,7 +235,7 @@ void PrepareForScan(j_decompress_ptr cinfo) {
HuffmanTableEntry* huff_lut =
&m->ac_huff_lut_[ac_tbl_idx * kJpegHuffmanLutSize];
if (!table) {
- return JPEGLI_ERROR("AC Huffman table %d not found", ac_tbl_idx);
+ JPEGLI_ERROR("AC Huffman table %d not found", ac_tbl_idx);
}
BuildHuffmanLookupTable(cinfo, table, huff_lut);
}
@@ -543,8 +545,8 @@ void jpegli_CreateDecompress(j_decompress_ptr cinfo, int version,
cinfo->is_decompressor = TRUE;
cinfo->progress = nullptr;
cinfo->src = nullptr;
- for (int i = 0; i < NUM_QUANT_TBLS; i++) {
- cinfo->quant_tbl_ptrs[i] = nullptr;
+ for (auto& quant_tbl_ptr : cinfo->quant_tbl_ptrs) {
+ quant_tbl_ptr = nullptr;
}
for (int i = 0; i < NUM_HUFF_TBLS; i++) {
cinfo->dc_huff_tbl_ptrs[i] = nullptr;
@@ -555,8 +557,8 @@ void jpegli_CreateDecompress(j_decompress_ptr cinfo, int version,
cinfo->rec_outbuf_height = 1; // output works with any buffer height
cinfo->master = new jpeg_decomp_master;
jpeg_decomp_master* m = cinfo->master;
- for (int i = 0; i < 16; ++i) {
- m->app_marker_parsers[i] = nullptr;
+ for (auto& app_marker_parser : m->app_marker_parsers) {
+ app_marker_parser = nullptr;
}
m->com_marker_parser = nullptr;
memset(m->markers_to_save_, 0, sizeof(m->markers_to_save_));
@@ -661,7 +663,7 @@ boolean jpegli_read_icc_profile(j_decompress_ptr cinfo, JOCTET** icc_data_ptr,
return FALSE;
}
*icc_data_len = m->icc_profile_.size();
- *icc_data_ptr = (JOCTET*)malloc(*icc_data_len);
+ *icc_data_ptr = static_cast<JOCTET*>(malloc(*icc_data_len));
if (*icc_data_ptr == nullptr) {
JPEGLI_ERROR("jpegli_read_icc_profile: Out of memory");
}
@@ -738,21 +740,26 @@ void jpegli_calc_output_dimensions(j_decompress_ptr cinfo) {
}
boolean jpegli_has_multiple_scans(j_decompress_ptr cinfo) {
- if (cinfo->input_scan_number == 0) {
- JPEGLI_ERROR("No SOS marker found.");
+ if (cinfo->global_state != jpegli::kDecHeaderDone &&
+ cinfo->global_state != jpegli::kDecProcessScan &&
+ cinfo->global_state != jpegli::kDecProcessMarkers) {
+ JPEGLI_ERROR("jpegli_has_multiple_scans: unexpected state %d",
+ cinfo->global_state);
}
- return cinfo->master->is_multiscan_;
+ return TO_JXL_BOOL(cinfo->master->is_multiscan_);
}
boolean jpegli_input_complete(j_decompress_ptr cinfo) {
- return cinfo->master->found_eoi_;
+ return TO_JXL_BOOL(cinfo->master->found_eoi_);
}
boolean jpegli_start_decompress(j_decompress_ptr cinfo) {
jpeg_decomp_master* m = cinfo->master;
if (cinfo->global_state == jpegli::kDecHeaderDone) {
- m->streaming_mode_ = !m->is_multiscan_ && !cinfo->buffered_image &&
- (!cinfo->quantize_colors || !cinfo->two_pass_quantize);
+ m->streaming_mode_ = !m->is_multiscan_ &&
+ !FROM_JXL_BOOL(cinfo->buffered_image) &&
+ (!FROM_JXL_BOOL(cinfo->quantize_colors) ||
+ !FROM_JXL_BOOL(cinfo->two_pass_quantize));
jpegli::AllocateCoefficientBuffer(cinfo);
jpegli_calc_output_dimensions(cinfo);
jpegli::PrepareForScan(cinfo);
diff --git a/third_party/jpeg-xl/lib/jpegli/decode_api_test.cc b/third_party/jpeg-xl/lib/jpegli/decode_api_test.cc
index c48b9377c3..0cc5a194d7 100644
--- a/third_party/jpeg-xl/lib/jpegli/decode_api_test.cc
+++ b/third_party/jpeg-xl/lib/jpegli/decode_api_test.cc
@@ -18,8 +18,8 @@
namespace jpegli {
namespace {
-static constexpr uint8_t kFakeEoiMarker[2] = {0xff, 0xd9};
-static constexpr size_t kNumSourceBuffers = 4;
+constexpr uint8_t kFakeEoiMarker[2] = {0xff, 0xd9};
+constexpr size_t kNumSourceBuffers = 4;
// Custom source manager that refills the input buffer in chunks, simulating
// a file reader with a fixed buffer size.
@@ -61,7 +61,7 @@ class SourceManager {
static void init_source(j_decompress_ptr cinfo) {}
static boolean fill_input_buffer(j_decompress_ptr cinfo) {
- auto src = reinterpret_cast<SourceManager*>(cinfo->src);
+ auto* src = reinterpret_cast<SourceManager*>(cinfo->src);
if (src->pos_ < src->len_) {
size_t chunk_size = std::min(src->len_ - src->pos_, src->max_chunk_size_);
size_t next_idx = ++src->chunk_idx_ % kNumSourceBuffers;
@@ -79,7 +79,7 @@ class SourceManager {
}
static void skip_input_data(j_decompress_ptr cinfo, long num_bytes) {
- auto src = reinterpret_cast<SourceManager*>(cinfo->src);
+ auto* src = reinterpret_cast<SourceManager*>(cinfo->src);
if (num_bytes <= 0) {
return;
}
@@ -166,9 +166,9 @@ void ReadOutputImage(const DecompressParams& dparams, j_decompress_ptr cinfo,
rowdata[c][i] =
y0 + i < ysize ? &output->raw_data[c][(y0 + i) * xsize] : nullptr;
}
- data[c] = &rowdata[c][0];
+ data[c] = rowdata[c].data();
}
- num_output_lines = jpegli_read_raw_data(cinfo, &data[0], max_lines);
+ num_output_lines = jpegli_read_raw_data(cinfo, data.data(), max_lines);
} else {
size_t max_output_lines = dparams.max_output_lines;
if (max_output_lines == 0) max_output_lines = cinfo->output_height;
@@ -189,7 +189,7 @@ void ReadOutputImage(const DecompressParams& dparams, j_decompress_ptr cinfo,
scanlines[i] = &output->pixels[yidx * stride];
}
num_output_lines =
- jpegli_read_scanlines(cinfo, &scanlines[0], max_lines);
+ jpegli_read_scanlines(cinfo, scanlines.data(), max_lines);
if (cinfo->quantize_colors) {
for (size_t i = 0; i < num_output_lines; ++i) {
UnmapColors(scanlines[i], cinfo->output_width,
@@ -222,7 +222,7 @@ struct TestConfig {
std::vector<uint8_t> GetTestJpegData(TestConfig& config) {
std::vector<uint8_t> compressed;
if (!config.fn.empty()) {
- compressed = ReadTestData(config.fn.c_str());
+ compressed = ReadTestData(config.fn);
} else {
GeneratePixels(&config.input);
JXL_CHECK(EncodeWithJpegli(config.input, config.jparams, &compressed));
@@ -297,10 +297,10 @@ void TestAPIBuffered(const CompressParams& jparams,
SetDecompressParams(dparams, cinfo);
jpegli_set_output_format(cinfo, dparams.data_type, dparams.endianness);
VerifyHeader(jparams, cinfo);
+ bool has_multiple_scans = FROM_JXL_BOOL(jpegli_has_multiple_scans(cinfo));
EXPECT_TRUE(jpegli_start_decompress(cinfo));
// start decompress should not read the whole input in buffered image mode
EXPECT_FALSE(jpegli_input_complete(cinfo));
- bool has_multiple_scans = jpegli_has_multiple_scans(cinfo);
EXPECT_EQ(0, cinfo->output_scan_number);
int sos_marker_cnt = 1; // read_header reads the first SOS marker
while (!jpegli_input_complete(cinfo)) {
@@ -341,8 +341,11 @@ void TestAPIBuffered(const CompressParams& jparams,
}
TEST(DecodeAPITest, ReuseCinfo) {
- TestImage input, output, expected;
- std::vector<TestImage> output_progression, expected_output_progression;
+ TestImage input;
+ TestImage output;
+ TestImage expected;
+ std::vector<TestImage> output_progression;
+ std::vector<TestImage> expected_output_progression;
CompressParams jparams;
DecompressParams dparams;
std::vector<uint8_t> compressed;
@@ -383,8 +386,8 @@ TEST(DecodeAPITest, ReuseCinfo) {
expected.Clear();
DecodeWithLibjpeg(jparams, dparams, compressed, &expected);
output.Clear();
- cinfo.buffered_image = false;
- cinfo.raw_data_out = false;
+ cinfo.buffered_image = JXL_FALSE;
+ cinfo.raw_data_out = JXL_FALSE;
cinfo.scale_num = cinfo.scale_denom = 1;
SourceManager src(compressed.data(), compressed.size(),
1u << 12);
@@ -1245,7 +1248,8 @@ std::ostream& operator<<(std::ostream& os, const DecompressParams& dparams) {
}
os << IOMethodName(dparams.data_type, dparams.endianness);
if (dparams.set_out_color_space) {
- os << "OutColor" << ColorSpaceName((J_COLOR_SPACE)dparams.out_color_space);
+ os << "OutColor"
+ << ColorSpaceName(static_cast<J_COLOR_SPACE>(dparams.out_color_space));
}
if (dparams.crop_output) {
os << "Crop";
@@ -1265,7 +1269,8 @@ std::ostream& operator<<(std::ostream& os, const DecompressParams& dparams) {
if (i > 0) os << "_";
const auto& sparam = dparams.scan_params[i];
os << QuantMode(sparam.color_quant_mode);
- os << DitherMode((J_DITHER_MODE)sparam.dither_mode) << "Dither";
+ os << DitherMode(static_cast<J_DITHER_MODE>(sparam.dither_mode))
+ << "Dither";
}
}
if (dparams.skip_scans) {
diff --git a/third_party/jpeg-xl/lib/jpegli/decode_internal.h b/third_party/jpeg-xl/lib/jpegli/decode_internal.h
index ed7baa39e9..37dfcc4526 100644
--- a/third_party/jpeg-xl/lib/jpegli/decode_internal.h
+++ b/third_party/jpeg-xl/lib/jpegli/decode_internal.h
@@ -45,12 +45,13 @@ struct jpeg_decomp_master {
size_t input_buffer_pos_;
// Number of bits after codestream_pos_ that were already processed.
size_t codestream_bits_ahead_;
- bool streaming_mode_;
// Coefficient buffers
jvirt_barray_ptr* coef_arrays;
JBLOCKARRAY coeff_rows[jpegli::kMaxComponents];
+ bool streaming_mode_;
+
//
// Marker data processing state.
//
@@ -58,6 +59,11 @@ struct jpeg_decomp_master {
bool found_dri_;
bool found_sof_;
bool found_eoi_;
+
+ // Whether this jpeg has multiple scans (progressive or non-interleaved
+ // sequential).
+ bool is_multiscan_;
+
size_t icc_index_;
size_t icc_total_;
std::vector<uint8_t> icc_profile_;
@@ -66,9 +72,6 @@ struct jpeg_decomp_master {
uint8_t markers_to_save_[32];
jpeg_marker_parser_method app_marker_parsers[16];
jpeg_marker_parser_method com_marker_parser;
- // Whether this jpeg has multiple scans (progressive or non-interleaved
- // sequential).
- bool is_multiscan_;
// Fields defined by SOF marker.
size_t iMCU_cols_;
@@ -96,9 +99,11 @@ struct jpeg_decomp_master {
//
int output_passes_done_;
JpegliDataType output_data_type_ = JPEGLI_TYPE_UINT8;
- bool swap_endianness_ = false;
size_t xoffset_;
+ bool swap_endianness_ = false;
bool need_context_rows_;
+ bool regenerate_inverse_colormap_;
+ bool apply_smoothing;
int min_scaled_dct_size;
int scaled_dct_size[jpegli::kMaxComponents];
@@ -127,7 +132,6 @@ struct jpeg_decomp_master {
uint8_t* pixels_;
JSAMPARRAY scanlines_;
std::vector<std::vector<uint8_t>> candidate_lists_;
- bool regenerate_inverse_colormap_;
float* dither_[jpegli::kMaxComponents];
float* error_row_[2 * jpegli::kMaxComponents];
size_t dither_size_;
@@ -145,7 +149,6 @@ struct jpeg_decomp_master {
// i.e. the bottom half when rendering incomplete scans.
int (*coef_bits_latch)[SAVED_COEFS];
int (*prev_coef_bits_latch)[SAVED_COEFS];
- bool apply_smoothing;
};
#endif // LIB_JPEGLI_DECODE_INTERNAL_H_
diff --git a/third_party/jpeg-xl/lib/jpegli/decode_marker.cc b/third_party/jpeg-xl/lib/jpegli/decode_marker.cc
index c5c5790cdf..a9ed4df329 100644
--- a/third_party/jpeg-xl/lib/jpegli/decode_marker.cc
+++ b/third_party/jpeg-xl/lib/jpegli/decode_marker.cc
@@ -5,6 +5,7 @@
#include "lib/jpegli/decode_marker.h"
+#include <jxl/types.h>
#include <string.h>
#include "lib/jpegli/common.h"
@@ -22,23 +23,22 @@ constexpr uint8_t kIccProfileTag[12] = "ICC_PROFILE";
// Macros for commonly used error conditions.
-#define JPEG_VERIFY_LEN(n) \
- if (pos + (n) > len) { \
- return JPEGLI_ERROR("Unexpected end of marker: pos=%" PRIuS \
- " need=%d len=%" PRIuS, \
- pos, static_cast<int>(n), len); \
+#define JPEG_VERIFY_LEN(n) \
+ if (pos + (n) > len) { \
+ JPEGLI_ERROR("Unexpected end of marker: pos=%" PRIuS \
+ " need=%d len=%" PRIuS, \
+ pos, static_cast<int>(n), len); \
}
-#define JPEG_VERIFY_INPUT(var, low, high) \
- if ((var) < (low) || (var) > (high)) { \
- return JPEGLI_ERROR("Invalid " #var ": %d", static_cast<int>(var)); \
+#define JPEG_VERIFY_INPUT(var, low, high) \
+ if ((var) < (low) || (var) > (high)) { \
+ JPEGLI_ERROR("Invalid " #var ": %d", static_cast<int>(var)); \
}
-#define JPEG_VERIFY_MARKER_END() \
- if (pos != len) { \
- return JPEGLI_ERROR("Invalid marker length: declared=%" PRIuS \
- " actual=%" PRIuS, \
- len, pos); \
+#define JPEG_VERIFY_MARKER_END() \
+ if (pos != len) { \
+ JPEGLI_ERROR("Invalid marker length: declared=%" PRIuS " actual=%" PRIuS, \
+ len, pos); \
}
inline int ReadUint8(const uint8_t* data, size_t* pos) {
@@ -60,7 +60,7 @@ void ProcessSOF(j_decompress_ptr cinfo, const uint8_t* data, size_t len) {
JPEGLI_ERROR("Duplicate SOF marker.");
}
m->found_sof_ = true;
- cinfo->progressive_mode = (cinfo->unread_marker == 0xc2);
+ cinfo->progressive_mode = TO_JXL_BOOL(cinfo->unread_marker == 0xc2);
cinfo->arith_code = 0;
size_t pos = 2;
JPEG_VERIFY_LEN(6);
@@ -181,7 +181,7 @@ void ProcessSOS(j_decompress_ptr cinfo, const uint8_t* data, size_t len) {
for (int i = 0; i < cinfo->comps_in_scan; ++i) {
int id = ReadUint8(data, &pos);
if (ids_seen[id]) { // (cf. section B.2.3, regarding CSj)
- return JPEGLI_ERROR("Duplicate ID %d in SOS.", id);
+ JPEGLI_ERROR("Duplicate ID %d in SOS.", id);
}
ids_seen[id] = 1;
jpeg_component_info* comp = nullptr;
@@ -192,8 +192,7 @@ void ProcessSOS(j_decompress_ptr cinfo, const uint8_t* data, size_t len) {
}
}
if (!comp) {
- return JPEGLI_ERROR("SOS marker: Could not find component with id %d",
- id);
+ JPEGLI_ERROR("SOS marker: Could not find component with id %d", id);
}
int c = ReadUint8(data, &pos);
comp->dc_tbl_no = c >> 4;
@@ -222,7 +221,7 @@ void ProcessSOS(j_decompress_ptr cinfo, const uint8_t* data, size_t len) {
if (cinfo->input_scan_number == 0) {
m->is_multiscan_ = (cinfo->comps_in_scan < cinfo->num_components ||
- cinfo->progressive_mode);
+ FROM_JXL_BOOL(cinfo->progressive_mode));
}
if (cinfo->Ah != 0 && cinfo->Al != cinfo->Ah - 1) {
// section G.1.1.1.2 : Successive approximation control only improves
@@ -261,12 +260,12 @@ void ProcessSOS(j_decompress_ptr cinfo, const uint8_t* data, size_t len) {
int comp_idx = cinfo->cur_comp_info[i]->component_index;
for (int k = cinfo->Ss; k <= cinfo->Se; ++k) {
if (m->scan_progression_[comp_idx][k] & scan_bitmask) {
- return JPEGLI_ERROR(
+ JPEGLI_ERROR(
"Overlapping scans: component=%d k=%d prev_mask: %u cur_mask %u",
comp_idx, k, m->scan_progression_[i][k], scan_bitmask);
}
if (m->scan_progression_[comp_idx][k] & refinement_bitmask) {
- return JPEGLI_ERROR(
+ JPEGLI_ERROR(
"Invalid scan order, a more refined scan was already done: "
"component=%d k=%d prev_mask=%u cur_mask=%u",
comp_idx, k, m->scan_progression_[i][k], scan_bitmask);
@@ -275,7 +274,7 @@ void ProcessSOS(j_decompress_ptr cinfo, const uint8_t* data, size_t len) {
}
}
if (cinfo->Al > 10) {
- return JPEGLI_ERROR("Scan parameter Al=%d is not supported.", cinfo->Al);
+ JPEGLI_ERROR("Scan parameter Al=%d is not supported.", cinfo->Al);
}
}
@@ -285,7 +284,7 @@ void ProcessSOS(j_decompress_ptr cinfo, const uint8_t* data, size_t len) {
void ProcessDHT(j_decompress_ptr cinfo, const uint8_t* data, size_t len) {
size_t pos = 2;
if (pos == len) {
- return JPEGLI_ERROR("DHT marker: no Huffman table found");
+ JPEGLI_ERROR("DHT marker: no Huffman table found");
}
while (pos < len) {
JPEG_VERIFY_LEN(1 + kJpegHuffmanMaxBitLength);
@@ -293,7 +292,7 @@ void ProcessDHT(j_decompress_ptr cinfo, const uint8_t* data, size_t len) {
// component Huffman codes, 0x10 is added to the index.
int slot_id = ReadUint8(data, &pos);
int huffman_index = slot_id;
- int is_ac_table = (slot_id & 0x10) != 0;
+ bool is_ac_table = ((slot_id & 0x10) != 0);
JHUFF_TBL** table;
if (is_ac_table) {
huffman_index -= 0x10;
@@ -343,7 +342,7 @@ void ProcessDQT(j_decompress_ptr cinfo, const uint8_t* data, size_t len) {
}
size_t pos = 2;
if (pos == len) {
- return JPEGLI_ERROR("DQT marker: no quantization table found");
+ JPEGLI_ERROR("DQT marker: no quantization table found");
}
while (pos < len) {
JPEG_VERIFY_LEN(1);
@@ -377,7 +376,7 @@ void ProcessDNL(j_decompress_ptr cinfo, const uint8_t* data, size_t len) {
void ProcessDRI(j_decompress_ptr cinfo, const uint8_t* data, size_t len) {
jpeg_decomp_master* m = cinfo->master;
if (m->found_dri_) {
- return JPEGLI_ERROR("Duplicate DRI marker.");
+ JPEGLI_ERROR("Duplicate DRI marker.");
}
m->found_dri_ = true;
size_t pos = 2;
@@ -411,24 +410,24 @@ void ProcessAPP(j_decompress_ptr cinfo, const uint8_t* data, size_t len) {
payload += sizeof(kIccProfileTag);
payload_size -= sizeof(kIccProfileTag);
if (payload_size < 2) {
- return JPEGLI_ERROR("ICC chunk is too small.");
+ JPEGLI_ERROR("ICC chunk is too small.");
}
uint8_t index = payload[0];
uint8_t total = payload[1];
++m->icc_index_;
if (m->icc_index_ != index) {
- return JPEGLI_ERROR("Invalid ICC chunk order.");
+ JPEGLI_ERROR("Invalid ICC chunk order.");
}
if (total == 0) {
- return JPEGLI_ERROR("Invalid ICC chunk total.");
+ JPEGLI_ERROR("Invalid ICC chunk total.");
}
if (m->icc_total_ == 0) {
m->icc_total_ = total;
} else if (m->icc_total_ != total) {
- return JPEGLI_ERROR("Invalid ICC chunk total.");
+ JPEGLI_ERROR("Invalid ICC chunk total.");
}
if (m->icc_index_ > m->icc_total_) {
- return JPEGLI_ERROR("Invalid ICC chunk index.");
+ JPEGLI_ERROR("Invalid ICC chunk index.");
}
m->icc_profile_.insert(m->icc_profile_.end(), payload + 2,
payload + payload_size);
@@ -494,8 +493,8 @@ uint8_t ProcessNextMarker(j_decompress_ptr cinfo, const uint8_t* const data,
marker = data[*pos + 1];
if (num_skipped > 0) {
if (m->found_soi_) {
- JPEGLI_WARN("Skipped %d bytes before marker 0x%02x", (int)num_skipped,
- marker);
+ JPEGLI_WARN("Skipped %d bytes before marker 0x%02x",
+ static_cast<int>(num_skipped), marker);
} else {
JPEGLI_ERROR("Did not find SOI marker.");
}
diff --git a/third_party/jpeg-xl/lib/jpegli/decode_marker.h b/third_party/jpeg-xl/lib/jpegli/decode_marker.h
index fb24b3ee87..f3d47f6ad2 100644
--- a/third_party/jpeg-xl/lib/jpegli/decode_marker.h
+++ b/third_party/jpeg-xl/lib/jpegli/decode_marker.h
@@ -22,8 +22,8 @@ namespace jpegli {
// EOI marker. Input buffer refill is handled by the caller;
// * JPEG_REACHED_SOS, if the next SOS marker is found;
// * JPEG_REACHED_EOR, if the end of the input is found.
-int ProcessMarkers(j_decompress_ptr cinfo, const uint8_t* const data,
- const size_t len, size_t* pos);
+int ProcessMarkers(j_decompress_ptr cinfo, const uint8_t* data, size_t len,
+ size_t* pos);
jpeg_marker_parser_method GetMarkerProcessor(j_decompress_ptr cinfo);
diff --git a/third_party/jpeg-xl/lib/jpegli/decode_scan.cc b/third_party/jpeg-xl/lib/jpegli/decode_scan.cc
index 05b1f37220..1b50792f0a 100644
--- a/third_party/jpeg-xl/lib/jpegli/decode_scan.cc
+++ b/third_party/jpeg-xl/lib/jpegli/decode_scan.cc
@@ -61,7 +61,7 @@ struct BitReaderState {
if (bits_left_ <= 16) {
while (bits_left_ <= 56) {
val_ <<= 8;
- val_ |= (uint64_t)GetNextByte();
+ val_ |= static_cast<uint64_t>(GetNextByte());
bits_left_ += 8;
}
}
@@ -427,7 +427,7 @@ void PrepareForiMCURow(j_decompress_ptr cinfo) {
int offset = m->streaming_mode_ ? 0 : by0;
m->coeff_rows[c] = (*cinfo->mem->access_virt_barray)(
reinterpret_cast<j_common_ptr>(cinfo), m->coef_arrays[c], offset,
- max_block_rows, true);
+ max_block_rows, TRUE);
}
}
@@ -451,7 +451,8 @@ int ProcessScan(j_decompress_ptr cinfo, const uint8_t* const data,
++num_skipped;
}
if (num_skipped > 0) {
- JPEGLI_WARN("Skipped %d bytes before restart marker", (int)num_skipped);
+ JPEGLI_WARN("Skipped %d bytes before restart marker",
+ static_cast<int>(num_skipped));
}
if (*pos + 2 > len) {
return kNeedMoreInput;
@@ -471,7 +472,7 @@ int ProcessScan(j_decompress_ptr cinfo, const uint8_t* const data,
}
// Decode one MCU.
- HWY_ALIGN_MAX coeff_t sink_block[DCTSIZE2];
+ HWY_ALIGN_MAX static coeff_t sink_block[DCTSIZE2] = {0};
bool scan_ok = true;
for (int i = 0; i < cinfo->comps_in_scan; ++i) {
const jpeg_component_info* comp = cinfo->cur_comp_info[i];
diff --git a/third_party/jpeg-xl/lib/jpegli/decode_scan.h b/third_party/jpeg-xl/lib/jpegli/decode_scan.h
index 1d7b18fc1a..dd1bfcd110 100644
--- a/third_party/jpeg-xl/lib/jpegli/decode_scan.h
+++ b/third_party/jpeg-xl/lib/jpegli/decode_scan.h
@@ -21,8 +21,8 @@ namespace jpegli {
// * JPEG_SUSPENDED, if the input buffer ends before the end of an iMCU row;
// * JPEG_ROW_COMPLETED, if the next iMCU row (but not the scan) is reached;
// * JPEG_SCAN_COMPLETED, if the end of the scan is reached.
-int ProcessScan(j_decompress_ptr cinfo, const uint8_t* const data,
- const size_t len, size_t* pos, size_t* bit_pos);
+int ProcessScan(j_decompress_ptr cinfo, const uint8_t* data, size_t len,
+ size_t* pos, size_t* bit_pos);
void PrepareForiMCURow(j_decompress_ptr cinfo);
diff --git a/third_party/jpeg-xl/lib/jpegli/destination_manager.cc b/third_party/jpeg-xl/lib/jpegli/destination_manager.cc
index 9bc269f0c9..6548130866 100644
--- a/third_party/jpeg-xl/lib/jpegli/destination_manager.cc
+++ b/third_party/jpeg-xl/lib/jpegli/destination_manager.cc
@@ -19,13 +19,13 @@ struct StdioDestinationManager {
uint8_t* buffer;
static void init_destination(j_compress_ptr cinfo) {
- auto dest = reinterpret_cast<StdioDestinationManager*>(cinfo->dest);
+ auto* dest = reinterpret_cast<StdioDestinationManager*>(cinfo->dest);
dest->pub.next_output_byte = dest->buffer;
dest->pub.free_in_buffer = kDestBufferSize;
}
static boolean empty_output_buffer(j_compress_ptr cinfo) {
- auto dest = reinterpret_cast<StdioDestinationManager*>(cinfo->dest);
+ auto* dest = reinterpret_cast<StdioDestinationManager*>(cinfo->dest);
if (fwrite(dest->buffer, 1, kDestBufferSize, dest->f) != kDestBufferSize) {
JPEGLI_ERROR("Failed to write to output stream.");
}
@@ -35,7 +35,7 @@ struct StdioDestinationManager {
}
static void term_destination(j_compress_ptr cinfo) {
- auto dest = reinterpret_cast<StdioDestinationManager*>(cinfo->dest);
+ auto* dest = reinterpret_cast<StdioDestinationManager*>(cinfo->dest);
size_t bytes_left = kDestBufferSize - dest->pub.free_in_buffer;
if (bytes_left &&
fwrite(dest->buffer, 1, bytes_left, dest->f) != bytes_left) {
@@ -62,7 +62,7 @@ struct MemoryDestinationManager {
static void init_destination(j_compress_ptr cinfo) {}
static boolean empty_output_buffer(j_compress_ptr cinfo) {
- auto dest = reinterpret_cast<MemoryDestinationManager*>(cinfo->dest);
+ auto* dest = reinterpret_cast<MemoryDestinationManager*>(cinfo->dest);
uint8_t* next_buffer =
reinterpret_cast<uint8_t*>(malloc(dest->buffer_size * 2));
memcpy(next_buffer, dest->current_buffer, dest->buffer_size);
@@ -80,7 +80,7 @@ struct MemoryDestinationManager {
}
static void term_destination(j_compress_ptr cinfo) {
- auto dest = reinterpret_cast<MemoryDestinationManager*>(cinfo->dest);
+ auto* dest = reinterpret_cast<MemoryDestinationManager*>(cinfo->dest);
*dest->output_size = dest->buffer_size - dest->pub.free_in_buffer;
}
};
@@ -99,7 +99,7 @@ void jpegli_stdio_dest(j_compress_ptr cinfo, FILE* outfile) {
cinfo->dest = reinterpret_cast<jpeg_destination_mgr*>(
jpegli::Allocate<jpegli::StdioDestinationManager>(cinfo, 1));
}
- auto dest = reinterpret_cast<jpegli::StdioDestinationManager*>(cinfo->dest);
+ auto* dest = reinterpret_cast<jpegli::StdioDestinationManager*>(cinfo->dest);
dest->f = outfile;
dest->buffer = jpegli::Allocate<uint8_t>(cinfo, jpegli::kDestBufferSize);
dest->pub.next_output_byte = dest->buffer;
@@ -122,11 +122,11 @@ void jpegli_mem_dest(j_compress_ptr cinfo, unsigned char** outbuffer,
JPEGLI_ERROR("jpegli_mem_dest: a different dest manager was already set");
}
if (!cinfo->dest) {
- auto dest = jpegli::Allocate<jpegli::MemoryDestinationManager>(cinfo, 1);
+ auto* dest = jpegli::Allocate<jpegli::MemoryDestinationManager>(cinfo, 1);
dest->temp_buffer = nullptr;
cinfo->dest = reinterpret_cast<jpeg_destination_mgr*>(dest);
}
- auto dest = reinterpret_cast<jpegli::MemoryDestinationManager*>(cinfo->dest);
+ auto* dest = reinterpret_cast<jpegli::MemoryDestinationManager*>(cinfo->dest);
dest->pub.init_destination =
jpegli::MemoryDestinationManager::init_destination;
dest->pub.empty_output_buffer =
diff --git a/third_party/jpeg-xl/lib/jpegli/downsample.cc b/third_party/jpeg-xl/lib/jpegli/downsample.cc
index df2c156972..f1e945d509 100644
--- a/third_party/jpeg-xl/lib/jpegli/downsample.cc
+++ b/third_party/jpeg-xl/lib/jpegli/downsample.cc
@@ -29,7 +29,7 @@ void DownsampleRow2x1(const float* row_in, size_t len, float* row_out) {
const size_t N = Lanes(d);
const size_t len_out = len / 2;
const auto mul = Set(d, 0.5f);
- Vec<D> v0, v1;
+ Vec<D> v0, v1; // NOLINT
for (size_t x = 0; x < len_out; x += N) {
LoadInterleaved2(d, row_in + 2 * x, v0, v1);
Store(Mul(mul, Add(v0, v1)), d, row_out + x);
@@ -40,7 +40,7 @@ void DownsampleRow3x1(const float* row_in, size_t len, float* row_out) {
const size_t N = Lanes(d);
const size_t len_out = len / 3;
const auto mul = Set(d, 1.0f / 3);
- Vec<D> v0, v1, v2;
+ Vec<D> v0, v1, v2; // NOLINT
for (size_t x = 0; x < len_out; x += N) {
LoadInterleaved3(d, row_in + 3 * x, v0, v1, v2);
Store(Mul(mul, Add(Add(v0, v1), v2)), d, row_out + x);
@@ -51,7 +51,7 @@ void DownsampleRow4x1(const float* row_in, size_t len, float* row_out) {
const size_t N = Lanes(d);
const size_t len_out = len / 4;
const auto mul = Set(d, 0.25f);
- Vec<D> v0, v1, v2, v3;
+ Vec<D> v0, v1, v2, v3; // NOLINT
for (size_t x = 0; x < len_out; x += N) {
LoadInterleaved4(d, row_in + 4 * x, v0, v1, v2, v3);
Store(Mul(mul, Add(Add(v0, v1), Add(v2, v3))), d, row_out + x);
@@ -91,7 +91,7 @@ void Downsample2x2(float* rows_in[MAX_SAMP_FACTOR], size_t len,
const auto mul = Set(d, 0.25f);
float* row0 = rows_in[0];
float* row1 = rows_in[1];
- Vec<D> v0, v1, v2, v3;
+ Vec<D> v0, v1, v2, v3; // NOLINT
for (size_t x = 0; x < len_out; x += N) {
LoadInterleaved2(d, row0 + 2 * x, v0, v1);
LoadInterleaved2(d, row1 + 2 * x, v2, v3);
diff --git a/third_party/jpeg-xl/lib/jpegli/encode.cc b/third_party/jpeg-xl/lib/jpegli/encode.cc
index 8a106e239a..5326f2cb0f 100644
--- a/third_party/jpeg-xl/lib/jpegli/encode.cc
+++ b/third_party/jpeg-xl/lib/jpegli/encode.cc
@@ -5,6 +5,8 @@
#include "lib/jpegli/encode.h"
+#include <jxl/types.h>
+
#include <cmath>
#include <initializer_list>
#include <vector>
@@ -323,8 +325,8 @@ void ProcessCompressionParams(j_compress_ptr cinfo) {
if (cinfo->scan_info == nullptr) {
SetDefaultScanScript(cinfo);
}
- cinfo->progressive_mode =
- cinfo->scan_info->Ss != 0 || cinfo->scan_info->Se != DCTSIZE2 - 1;
+ cinfo->progressive_mode = TO_JXL_BOOL(cinfo->scan_info->Ss != 0 ||
+ cinfo->scan_info->Se != DCTSIZE2 - 1);
ValidateScanScript(cinfo);
m->scan_token_info =
Allocate<ScanTokenInfo>(cinfo, cinfo->num_scans, JPOOL_IMAGE);
@@ -449,7 +451,7 @@ void AllocateBuffers(j_compress_ptr cinfo) {
const size_t ysize_blocks = comp->height_in_blocks;
m->coeff_buffers[c] = (*cinfo->mem->request_virt_barray)(
reinterpret_cast<j_common_ptr>(cinfo), JPOOL_IMAGE,
- /*pre_zero=*/false, xsize_blocks, ysize_blocks, comp->v_samp_factor);
+ /*pre_zero=*/FALSE, xsize_blocks, ysize_blocks, comp->v_samp_factor);
}
}
if (m->use_adaptive_quantization) {
@@ -663,8 +665,8 @@ void jpegli_CreateCompress(j_compress_ptr cinfo, int version,
cinfo->num_components = 0;
cinfo->jpeg_color_space = JCS_UNKNOWN;
cinfo->comp_info = nullptr;
- for (int i = 0; i < NUM_QUANT_TBLS; ++i) {
- cinfo->quant_tbl_ptrs[i] = nullptr;
+ for (auto& quant_tbl_ptr : cinfo->quant_tbl_ptrs) {
+ quant_tbl_ptr = nullptr;
}
for (int i = 0; i < NUM_HUFF_TBLS; ++i) {
cinfo->dc_huff_tbl_ptrs[i] = nullptr;
@@ -673,7 +675,7 @@ void jpegli_CreateCompress(j_compress_ptr cinfo, int version,
memset(cinfo->arith_dc_L, 0, sizeof(cinfo->arith_dc_L));
memset(cinfo->arith_dc_U, 0, sizeof(cinfo->arith_dc_U));
memset(cinfo->arith_ac_K, 0, sizeof(cinfo->arith_ac_K));
- cinfo->write_Adobe_marker = false;
+ cinfo->write_Adobe_marker = FALSE;
cinfo->master = jpegli::Allocate<jpeg_comp_master>(cinfo, 1);
jpegli::InitializeCompressParams(cinfo);
cinfo->master->force_baseline = true;
@@ -763,7 +765,7 @@ void jpegli_set_colorspace(j_compress_ptr cinfo, J_COLOR_SPACE colorspace) {
JPEGLI_ERROR("Unsupported jpeg colorspace %d", colorspace);
}
// Adobe marker is only needed to distinguish CMYK and YCCK JPEGs.
- cinfo->write_Adobe_marker = (cinfo->jpeg_color_space == JCS_YCCK);
+ cinfo->write_Adobe_marker = TO_JXL_BOOL(cinfo->jpeg_color_space == JCS_YCCK);
if (cinfo->comp_info == nullptr) {
cinfo->comp_info =
jpegli::Allocate<jpeg_component_info>(cinfo, MAX_COMPONENTS);
@@ -810,7 +812,7 @@ void jpegli_set_colorspace(j_compress_ptr cinfo, J_COLOR_SPACE colorspace) {
void jpegli_set_distance(j_compress_ptr cinfo, float distance,
boolean force_baseline) {
CheckState(cinfo, jpegli::kEncStart);
- cinfo->master->force_baseline = force_baseline;
+ cinfo->master->force_baseline = FROM_JXL_BOOL(force_baseline);
float distances[NUM_QUANT_TBLS] = {distance, distance, distance};
jpegli::SetQuantMatrices(cinfo, distances, /*add_two_chroma_tables=*/true);
}
@@ -834,7 +836,7 @@ void jpegli_set_psnr(j_compress_ptr cinfo, float psnr, float tolerance,
void jpegli_set_quality(j_compress_ptr cinfo, int quality,
boolean force_baseline) {
CheckState(cinfo, jpegli::kEncStart);
- cinfo->master->force_baseline = force_baseline;
+ cinfo->master->force_baseline = FROM_JXL_BOOL(force_baseline);
float distance = jpegli_quality_to_distance(quality);
float distances[NUM_QUANT_TBLS] = {distance, distance, distance};
jpegli::SetQuantMatrices(cinfo, distances, /*add_two_chroma_tables=*/false);
@@ -843,7 +845,7 @@ void jpegli_set_quality(j_compress_ptr cinfo, int quality,
void jpegli_set_linear_quality(j_compress_ptr cinfo, int scale_factor,
boolean force_baseline) {
CheckState(cinfo, jpegli::kEncStart);
- cinfo->master->force_baseline = force_baseline;
+ cinfo->master->force_baseline = FROM_JXL_BOOL(force_baseline);
float distance = jpegli::LinearQualityToDistance(scale_factor);
float distances[NUM_QUANT_TBLS] = {distance, distance, distance};
jpegli::SetQuantMatrices(cinfo, distances, /*add_two_chroma_tables=*/false);
@@ -894,7 +896,7 @@ void jpegli_add_quant_table(j_compress_ptr cinfo, int which_tbl,
void jpegli_enable_adaptive_quantization(j_compress_ptr cinfo, boolean value) {
CheckState(cinfo, jpegli::kEncStart);
- cinfo->master->use_adaptive_quantization = value;
+ cinfo->master->use_adaptive_quantization = FROM_JXL_BOOL(value);
}
void jpegli_simple_progression(j_compress_ptr cinfo) {
@@ -955,7 +957,7 @@ void jpegli_copy_critical_parameters(j_decompress_ptr srcinfo,
jpegli_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
if (dstinfo->num_components != srcinfo->num_components) {
const auto& cinfo = dstinfo;
- return JPEGLI_ERROR("Mismatch between src colorspace and components");
+ JPEGLI_ERROR("Mismatch between src colorspace and components");
}
dstinfo->data_precision = srcinfo->data_precision;
dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
@@ -1005,7 +1007,7 @@ void jpegli_write_coefficients(j_compress_ptr cinfo,
jvirt_barray_ptr* coef_arrays) {
CheckState(cinfo, jpegli::kEncStart);
cinfo->global_state = jpegli::kEncWriteCoeffs;
- jpegli::InitCompress(cinfo, /*write_all_tables=*/true);
+ jpegli::InitCompress(cinfo, /*write_all_tables=*/TRUE);
cinfo->master->coeff_buffers = coef_arrays;
cinfo->next_scanline = cinfo->image_height;
cinfo->master->next_input_row = cinfo->image_height;
@@ -1047,7 +1049,7 @@ void jpegli_write_m_header(j_compress_ptr cinfo, int marker,
marker_data[1] = marker;
marker_data[2] = (datalen + 2) >> 8;
marker_data[3] = (datalen + 2) & 0xff;
- jpegli::WriteOutput(cinfo, &marker_data[0], 4);
+ jpegli::WriteOutput(cinfo, marker_data.data(), 4);
}
void jpegli_write_m_byte(j_compress_ptr cinfo, int val) {
@@ -1213,7 +1215,8 @@ void jpegli_finish_compress(j_compress_ptr cinfo) {
}
const bool tokens_done = jpegli::IsStreamingSupported(cinfo);
- const bool bitstream_done = tokens_done && !cinfo->optimize_coding;
+ const bool bitstream_done =
+ tokens_done && !FROM_JXL_BOOL(cinfo->optimize_coding);
if (!tokens_done) {
jpegli::TokenizeJpeg(cinfo);
diff --git a/third_party/jpeg-xl/lib/jpegli/encode_api_test.cc b/third_party/jpeg-xl/lib/jpegli/encode_api_test.cc
index 8d53557567..1afdcf610d 100644
--- a/third_party/jpeg-xl/lib/jpegli/encode_api_test.cc
+++ b/third_party/jpeg-xl/lib/jpegli/encode_api_test.cc
@@ -133,12 +133,11 @@ TEST(EncodeAPITest, ReuseCinfoSameMemOutput) {
jpegli_destroy_compress(&cinfo);
}
size_t pos = 0;
- for (size_t i = 0; i < all_configs.size(); ++i) {
+ for (auto& config : all_configs) {
TestImage output;
- pos +=
- DecodeWithLibjpeg(all_configs[i].jparams, DecompressParams(), nullptr,
- 0, buffer + pos, buffer_size - pos, &output);
- VerifyOutputImage(all_configs[i].input, output, all_configs[i].max_dist);
+ pos += DecodeWithLibjpeg(config.jparams, DecompressParams(), nullptr, 0,
+ buffer + pos, buffer_size - pos, &output);
+ VerifyOutputImage(config.input, output, config.max_dist);
}
if (buffer) free(buffer);
}
@@ -164,20 +163,21 @@ TEST(EncodeAPITest, ReuseCinfoSameStdOutput) {
size_t total_size = ftell(tmpf);
rewind(tmpf);
std::vector<uint8_t> compressed(total_size);
- JXL_CHECK(total_size == fread(&compressed[0], 1, total_size, tmpf));
+ JXL_CHECK(total_size == fread(compressed.data(), 1, total_size, tmpf));
fclose(tmpf);
size_t pos = 0;
- for (size_t i = 0; i < all_configs.size(); ++i) {
+ for (auto& config : all_configs) {
TestImage output;
- pos += DecodeWithLibjpeg(all_configs[i].jparams, DecompressParams(),
- nullptr, 0, &compressed[pos],
- compressed.size() - pos, &output);
- VerifyOutputImage(all_configs[i].input, output, all_configs[i].max_dist);
+ pos +=
+ DecodeWithLibjpeg(config.jparams, DecompressParams(), nullptr, 0,
+ &compressed[pos], compressed.size() - pos, &output);
+ VerifyOutputImage(config.input, output, config.max_dist);
}
}
TEST(EncodeAPITest, ReuseCinfoChangeParams) {
- TestImage input, output;
+ TestImage input;
+ TestImage output;
CompressParams jparams;
DecompressParams dparams;
uint8_t* buffer = nullptr;
diff --git a/third_party/jpeg-xl/lib/jpegli/encode_finish.cc b/third_party/jpeg-xl/lib/jpegli/encode_finish.cc
index 955676bdee..767a6532c5 100644
--- a/third_party/jpeg-xl/lib/jpegli/encode_finish.cc
+++ b/third_party/jpeg-xl/lib/jpegli/encode_finish.cc
@@ -213,6 +213,8 @@ float FindDistanceForPSNR(j_compress_ptr cinfo) {
d = best_distance;
if (sampling == 1 && PSNR_SEARCH_DBG) {
printf("Final PSNR %.2f at distance %.4f\n", best_psnr, d);
+ } else {
+ (void)best_psnr;
}
}
return d;
diff --git a/third_party/jpeg-xl/lib/jpegli/entropy_coding.cc b/third_party/jpeg-xl/lib/jpegli/entropy_coding.cc
index 7e50bbc3a7..515996a43d 100644
--- a/third_party/jpeg-xl/lib/jpegli/entropy_coding.cc
+++ b/third_party/jpeg-xl/lib/jpegli/entropy_coding.cc
@@ -99,10 +99,16 @@ void TokenizeACProgressiveScan(j_compress_ptr cinfo, int scan_index,
TokenArray* ta = &m->token_arrays[m->cur_token_array];
sti->token_offset = m->total_num_tokens + ta->num_tokens;
sti->restarts = Allocate<size_t>(cinfo, num_restarts, JPOOL_IMAGE);
+ const auto emit_eob_run = [&]() {
+ int nbits = jxl::FloorLog2Nonzero<uint32_t>(eob_run);
+ int symbol = nbits << 4u;
+ *m->next_token++ = Token(context, symbol, eob_run & ((1 << nbits) - 1));
+ eob_run = 0;
+ };
for (JDIMENSION by = 0; by < comp->height_in_blocks; ++by) {
JBLOCKARRAY ba = (*cinfo->mem->access_virt_barray)(
reinterpret_cast<j_common_ptr>(cinfo), m->coeff_buffers[comp_idx], by,
- 1, false);
+ 1, FALSE);
// Each coefficient can appear in at most one token, but we have to reserve
// one extra EOBrun token that was rolled over from the previous block-row
// and has to be flushed at the end.
@@ -121,13 +127,7 @@ void TokenizeACProgressiveScan(j_compress_ptr cinfo, int scan_index,
}
for (JDIMENSION bx = 0; bx < comp->width_in_blocks; ++bx) {
if (restart_interval > 0 && restarts_to_go == 0) {
- if (eob_run > 0) {
- int nbits = jxl::FloorLog2Nonzero<uint32_t>(eob_run);
- int symbol = nbits << 4u;
- *m->next_token++ =
- Token(context, symbol, eob_run & ((1 << nbits) - 1));
- eob_run = 0;
- }
+ if (eob_run > 0) emit_eob_run();
ta->num_tokens = m->next_token - ta->tokens;
sti->restarts[restart_idx++] = m->total_num_tokens + ta->num_tokens;
restarts_to_go = restart_interval;
@@ -139,7 +139,8 @@ void TokenizeACProgressiveScan(j_compress_ptr cinfo, int scan_index,
int num_nzeros = 0;
int num_future_nzeros = 0;
for (int k = Ss; k <= Se; ++k) {
- if ((temp = block[k]) == 0) {
+ temp = block[k];
+ if (temp == 0) {
r++;
continue;
}
@@ -156,13 +157,7 @@ void TokenizeACProgressiveScan(j_compress_ptr cinfo, int scan_index,
num_future_nzeros++;
continue;
}
- if (eob_run > 0) {
- int nbits = jxl::FloorLog2Nonzero<uint32_t>(eob_run);
- int symbol = nbits << 4u;
- *m->next_token++ =
- Token(context, symbol, eob_run & ((1 << nbits) - 1));
- eob_run = 0;
- }
+ if (eob_run > 0) emit_eob_run();
while (r > 15) {
*m->next_token++ = Token(context, 0xf0, 0);
r -= 16;
@@ -175,13 +170,7 @@ void TokenizeACProgressiveScan(j_compress_ptr cinfo, int scan_index,
}
if (r > 0) {
++eob_run;
- if (eob_run == 0x7FFF) {
- int nbits = jxl::FloorLog2Nonzero<uint32_t>(eob_run);
- int symbol = nbits << 4u;
- *m->next_token++ =
- Token(context, symbol, eob_run & ((1 << nbits) - 1));
- eob_run = 0;
- }
+ if (eob_run == 0x7FFF) emit_eob_run();
}
sti->num_nonzeros += num_nzeros;
sti->num_future_nonzeros += num_future_nzeros;
@@ -190,11 +179,8 @@ void TokenizeACProgressiveScan(j_compress_ptr cinfo, int scan_index,
ta->num_tokens = m->next_token - ta->tokens;
}
if (eob_run > 0) {
- int nbits = jxl::FloorLog2Nonzero<uint32_t>(eob_run);
- int symbol = nbits << 4u;
- *m->next_token++ = Token(context, symbol, eob_run & ((1 << nbits) - 1));
+ emit_eob_run();
++ta->num_tokens;
- eob_run = 0;
}
sti->num_tokens = m->total_num_tokens + ta->num_tokens - sti->token_offset;
sti->restarts[restart_idx++] = m->total_num_tokens + ta->num_tokens;
@@ -229,7 +215,7 @@ void TokenizeACRefinementScan(j_compress_ptr cinfo, int scan_index,
for (JDIMENSION by = 0; by < comp->height_in_blocks; ++by) {
JBLOCKARRAY ba = (*cinfo->mem->access_virt_barray)(
reinterpret_cast<j_common_ptr>(cinfo), m->coeff_buffers[comp_idx], by,
- 1, false);
+ 1, FALSE);
for (JDIMENSION bx = 0; bx < comp->width_in_blocks; ++bx) {
if (restart_interval > 0 && restarts_to_go == 0) {
sti->restarts[restart_idx++] = next_token - sti->tokens;
@@ -337,7 +323,7 @@ void TokenizeScan(j_compress_ptr cinfo, size_t scan_index, int ac_ctx_offset,
// "Non-interleaved" means color data comes in separate scans, in other words
// each scan can contain only one color component.
const bool is_interleaved = (scan_info->comps_in_scan > 1);
- const bool is_progressive = cinfo->progressive_mode;
+ const bool is_progressive = FROM_JXL_BOOL(cinfo->progressive_mode);
const int Ah = scan_info->Ah;
const int Al = scan_info->Al;
HWY_ALIGN constexpr coeff_t kSinkBlock[DCTSIZE2] = {0};
@@ -373,7 +359,7 @@ void TokenizeScan(j_compress_ptr cinfo, size_t scan_index, int ac_ctx_offset,
int max_block_rows = std::min(n_blocks_y, block_rows_left);
ba[i] = (*cinfo->mem->access_virt_barray)(
reinterpret_cast<j_common_ptr>(cinfo), m->coeff_buffers[comp_idx],
- by0, max_block_rows, false);
+ by0, max_block_rows, FALSE);
}
if (!cinfo->progressive_mode) {
int max_tokens_per_mcu_row = MaxNumTokensPerMCURow(cinfo);
@@ -557,7 +543,7 @@ float HistogramCost(const Histogram& histo) {
}
counts[kJpegHuffmanAlphabetSize] = 1;
CreateHuffmanTree(counts.data(), counts.size(), kJpegHuffmanMaxBitLength,
- &depths[0]);
+ depths.data());
size_t header_bits = (1 + kJpegHuffmanMaxBitLength) * 8;
size_t data_bits = 0;
for (size_t i = 0; i < kJpegHuffmanAlphabetSize; ++i) {
@@ -576,8 +562,8 @@ void AddHistograms(const Histogram& a, const Histogram& b, Histogram* c) {
}
bool IsEmptyHistogram(const Histogram& histo) {
- for (size_t i = 0; i < kJpegHuffmanAlphabetSize; ++i) {
- if (histo.count[i]) return false;
+ for (int count : histo.count) {
+ if (count) return false;
}
return true;
}
@@ -668,7 +654,7 @@ void BuildJpegHuffmanTable(const Histogram& histo, JHUFF_TBL* table) {
}
counts[kJpegHuffmanAlphabetSize] = 1;
CreateHuffmanTree(counts.data(), counts.size(), kJpegHuffmanMaxBitLength,
- &depths[0]);
+ depths.data());
memset(table, 0, sizeof(JHUFF_TBL));
for (size_t i = 0; i < kJpegHuffmanAlphabetSize; ++i) {
if (depths[i] > 0) {
@@ -726,7 +712,7 @@ void OptimizeHuffmanCodes(j_compress_ptr cinfo) {
jpeg_comp_master* m = cinfo->master;
// Build DC and AC histograms.
std::vector<Histogram> histograms(m->num_contexts);
- BuildHistograms(cinfo, &histograms[0]);
+ BuildHistograms(cinfo, histograms.data());
// Cluster DC histograms.
JpegClusteredHistograms dc_clusters;
@@ -760,7 +746,7 @@ void OptimizeHuffmanCodes(j_compress_ptr cinfo) {
m->context_map = Allocate<uint8_t>(cinfo, m->num_contexts, JPOOL_IMAGE);
memset(m->context_map, 0, m->num_contexts);
for (size_t i = 0; i < m->num_contexts; ++i) {
- if (i < (size_t)cinfo->num_components) {
+ if (i < static_cast<size_t>(cinfo->num_components)) {
m->context_map[i] = dc_clusters.histogram_indexes[i];
} else if (i >= 4) {
m->context_map[i] = num_dc_huff + ac_clusters.histogram_indexes[i - 4];
diff --git a/third_party/jpeg-xl/lib/jpegli/error.h b/third_party/jpeg-xl/lib/jpegli/error.h
index 4451abd416..5f266baee1 100644
--- a/third_party/jpeg-xl/lib/jpegli/error.h
+++ b/third_party/jpeg-xl/lib/jpegli/error.h
@@ -10,6 +10,7 @@
#include <stdint.h>
#include "lib/jpegli/common.h"
+#include "lib/jxl/base/status.h"
namespace jpegli {
@@ -17,10 +18,12 @@ bool FormatString(char* buffer, const char* format, ...);
} // namespace jpegli
+// `error_exit` should be no-return; but let's add some guarantees on our side.
#define JPEGLI_ERROR(format, ...) \
jpegli::FormatString(cinfo->err->msg_parm.s, ("%s:%d: " format), __FILE__, \
__LINE__, ##__VA_ARGS__), \
- (*cinfo->err->error_exit)(reinterpret_cast<j_common_ptr>(cinfo))
+ (*cinfo->err->error_exit)(reinterpret_cast<j_common_ptr>(cinfo)), \
+ (void)jxl::Abort()
#define JPEGLI_WARN(format, ...) \
jpegli::FormatString(cinfo->err->msg_parm.s, ("%s:%d: " format), __FILE__, \
diff --git a/third_party/jpeg-xl/lib/jpegli/error_handling_test.cc b/third_party/jpeg-xl/lib/jpegli/error_handling_test.cc
index 0d481c572a..3eaf6a313b 100644
--- a/third_party/jpeg-xl/lib/jpegli/error_handling_test.cc
+++ b/third_party/jpeg-xl/lib/jpegli/error_handling_test.cc
@@ -241,9 +241,10 @@ TEST(EncoderErrorHandlingTest, InvalidQuantValue) {
cinfo.image_height = 1;
cinfo.input_components = 1;
jpegli_set_defaults(&cinfo);
- cinfo.quant_tbl_ptrs[0] = jpegli_alloc_quant_table((j_common_ptr)&cinfo);
- for (size_t k = 0; k < DCTSIZE2; ++k) {
- cinfo.quant_tbl_ptrs[0]->quantval[k] = 0;
+ cinfo.quant_tbl_ptrs[0] =
+ jpegli_alloc_quant_table(reinterpret_cast<j_common_ptr>(&cinfo));
+ for (UINT16& q : cinfo.quant_tbl_ptrs[0]->quantval) {
+ q = 0;
}
jpegli_start_compress(&cinfo, TRUE);
JSAMPLE image[1] = {0};
@@ -992,7 +993,7 @@ TEST(EncoderErrorHandlingTest, AddOnTableNoStringParam) {
jpegli_destroy_compress(&cinfo);
}
-static const uint8_t kCompressed0[] = {
+const uint8_t kCompressed0[] = {
// SOI
0xff, 0xd8, //
// DQT
@@ -1036,12 +1037,12 @@ static const uint8_t kCompressed0[] = {
// EOI
0xff, 0xd9, //
};
-static const size_t kLen0 = sizeof(kCompressed0);
+const size_t kLen0 = sizeof(kCompressed0);
-static const size_t kDQTOffset = 2;
-static const size_t kSOFOffset = 71;
-static const size_t kDHTOffset = 84;
-static const size_t kSOSOffset = 296;
+const size_t kDQTOffset = 2;
+const size_t kSOFOffset = 71;
+const size_t kDHTOffset = 84;
+const size_t kSOSOffset = 296;
TEST(DecoderErrorHandlingTest, MinimalSuccess) {
JXL_CHECK(kCompressed0[kDQTOffset] == 0xff);
@@ -1130,7 +1131,7 @@ TEST(DecoderErrorHandlingTest, NoReadScanlines) {
jpegli_destroy_decompress(&cinfo);
}
-static const size_t kMaxImageWidth = 0xffff;
+const size_t kMaxImageWidth = 0xffff;
JSAMPLE kOutputBuffer[MAX_COMPONENTS * kMaxImageWidth];
bool ParseCompressed(const std::vector<uint8_t>& compressed) {
diff --git a/third_party/jpeg-xl/lib/jpegli/huffman.cc b/third_party/jpeg-xl/lib/jpegli/huffman.cc
index 1cf88a5536..5391030213 100644
--- a/third_party/jpeg-xl/lib/jpegli/huffman.cc
+++ b/third_party/jpeg-xl/lib/jpegli/huffman.cc
@@ -183,7 +183,8 @@ void CreateHuffmanTree(const uint32_t* data, const size_t length,
size_t i = 0; // Points to the next leaf node.
size_t j = n + 1; // Points to the next non-leaf node.
for (size_t k = n - 1; k != 0; --k) {
- size_t left, right;
+ size_t left;
+ size_t right;
if (tree[i].total_count <= tree[j].total_count) {
left = i;
++i;
@@ -210,7 +211,7 @@ void CreateHuffmanTree(const uint32_t* data, const size_t length,
tree.push_back(sentinel);
}
JXL_DASSERT(tree.size() == 2 * n + 1);
- SetDepth(tree[2 * n - 1], &tree[0], depth, 0);
+ SetDepth(tree[2 * n - 1], tree.data(), depth, 0);
// We need to pack the Huffman tree in tree_limit bits.
// If this was not successful, add fake entities to the lowest values
diff --git a/third_party/jpeg-xl/lib/jpegli/idct.cc b/third_party/jpeg-xl/lib/jpegli/idct.cc
index 4d10563583..9859e8ef85 100644
--- a/third_party/jpeg-xl/lib/jpegli/idct.cc
+++ b/third_party/jpeg-xl/lib/jpegli/idct.cc
@@ -197,7 +197,7 @@ void InverseTransformBlock8x8(const int16_t* JXL_RESTRICT qblock,
// Computes the N-point IDCT of in[], and stores the result in out[]. The in[]
// array is at most 8 values long, values in[8:N-1] are assumed to be 0.
-void Compute1dIDCT(float* in, float* out, size_t N) {
+void Compute1dIDCT(const float* in, float* out, size_t N) {
switch (N) {
case 3: {
static constexpr float kC3[3] = {
@@ -608,6 +608,9 @@ void Compute1dIDCT(float* in, float* out, size_t N) {
out[8] = even7 - odd7;
break;
}
+ default:
+ JXL_ABORT("Compute1dIDCT does not support N=%d", static_cast<int>(N));
+ break;
}
}
diff --git a/third_party/jpeg-xl/lib/jpegli/input.cc b/third_party/jpeg-xl/lib/jpegli/input.cc
index 765bf98946..16299477f7 100644
--- a/third_party/jpeg-xl/lib/jpegli/input.cc
+++ b/third_party/jpeg-xl/lib/jpegli/input.cc
@@ -89,7 +89,7 @@ void ReadUint8RowInterleaved2(const uint8_t* row_in, size_t len,
const size_t simd_len = len & (~(N - 1));
float* JXL_RESTRICT const row0 = row_out[0];
float* JXL_RESTRICT const row1 = row_out[1];
- Vec<DU8> out0, out1;
+ Vec<DU8> out0, out1; // NOLINT
for (size_t x = 0; x < simd_len; x += N) {
LoadInterleaved2(du8, row_in + 2 * x, out0, out1);
Store(ConvertTo(d, PromoteTo(du, out0)), d, row0 + x);
@@ -105,7 +105,7 @@ void ReadUint8RowInterleaved3(const uint8_t* row_in, size_t len,
float* JXL_RESTRICT const row0 = row_out[0];
float* JXL_RESTRICT const row1 = row_out[1];
float* JXL_RESTRICT const row2 = row_out[2];
- Vec<DU8> out0, out1, out2;
+ Vec<DU8> out0, out1, out2; // NOLINT
for (size_t x = 0; x < simd_len; x += N) {
LoadInterleaved3(du8, row_in + 3 * x, out0, out1, out2);
Store(ConvertTo(d, PromoteTo(du, out0)), d, row0 + x);
@@ -123,7 +123,7 @@ void ReadUint8RowInterleaved4(const uint8_t* row_in, size_t len,
float* JXL_RESTRICT const row1 = row_out[1];
float* JXL_RESTRICT const row2 = row_out[2];
float* JXL_RESTRICT const row3 = row_out[3];
- Vec<DU8> out0, out1, out2, out3;
+ Vec<DU8> out0, out1, out2, out3; // NOLINT
for (size_t x = 0; x < simd_len; x += N) {
LoadInterleaved4(du8, row_in + 4 * x, out0, out1, out2, out3);
Store(ConvertTo(d, PromoteTo(du, out0)), d, row0 + x);
@@ -158,7 +158,7 @@ void ReadUint16RowInterleaved2(const uint8_t* row_in, size_t len,
reinterpret_cast<const uint16_t*>(row_in);
float* JXL_RESTRICT const row0 = row_out[0];
float* JXL_RESTRICT const row1 = row_out[1];
- Vec<DU16> out0, out1;
+ Vec<DU16> out0, out1; // NOLINT
for (size_t x = 0; x < simd_len; x += N) {
LoadInterleaved2(du16, row + 2 * x, out0, out1);
Store(Mul(mul, ConvertTo(d, PromoteTo(du, out0))), d, row0 + x);
@@ -177,7 +177,7 @@ void ReadUint16RowInterleaved3(const uint8_t* row_in, size_t len,
float* JXL_RESTRICT const row0 = row_out[0];
float* JXL_RESTRICT const row1 = row_out[1];
float* JXL_RESTRICT const row2 = row_out[2];
- Vec<DU16> out0, out1, out2;
+ Vec<DU16> out0, out1, out2; // NOLINT
for (size_t x = 0; x < simd_len; x += N) {
LoadInterleaved3(du16, row + 3 * x, out0, out1, out2);
Store(Mul(mul, ConvertTo(d, PromoteTo(du, out0))), d, row0 + x);
@@ -198,7 +198,7 @@ void ReadUint16RowInterleaved4(const uint8_t* row_in, size_t len,
float* JXL_RESTRICT const row1 = row_out[1];
float* JXL_RESTRICT const row2 = row_out[2];
float* JXL_RESTRICT const row3 = row_out[3];
- Vec<DU16> out0, out1, out2, out3;
+ Vec<DU16> out0, out1, out2, out3; // NOLINT
for (size_t x = 0; x < simd_len; x += N) {
LoadInterleaved4(du16, row + 4 * x, out0, out1, out2, out3);
Store(Mul(mul, ConvertTo(d, PromoteTo(du, out0))), d, row0 + x);
@@ -250,7 +250,7 @@ void ReadFloatRowInterleaved2(const uint8_t* row_in, size_t len,
const float* JXL_RESTRICT const row = reinterpret_cast<const float*>(row_in);
float* JXL_RESTRICT const row0 = row_out[0];
float* JXL_RESTRICT const row1 = row_out[1];
- Vec<D> out0, out1;
+ Vec<D> out0, out1; // NOLINT
for (size_t x = 0; x < simd_len; x += N) {
LoadInterleaved2(d, row + 2 * x, out0, out1);
Store(Mul(mul, out0), d, row0 + x);
@@ -268,7 +268,7 @@ void ReadFloatRowInterleaved3(const uint8_t* row_in, size_t len,
float* JXL_RESTRICT const row0 = row_out[0];
float* JXL_RESTRICT const row1 = row_out[1];
float* JXL_RESTRICT const row2 = row_out[2];
- Vec<D> out0, out1, out2;
+ Vec<D> out0, out1, out2; // NOLINT
for (size_t x = 0; x < simd_len; x += N) {
LoadInterleaved3(d, row + 3 * x, out0, out1, out2);
Store(Mul(mul, out0), d, row0 + x);
@@ -288,7 +288,7 @@ void ReadFloatRowInterleaved4(const uint8_t* row_in, size_t len,
float* JXL_RESTRICT const row1 = row_out[1];
float* JXL_RESTRICT const row2 = row_out[2];
float* JXL_RESTRICT const row3 = row_out[3];
- Vec<D> out0, out1, out2, out3;
+ Vec<D> out0, out1, out2, out3; // NOLINT
for (size_t x = 0; x < simd_len; x += N) {
LoadInterleaved4(d, row + 4 * x, out0, out1, out2, out3);
Store(Mul(mul, out0), d, row0 + x);
diff --git a/third_party/jpeg-xl/lib/jpegli/input_suspension_test.cc b/third_party/jpeg-xl/lib/jpegli/input_suspension_test.cc
index 09bafd9188..eb8b7ebc26 100644
--- a/third_party/jpeg-xl/lib/jpegli/input_suspension_test.cc
+++ b/third_party/jpeg-xl/lib/jpegli/input_suspension_test.cc
@@ -17,7 +17,7 @@
namespace jpegli {
namespace {
-static constexpr uint8_t kFakeEoiMarker[2] = {0xff, 0xd9};
+constexpr uint8_t kFakeEoiMarker[2] = {0xff, 0xd9};
struct SourceManager {
SourceManager(const uint8_t* data, size_t len, size_t max_chunk_size,
@@ -50,14 +50,14 @@ struct SourceManager {
}
if (pub_.bytes_in_buffer > 0) {
EXPECT_LE(pub_.bytes_in_buffer, buffer_.size());
- memmove(&buffer_[0], pub_.next_input_byte, pub_.bytes_in_buffer);
+ memmove(buffer_.data(), pub_.next_input_byte, pub_.bytes_in_buffer);
}
size_t chunk_size =
pos_ < len_ ? std::min(len_ - pos_, max_chunk_size_) : 2;
buffer_.resize(pub_.bytes_in_buffer + chunk_size);
memcpy(&buffer_[pub_.bytes_in_buffer],
pos_ < len_ ? data_ + pos_ : kFakeEoiMarker, chunk_size);
- pub_.next_input_byte = &buffer_[0];
+ pub_.next_input_byte = buffer_.data();
pub_.bytes_in_buffer += chunk_size;
pos_ += chunk_size;
return true;
@@ -73,7 +73,7 @@ struct SourceManager {
bool is_partial_file_;
static void init_source(j_decompress_ptr cinfo) {
- auto src = reinterpret_cast<SourceManager*>(cinfo->src);
+ auto* src = reinterpret_cast<SourceManager*>(cinfo->src);
src->pub_.next_input_byte = nullptr;
src->pub_.bytes_in_buffer = 0;
}
@@ -81,7 +81,7 @@ struct SourceManager {
static boolean fill_input_buffer(j_decompress_ptr cinfo) { return FALSE; }
static void skip_input_data(j_decompress_ptr cinfo, long num_bytes) {
- auto src = reinterpret_cast<SourceManager*>(cinfo->src);
+ auto* src = reinterpret_cast<SourceManager*>(cinfo->src);
if (num_bytes <= 0) {
return;
}
@@ -156,10 +156,10 @@ void ReadOutputImage(const DecompressParams& dparams, j_decompress_ptr cinfo,
rowdata[c][i] =
y0 + i < ysize ? &output->raw_data[c][(y0 + i) * xsize] : nullptr;
}
- data[c] = &rowdata[c][0];
+ data[c] = rowdata[c].data();
}
while ((num_output_lines =
- jpegli_read_raw_data(cinfo, &data[0], max_lines)) == 0) {
+ jpegli_read_raw_data(cinfo, data.data(), max_lines)) == 0) {
JXL_CHECK(src && src->LoadNextChunk());
}
} else {
@@ -173,7 +173,7 @@ void ReadOutputImage(const DecompressParams& dparams, j_decompress_ptr cinfo,
size_t yidx = cinfo->output_scanline + i;
scanlines[i] = &output->pixels[yidx * stride];
}
- while ((num_output_lines = jpegli_read_scanlines(cinfo, &scanlines[0],
+ while ((num_output_lines = jpegli_read_scanlines(cinfo, scanlines.data(),
max_lines)) == 0) {
JXL_CHECK(src && src->LoadNextChunk());
}
@@ -197,7 +197,7 @@ struct TestConfig {
std::vector<uint8_t> GetTestJpegData(TestConfig& config) {
if (!config.fn.empty()) {
- return ReadTestData(config.fn.c_str());
+ return ReadTestData(config.fn);
}
GeneratePixels(&config.input);
std::vector<uint8_t> compressed;
@@ -249,7 +249,7 @@ TEST_P(InputSuspensionTestParam, InputOutputLockStepNonBuffered) {
EXPECT_EQ(0, memcmp(markers_seen, kMarkerSequence, num_markers_seen));
}
VerifyHeader(config.jparams, &cinfo);
- cinfo.raw_data_out = dparams.output_mode == RAW_DATA;
+ cinfo.raw_data_out = TO_JXL_BOOL(dparams.output_mode == RAW_DATA);
if (dparams.output_mode == COEFFICIENTS) {
jvirt_barray_ptr* coef_arrays;
@@ -303,7 +303,7 @@ TEST_P(InputSuspensionTestParam, InputOutputLockStepBuffered) {
jpegli_set_output_format(&cinfo, dparams.data_type, dparams.endianness);
cinfo.buffered_image = TRUE;
- cinfo.raw_data_out = dparams.output_mode == RAW_DATA;
+ cinfo.raw_data_out = TO_JXL_BOOL(dparams.output_mode == RAW_DATA);
EXPECT_TRUE(jpegli_start_decompress(&cinfo));
EXPECT_FALSE(jpegli_input_complete(&cinfo));
@@ -380,8 +380,8 @@ TEST_P(InputSuspensionTestParam, PreConsumeInputBuffered) {
}
EXPECT_EQ(JPEG_REACHED_SOS, jpegli_consume_input(&cinfo));
cinfo.buffered_image = TRUE;
- cinfo.raw_data_out = dparams.output_mode == RAW_DATA;
- cinfo.do_block_smoothing = dparams.do_block_smoothing;
+ cinfo.raw_data_out = TO_JXL_BOOL(dparams.output_mode == RAW_DATA);
+ cinfo.do_block_smoothing = TO_JXL_BOOL(dparams.do_block_smoothing);
EXPECT_TRUE(jpegli_start_decompress(&cinfo));
EXPECT_FALSE(jpegli_input_complete(&cinfo));
@@ -446,8 +446,8 @@ TEST_P(InputSuspensionTestParam, PreConsumeInputNonBuffered) {
}
}
EXPECT_EQ(JPEG_REACHED_SOS, jpegli_consume_input(&cinfo));
- cinfo.raw_data_out = dparams.output_mode == RAW_DATA;
- cinfo.do_block_smoothing = dparams.do_block_smoothing;
+ cinfo.raw_data_out = TO_JXL_BOOL(dparams.output_mode == RAW_DATA);
+ cinfo.do_block_smoothing = TO_JXL_BOOL(dparams.do_block_smoothing);
if (dparams.output_mode == COEFFICIENTS) {
jpegli_read_coefficients(&cinfo);
diff --git a/third_party/jpeg-xl/lib/jpegli/libjpeg_test_util.cc b/third_party/jpeg-xl/lib/jpegli/libjpeg_test_util.cc
index de2303756e..020adf5e9e 100644
--- a/third_party/jpeg-xl/lib/jpegli/libjpeg_test_util.cc
+++ b/third_party/jpeg-xl/lib/jpegli/libjpeg_test_util.cc
@@ -37,12 +37,13 @@ void ReadOutputPass(j_decompress_ptr cinfo, const DecompressParams& dparams,
output->ysize = ysize_cropped;
output->components = cinfo->out_color_components;
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));
}
}
if (!cinfo->raw_data_out) {
@@ -89,10 +90,10 @@ void ReadOutputPass(j_decompress_ptr cinfo, const DecompressParams& dparams,
rowdata[c][i] =
y0 + i < ysize ? &output->raw_data[c][(y0 + i) * xsize] : nullptr;
}
- data[c] = &rowdata[c][0];
+ data[c] = rowdata[c].data();
}
JXL_CHECK(iMCU_height ==
- jpeg_read_raw_data(cinfo, &data[0], iMCU_height));
+ jpeg_read_raw_data(cinfo, data.data(), iMCU_height));
}
}
JXL_CHECK(cinfo->total_iMCU_rows ==
@@ -113,7 +114,7 @@ void DecodeWithLibjpeg(const CompressParams& jparams,
jpeg_read_header(cinfo, /*require_image=*/TRUE));
if (!jparams.icc.empty()) {
uint8_t* icc_data = nullptr;
- unsigned int icc_len;
+ unsigned int icc_len = 0; // "unpoison" via initialization
JXL_CHECK(jpeg_read_icc_profile(cinfo, &icc_data, &icc_len));
JXL_CHECK(icc_data);
jxl::msan::UnpoisonMemory(icc_data, icc_len);
diff --git a/third_party/jpeg-xl/lib/jpegli/libjpeg_wrapper.cc b/third_party/jpeg-xl/lib/jpegli/libjpeg_wrapper.cc
index b38d16f255..471b7c7192 100644
--- a/third_party/jpeg-xl/lib/jpegli/libjpeg_wrapper.cc
+++ b/third_party/jpeg-xl/lib/jpegli/libjpeg_wrapper.cc
@@ -122,11 +122,11 @@ boolean jpeg_read_icc_profile(j_decompress_ptr cinfo, JOCTET **icc_data_ptr,
}
void jpeg_abort_decompress(j_decompress_ptr cinfo) {
- return jpegli_abort_decompress(cinfo);
+ jpegli_abort_decompress(cinfo);
}
void jpeg_destroy_decompress(j_decompress_ptr cinfo) {
- return jpegli_destroy_decompress(cinfo);
+ jpegli_destroy_decompress(cinfo);
}
void jpeg_CreateCompress(j_compress_ptr cinfo, int version, size_t structsize) {
diff --git a/third_party/jpeg-xl/lib/jpegli/memory_manager.h b/third_party/jpeg-xl/lib/jpegli/memory_manager.h
index 3e2bdabe06..c650caad49 100644
--- a/third_party/jpeg-xl/lib/jpegli/memory_manager.h
+++ b/third_party/jpeg-xl/lib/jpegli/memory_manager.h
@@ -19,7 +19,8 @@ void InitMemoryManager(j_common_ptr cinfo);
template <typename T>
T* Allocate(j_common_ptr cinfo, size_t len, int pool_id = JPOOL_PERMANENT) {
- void* p = (*cinfo->mem->alloc_small)(cinfo, pool_id, len * sizeof(T));
+ const size_t size = len * sizeof(T); // NOLINT
+ void* p = (*cinfo->mem->alloc_small)(cinfo, pool_id, size);
return reinterpret_cast<T*>(p);
}
diff --git a/third_party/jpeg-xl/lib/jpegli/output_suspension_test.cc b/third_party/jpeg-xl/lib/jpegli/output_suspension_test.cc
index 73db791727..3cb2fd3ee4 100644
--- a/third_party/jpeg-xl/lib/jpegli/output_suspension_test.cc
+++ b/third_party/jpeg-xl/lib/jpegli/output_suspension_test.cc
@@ -10,8 +10,8 @@
namespace jpegli {
namespace {
-static constexpr size_t kInitialBufferSize = 1024;
-static constexpr size_t kFinalBufferSize = 18;
+constexpr size_t kInitialBufferSize = 1024;
+constexpr size_t kFinalBufferSize = 18;
struct DestinationManager {
jpeg_destination_mgr pub;
@@ -37,7 +37,7 @@ struct DestinationManager {
}
static void init_destination(j_compress_ptr cinfo) {
- auto us = reinterpret_cast<DestinationManager*>(cinfo->dest);
+ auto* us = reinterpret_cast<DestinationManager*>(cinfo->dest);
us->buffer.resize(kInitialBufferSize);
us->Rewind();
}
@@ -84,7 +84,7 @@ TEST_P(OutputSuspensionTestParam, PixelData) {
while (cinfo.next_scanline < cinfo.image_height) {
size_t lines_left = cinfo.image_height - cinfo.next_scanline;
size_t num_lines = std::min(config.lines_batch_size, lines_left);
- memcpy(&row_bytes[0], &input.pixels[cinfo.next_scanline * stride],
+ memcpy(row_bytes.data(), &input.pixels[cinfo.next_scanline * stride],
num_lines * stride);
std::vector<JSAMPROW> rows(num_lines);
for (size_t i = 0; i < num_lines; ++i) {
@@ -142,7 +142,7 @@ TEST_P(OutputSuspensionTestParam, RawData) {
std::vector<JSAMPARRAY> data(cinfo.num_components);
for (int c = 0; c < cinfo.num_components; ++c) {
rowdata[c].resize(config.jparams.v_samp(c) * DCTSIZE);
- data[c] = &rowdata[c][0];
+ data[c] = rowdata[c].data();
}
while (cinfo.next_scanline < cinfo.image_height) {
for (int c = 0; c < cinfo.num_components; ++c) {
@@ -155,7 +155,7 @@ TEST_P(OutputSuspensionTestParam, RawData) {
(y0 + i < cheight ? &raw_data[c][(y0 + i) * cwidth] : nullptr);
}
}
- while (jpegli_write_raw_data(&cinfo, &data[0], max_lines) == 0) {
+ while (jpegli_write_raw_data(&cinfo, data.data(), max_lines) == 0) {
dest.EmptyTo(&compressed, config.buffer_size);
}
}
diff --git a/third_party/jpeg-xl/lib/jpegli/quant.cc b/third_party/jpeg-xl/lib/jpegli/quant.cc
index 36f1df4cdd..14db6701b2 100644
--- a/third_party/jpeg-xl/lib/jpegli/quant.cc
+++ b/third_party/jpeg-xl/lib/jpegli/quant.cc
@@ -26,7 +26,7 @@ namespace {
constexpr float kGlobalScaleXYB = 1.43951668f;
constexpr float kGlobalScaleYCbCr = 1.73966010f;
-static constexpr float kBaseQuantMatrixXYB[] = {
+constexpr float kBaseQuantMatrixXYB[] = {
// c = 0
7.5629935265f,
19.8247814178f,
@@ -224,7 +224,7 @@ static constexpr float kBaseQuantMatrixXYB[] = {
63.6065597534f,
};
-static const float kBaseQuantMatrixYCbCr[] = {
+const float kBaseQuantMatrixYCbCr[] = {
// c = 0
1.2397409345866273f, //
1.7227115097630963f, //
@@ -422,8 +422,8 @@ static const float kBaseQuantMatrixYCbCr[] = {
114.89202448569779f, //
};
-static const float k420GlobalScale = 1.22;
-static const float k420Rescale[64] = {
+const float k420GlobalScale = 1.22;
+const float k420Rescale[64] = {
0.4093, 0.3209, 0.3477, 0.3333, 0.3144, 0.2823, 0.3214, 0.3354, //
0.3209, 0.3111, 0.3489, 0.2801, 0.3059, 0.3119, 0.4135, 0.3445, //
0.3477, 0.3489, 0.3586, 0.3257, 0.2727, 0.3754, 0.3369, 0.3484, //
@@ -434,7 +434,7 @@ static const float k420Rescale[64] = {
0.3354, 0.3445, 0.3484, 0.3839, 0.3836, 0.0726, 0.0553, 0.3368, //
};
-static const float kBaseQuantMatrixStd[] = {
+const float kBaseQuantMatrixStd[] = {
// c = 0
16.0f, 11.0f, 10.0f, 16.0f, 24.0f, 40.0f, 51.0f, 61.0f, //
12.0f, 12.0f, 14.0f, 19.0f, 26.0f, 58.0f, 60.0f, 55.0f, //
@@ -455,7 +455,7 @@ static const float kBaseQuantMatrixStd[] = {
99.0f, 99.0f, 99.0f, 99.0f, 99.0f, 99.0f, 99.0f, 99.0f, //
};
-static const float kZeroBiasMulYCbCrLQ[] = {
+const float kZeroBiasMulYCbCrLQ[] = {
// c = 0
0.0000f, 0.0568f, 0.3880f, 0.6190f, 0.6190f, 0.4490f, 0.4490f, 0.6187f, //
0.0568f, 0.5829f, 0.6189f, 0.6190f, 0.6190f, 0.7190f, 0.6190f, 0.6189f, //
@@ -485,7 +485,7 @@ static const float kZeroBiasMulYCbCrLQ[] = {
0.2960f, 0.2113f, 0.2426f, 0.1590f, 0.5403f, 0.3060f, 0.3060f, 0.3060f, //
};
-static const float kZeroBiasMulYCbCrHQ[] = {
+const float kZeroBiasMulYCbCrHQ[] = {
// c = 0
0.0000f, 0.0044f, 0.2521f, 0.6547f, 0.8161f, 0.6130f, 0.8841f, 0.8155f, //
0.0044f, 0.6831f, 0.6553f, 0.6295f, 0.7848f, 0.7843f, 0.8474f, 0.7836f, //
@@ -515,9 +515,9 @@ static const float kZeroBiasMulYCbCrHQ[] = {
0.4836f, 0.4897f, 0.2583f, 0.3565f, 0.5949f, 0.6629f, 0.6644f, 0.6644f, //
};
-static const float kZeroBiasOffsetYCbCrDC[] = {0.0f, 0.0f, 0.0f};
+const float kZeroBiasOffsetYCbCrDC[] = {0.0f, 0.0f, 0.0f};
-static const float kZeroBiasOffsetYCbCrAC[] = {
+const float kZeroBiasOffsetYCbCrAC[] = {
0.59082f,
0.58146f,
0.57988f,
diff --git a/third_party/jpeg-xl/lib/jpegli/render.cc b/third_party/jpeg-xl/lib/jpegli/render.cc
index 24e7e99618..c550f9a575 100644
--- a/third_party/jpeg-xl/lib/jpegli/render.cc
+++ b/third_party/jpeg-xl/lib/jpegli/render.cc
@@ -8,7 +8,6 @@
#include <string.h>
#include <array>
-#include <atomic>
#include <cmath>
#include <cstddef>
#include <cstdint>
@@ -203,12 +202,13 @@ void WriteToOutput(j_decompress_ptr cinfo, float* JXL_RESTRICT rows[],
if (cinfo->quantize_colors && m->quant_pass_ == 1) {
float* error_row[kMaxComponents];
float* next_error_row[kMaxComponents];
- if (cinfo->dither_mode == JDITHER_ORDERED) {
+ J_DITHER_MODE dither_mode = cinfo->dither_mode;
+ if (dither_mode == JDITHER_ORDERED) {
for (size_t c = 0; c < num_channels; ++c) {
DitherRow(cinfo, &rows[c][xoffset], c, cinfo->output_scanline,
cinfo->output_width);
}
- } else if (cinfo->dither_mode == JDITHER_FS) {
+ } else if (dither_mode == JDITHER_FS) {
for (size_t c = 0; c < num_channels; ++c) {
if (cinfo->output_scanline % 2 == 0) {
error_row[c] = m->error_row_[c];
@@ -221,12 +221,12 @@ void WriteToOutput(j_decompress_ptr cinfo, float* JXL_RESTRICT rows[],
}
}
const float mul = 255.0f;
- if (cinfo->dither_mode != JDITHER_FS) {
+ if (dither_mode != JDITHER_FS) {
StoreUnsignedRow(rows, xoffset, len, num_channels, mul, scratch_space);
}
for (size_t i = 0; i < len; ++i) {
uint8_t* pixel = &scratch_space[num_channels * i];
- if (cinfo->dither_mode == JDITHER_FS) {
+ if (dither_mode == JDITHER_FS) {
for (size_t c = 0; c < num_channels; ++c) {
float val = rows[c][i] * mul + LimitError(error_row[c][i]);
pixel[c] = std::round(std::min(255.0f, std::max(0.0f, val)));
@@ -234,7 +234,7 @@ void WriteToOutput(j_decompress_ptr cinfo, float* JXL_RESTRICT rows[],
}
int index = LookupColorIndex(cinfo, pixel);
output[i] = index;
- if (cinfo->dither_mode == JDITHER_FS) {
+ if (dither_mode == JDITHER_FS) {
size_t prev_i = i > 0 ? i - 1 : 0;
size_t next_i = i + 1 < len ? i + 1 : len - 1;
for (size_t c = 0; c < num_channels; ++c) {
@@ -293,19 +293,18 @@ HWY_EXPORT(DecenterRow);
void GatherBlockStats(const int16_t* JXL_RESTRICT coeffs,
const size_t coeffs_size, int32_t* JXL_RESTRICT nonzeros,
int32_t* JXL_RESTRICT sumabs) {
- return HWY_DYNAMIC_DISPATCH(GatherBlockStats)(coeffs, coeffs_size, nonzeros,
- sumabs);
+ HWY_DYNAMIC_DISPATCH(GatherBlockStats)(coeffs, coeffs_size, nonzeros, sumabs);
}
void WriteToOutput(j_decompress_ptr cinfo, float* JXL_RESTRICT rows[],
size_t xoffset, size_t len, size_t num_channels,
uint8_t* JXL_RESTRICT output) {
- return HWY_DYNAMIC_DISPATCH(WriteToOutput)(cinfo, rows, xoffset, len,
- num_channels, output);
+ HWY_DYNAMIC_DISPATCH(WriteToOutput)
+ (cinfo, rows, xoffset, len, num_channels, output);
}
void DecenterRow(float* row, size_t xsize) {
- return HWY_DYNAMIC_DISPATCH(DecenterRow)(row, xsize);
+ HWY_DYNAMIC_DISPATCH(DecenterRow)(row, xsize);
}
bool ShouldApplyDequantBiases(j_decompress_ptr cinfo, int ci) {
@@ -360,8 +359,8 @@ bool do_smoothing(j_decompress_ptr cinfo) {
if (!cinfo->progressive_mode || cinfo->coef_bits == nullptr) {
return false;
}
- auto coef_bits_latch = m->coef_bits_latch;
- auto prev_coef_bits_latch = m->prev_coef_bits_latch;
+ auto* coef_bits_latch = m->coef_bits_latch;
+ auto* prev_coef_bits_latch = m->prev_coef_bits_latch;
for (int ci = 0; ci < cinfo->num_components; ci++) {
jpeg_component_info* compptr = &cinfo->comp_info[ci];
@@ -468,6 +467,7 @@ void PredictSmooth(j_decompress_ptr cinfo, JBLOCKARRAY blocks, int component,
return swap_indices ? dc_values[j][i] : dc_values[i][j];
};
Al = coef_bits[coef_index];
+ JXL_ASSERT(coef_index >= 0 && coef_index < 10);
switch (coef_index) {
case 0:
// set the DC
@@ -520,6 +520,7 @@ void PredictSmooth(j_decompress_ptr cinfo, JBLOCKARRAY blocks, int component,
break;
case 7:
case 8:
+ default:
// set Q12 and Q21
num = (dc(1, 1) - 3 * dc(1, 2) + dc(1, 3) - dc(3, 1) + 3 * dc(3, 2) -
dc(3, 3));
@@ -551,7 +552,7 @@ void PredictSmooth(j_decompress_ptr cinfo, JBLOCKARRAY blocks, int component,
void PrepareForOutput(j_decompress_ptr cinfo) {
jpeg_decomp_master* m = cinfo->master;
bool smoothing = do_smoothing(cinfo);
- m->apply_smoothing = smoothing && cinfo->do_block_smoothing;
+ m->apply_smoothing = smoothing && FROM_JXL_BOOL(cinfo->do_block_smoothing);
size_t coeffs_per_block = cinfo->num_components * DCTSIZE2;
memset(m->nonzeros_, 0, coeffs_per_block * sizeof(m->nonzeros_[0]));
memset(m->sumabs_, 0, coeffs_per_block * sizeof(m->sumabs_[0]));
@@ -584,7 +585,7 @@ void DecodeCurrentiMCURow(j_decompress_ptr cinfo) {
int offset = m->streaming_mode_ ? 0 : by0;
ba[c] = (*cinfo->mem->access_virt_barray)(
reinterpret_cast<j_common_ptr>(cinfo), m->coef_arrays[c], offset,
- max_block_rows, false);
+ max_block_rows, FALSE);
}
for (int c = 0; c < cinfo->num_components; ++c) {
size_t k0 = c * DCTSIZE2;
diff --git a/third_party/jpeg-xl/lib/jpegli/source_manager.cc b/third_party/jpeg-xl/lib/jpegli/source_manager.cc
index 0b8e0a5c8c..58adf803b1 100644
--- a/third_party/jpeg-xl/lib/jpegli/source_manager.cc
+++ b/third_party/jpeg-xl/lib/jpegli/source_manager.cc
@@ -39,7 +39,7 @@ struct StdioSourceManager {
uint8_t* buffer;
static boolean fill_input_buffer(j_decompress_ptr cinfo) {
- auto src = reinterpret_cast<StdioSourceManager*>(cinfo->src);
+ auto* src = reinterpret_cast<StdioSourceManager*>(cinfo->src);
size_t num_bytes_read = fread(src->buffer, 1, kStdioBufferSize, src->f);
if (num_bytes_read == 0) {
return EmitFakeEoiMarker(cinfo);
@@ -77,7 +77,7 @@ void jpegli_stdio_src(j_decompress_ptr cinfo, FILE* infile) {
cinfo->src = reinterpret_cast<jpeg_source_mgr*>(
jpegli::Allocate<jpegli::StdioSourceManager>(cinfo, 1));
}
- auto src = reinterpret_cast<jpegli::StdioSourceManager*>(cinfo->src);
+ auto* src = reinterpret_cast<jpegli::StdioSourceManager*>(cinfo->src);
src->f = infile;
src->buffer = jpegli::Allocate<uint8_t>(cinfo, jpegli::kStdioBufferSize);
src->pub.next_input_byte = src->buffer;
diff --git a/third_party/jpeg-xl/lib/jpegli/source_manager_test.cc b/third_party/jpeg-xl/lib/jpegli/source_manager_test.cc
index 4e137876c9..59d12b001b 100644
--- a/third_party/jpeg-xl/lib/jpegli/source_manager_test.cc
+++ b/third_party/jpeg-xl/lib/jpegli/source_manager_test.cc
@@ -50,7 +50,7 @@ FILE* MemOpen(const std::vector<uint8_t>& data) {
TEST_P(SourceManagerTestParam, TestStdioSourceManager) {
TestConfig config = GetParam();
- std::vector<uint8_t> compressed = ReadTestData(config.fn.c_str());
+ std::vector<uint8_t> compressed = ReadTestData(config.fn);
if (config.dparams.size_factor < 1.0) {
compressed.resize(compressed.size() * config.dparams.size_factor);
}
@@ -77,7 +77,7 @@ TEST_P(SourceManagerTestParam, TestStdioSourceManager) {
TEST_P(SourceManagerTestParam, TestMemSourceManager) {
TestConfig config = GetParam();
- std::vector<uint8_t> compressed = ReadTestData(config.fn.c_str());
+ std::vector<uint8_t> compressed = ReadTestData(config.fn);
if (config.dparams.size_factor < 1.0f) {
compressed.resize(compressed.size() * config.dparams.size_factor);
}
diff --git a/third_party/jpeg-xl/lib/jpegli/streaming_test.cc b/third_party/jpeg-xl/lib/jpegli/streaming_test.cc
index 8d2e3577f3..2e6f7029b0 100644
--- a/third_party/jpeg-xl/lib/jpegli/streaming_test.cc
+++ b/third_party/jpeg-xl/lib/jpegli/streaming_test.cc
@@ -36,13 +36,13 @@ struct SourceManager {
// input buffer. The buffer size is kept short because empty_output_buffer() is
// called only when the output buffer is full, and we want to update the decoder
// input frequently to demonstrate that streaming works.
-static constexpr size_t kOutputBufferSize = 1024;
+constexpr size_t kOutputBufferSize = 1024;
struct DestinationManager {
jpeg_destination_mgr pub;
std::vector<uint8_t> buffer;
SourceManager* dest;
- DestinationManager(SourceManager* src)
+ explicit DestinationManager(SourceManager* src)
: buffer(kOutputBufferSize), dest(src) {
pub.next_output_byte = buffer.data();
pub.free_in_buffer = buffer.size();
@@ -54,7 +54,7 @@ struct DestinationManager {
static void init_destination(j_compress_ptr cinfo) {}
static boolean empty_output_buffer(j_compress_ptr cinfo) {
- auto us = reinterpret_cast<DestinationManager*>(cinfo->dest);
+ auto* us = reinterpret_cast<DestinationManager*>(cinfo->dest);
jpeg_destination_mgr* src = &us->pub;
jpeg_source_mgr* dst = &us->dest->pub;
std::vector<uint8_t>& src_buf = us->buffer;
@@ -69,7 +69,7 @@ struct DestinationManager {
dst->bytes_in_buffer = dst_buf.size();
src->next_output_byte = src_buf.data();
src->free_in_buffer = src_buf.size();
- return true;
+ return TRUE;
}
static void term_destination(j_compress_ptr cinfo) {
@@ -87,6 +87,7 @@ class StreamingTestParam : public ::testing::TestWithParam<TestConfig> {};
TEST_P(StreamingTestParam, TestStreaming) {
jpeg_decompress_struct dinfo = {};
jpeg_compress_struct cinfo = {};
+ SourceManager src;
TestConfig config = GetParam();
TestImage& input = config.input;
TestImage output;
@@ -99,7 +100,6 @@ TEST_P(StreamingTestParam, TestStreaming) {
// compressor's output is connected to the decompressor's input.
jpegli_create_decompress(&dinfo);
jpegli_create_compress(&cinfo);
- SourceManager src;
dinfo.src = reinterpret_cast<jpeg_source_mgr*>(&src);
DestinationManager dest(&src);
cinfo.dest = reinterpret_cast<jpeg_destination_mgr*>(&dest);
@@ -107,7 +107,7 @@ TEST_P(StreamingTestParam, TestStreaming) {
cinfo.image_width = input.xsize;
cinfo.image_height = input.ysize;
cinfo.input_components = input.components;
- cinfo.in_color_space = (J_COLOR_SPACE)input.color_space;
+ cinfo.in_color_space = static_cast<J_COLOR_SPACE>(input.color_space);
jpegli_set_defaults(&cinfo);
cinfo.comp_info[0].v_samp_factor = config.jparams.v_sampling[0];
jpegli_set_progressive_level(&cinfo, 0);
@@ -122,13 +122,13 @@ TEST_P(StreamingTestParam, TestStreaming) {
while (yin < cinfo.image_height) {
// Feed one iMCU row at a time to the compressor.
size_t lines_in = std::min(iMCU_height, cinfo.image_height - yin);
- memcpy(&row_bytes[0], &input.pixels[yin * stride], lines_in * stride);
+ memcpy(row_bytes.data(), &input.pixels[yin * stride], lines_in * stride);
std::vector<JSAMPROW> rows_in(lines_in);
for (size_t i = 0; i < lines_in; ++i) {
rows_in[i] = &row_bytes[i * stride];
}
EXPECT_EQ(lines_in,
- jpegli_write_scanlines(&cinfo, &rows_in[0], lines_in));
+ jpegli_write_scanlines(&cinfo, rows_in.data(), lines_in));
yin += lines_in;
if (yin == cinfo.image_height) {
jpegli_finish_compress(&cinfo);
@@ -180,7 +180,7 @@ TEST_P(StreamingTestParam, TestStreaming) {
reinterpret_cast<JSAMPLE*>(&output.pixels[(yout + i) * stride]);
}
EXPECT_EQ(lines_out,
- jpegli_read_scanlines(&dinfo, &rows_out[0], lines_out));
+ jpegli_read_scanlines(&dinfo, rows_out.data(), lines_out));
VerifyOutputImage(input, output, yout, lines_out, 3.8f);
yout += lines_out;
diff --git a/third_party/jpeg-xl/lib/jpegli/test_utils-inl.h b/third_party/jpeg-xl/lib/jpegli/test_utils-inl.h
index a454917187..4fbcb721e4 100644
--- a/third_party/jpeg-xl/lib/jpegli/test_utils-inl.h
+++ b/third_party/jpeg-xl/lib/jpegli/test_utils-inl.h
@@ -8,20 +8,20 @@
// include paths for the jpeg headers.
// Sequential non-interleaved.
-static constexpr jpeg_scan_info kScript1[] = {
+constexpr jpeg_scan_info kScript1[] = {
{1, {0}, 0, 63, 0, 0},
{1, {1}, 0, 63, 0, 0},
{1, {2}, 0, 63, 0, 0},
};
// Sequential partially interleaved, chroma first.
-static constexpr jpeg_scan_info kScript2[] = {
+constexpr jpeg_scan_info kScript2[] = {
{2, {1, 2}, 0, 63, 0, 0},
{1, {0}, 0, 63, 0, 0},
};
// Rest of the scan scripts are progressive.
-static constexpr jpeg_scan_info kScript3[] = {
+constexpr jpeg_scan_info kScript3[] = {
// Interleaved full DC.
{3, {0, 1, 2}, 0, 0, 0, 0},
// Full AC scans.
@@ -29,7 +29,7 @@ static constexpr jpeg_scan_info kScript3[] = {
{1, {1}, 1, 63, 0, 0},
{1, {2}, 1, 63, 0, 0},
};
-static constexpr jpeg_scan_info kScript4[] = {
+constexpr jpeg_scan_info kScript4[] = {
// Non-interleaved full DC.
{1, {0}, 0, 0, 0, 0},
{1, {1}, 0, 0, 0, 0},
@@ -39,7 +39,7 @@ static constexpr jpeg_scan_info kScript4[] = {
{1, {1}, 1, 63, 0, 0},
{1, {2}, 1, 63, 0, 0},
};
-static constexpr jpeg_scan_info kScript5[] = {
+constexpr jpeg_scan_info kScript5[] = {
// Partially interleaved full DC, chroma first.
{2, {1, 2}, 0, 0, 0, 0},
{1, {0}, 0, 0, 0, 0},
@@ -52,7 +52,7 @@ static constexpr jpeg_scan_info kScript5[] = {
{1, {1}, 1, 63, 1, 0},
{1, {2}, 1, 63, 1, 0},
};
-static constexpr jpeg_scan_info kScript6[] = {
+constexpr jpeg_scan_info kScript6[] = {
// Interleaved DC shifted by 2 bits.
{3, {0, 1, 2}, 0, 0, 0, 2},
// Interleaved DC refinement scans.
@@ -64,7 +64,7 @@ static constexpr jpeg_scan_info kScript6[] = {
{1, {2}, 1, 63, 0, 0},
};
-static constexpr jpeg_scan_info kScript7[] = {
+constexpr jpeg_scan_info kScript7[] = {
// Non-interleaved DC shifted by 2 bits.
{1, {0}, 0, 0, 0, 2},
{1, {1}, 0, 0, 0, 2},
@@ -83,7 +83,7 @@ static constexpr jpeg_scan_info kScript7[] = {
{1, {2}, 1, 63, 0, 0},
};
-static constexpr jpeg_scan_info kScript8[] = {
+constexpr jpeg_scan_info kScript8[] = {
// Partially interleaved DC shifted by 2 bits, chroma first
{2, {1, 2}, 0, 0, 0, 2},
{1, {0}, 0, 0, 0, 2},
@@ -99,7 +99,7 @@ static constexpr jpeg_scan_info kScript8[] = {
{1, {2}, 1, 63, 0, 0},
};
-static constexpr jpeg_scan_info kScript9[] = {
+constexpr jpeg_scan_info kScript9[] = {
// Interleaved full DC.
{3, {0, 1, 2}, 0, 0, 0, 0},
// AC scans for component 0
@@ -123,7 +123,7 @@ static constexpr jpeg_scan_info kScript9[] = {
{1, {2}, 17, 63, 1, 0},
};
-static constexpr jpeg_scan_info kScript10[] = {
+constexpr jpeg_scan_info kScript10[] = {
// Interleaved full DC.
{3, {0, 1, 2}, 0, 0, 0, 0},
// AC scans for spectral range 1..16
@@ -156,14 +156,14 @@ struct ScanScript {
const jpeg_scan_info* scans;
};
-static constexpr ScanScript kTestScript[] = {
+constexpr ScanScript kTestScript[] = {
{ARRAY_SIZE(kScript1), kScript1}, {ARRAY_SIZE(kScript2), kScript2},
{ARRAY_SIZE(kScript3), kScript3}, {ARRAY_SIZE(kScript4), kScript4},
{ARRAY_SIZE(kScript5), kScript5}, {ARRAY_SIZE(kScript6), kScript6},
{ARRAY_SIZE(kScript7), kScript7}, {ARRAY_SIZE(kScript8), kScript8},
{ARRAY_SIZE(kScript9), kScript9}, {ARRAY_SIZE(kScript10), kScript10},
};
-static constexpr int kNumTestScripts = ARRAY_SIZE(kTestScript);
+constexpr int kNumTestScripts = ARRAY_SIZE(kTestScript);
void SetScanDecompressParams(const DecompressParams& dparams,
j_decompress_ptr cinfo, int scan_number) {
@@ -178,7 +178,7 @@ void SetScanDecompressParams(const DecompressParams& dparams,
return;
}
if (dparams.quantize_colors) {
- cinfo->dither_mode = (J_DITHER_MODE)sparams->dither_mode;
+ cinfo->dither_mode = static_cast<J_DITHER_MODE>(sparams->dither_mode);
if (sparams->color_quant_mode == CQUANT_1PASS) {
cinfo->two_pass_quantize = FALSE;
cinfo->colormap = nullptr;
@@ -194,7 +194,8 @@ void SetScanDecompressParams(const DecompressParams& dparams,
cinfo->colormap = (*cinfo->mem->alloc_sarray)(
reinterpret_cast<j_common_ptr>(cinfo), JPOOL_IMAGE,
cinfo->actual_number_of_colors, 3);
- jxl::msan::UnpoisonMemory(cinfo->colormap, 3 * sizeof(JSAMPROW));
+ jxl::msan::UnpoisonMemory(reinterpret_cast<void*>(cinfo->colormap),
+ 3 * sizeof(JSAMPLE*));
for (int i = 0; i < kTestColorMapNumColors; ++i) {
cinfo->colormap[0][i] = (kTestColorMap[i] >> 16) & 0xff;
cinfo->colormap[1][i] = (kTestColorMap[i] >> 8) & 0xff;
@@ -212,20 +213,21 @@ void SetScanDecompressParams(const DecompressParams& dparams,
void SetDecompressParams(const DecompressParams& dparams,
j_decompress_ptr cinfo) {
- cinfo->do_block_smoothing = dparams.do_block_smoothing;
- cinfo->do_fancy_upsampling = dparams.do_fancy_upsampling;
+ cinfo->do_block_smoothing = dparams.do_block_smoothing ? 1 : 0;
+ cinfo->do_fancy_upsampling = dparams.do_fancy_upsampling ? 1 : 0;
if (dparams.output_mode == RAW_DATA) {
cinfo->raw_data_out = TRUE;
}
if (dparams.set_out_color_space) {
- cinfo->out_color_space = (J_COLOR_SPACE)dparams.out_color_space;
+ cinfo->out_color_space =
+ static_cast<J_COLOR_SPACE>(dparams.out_color_space);
if (dparams.out_color_space == JCS_UNKNOWN) {
cinfo->jpeg_color_space = JCS_UNKNOWN;
}
}
cinfo->scale_num = dparams.scale_num;
cinfo->scale_denom = dparams.scale_denom;
- cinfo->quantize_colors = dparams.quantize_colors;
+ cinfo->quantize_colors = dparams.quantize_colors ? 1 : 0;
cinfo->desired_number_of_colors = dparams.desired_number_of_colors;
if (!dparams.scan_params.empty()) {
if (cinfo->buffered_image) {
@@ -420,7 +422,7 @@ void CopyCoefficients(j_decompress_ptr cinfo, jvirt_barray_ptr* coef_arrays,
DCTSIZE2);
for (size_t by = 0; by < comp->height_in_blocks; ++by) {
JBLOCKARRAY ba = (*cinfo->mem->access_virt_barray)(comptr, coef_arrays[c],
- by, 1, true);
+ by, 1, TRUE);
size_t stride = comp->width_in_blocks * sizeof(JBLOCK);
size_t offset = by * comp->width_in_blocks * DCTSIZE2;
memcpy(&coeffs[offset], ba[0], stride);
diff --git a/third_party/jpeg-xl/lib/jpegli/test_utils.cc b/third_party/jpeg-xl/lib/jpegli/test_utils.cc
index 232b937496..4e675070cf 100644
--- a/third_party/jpeg-xl/lib/jpegli/test_utils.cc
+++ b/third_party/jpeg-xl/lib/jpegli/test_utils.cc
@@ -153,7 +153,7 @@ bool ReadPNM(const std::vector<uint8_t>& data, size_t* xsize, size_t* ysize,
return false;
}
pixels->resize(data.data() + data.size() - pos);
- memcpy(&(*pixels)[0], pos, pixels->size());
+ memcpy(pixels->data(), pos, pixels->size());
return true;
}
@@ -216,7 +216,8 @@ std::ostream& operator<<(std::ostream& os, const TestImage& input) {
os << input.xsize << "x" << input.ysize;
os << IOMethodName(input.data_type, input.endianness);
if (input.color_space != JCS_RGB) {
- os << "InputColor" << ColorSpaceName((J_COLOR_SPACE)input.color_space);
+ os << "InputColor"
+ << ColorSpaceName(static_cast<J_COLOR_SPACE>(input.color_space));
}
if (input.color_space == JCS_UNKNOWN) {
os << input.components;
@@ -229,18 +230,18 @@ std::ostream& operator<<(std::ostream& os, const CompressParams& jparams) {
os << SamplingId(jparams);
if (jparams.set_jpeg_colorspace) {
os << "JpegColor"
- << ColorSpaceName((J_COLOR_SPACE)jparams.jpeg_color_space);
+ << ColorSpaceName(static_cast<J_COLOR_SPACE>(jparams.jpeg_color_space));
}
if (!jparams.comp_ids.empty()) {
os << "CID";
- for (size_t i = 0; i < jparams.comp_ids.size(); ++i) {
- os << jparams.comp_ids[i];
+ for (int cid : jparams.comp_ids) {
+ os << cid;
}
}
if (!jparams.quant_indexes.empty()) {
os << "QIDX";
- for (size_t i = 0; i < jparams.quant_indexes.size(); ++i) {
- os << jparams.quant_indexes[i];
+ for (int qi : jparams.quant_indexes) {
+ os << qi;
}
for (const auto& table : jparams.quant_tables) {
os << "TABLE" << table.slot_idx << "T" << table.table_type << "F"
@@ -320,7 +321,7 @@ void RGBToYCbCr(float r, float g, float b, float* y, float* cb, float* cr) {
void ConvertPixel(const uint8_t* input_rgb, uint8_t* out,
J_COLOR_SPACE colorspace, size_t num_channels,
JpegliDataType data_type = JPEGLI_TYPE_UINT8,
- bool swap_endianness = JPEGLI_NATIVE_ENDIAN) {
+ JXL_BOOL swap_endianness = JPEGLI_NATIVE_ENDIAN) {
const float kMul = 255.0f;
float r = input_rgb[0] / kMul;
float g = input_rgb[1] / kMul;
@@ -334,7 +335,9 @@ void ConvertPixel(const uint8_t* input_rgb, uint8_t* out,
out8[c] = input_rgb[std::min<size_t>(2, c)];
}
} else if (colorspace == JCS_YCbCr) {
- float Y, Cb, Cr;
+ float Y;
+ float Cb;
+ float Cr;
RGBToYCbCr(r, g, b, &Y, &Cb, &Cr);
out8[0] = static_cast<uint8_t>(std::round(Y * kMul));
out8[1] = static_cast<uint8_t>(std::round(Cb * kMul));
@@ -350,7 +353,9 @@ void ConvertPixel(const uint8_t* input_rgb, uint8_t* out,
out8[1] = static_cast<uint8_t>(std::round((1.0f - g) * kMul));
out8[2] = static_cast<uint8_t>(std::round((1.0f - b) * kMul));
} else if (colorspace == JCS_YCCK) {
- float Y, Cb, Cr;
+ float Y;
+ float Cb;
+ float Cr;
RGBToYCbCr(r, g, b, &Y, &Cb, &Cr);
out8[0] = static_cast<uint8_t>(std::round(Y * kMul));
out8[1] = static_cast<uint8_t>(std::round(Cb * kMul));
@@ -399,7 +404,10 @@ void ConvertToGrayscale(TestImage* img) {
void GeneratePixels(TestImage* img) {
const std::vector<uint8_t> imgdata = ReadTestData("jxl/flower/flower.pnm");
- size_t xsize, ysize, channels, bitdepth;
+ size_t xsize;
+ size_t ysize;
+ size_t channels;
+ size_t bitdepth;
std::vector<uint8_t> pixels;
JXL_CHECK(ReadPNM(imgdata, &xsize, &ysize, &channels, &bitdepth, &pixels));
if (img->xsize == 0) img->xsize = xsize;
@@ -412,7 +420,8 @@ void GeneratePixels(TestImage* img) {
size_t in_stride = xsize * in_bytes_per_pixel;
size_t x0 = (xsize - img->xsize) / 2;
size_t y0 = (ysize - img->ysize) / 2;
- SetNumChannels((J_COLOR_SPACE)img->color_space, &img->components);
+ SetNumChannels(static_cast<J_COLOR_SPACE>(img->color_space),
+ &img->components);
size_t out_bytes_per_pixel =
jpegli_bytes_per_sample(img->data_type) * img->components;
size_t out_stride = img->xsize * out_bytes_per_pixel;
@@ -427,8 +436,9 @@ void GeneratePixels(TestImage* img) {
size_t idx_in = y * in_stride + x * in_bytes_per_pixel;
size_t idx_out = iy * out_stride + ix * out_bytes_per_pixel;
ConvertPixel(&pixels[idx_in], &img->pixels[idx_out],
- (J_COLOR_SPACE)img->color_space, img->components,
- img->data_type, swap_endianness);
+ static_cast<J_COLOR_SPACE>(img->color_space),
+ img->components, img->data_type,
+ TO_JXL_BOOL(swap_endianness));
}
}
}
@@ -492,7 +502,7 @@ void EncodeWithJpegli(const TestImage& input, const CompressParams& jparams,
jpegli_set_progressive_level(cinfo, 0);
}
jpegli_set_defaults(cinfo);
- cinfo->in_color_space = (J_COLOR_SPACE)input.color_space;
+ cinfo->in_color_space = static_cast<J_COLOR_SPACE>(input.color_space);
jpegli_default_colorspace(cinfo);
if (jparams.override_JFIF >= 0) {
cinfo->write_JFIF_header = jparams.override_JFIF;
@@ -501,7 +511,8 @@ void EncodeWithJpegli(const TestImage& input, const CompressParams& jparams,
cinfo->write_Adobe_marker = jparams.override_Adobe;
}
if (jparams.set_jpeg_colorspace) {
- jpegli_set_colorspace(cinfo, (J_COLOR_SPACE)jparams.jpeg_color_space);
+ jpegli_set_colorspace(cinfo,
+ static_cast<J_COLOR_SPACE>(jparams.jpeg_color_space));
}
if (!jparams.comp_ids.empty()) {
for (int c = 0; c < cinfo->num_components; ++c) {
@@ -522,15 +533,16 @@ void EncodeWithJpegli(const TestImage& input, const CompressParams& jparams,
for (const auto& table : jparams.quant_tables) {
if (table.add_raw) {
cinfo->quant_tbl_ptrs[table.slot_idx] =
- jpegli_alloc_quant_table((j_common_ptr)cinfo);
+ jpegli_alloc_quant_table(reinterpret_cast<j_common_ptr>(cinfo));
for (int k = 0; k < DCTSIZE2; ++k) {
cinfo->quant_tbl_ptrs[table.slot_idx]->quantval[k] =
table.quantval[k];
}
cinfo->quant_tbl_ptrs[table.slot_idx]->sent_table = FALSE;
} else {
- jpegli_add_quant_table(cinfo, table.slot_idx, &table.basic_table[0],
- table.scale_factor, table.force_baseline);
+ jpegli_add_quant_table(cinfo, table.slot_idx, table.basic_table.data(),
+ table.scale_factor,
+ TO_JXL_BOOL(table.force_baseline));
}
}
}
@@ -546,7 +558,8 @@ void EncodeWithJpegli(const TestImage& input, const CompressParams& jparams,
jpegli_set_progressive_level(cinfo, jparams.progressive_mode);
}
jpegli_set_input_format(cinfo, input.data_type, input.endianness);
- jpegli_enable_adaptive_quantization(cinfo, jparams.use_adaptive_quantization);
+ jpegli_enable_adaptive_quantization(
+ cinfo, TO_JXL_BOOL(jparams.use_adaptive_quantization));
cinfo->restart_interval = jparams.restart_interval;
cinfo->restart_in_rows = jparams.restart_in_rows;
cinfo->smoothing_factor = jparams.smoothing_factor;
@@ -555,7 +568,7 @@ void EncodeWithJpegli(const TestImage& input, const CompressParams& jparams,
} else if (jparams.optimize_coding == 0) {
cinfo->optimize_coding = FALSE;
}
- cinfo->raw_data_in = !input.raw_data.empty();
+ cinfo->raw_data_in = TO_JXL_BOOL(!input.raw_data.empty());
if (jparams.optimize_coding == 0 && jparams.use_flat_dc_luma_code) {
JHUFF_TBL* tbl = cinfo->dc_huff_tbl_ptrs[0];
memset(tbl, 0, sizeof(*tbl));
@@ -572,13 +585,13 @@ void EncodeWithJpegli(const TestImage& input, const CompressParams& jparams,
cinfo->ac_huff_tbl_ptrs[0]->sent_table = TRUE;
cinfo->ac_huff_tbl_ptrs[1]->sent_table = TRUE;
}
- jpegli_start_compress(cinfo, write_all_tables);
+ jpegli_start_compress(cinfo, TO_JXL_BOOL(write_all_tables));
if (jparams.add_marker) {
jpegli_write_marker(cinfo, kSpecialMarker0, kMarkerData,
sizeof(kMarkerData));
jpegli_write_m_header(cinfo, kSpecialMarker1, sizeof(kMarkerData));
- for (size_t p = 0; p < sizeof(kMarkerData); ++p) {
- jpegli_write_m_byte(cinfo, kMarkerData[p]);
+ for (uint8_t c : kMarkerData) {
+ jpegli_write_m_byte(cinfo, c);
}
for (size_t i = 0; i < kMarkerSequenceLen; ++i) {
jpegli_write_marker(cinfo, kMarkerSequence[i], kMarkerData,
@@ -597,7 +610,7 @@ void EncodeWithJpegli(const TestImage& input, const CompressParams& jparams,
std::vector<JSAMPARRAY> data(cinfo->num_components);
for (int c = 0; c < cinfo->num_components; ++c) {
rowdata[c].resize(jparams.v_samp(c) * DCTSIZE);
- data[c] = &rowdata[c][0];
+ data[c] = rowdata[c].data();
}
while (cinfo->next_scanline < cinfo->image_height) {
for (int c = 0; c < cinfo->num_components; ++c) {
@@ -610,7 +623,7 @@ void EncodeWithJpegli(const TestImage& input, const CompressParams& jparams,
(y0 + i < cheight ? &raw_data[c][(y0 + i) * cwidth] : nullptr);
}
}
- size_t num_lines = jpegli_write_raw_data(cinfo, &data[0], max_lines);
+ size_t num_lines = jpegli_write_raw_data(cinfo, data.data(), max_lines);
JXL_CHECK(num_lines == max_lines);
}
} else if (!input.coeffs.empty()) {
@@ -630,15 +643,15 @@ void EncodeWithJpegli(const TestImage& input, const CompressParams& jparams,
jpegli_write_marker(cinfo, kSpecialMarker0, kMarkerData,
sizeof(kMarkerData));
jpegli_write_m_header(cinfo, kSpecialMarker1, sizeof(kMarkerData));
- for (size_t p = 0; p < sizeof(kMarkerData); ++p) {
- jpegli_write_m_byte(cinfo, kMarkerData[p]);
+ for (uint8_t c : kMarkerData) {
+ jpegli_write_m_byte(cinfo, c);
}
}
for (int c = 0; c < cinfo->num_components; ++c) {
jpeg_component_info* comp = &cinfo->comp_info[c];
for (size_t by = 0; by < comp->height_in_blocks; ++by) {
JBLOCKARRAY ba = (*cinfo->mem->access_virt_barray)(
- comptr, coef_arrays[c], by, 1, true);
+ comptr, coef_arrays[c], by, 1, TRUE);
size_t stride = comp->width_in_blocks * sizeof(JBLOCK);
size_t offset = by * comp->width_in_blocks * DCTSIZE2;
memcpy(ba[0], &input.coeffs[c][offset], stride);
@@ -649,7 +662,7 @@ void EncodeWithJpegli(const TestImage& input, const CompressParams& jparams,
jpegli_bytes_per_sample(input.data_type);
std::vector<uint8_t> row_bytes(stride);
for (size_t y = 0; y < cinfo->image_height; ++y) {
- memcpy(&row_bytes[0], &input.pixels[y * stride], stride);
+ memcpy(row_bytes.data(), &input.pixels[y * stride], stride);
JSAMPROW row[] = {row_bytes.data()};
jpegli_write_scanlines(cinfo, row, 1);
}
@@ -681,15 +694,15 @@ bool EncodeWithJpegli(const TestImage& input, const CompressParams& jparams,
int NumTestScanScripts() { return kNumTestScripts; }
-void DumpImage(const TestImage& image, const std::string fn) {
+void DumpImage(const TestImage& image, const std::string& fn) {
JXL_CHECK(image.components == 1 || image.components == 3);
size_t bytes_per_sample = jpegli_bytes_per_sample(image.data_type);
uint32_t maxval = (1u << (8 * bytes_per_sample)) - 1;
char type = image.components == 1 ? '5' : '6';
std::ofstream out(fn.c_str(), std::ofstream::binary);
- out << "P" << type << std::endl
- << image.xsize << " " << image.ysize << std::endl
- << maxval << std::endl;
+ out << "P" << type << "\n"
+ << image.xsize << " " << image.ysize << "\n"
+ << maxval << "\n";
out.write(reinterpret_cast<const char*>(image.pixels.data()),
image.pixels.size());
out.close();
diff --git a/third_party/jpeg-xl/lib/jpegli/testing.h b/third_party/jpeg-xl/lib/jpegli/testing.h
index 873a0171e7..6a6e0ca638 100644
--- a/third_party/jpeg-xl/lib/jpegli/testing.h
+++ b/third_party/jpeg-xl/lib/jpegli/testing.h
@@ -6,15 +6,7 @@
#ifndef LIB_JPEGLI_TESTING_H_
#define LIB_JPEGLI_TESTING_H_
-// GTest/GMock specific macros / wrappers.
-
-// gmock unconditionally redefines those macros (to wrong values).
-// Lets include it only here and mitigate the problem.
-#pragma push_macro("PRIdS")
-#pragma push_macro("PRIuS")
-#include "gmock/gmock.h"
-#pragma pop_macro("PRIuS")
-#pragma pop_macro("PRIdS")
+// GTest specific macros / wrappers.
#include "gtest/gtest.h"
@@ -28,8 +20,12 @@
// Ensures that we don't make our test bounds too lax, effectively disabling the
// tests.
-MATCHER_P(IsSlightlyBelow, max, "") {
- return max * 0.75 <= arg && arg <= max * 1.0;
-}
+#define EXPECT_SLIGHTLY_BELOW(A, E) \
+ { \
+ double _actual = (A); \
+ double _expected = (E); \
+ EXPECT_LE(_actual, _expected); \
+ EXPECT_GE(_actual, 0.75 * _expected); \
+ }
#endif // LIB_JPEGLI_TESTING_H_
diff --git a/third_party/jpeg-xl/lib/jpegli/transpose-inl.h b/third_party/jpeg-xl/lib/jpegli/transpose-inl.h
index 9fdd222f4e..cdc289f96c 100644
--- a/third_party/jpeg-xl/lib/jpegli/transpose-inl.h
+++ b/third_party/jpeg-xl/lib/jpegli/transpose-inl.h
@@ -18,8 +18,8 @@ namespace HWY_NAMESPACE {
namespace {
#if HWY_CAP_GE256
-static JXL_INLINE void Transpose8x8Block(const float* JXL_RESTRICT from,
- float* JXL_RESTRICT to) {
+JXL_INLINE void Transpose8x8Block(const float* JXL_RESTRICT from,
+ float* JXL_RESTRICT to) {
const HWY_CAPPED(float, 8) d;
auto i0 = Load(d, from);
auto i1 = Load(d, from + 1 * 8);
@@ -67,8 +67,8 @@ static JXL_INLINE void Transpose8x8Block(const float* JXL_RESTRICT from,
Store(i7, d, to + 7 * 8);
}
#elif HWY_TARGET != HWY_SCALAR
-static JXL_INLINE void Transpose8x8Block(const float* JXL_RESTRICT from,
- float* JXL_RESTRICT to) {
+JXL_INLINE void Transpose8x8Block(const float* JXL_RESTRICT from,
+ float* JXL_RESTRICT to) {
const HWY_CAPPED(float, 4) d;
for (size_t n = 0; n < 8; n += 4) {
for (size_t m = 0; m < 8; m += 4) {
diff --git a/third_party/jpeg-xl/lib/jpegli/upsample.cc b/third_party/jpeg-xl/lib/jpegli/upsample.cc
index 5559aa78a6..7dae841b8a 100644
--- a/third_party/jpeg-xl/lib/jpegli/upsample.cc
+++ b/third_party/jpeg-xl/lib/jpegli/upsample.cc
@@ -122,7 +122,7 @@ HWY_EXPORT(Upsample2Vertical);
void Upsample2Horizontal(float* JXL_RESTRICT row,
float* JXL_RESTRICT scratch_space, size_t len_out) {
- return HWY_DYNAMIC_DISPATCH(Upsample2Horizontal)(row, scratch_space, len_out);
+ HWY_DYNAMIC_DISPATCH(Upsample2Horizontal)(row, scratch_space, len_out);
}
void Upsample2Vertical(const float* JXL_RESTRICT row_top,
@@ -130,8 +130,8 @@ void Upsample2Vertical(const float* JXL_RESTRICT row_top,
const float* JXL_RESTRICT row_bot,
float* JXL_RESTRICT row_out0,
float* JXL_RESTRICT row_out1, size_t len) {
- return HWY_DYNAMIC_DISPATCH(Upsample2Vertical)(row_top, row_mid, row_bot,
- row_out0, row_out1, len);
+ HWY_DYNAMIC_DISPATCH(Upsample2Vertical)
+ (row_top, row_mid, row_bot, row_out0, row_out1, len);
}
} // namespace jpegli
#endif // HWY_ONCE