diff --git a/src/BC1/BC1Encoder.cpp b/src/BC1/BC1Encoder.cpp index f8f09a6..52d854a 100644 --- a/src/BC1/BC1Encoder.cpp +++ b/src/BC1/BC1Encoder.cpp @@ -19,23 +19,22 @@ #include "BC1Encoder.h" +#include #include #include -#include #include -#include #include #include #include #include "../BlockView.h" #include "../Color.h" -#include "../Interpolator.h" #include "../Matrix4x4.h" #include "../Vector4.h" #include "../Vector4Int.h" #include "../bitwiseEnums.h" #include "../util.h" +#include "Histogram.h" #include "OrderTable.h" #include "SingleColorTable.h" @@ -288,6 +287,7 @@ void BC1Encoder::FindEndpoints(Color4x4 pixels, EncodeResults &block, const Bloc uint8_t hr6 = scale8To6(metrics.max.r); block.low = Color(lr5, lr6, lr5); + block.high = Color(hr5, hr6, hr5); } } else if (endpoint_mode == EndpointMode::LeastSquares) { // 2D Least Squares approach from Humus's example, with added inset and optimal rounding. @@ -297,7 +297,6 @@ void BC1Encoder::FindEndpoints(Color4x4 pixels, EncodeResults &block, const Bloc auto &sums = metrics.sums; auto &min = metrics.min; - auto &max = metrics.max; unsigned chan0 = (unsigned)diff.MaxChannelRGB(); // primary axis of the bounding box l[chan0] = (float)min[chan0]; @@ -312,8 +311,8 @@ void BC1Encoder::FindEndpoints(Color4x4 pixels, EncodeResults &block, const Bloc for (unsigned c = 0; c < 3; c++) { sums_xy[c] += val[chan0] * val[c]; } } - const auto &sum_x = sums[chan0]; - const auto &sum_xx = sums_xy[chan0]; + const unsigned sum_x = (unsigned)sums[chan0]; + const unsigned sum_xx = sums_xy[chan0]; float denominator = (float)(16 * sum_xx) - (float)(sum_x * sum_x); @@ -326,9 +325,9 @@ void BC1Encoder::FindEndpoints(Color4x4 pixels, EncodeResults &block, const Bloc * a = (m∑xy - ∑x∑y) / m∑x² - (∑x)² * b = (∑x²∑y - ∑xy∑x) / m∑x² - (∑x)² * see Giordano/Weir pg.103 */ - const auto chan = (chan0 + i) % 3; - const auto &sum_y = sums[chan]; - const auto &sum_xy = sums_xy[chan]; + const unsigned chan = (chan0 + i) % 3; + const unsigned sum_y = (unsigned)sums[chan]; + const unsigned sum_xy = sums_xy[chan]; float a = (float)((16 * sum_xy) - (sum_x * sum_y)) / denominator; float b = (float)((sum_xx * sum_y) - (sum_xy * sum_x)) / denominator; @@ -709,9 +708,8 @@ void BC1Encoder::RefineBlockCF(Color4x4 &pixels, EncodeResults &block, BlockMetr sums[i + 1] = sums[i] + color_vectors[p]; } - const Hash q_total = ((_flags & Flags::Exhaustive) != Flags::None) ? OrderTable::OrderCount : orderings; + const unsigned q_total = ((_flags & Flags::Exhaustive) != Flags::None) ? OrderTable::OrderCount : orderings; for (Hash q = 0; q < q_total; q++) { - Hash trial_hash = ((_flags & Flags::Exhaustive) != Flags::None) ? q : OrderTable::BestOrders[start_hash][q]; Vector4 trial_matrix = OrderTable::GetFactors(trial_hash); diff --git a/src/BC1/BC1Encoder.h b/src/BC1/BC1Encoder.h index 01d563e..40b5f70 100644 --- a/src/BC1/BC1Encoder.h +++ b/src/BC1/BC1Encoder.h @@ -20,21 +20,19 @@ #pragma once #include -#include +#include #include -#include +#include #include "../BlockEncoder.h" #include "../BlockView.h" -#include "../Interpolator.h" -#include "../bitwiseEnums.h" -#include "../ndebug.h" +#include "../Color.h" #include "BC1Block.h" -#include "OrderTable.h" #include "SingleColorTable.h" -#include "Tables.h" namespace rgbcx { +class Interpolator; +class Vector4; class BC1Encoder final : public BlockEncoder { public: @@ -163,6 +161,6 @@ class BC1Encoder final : public BlockEncoder { template void RefineBlockLS(Color4x4 &pixels, EncodeResults &block, BlockMetrics &metrics, ErrorMode error_mode, unsigned passes) const; - template void RefineBlockCF(Color4x4 &pixels, EncodeResults &block, BlockMetrics &metrics, ErrorMode error_mode, unsigned orderings) const; + template void RefineBlockCF(Color4x4 &pixels, EncodeResults &block, BlockMetrics &metrics, ErrorMode error_mode, unsigned orderings) const; }; } // namespace rgbcx diff --git a/src/BC1/Histogram.h b/src/BC1/Histogram.h index 812ae70..94d586e 100644 --- a/src/BC1/Histogram.h +++ b/src/BC1/Histogram.h @@ -72,7 +72,7 @@ template class Histogram { unsigned GetPacked() const { unsigned packed = 0; - for (unsigned i = 0; i < (N - 1); i++) { packed |= (_bins[i] << (4 * i)); } + for (unsigned i = 0; i < (N - 1); i++) { packed |= (_bins[i] << (4U * i)); } // assert(packed < HashCount); diff --git a/src/BC1/OrderTable.cpp b/src/BC1/OrderTable.cpp index 2924972..1388836 100644 --- a/src/BC1/OrderTable.cpp +++ b/src/BC1/OrderTable.cpp @@ -22,7 +22,6 @@ #include #include "../Vector4.h" -#include "Histogram.h" namespace rgbcx { using Hash = uint16_t; diff --git a/src/BC1/OrderTable.h b/src/BC1/OrderTable.h index e4410ad..0a3a901 100644 --- a/src/BC1/OrderTable.h +++ b/src/BC1/OrderTable.h @@ -21,14 +21,12 @@ #include #include +#include +#include +#include #include -#include -#include #include "../Vector4.h" -#include "../util.h" -#include "Histogram.h" -#include "Tables.h" namespace rgbcx { template class Histogram; @@ -106,7 +104,7 @@ template class OrderTable { } static Vector4 GetFactors(Hash hash) { - assert(generated); + assert(generated.load()); assert(factors != nullptr); return factors->at(hash); diff --git a/src/BlockEncoder.h b/src/BlockEncoder.h index 9568a3e..bf78fab 100644 --- a/src/BlockEncoder.h +++ b/src/BlockEncoder.h @@ -19,8 +19,8 @@ #pragma once -#include #include +#include #include "BlockView.h" @@ -59,11 +59,7 @@ template class BlockEncoder { assert(pixel_x + N <= image_width); unsigned top_left = pixel_x + (pixel_y * image_width); - auto src = DecodedBlock(&decoded[top_left], image_width); - - if (pixel_x == 272 && pixel_y == 748) { - int foo = 3; - } + auto src = DecodedBlock(&decoded[top_left], (int)image_width); EncodeBlock(src, &blocks[x + block_width * y]); } diff --git a/src/BlockView.h b/src/BlockView.h index d064f89..feffc86 100644 --- a/src/BlockView.h +++ b/src/BlockView.h @@ -150,7 +150,7 @@ template class ColorBlockView : public BlockView