Ground work for 3Color-black blocks

This commit is contained in:
Andrew Cassidy 2021-03-02 18:27:35 -08:00
parent f7f5a10b66
commit 4eb8c397f9
3 changed files with 15 additions and 6 deletions

View File

@ -667,6 +667,7 @@ void BC1Encoder::RefineBlockLS(Color4x4 &pixels, EncodeResults &block, BlockMetr
}
}
}
template <ColorMode M>
void BC1Encoder::RefineBlockCF(Color4x4 &pixels, EncodeResults &block, BlockMetrics &metrics, ErrorMode error_mode, unsigned orderings) const {
const int color_count = (unsigned)M & 0x0F;

View File

@ -131,7 +131,7 @@ template <size_t M, size_t N> class ColorBlockView : public BlockView<Color, M,
return true;
}
BlockMetrics GetMetrics(unsigned black_threshold = 4) {
BlockMetrics GetMetrics(bool ignore_black = false) {
BlockMetrics metrics;
metrics.min = Color(UINT8_MAX, UINT8_MAX, UINT8_MAX);
metrics.max = Color(0, 0, 0);
@ -139,18 +139,26 @@ template <size_t M, size_t N> class ColorBlockView : public BlockView<Color, M,
metrics.is_greyscale = true;
metrics.sums = {0, 0, 0};
unsigned total = 0;
for (unsigned i = 0; i < M * N; i++) {
auto val = Base::Get(i);
Color val = Base::Get(i);
bool is_black = val.IsBlack();
metrics.has_black |= is_black;
if (ignore_black && is_black) { continue; }
metrics.is_greyscale &= val.IsGrayscale();
for (unsigned c = 0; c < 3; c++) {
metrics.min[c] = std::min(metrics.min[c], val[c]);
metrics.max[c] = std::max(metrics.max[c], val[c]);
metrics.sums[c] += val[c];
}
metrics.is_greyscale &= ((val.r == val.g) && (val.r == val.b));
metrics.has_black |= (val.r | val.g | val.b < black_threshold);
total++;
}
for (unsigned c = 0; c < 3; c++) { metrics.avg[c] = (uint8_t)((unsigned)metrics.sums[c] / (M * N)); }
if (total > 0) metrics.avg = (metrics.sum + Vector4Int(total / 2)) / total; // half-total added for better rounding
return metrics;
}

View File

@ -29,7 +29,7 @@ namespace rgbcx {
class Vector4Int {
public:
Vector4Int(int x = 0, int y = 0, int z = 0, int w = 0) {
Vector4Int(int x, int y, int z = 0, int w = 0) {
_c[0] = x;
_c[1] = y;
_c[2] = z;