summaryrefslogtreecommitdiffstats
path: root/third_party/jpeg-xl/lib/jxl/base
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
commitfbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch)
tree4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /third_party/jpeg-xl/lib/jxl/base
parentReleasing progress-linux version 124.0.1-1~progress7.99u1. (diff)
downloadfirefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz
firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/jpeg-xl/lib/jxl/base')
-rw-r--r--third_party/jpeg-xl/lib/jxl/base/bits.h3
-rw-r--r--third_party/jpeg-xl/lib/jxl/base/byte_order.h8
-rw-r--r--third_party/jpeg-xl/lib/jxl/base/common.h44
-rw-r--r--third_party/jpeg-xl/lib/jxl/base/exif.h1
-rw-r--r--third_party/jpeg-xl/lib/jxl/base/float.h10
-rw-r--r--third_party/jpeg-xl/lib/jxl/base/matrix_ops.h78
-rw-r--r--third_party/jpeg-xl/lib/jxl/base/override.h4
-rw-r--r--third_party/jpeg-xl/lib/jxl/base/rational_polynomial-inl.h3
-rw-r--r--third_party/jpeg-xl/lib/jxl/base/scope_guard.h6
-rw-r--r--third_party/jpeg-xl/lib/jxl/base/span.h4
-rw-r--r--third_party/jpeg-xl/lib/jxl/base/status.h15
11 files changed, 115 insertions, 61 deletions
diff --git a/third_party/jpeg-xl/lib/jxl/base/bits.h b/third_party/jpeg-xl/lib/jxl/base/bits.h
index 9f86118e72..a79fdc2c99 100644
--- a/third_party/jpeg-xl/lib/jxl/base/bits.h
+++ b/third_party/jpeg-xl/lib/jxl/base/bits.h
@@ -26,7 +26,8 @@ struct SizeTag {};
template <typename T>
constexpr bool IsSigned() {
- return T(0) > T(-1);
+ // TODO(eustas): remove dupes
+ return static_cast<T>(0) > static_cast<T>(-1);
}
// Undefined results for x == 0.
diff --git a/third_party/jpeg-xl/lib/jxl/base/byte_order.h b/third_party/jpeg-xl/lib/jxl/base/byte_order.h
index 8966834e08..cf8d7db082 100644
--- a/third_party/jpeg-xl/lib/jxl/base/byte_order.h
+++ b/third_party/jpeg-xl/lib/jxl/base/byte_order.h
@@ -237,22 +237,22 @@ struct OrderLE {};
// Wrappers for calling from generic code.
static JXL_INLINE void Store16(OrderBE /*tag*/, const uint32_t native,
uint8_t* p) {
- return StoreBE16(native, p);
+ StoreBE16(native, p);
}
static JXL_INLINE void Store16(OrderLE /*tag*/, const uint32_t native,
uint8_t* p) {
- return StoreLE16(native, p);
+ StoreLE16(native, p);
}
static JXL_INLINE void Store32(OrderBE /*tag*/, const uint32_t native,
uint8_t* p) {
- return StoreBE32(native, p);
+ StoreBE32(native, p);
}
static JXL_INLINE void Store32(OrderLE /*tag*/, const uint32_t native,
uint8_t* p) {
- return StoreLE32(native, p);
+ StoreLE32(native, p);
}
static JXL_INLINE uint32_t Load16(OrderBE /*tag*/, const uint8_t* p) {
diff --git a/third_party/jpeg-xl/lib/jxl/base/common.h b/third_party/jpeg-xl/lib/jxl/base/common.h
index b7fe6ab0bc..0893ef26b5 100644
--- a/third_party/jpeg-xl/lib/jxl/base/common.h
+++ b/third_party/jpeg-xl/lib/jxl/base/common.h
@@ -8,11 +8,13 @@
// Shared constants and helper functions.
+#include <array>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <memory>
#include <string>
+#include <type_traits>
#include "lib/jxl/base/compiler_specific.h"
@@ -22,11 +24,11 @@ namespace jxl {
constexpr size_t kBitsPerByte = 8; // more clear than CHAR_BIT
constexpr inline size_t RoundUpBitsToByteMultiple(size_t bits) {
- return (bits + 7) & ~size_t(7);
+ return (bits + 7) & ~static_cast<size_t>(7);
}
constexpr inline size_t RoundUpToBlockDim(size_t dim) {
- return (dim + 7) & ~size_t(7);
+ return (dim + 7) & ~static_cast<size_t>(7);
}
static inline bool JXL_MAYBE_UNUSED SafeAdd(const uint64_t a, const uint64_t b,
@@ -68,6 +70,37 @@ std::unique_ptr<T> make_unique(Args&&... args) {
using std::make_unique;
#endif
+typedef std::array<float, 3> Color;
+
+// Backported std::experimental::to_array
+
+template <typename T>
+using remove_cv_t = typename std::remove_cv<T>::type;
+
+template <size_t... I>
+struct index_sequence {};
+
+template <size_t N, size_t... I>
+struct make_index_sequence : make_index_sequence<N - 1, N - 1, I...> {};
+
+template <size_t... I>
+struct make_index_sequence<0, I...> : index_sequence<I...> {};
+
+namespace detail {
+
+template <typename T, size_t N, size_t... I>
+constexpr auto to_array(T (&&arr)[N], index_sequence<I...> _)
+ -> std::array<remove_cv_t<T>, N> {
+ return {{std::move(arr[I])...}};
+}
+
+} // namespace detail
+
+template <typename T, size_t N>
+constexpr auto to_array(T (&&arr)[N]) -> std::array<remove_cv_t<T>, N> {
+ return detail::to_array(std::move(arr), make_index_sequence<N>());
+}
+
template <typename T>
JXL_INLINE T Clamp1(T val, T low, T hi) {
return val < low ? low : val > hi ? hi : val;
@@ -77,10 +110,10 @@ JXL_INLINE T Clamp1(T val, T low, T hi) {
template <typename T>
std::string ToString(T n) {
char data[32] = {};
- if (T(0.1) != T(0)) {
+ if (std::is_floating_point<T>::value) {
// float
snprintf(data, sizeof(data), "%g", static_cast<double>(n));
- } else if (T(-1) > T(0)) {
+ } else if (std::is_unsigned<T>::value) {
// unsigned
snprintf(data, sizeof(data), "%llu", static_cast<unsigned long long>(n));
} else {
@@ -90,6 +123,9 @@ std::string ToString(T n) {
return data;
}
+#define JXL_JOIN(x, y) JXL_DO_JOIN(x, y)
+#define JXL_DO_JOIN(x, y) x##y
+
} // namespace jxl
#endif // LIB_JXL_BASE_COMMON_H_
diff --git a/third_party/jpeg-xl/lib/jxl/base/exif.h b/third_party/jpeg-xl/lib/jxl/base/exif.h
index 2caafddc04..a3574a16ff 100644
--- a/third_party/jpeg-xl/lib/jxl/base/exif.h
+++ b/third_party/jpeg-xl/lib/jxl/base/exif.h
@@ -79,7 +79,6 @@ JXL_INLINE void InterpretExif(const std::vector<uint8_t>& exif,
uint32_t count = (bigendian ? LoadBE32(t) : LoadLE32(t));
t += 4;
uint16_t value = (bigendian ? LoadBE16(t) : LoadLE16(t));
- t += 4;
if (type == 3 && count == 1 && value >= 1 && value <= 8) {
*orientation = static_cast<JxlOrientation>(value);
}
diff --git a/third_party/jpeg-xl/lib/jxl/base/float.h b/third_party/jpeg-xl/lib/jxl/base/float.h
index 00e112bb34..0f5b3b1f3a 100644
--- a/third_party/jpeg-xl/lib/jxl/base/float.h
+++ b/third_party/jpeg-xl/lib/jxl/base/float.h
@@ -17,9 +17,9 @@
namespace jxl {
-namespace {
+namespace detail {
// Based on highway scalar implementation, for testing
-float LoadFloat16(uint16_t bits16) {
+static JXL_INLINE float LoadFloat16(uint16_t bits16) {
const uint32_t sign = bits16 >> 15;
const uint32_t biased_exp = (bits16 >> 10) & 0x1F;
const uint32_t mantissa = bits16 & 0x3FF;
@@ -40,7 +40,7 @@ float LoadFloat16(uint16_t bits16) {
memcpy(&result, &bits32, 4);
return result;
}
-} // namespace
+} // namespace detail
template <typename SaveFloatAtFn>
static Status JXL_INLINE LoadFloatRow(const uint8_t* src, size_t count,
@@ -83,11 +83,11 @@ static Status JXL_INLINE LoadFloatRow(const uint8_t* src, size_t count,
case JXL_TYPE_FLOAT16:
if (little_endian) {
for (size_t i = 0; i < count; ++i) {
- callback(i, LoadFloat16(LoadLE16(src + stride * i)));
+ callback(i, detail::LoadFloat16(LoadLE16(src + stride * i)));
}
} else {
for (size_t i = 0; i < count; ++i) {
- callback(i, LoadFloat16(LoadBE16(src + stride * i)));
+ callback(i, detail::LoadFloat16(LoadBE16(src + stride * i)));
}
}
return true;
diff --git a/third_party/jpeg-xl/lib/jxl/base/matrix_ops.h b/third_party/jpeg-xl/lib/jxl/base/matrix_ops.h
index 1a969bd4f0..cde6a64b1e 100644
--- a/third_party/jpeg-xl/lib/jxl/base/matrix_ops.h
+++ b/third_party/jpeg-xl/lib/jxl/base/matrix_ops.h
@@ -8,6 +8,7 @@
// 3x3 matrix operations.
+#include <array>
#include <cmath> // abs
#include <cstddef>
@@ -15,66 +16,67 @@
namespace jxl {
+typedef std::array<float, 3> Vector3;
+typedef std::array<double, 3> Vector3d;
+typedef std::array<Vector3, 3> Matrix3x3;
+typedef std::array<Vector3d, 3> Matrix3x3d;
+
// Computes C = A * B, where A, B, C are 3x3 matrices.
-template <typename T>
-void Mul3x3Matrix(const T* a, const T* b, T* c) {
- alignas(16) T temp[3]; // For transposed column
+template <typename Matrix>
+void Mul3x3Matrix(const Matrix& a, const Matrix& b, Matrix& c) {
for (size_t x = 0; x < 3; x++) {
- for (size_t z = 0; z < 3; z++) {
- temp[z] = b[z * 3 + x];
- }
+ alignas(16) Vector3d temp{b[0][x], b[1][x], b[2][x]}; // transpose
for (size_t y = 0; y < 3; y++) {
- double e = 0;
- for (size_t z = 0; z < 3; z++) {
- e += a[y * 3 + z] * temp[z];
- }
- c[y * 3 + x] = e;
+ c[y][x] = a[y][0] * temp[0] + a[y][1] * temp[1] + a[y][2] * temp[2];
}
}
}
// Computes C = A * B, where A is 3x3 matrix and B is vector.
-template <typename T>
-void Mul3x3Vector(const T* a, const T* b, T* c) {
+template <typename Matrix, typename Vector>
+void Mul3x3Vector(const Matrix& a, const Vector& b, Vector& c) {
for (size_t y = 0; y < 3; y++) {
double e = 0;
for (size_t x = 0; x < 3; x++) {
- e += a[y * 3 + x] * b[x];
+ e += a[y][x] * b[x];
}
c[y] = e;
}
}
// Inverts a 3x3 matrix in place.
-template <typename T>
-Status Inv3x3Matrix(T* matrix) {
+template <typename Matrix>
+Status Inv3x3Matrix(Matrix& matrix) {
// Intermediate computation is done in double precision.
- double temp[9];
- temp[0] = static_cast<double>(matrix[4]) * matrix[8] -
- static_cast<double>(matrix[5]) * matrix[7];
- temp[1] = static_cast<double>(matrix[2]) * matrix[7] -
- static_cast<double>(matrix[1]) * matrix[8];
- temp[2] = static_cast<double>(matrix[1]) * matrix[5] -
- static_cast<double>(matrix[2]) * matrix[4];
- temp[3] = static_cast<double>(matrix[5]) * matrix[6] -
- static_cast<double>(matrix[3]) * matrix[8];
- temp[4] = static_cast<double>(matrix[0]) * matrix[8] -
- static_cast<double>(matrix[2]) * matrix[6];
- temp[5] = static_cast<double>(matrix[2]) * matrix[3] -
- static_cast<double>(matrix[0]) * matrix[5];
- temp[6] = static_cast<double>(matrix[3]) * matrix[7] -
- static_cast<double>(matrix[4]) * matrix[6];
- temp[7] = static_cast<double>(matrix[1]) * matrix[6] -
- static_cast<double>(matrix[0]) * matrix[7];
- temp[8] = static_cast<double>(matrix[0]) * matrix[4] -
- static_cast<double>(matrix[1]) * matrix[3];
- double det = matrix[0] * temp[0] + matrix[1] * temp[3] + matrix[2] * temp[6];
+ Matrix3x3d temp;
+ temp[0][0] = static_cast<double>(matrix[1][1]) * matrix[2][2] -
+ static_cast<double>(matrix[1][2]) * matrix[2][1];
+ temp[0][1] = static_cast<double>(matrix[0][2]) * matrix[2][1] -
+ static_cast<double>(matrix[0][1]) * matrix[2][2];
+ temp[0][2] = static_cast<double>(matrix[0][1]) * matrix[1][2] -
+ static_cast<double>(matrix[0][2]) * matrix[1][1];
+ temp[1][0] = static_cast<double>(matrix[1][2]) * matrix[2][0] -
+ static_cast<double>(matrix[1][0]) * matrix[2][2];
+ temp[1][1] = static_cast<double>(matrix[0][0]) * matrix[2][2] -
+ static_cast<double>(matrix[0][2]) * matrix[2][0];
+ temp[1][2] = static_cast<double>(matrix[0][2]) * matrix[1][0] -
+ static_cast<double>(matrix[0][0]) * matrix[1][2];
+ temp[2][0] = static_cast<double>(matrix[1][0]) * matrix[2][1] -
+ static_cast<double>(matrix[1][1]) * matrix[2][0];
+ temp[2][1] = static_cast<double>(matrix[0][1]) * matrix[2][0] -
+ static_cast<double>(matrix[0][0]) * matrix[2][1];
+ temp[2][2] = static_cast<double>(matrix[0][0]) * matrix[1][1] -
+ static_cast<double>(matrix[0][1]) * matrix[1][0];
+ double det = matrix[0][0] * temp[0][0] + matrix[0][1] * temp[1][0] +
+ matrix[0][2] * temp[2][0];
if (std::abs(det) < 1e-10) {
return JXL_FAILURE("Matrix determinant is too close to 0");
}
double idet = 1.0 / det;
- for (size_t i = 0; i < 9; i++) {
- matrix[i] = temp[i] * idet;
+ for (size_t j = 0; j < 3; j++) {
+ for (size_t i = 0; i < 3; i++) {
+ matrix[j][i] = temp[j][i] * idet;
+ }
}
return true;
}
diff --git a/third_party/jpeg-xl/lib/jxl/base/override.h b/third_party/jpeg-xl/lib/jxl/base/override.h
index 1f8b657974..da070e6e62 100644
--- a/third_party/jpeg-xl/lib/jxl/base/override.h
+++ b/third_party/jpeg-xl/lib/jxl/base/override.h
@@ -6,13 +6,15 @@
#ifndef LIB_JXL_BASE_OVERRIDE_H_
#define LIB_JXL_BASE_OVERRIDE_H_
+#include <cstdint>
+
// 'Trool' for command line arguments: force enable/disable, or use default.
namespace jxl {
// No effect if kDefault, otherwise forces a feature (typically a FrameHeader
// flag) on or off.
-enum class Override : int { kOn = 1, kOff = 0, kDefault = -1 };
+enum class Override : int8_t { kOn = 1, kOff = 0, kDefault = -1 };
static inline Override OverrideFromBool(bool flag) {
return flag ? Override::kOn : Override::kOff;
diff --git a/third_party/jpeg-xl/lib/jxl/base/rational_polynomial-inl.h b/third_party/jpeg-xl/lib/jxl/base/rational_polynomial-inl.h
index e073937675..7a89c0bac1 100644
--- a/third_party/jpeg-xl/lib/jxl/base/rational_polynomial-inl.h
+++ b/third_party/jpeg-xl/lib/jxl/base/rational_polynomial-inl.h
@@ -13,6 +13,7 @@
#define LIB_JXL_BASE_RATIONAL_POLYNOMIAL_INL_H_
#endif
+#include <jxl/types.h>
#include <stddef.h>
#include <hwy/highway.h>
@@ -42,7 +43,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);
diff --git a/third_party/jpeg-xl/lib/jxl/base/scope_guard.h b/third_party/jpeg-xl/lib/jxl/base/scope_guard.h
index a18a44cb79..f060c5bc1d 100644
--- a/third_party/jpeg-xl/lib/jxl/base/scope_guard.h
+++ b/third_party/jpeg-xl/lib/jxl/base/scope_guard.h
@@ -24,8 +24,8 @@ class ScopeGuard {
}
template <typename CallbackParam>
- explicit ScopeGuard(CallbackParam &&callback)
- : callback_(std::forward<CallbackParam>(callback)), armed_(true) {}
+ ScopeGuard(CallbackParam &&callback, bool armed)
+ : callback_(std::forward<CallbackParam>(callback)), armed_(armed) {}
~ScopeGuard() {
if (armed_) callback_();
@@ -40,7 +40,7 @@ class ScopeGuard {
template <typename Callback>
ScopeGuard<Callback> MakeScopeGuard(Callback &&callback) {
- return ScopeGuard<Callback>{std::forward<Callback>(callback)};
+ return ScopeGuard<Callback>{std::forward<Callback>(callback), true};
}
} // namespace jxl
diff --git a/third_party/jpeg-xl/lib/jxl/base/span.h b/third_party/jpeg-xl/lib/jxl/base/span.h
index dc1c781b9d..ba09d62316 100644
--- a/third_party/jpeg-xl/lib/jxl/base/span.h
+++ b/third_party/jpeg-xl/lib/jxl/base/span.h
@@ -64,8 +64,8 @@ class Span {
// NCT == non-const-T; compiler will complain if NCT is not compatible with T.
template <typename NCT>
- void AppendTo(std::vector<NCT>* dst) const {
- dst->insert(dst->end(), begin(), end());
+ void AppendTo(std::vector<NCT>& dst) const {
+ dst.insert(dst.end(), begin(), end());
}
private:
diff --git a/third_party/jpeg-xl/lib/jxl/base/status.h b/third_party/jpeg-xl/lib/jxl/base/status.h
index b33bd64fc3..2e88ba68ae 100644
--- a/third_party/jpeg-xl/lib/jxl/base/status.h
+++ b/third_party/jpeg-xl/lib/jxl/base/status.h
@@ -16,6 +16,7 @@
#include <type_traits>
#include <utility>
+#include "lib/jxl/base/common.h"
#include "lib/jxl/base/compiler_specific.h"
#include "lib/jxl/base/sanitizer_definitions.h"
@@ -442,7 +443,7 @@ class JXL_MUST_USE_RESULT StatusOr {
#define JXL_ASSIGN_OR_RETURN(lhs, statusor) \
PRIVATE_JXL_ASSIGN_OR_RETURN_IMPL( \
- assign_or_return_temporary_variable##__LINE__, lhs, statusor)
+ JXL_JOIN(assign_or_return_temporary_variable, __LINE__), lhs, statusor)
// NOLINTBEGIN(bugprone-macro-parentheses)
#define PRIVATE_JXL_ASSIGN_OR_RETURN_IMPL(name, lhs, statusor) \
@@ -451,6 +452,18 @@ class JXL_MUST_USE_RESULT StatusOr {
lhs = std::move(name).value();
// NOLINTEND(bugprone-macro-parentheses)
+// NB: do not use outside of tests / tools!!!
+#define JXL_ASSIGN_OR_DIE(lhs, statusor) \
+ PRIVATE_JXL_ASSIGN_OR_DIE_IMPL( \
+ JXL_JOIN(assign_or_die_temporary_variable, __LINE__), lhs, statusor)
+
+// NOLINTBEGIN(bugprone-macro-parentheses)
+#define PRIVATE_JXL_ASSIGN_OR_DIE_IMPL(name, lhs, statusor) \
+ auto name = statusor; \
+ if (!name.ok()) jxl::Abort(); \
+ lhs = std::move(name).value();
+// NOLINTEND(bugprone-macro-parentheses)
+
} // namespace jxl
#endif // LIB_JXL_BASE_STATUS_H_