3 Commits

Author SHA1 Message Date
6427edb050 mark matrix functions as const 2021-02-21 16:32:14 -08:00
d0f8272fa5 Add more notes for future optimization 2021-02-21 16:27:43 -08:00
d21798d4a4 Include cmath 2021-02-21 16:25:58 -08:00
3 changed files with 7 additions and 5 deletions

View File

@ -21,6 +21,7 @@
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <cmath>
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
@ -339,7 +340,8 @@ void BC1Encoder::FindEndpoints(Color4x4 pixels, BC1Encoder::Flags flags, const B
if (covariance[0][2] < 0) delta[0] = -delta[0]; // r vs b if (covariance[0][2] < 0) delta[0] = -delta[0]; // r vs b
if (covariance[1][2] < 0) delta[1] = -delta[1]; // g vs b if (covariance[1][2] < 0) delta[1] = -delta[1]; // g vs b
// using the covariance matrix, iteratively stretch the delta vector towards the primary axis of the data // using the covariance matrix, stretch the delta vector towards the primary axis of the data using power iteration
// the end result of this may actually be the same as the least squares approach, will have to do more research
for (unsigned power_iter = 0; power_iter < total_power_iters; power_iter++) { delta = covariance * delta; } for (unsigned power_iter = 0; power_iter < total_power_iters; power_iter++) { delta = covariance * delta; }
// if we found any correlation, then this is our new axis. otherwise we fallback to the luma vector // if we found any correlation, then this is our new axis. otherwise we fallback to the luma vector

View File

@ -21,7 +21,7 @@
namespace rgbcx { namespace rgbcx {
Matrix4x4 operator*(Matrix4x4& lhs, Matrix4x4& rhs) { Matrix4x4 operator*(const Matrix4x4& lhs, const Matrix4x4& rhs) {
Matrix4x4 trans_rhs = rhs.Transpose(); // 🏳️‍⚧️ Matrix4x4 trans_rhs = rhs.Transpose(); // 🏳️‍⚧️
Matrix4x4 result; Matrix4x4 result;
for (unsigned r = 0; r < 4; r++) { for (unsigned r = 0; r < 4; r++) {
@ -31,7 +31,7 @@ Matrix4x4 operator*(Matrix4x4& lhs, Matrix4x4& rhs) {
return result; return result;
} }
Vector4 operator*(Matrix4x4& lhs, Vector4& rhs) { Vector4 operator*(const Matrix4x4& lhs, const Vector4& rhs) {
Vector4 result; Vector4 result;
for (unsigned r = 0; r < 4; r++) { result[r] = rhs.Dot(lhs[r]); } for (unsigned r = 0; r < 4; r++) { result[r] = rhs.Dot(lhs[r]); }

View File

@ -34,7 +34,7 @@ class Matrix4x4 {
return result; return result;
} }
static Matrix4x4 Transpose(Matrix4x4 &val) { static Matrix4x4 Transpose(const Matrix4x4 &val) {
Matrix4x4 result; Matrix4x4 result;
for (unsigned r = 0; r < 3; r++) { for (unsigned r = 0; r < 3; r++) {
for (unsigned c = 0; c < 3; c++) { result[r][c] = val[c][r]; } for (unsigned c = 0; c < 3; c++) { result[r][c] = val[c][r]; }
@ -71,7 +71,7 @@ class Matrix4x4 {
friend Matrix4x4 &operator*=(Matrix4x4 &lhs, const float &rhs) { return lhs = lhs * rhs; } friend Matrix4x4 &operator*=(Matrix4x4 &lhs, const float &rhs) { return lhs = lhs * rhs; }
friend Matrix4x4 &operator/=(Matrix4x4 &lhs, const float &rhs) { return lhs = lhs / rhs; } friend Matrix4x4 &operator/=(Matrix4x4 &lhs, const float &rhs) { return lhs = lhs / rhs; }
Matrix4x4 Transpose() { return Transpose(*this); } Matrix4x4 Transpose() const { return Transpose(*this); }
void Mirror(); void Mirror();