mirror of
https://github.com/drewcassidy/quicktex.git
synced 2024-09-13 06:37:34 +00:00
Ground work for 3Color-black blocks
This commit is contained in:
parent
f7f5a10b66
commit
4eb8c397f9
@ -667,6 +667,7 @@ void BC1Encoder::RefineBlockLS(Color4x4 &pixels, EncodeResults &block, BlockMetr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <ColorMode M>
|
template <ColorMode M>
|
||||||
void BC1Encoder::RefineBlockCF(Color4x4 &pixels, EncodeResults &block, BlockMetrics &metrics, ErrorMode error_mode, unsigned orderings) const {
|
void BC1Encoder::RefineBlockCF(Color4x4 &pixels, EncodeResults &block, BlockMetrics &metrics, ErrorMode error_mode, unsigned orderings) const {
|
||||||
const int color_count = (unsigned)M & 0x0F;
|
const int color_count = (unsigned)M & 0x0F;
|
||||||
|
@ -131,7 +131,7 @@ template <size_t M, size_t N> class ColorBlockView : public BlockView<Color, M,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockMetrics GetMetrics(unsigned black_threshold = 4) {
|
BlockMetrics GetMetrics(bool ignore_black = false) {
|
||||||
BlockMetrics metrics;
|
BlockMetrics metrics;
|
||||||
metrics.min = Color(UINT8_MAX, UINT8_MAX, UINT8_MAX);
|
metrics.min = Color(UINT8_MAX, UINT8_MAX, UINT8_MAX);
|
||||||
metrics.max = Color(0, 0, 0);
|
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.is_greyscale = true;
|
||||||
metrics.sums = {0, 0, 0};
|
metrics.sums = {0, 0, 0};
|
||||||
|
|
||||||
|
unsigned total = 0;
|
||||||
|
|
||||||
for (unsigned i = 0; i < M * N; i++) {
|
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++) {
|
for (unsigned c = 0; c < 3; c++) {
|
||||||
metrics.min[c] = std::min(metrics.min[c], val[c]);
|
metrics.min[c] = std::min(metrics.min[c], val[c]);
|
||||||
metrics.max[c] = std::max(metrics.max[c], val[c]);
|
metrics.max[c] = std::max(metrics.max[c], val[c]);
|
||||||
metrics.sums[c] += val[c];
|
metrics.sums[c] += val[c];
|
||||||
}
|
}
|
||||||
metrics.is_greyscale &= ((val.r == val.g) && (val.r == val.b));
|
total++;
|
||||||
metrics.has_black |= (val.r | val.g | val.b < black_threshold);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
return metrics;
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ namespace rgbcx {
|
|||||||
|
|
||||||
class Vector4Int {
|
class Vector4Int {
|
||||||
public:
|
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[0] = x;
|
||||||
_c[1] = y;
|
_c[1] = y;
|
||||||
_c[2] = z;
|
_c[2] = z;
|
||||||
|
Loading…
Reference in New Issue
Block a user