summaryrefslogtreecommitdiffstats
path: root/third_party/jpeg-xl/lib/jxl/enc_linalg.cc
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/jpeg-xl/lib/jxl/enc_linalg.cc')
-rw-r--r--third_party/jpeg-xl/lib/jxl/enc_linalg.cc37
1 files changed, 17 insertions, 20 deletions
diff --git a/third_party/jpeg-xl/lib/jxl/enc_linalg.cc b/third_party/jpeg-xl/lib/jxl/enc_linalg.cc
index fe2090a909..452c17f4e8 100644
--- a/third_party/jpeg-xl/lib/jxl/enc_linalg.cc
+++ b/third_party/jpeg-xl/lib/jxl/enc_linalg.cc
@@ -7,46 +7,43 @@
#include <cmath>
-#include "lib/jxl/base/compiler_specific.h"
#include "lib/jxl/base/status.h"
namespace jxl {
-void ConvertToDiagonal(const ImageD& A, ImageD* const JXL_RESTRICT diag,
- ImageD* const JXL_RESTRICT U) {
+void ConvertToDiagonal(const Matrix2x2& A, Vector2& diag, Matrix2x2& U) {
#if JXL_ENABLE_ASSERT
- JXL_ASSERT(A.xsize() == 2);
- JXL_ASSERT(A.ysize() == 2);
- JXL_ASSERT(std::abs(A.Row(0)[1] - A.Row(1)[0]) < 1e-15);
+ // Check A is symmetric.
+ JXL_ASSERT(std::abs(A[0][1] - A[1][0]) < 1e-15);
#endif
- if (std::abs(A.ConstRow(0)[1]) < 1e-15) {
+ if (std::abs(A[0][1]) < 1e-15) {
// Already diagonal.
- diag->Row(0)[0] = A.ConstRow(0)[0];
- diag->Row(0)[1] = A.ConstRow(1)[1];
- U->Row(0)[0] = U->Row(1)[1] = 1.0;
- U->Row(0)[1] = U->Row(1)[0] = 0.0;
+ diag[0] = A[0][0];
+ diag[1] = A[1][1];
+ U[0][0] = U[1][1] = 1.0;
+ U[0][1] = U[1][0] = 0.0;
return;
}
- double b = -(A.Row(0)[0] + A.Row(1)[1]);
- double c = A.Row(0)[0] * A.Row(1)[1] - A.Row(0)[1] * A.Row(0)[1];
+ double b = -(A[0][0] + A[1][1]);
+ double c = A[0][0] * A[1][1] - A[0][1] * A[0][1];
double d = b * b - 4.0 * c;
double sqd = std::sqrt(d);
double l1 = (-b - sqd) * 0.5;
double l2 = (-b + sqd) * 0.5;
- double v1[2] = {A.Row(0)[0] - l1, A.Row(1)[0]};
+ Vector2 v1 = {A[0][0] - l1, A[1][0]};
double v1n = 1.0 / std::hypot(v1[0], v1[1]);
v1[0] = v1[0] * v1n;
v1[1] = v1[1] * v1n;
- diag->Row(0)[0] = l1;
- diag->Row(0)[1] = l2;
+ diag[0] = l1;
+ diag[1] = l2;
- U->Row(0)[0] = v1[1];
- U->Row(0)[1] = -v1[0];
- U->Row(1)[0] = v1[0];
- U->Row(1)[1] = v1[1];
+ U[0][0] = v1[1];
+ U[0][1] = -v1[0];
+ U[1][0] = v1[0];
+ U[1][1] = v1[1];
}
} // namespace jxl