Rename Color to prepare for refactor

This commit is contained in:
Andrew Cassidy 2022-05-25 23:42:06 -07:00
parent fffa291765
commit c96450b5fe
17 changed files with 134 additions and 133 deletions

View File

@ -25,7 +25,7 @@
#include <cstring>
#include <stdexcept>
#include "Color.h"
#include "OldColor.h"
#include "Vector4Int.h"
namespace quicktex {
@ -34,9 +34,9 @@ using Coords = std::tuple<int, int>;
template <int N, int M> class ColorBlock {
public:
struct Metrics {
Color min;
Color max;
Color avg;
OldColor min;
OldColor max;
OldColor avg;
bool is_greyscale;
bool has_black;
Vector4Int sums;
@ -45,37 +45,37 @@ template <int N, int M> class ColorBlock {
static constexpr int Width = N;
static constexpr int Height = M;
constexpr Color Get(int x, int y) const {
constexpr OldColor Get(int x, int y) const {
if (x >= Width || x < 0) throw std::invalid_argument("x value out of range");
if (y >= Height || y < 0) throw std::invalid_argument("y value out of range");
return _pixels[x + (N * y)];
}
constexpr Color Get(int i) const {
constexpr OldColor Get(int i) const {
if (i >= N * M || i < 0) throw std::invalid_argument("i value out of range");
return _pixels[i];
}
void Set(int x, int y, const Color &value) {
void Set(int x, int y, const OldColor &value) {
if (x >= Width || x < 0) throw std::invalid_argument("x value out of range");
if (y >= Height || y < 0) throw std::invalid_argument("y value out of range");
_pixels[x + (N * y)] = value;
}
void Set(int i, const Color &value) {
void Set(int i, const OldColor &value) {
if (i >= N * M || i < 0) throw std::invalid_argument("i value out of range");
_pixels[i] = value;
}
void GetRow(int y, Color *dst) const {
void GetRow(int y, OldColor *dst) const {
if (y >= Height || y < 0) throw std::invalid_argument("y value out of range");
std::memcpy(dst, &_pixels[N * y], N * sizeof(Color));
std::memcpy(dst, &_pixels[N * y], N * sizeof(OldColor));
}
void SetRow(int y, const Color *src) {
void SetRow(int y, const OldColor *src) {
if (y >= Height || y < 0) throw std::invalid_argument("y value out of range");
std::memcpy(&_pixels[N * y], src, N * sizeof(Color));
std::memcpy(&_pixels[N * y], src, N * sizeof(OldColor));
}
bool IsSingleColor() const {
@ -88,8 +88,8 @@ template <int N, int M> class ColorBlock {
Metrics GetMetrics(bool ignore_black = false) const {
Metrics metrics;
metrics.min = Color(UINT8_MAX, UINT8_MAX, UINT8_MAX);
metrics.max = Color(0, 0, 0);
metrics.min = OldColor(UINT8_MAX, UINT8_MAX, UINT8_MAX);
metrics.max = OldColor(0, 0, 0);
metrics.has_black = false;
metrics.is_greyscale = true;
metrics.sums = {0, 0, 0};
@ -97,7 +97,7 @@ template <int N, int M> class ColorBlock {
unsigned total = 0;
for (unsigned i = 0; i < M * N; i++) {
Color val = Get(i);
OldColor val = Get(i);
bool is_black = val.IsBlack();
metrics.has_black |= is_black;
@ -118,7 +118,7 @@ template <int N, int M> class ColorBlock {
}
private:
std::array<Color, N * M> _pixels;
std::array<OldColor, N * M> _pixels;
};
} // namespace quicktex

View File

@ -16,7 +16,7 @@
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Color.h"
#include "OldColor.h"
#include <algorithm>
#include <stdexcept>
@ -27,7 +27,7 @@
namespace quicktex {
Color::Color(Vector4Int v) {
OldColor::OldColor(Vector4Int v) {
if (v.MaxAbs() > 0xFF) throw std::invalid_argument("Vector members out of range");
for (int i = 0; i < 4; i++) {
if (v[i] < 0) throw std::range_error("Color members cannot be negative");
@ -39,32 +39,32 @@ Color::Color(Vector4Int v) {
a = static_cast<uint8_t>(v[3]);
}
uint16_t Color::Pack565Unscaled(uint8_t r, uint8_t g, uint8_t b) {
uint16_t OldColor::Pack565Unscaled(uint8_t r, uint8_t g, uint8_t b) {
assert5bit(r);
assert6bit(g);
assert5bit(b);
return static_cast<uint16_t>(b | (g << 5) | (r << 11));
}
uint16_t Color::Pack565(uint8_t r, uint8_t g, uint8_t b) { return Pack565Unscaled(scale8To5(r), scale8To6(g), scale8To5(b)); }
uint16_t OldColor::Pack565(uint8_t r, uint8_t g, uint8_t b) { return Pack565Unscaled(scale8To5(r), scale8To6(g), scale8To5(b)); }
Color Color::Unpack565Unscaled(uint16_t Packed) {
OldColor OldColor::Unpack565Unscaled(uint16_t Packed) {
uint8_t r = (Packed >> 11) & 0x1F;
uint8_t g = (Packed >> 5) & 0x3F;
uint8_t b = Packed & 0x1F;
return Color(r, g, b);
return OldColor(r, g, b);
}
Color Color::Unpack565(uint16_t Packed) {
OldColor OldColor::Unpack565(uint16_t Packed) {
uint8_t r = static_cast<uint8_t>(scale5To8((Packed >> 11) & 0x1FU));
uint8_t g = static_cast<uint8_t>(scale6To8((Packed >> 5) & 0x3FU));
uint8_t b = static_cast<uint8_t>(scale5To8(Packed & 0x1FU));
return Color(r, g, b);
return OldColor(r, g, b);
}
Color Color::PreciseRound565(Vector4 &v) {
OldColor OldColor::PreciseRound565(Vector4 &v) {
int trial_r = (int)(v[0] * UINT5_MAX);
int trial_g = (int)(v[1] * UINT6_MAX);
int trial_b = (int)(v[2] * UINT5_MAX);
@ -83,46 +83,46 @@ Color Color::PreciseRound565(Vector4 &v) {
assert6bit(g);
assert5bit(b);
return Color(r, g, b);
return OldColor(r, g, b);
}
void Color::SetRGB(uint8_t vr, uint8_t vg, uint8_t vb) {
void OldColor::SetRGB(uint8_t vr, uint8_t vg, uint8_t vb) {
r = vr;
g = vg;
b = vb;
}
size_t Color::MinChannelRGB() {
size_t OldColor::MinChannelRGB() {
if (r <= g && r <= b) return 0;
if (g <= b && g <= r) return 1;
return 2;
}
size_t Color::MaxChannelRGB() {
size_t OldColor::MaxChannelRGB() {
if (r >= g && r >= b) return 0;
if (g >= b && g >= r) return 1;
return 2;
}
Color Color::Min(const Color &A, const Color &B) { return Color(std::min(A[0], B[0]), std::min(A[1], B[1]), std::min(A[2], B[2]), std::min(A[3], B[3])); }
OldColor OldColor::Min(const OldColor &A, const OldColor &B) { return OldColor(std::min(A[0], B[0]), std::min(A[1], B[1]), std::min(A[2], B[2]), std::min(A[3], B[3])); }
Color Color::Max(const Color &a, const Color &b) { return Color(std::max(a[0], b[0]), std::max(a[1], b[1]), std::max(a[2], b[2]), std::max(a[3], b[3])); }
OldColor OldColor::Max(const OldColor &a, const OldColor &b) { return OldColor(std::max(a[0], b[0]), std::max(a[1], b[1]), std::max(a[2], b[2]), std::max(a[3], b[3])); }
Color::operator Vector4() const { return Vector4(r, g, b, a); }
Color::operator Vector4Int() const { return Vector4Int(r, g, b, a); }
Vector4Int operator-(const Color &lhs, const Color &rhs) {
OldColor::operator Vector4() const { return Vector4(r, g, b, a); }
OldColor::operator Vector4Int() const { return Vector4Int(r, g, b, a); }
Vector4Int operator-(const OldColor &lhs, const OldColor &rhs) {
Vector4Int result;
for (unsigned i = 0; i < 4; i++) { result[i] = (int)lhs[i] - rhs[i]; }
return result;
}
uint16_t Color::Pack565() const { return Pack565(r, g, b); }
uint16_t Color::Pack565Unscaled() const { return Pack565Unscaled(r, g, b); }
uint16_t OldColor::Pack565() const { return Pack565(r, g, b); }
uint16_t OldColor::Pack565Unscaled() const { return Pack565Unscaled(r, g, b); }
Color Color::ScaleTo565() const { return Color(scale8To5(r), scale8To6(g), scale8To5(b)); }
Color Color::ScaleFrom565() const { return Color(scale5To8(r), scale6To8(g), scale5To8(b)); }
OldColor OldColor::ScaleTo565() const { return OldColor(scale8To5(r), scale8To6(g), scale8To5(b)); }
OldColor OldColor::ScaleFrom565() const { return OldColor(scale5To8(r), scale6To8(g), scale5To8(b)); }
bool Color::operator==(const Color &Rhs) const { return r == Rhs.r && g == Rhs.g && b == Rhs.b && a == Rhs.a; }
bool Color::operator!=(const Color &Rhs) const { return !(Rhs == *this); }
bool OldColor::operator==(const OldColor &Rhs) const { return r == Rhs.r && g == Rhs.g && b == Rhs.b && a == Rhs.a; }
bool OldColor::operator!=(const OldColor &Rhs) const { return !(Rhs == *this); }
} // namespace quicktex

View File

@ -27,32 +27,32 @@ class Vector4;
class Vector4Int;
#pragma pack(push, 1)
class Color {
class OldColor {
public:
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
constexpr Color() : Color(0, 0, 0, 0xFF) {}
constexpr OldColor() : OldColor(0, 0, 0, 0xFF) {}
constexpr Color(uint8_t vr, uint8_t vg, uint8_t vb, uint8_t va = 0xFF) : r(vr), g(vg), b(vb), a(va) {}
constexpr OldColor(uint8_t vr, uint8_t vg, uint8_t vb, uint8_t va = 0xFF) : r(vr), g(vg), b(vb), a(va) {}
Color(Vector4Int v);
OldColor(Vector4Int v);
static uint16_t Pack565Unscaled(uint8_t r, uint8_t g, uint8_t b);
static uint16_t Pack565(uint8_t r, uint8_t g, uint8_t b);
static Color Unpack565Unscaled(uint16_t Packed);
static Color Unpack565(uint16_t Packed);
static OldColor Unpack565Unscaled(uint16_t Packed);
static OldColor Unpack565(uint16_t Packed);
static Color PreciseRound565(Vector4 &v);
static OldColor PreciseRound565(Vector4 &v);
static Color Min(const Color &A, const Color &B);
static Color Max(const Color &A, const Color &B);
static OldColor Min(const OldColor &A, const OldColor &B);
static OldColor Max(const OldColor &A, const OldColor &B);
bool operator==(const Color &Rhs) const;
bool operator!=(const Color &Rhs) const;
bool operator==(const OldColor &Rhs) const;
bool operator!=(const OldColor &Rhs) const;
uint8_t operator[](size_t index) const {
assert(index < 4);
@ -65,16 +65,16 @@ class Color {
operator Vector4() const;
operator Vector4Int() const;
friend Vector4Int operator-(const Color &lhs, const Color &rhs);
friend Vector4Int operator-(const OldColor &lhs, const OldColor &rhs);
void SetRGB(uint8_t vr, uint8_t vg, uint8_t vb);
void SetRGB(const Color &other) { SetRGB(other.r, other.g, other.b); }
void SetRGB(const OldColor &other) { SetRGB(other.r, other.g, other.b); }
uint16_t Pack565() const;
uint16_t Pack565Unscaled() const;
Color ScaleTo565() const;
Color ScaleFrom565() const;
OldColor ScaleTo565() const;
OldColor ScaleFrom565() const;
size_t MinChannelRGB();
size_t MaxChannelRGB();

View File

@ -30,8 +30,8 @@
#include <type_traits>
#include <vector>
#include "Color.h"
#include "ColorBlock.h"
#include "OldColor.h"
namespace quicktex {
@ -73,19 +73,19 @@ class RawTexture : public Texture {
*/
RawTexture(int width, int height) : Base(width, height), _pixels(_width * _height) {}
Color GetPixel(int x, int y) const {
OldColor GetPixel(int x, int y) const {
if (x < 0 || x >= _width) throw std::invalid_argument("x value out of range.");
if (y < 0 || y >= _height) throw std::invalid_argument("y value out of range.");
return _pixels.at(x + (y * _width));
}
void SetPixel(int x, int y, Color val) {
void SetPixel(int x, int y, OldColor val) {
if (x < 0 || x >= _width) throw std::invalid_argument("x value out of range.");
if (y < 0 || y >= _height) throw std::invalid_argument("y value out of range.");
_pixels.at(x + (y * _width)) = val;
}
size_t NBytes() const noexcept override { return static_cast<unsigned long>(Width() * Height()) * sizeof(Color); }
size_t NBytes() const noexcept override { return static_cast<unsigned long>(Width() * Height()) * sizeof(OldColor); }
template <int N, int M> ColorBlock<N, M> GetBlock(int block_x, int block_y) const {
if (block_x < 0) throw std::out_of_range("x value out of range.");
@ -138,7 +138,7 @@ class RawTexture : public Texture {
virtual uint8_t *Data() noexcept override { return reinterpret_cast<uint8_t *>(_pixels.data()); }
protected:
std::vector<Color> _pixels;
std::vector<OldColor> _pixels;
};
template <typename B> class BlockTexture final : public Texture {

View File

@ -23,7 +23,7 @@
#include <cmath>
#include <functional>
#include "Color.h"
#include "OldColor.h"
namespace quicktex {
@ -45,11 +45,11 @@ class Vector4 {
_c[3] = scalar;
}
Vector4(const Color &c) : Vector4(c.r, c.g, c.b, c.a) {}
Vector4(const OldColor &c) : Vector4(c.r, c.g, c.b, c.a) {}
static Vector4 FromColor(const Color &c) { return Vector4(c); }
static Vector4 FromColor(const OldColor &c) { return Vector4(c); }
static Vector4 FromColorRGB(const Color &c) { return Vector4(c.r, c.g, c.b); }
static Vector4 FromColorRGB(const OldColor &c) { return Vector4(c.r, c.g, c.b); }
static float Dot(const Vector4 &lhs, const Vector4 &rhs) {
float sum = 0;

View File

@ -22,7 +22,7 @@
#include <array>
#include <functional>
#include "Color.h"
#include "OldColor.h"
#include "Vector4.h"
namespace quicktex {
@ -45,11 +45,11 @@ class Vector4Int {
_c[3] = scalar;
}
Vector4Int(const Color &c) : Vector4Int(c.r, c.g, c.b, c.a) {}
Vector4Int(const OldColor &c) : Vector4Int(c.r, c.g, c.b, c.a) {}
static Vector4Int FromColor(const Color &c) { return Vector4Int(c); }
static Vector4Int FromColor(const OldColor &c) { return Vector4Int(c); }
static Vector4Int FromColorRGB(const Color &c) { return Vector4Int(c.r, c.g, c.b); }
static Vector4Int FromColorRGB(const OldColor &c) { return Vector4Int(c.r, c.g, c.b); }
static int Dot(const Vector4Int &lhs, const Vector4Int &rhs) {
int sum = 0;

View File

@ -22,9 +22,9 @@
#include <pybind11/pybind11.h>
#include <utest.h>
#include "Color.h"
#include "Decoder.h"
#include "Encoder.h"
#include "OldColor.h"
#include "Texture.h"
#include "_bindings.h"

View File

@ -28,17 +28,17 @@
#include <stdexcept>
#include <type_traits>
#include "Color.h"
#include "ColorBlock.h"
#include "OldColor.h"
#include "Texture.h"
#include "util.h"
namespace pybind11::detail {
using namespace quicktex;
/// Type caster for color class to allow it to be converted to and from a python tuple
template <> struct type_caster<Color> {
template <> struct type_caster<OldColor> {
public:
PYBIND11_TYPE_CASTER(Color, _("Color"));
PYBIND11_TYPE_CASTER(OldColor, _("Color"));
bool load(handle src, bool) {
PyObject* source = src.ptr();
@ -70,7 +70,7 @@ template <> struct type_caster<Color> {
return !PyErr_Occurred();
}
static handle cast(Color src, return_value_policy, handle) {
static handle cast(OldColor src, return_value_policy, handle) {
PyObject* val = PyTuple_New(4);
for (int i = 0; i < 4; i++) {

View File

@ -24,7 +24,7 @@
#include <cstdlib>
#include <utility>
#include "../../Color.h"
#include "../../OldColor.h"
namespace quicktex::s3tc {
@ -39,7 +39,7 @@ class alignas(8) BC1Block {
static constexpr uint8_t SelectorMax = (1 << SelectorBits) - 1; // maximum value of a selector
using SelectorArray = std::array<std::array<uint8_t, Width>, Height>;
using ColorPair = std::pair<Color, Color>;
using ColorPair = std::pair<OldColor, OldColor>;
private:
std::array<uint8_t, EndpointSize> _color0;
@ -60,7 +60,7 @@ class alignas(8) BC1Block {
* @param color1 second endpoint color
* @param selectors the selectors as a 4x4 list of integers, between 0 and 3 inclusive.
*/
BC1Block(Color color0, Color color1, const SelectorArray& selectors) {
BC1Block(OldColor color0, OldColor color1, const SelectorArray& selectors) {
SetColor0(color0);
SetColor1(color1);
SetSelectors(selectors);
@ -96,12 +96,12 @@ class alignas(8) BC1Block {
void SetColor0Raw(uint16_t c);
void SetColor1Raw(uint16_t c);
Color GetColor0() const { return Color::Unpack565(GetColor0Raw()); }
Color GetColor1() const { return Color::Unpack565(GetColor1Raw()); }
OldColor GetColor0() const { return OldColor::Unpack565(GetColor0Raw()); }
OldColor GetColor1() const { return OldColor::Unpack565(GetColor1Raw()); }
ColorPair GetColors() const { return {GetColor0(), GetColor1()}; }
void SetColor0(Color c) { SetColor0Raw(c.Pack565()); }
void SetColor1(Color c) { SetColor1Raw(c.Pack565()); }
void SetColor0(OldColor c) { SetColor0Raw(c.Pack565()); }
void SetColor1(OldColor c) { SetColor1Raw(c.Pack565()); }
void SetColors(ColorPair cs) {
SetColor0(cs.first);
SetColor1(cs.second);

View File

@ -23,8 +23,8 @@
#include <cassert>
#include <cstdint>
#include "../../Color.h"
#include "../../ColorBlock.h"
#include "../../OldColor.h"
#include "BC1Block.h"
namespace quicktex::s3tc {

View File

@ -29,9 +29,9 @@
#include <stdexcept>
#include <type_traits>
#include "../../Color.h"
#include "../../ColorBlock.h"
#include "../../Matrix4x4.h"
#include "../../OldColor.h"
#include "../../Texture.h"
#include "../../VecUtil.h"
#include "../../Vector4.h"
@ -358,7 +358,7 @@ BC1Block BC1Encoder::EncodeBlock(const ColorBlock<4, 4> &pixels) const {
}
// Private methods
BC1Block BC1Encoder::WriteBlockSolid(Color color) const {
BC1Block BC1Encoder::WriteBlockSolid(OldColor color) const {
uint8_t mask = 0xAA; // 2222
uint16_t min16, max16;
@ -456,7 +456,7 @@ BC1Block BC1Encoder::WriteBlock(EncodeResults &result) const {
return BC1Block(ep0, ep1, selectors);
}
void BC1Encoder::FindEndpointsSingleColor(EncodeResults &result, Color color, bool is_3color) const {
void BC1Encoder::FindEndpointsSingleColor(EncodeResults &result, OldColor color, bool is_3color) const {
auto &match5 = is_3color ? _single_match5_half : _single_match5;
auto &match6 = is_3color ? _single_match6_half : _single_match6;
@ -466,14 +466,14 @@ void BC1Encoder::FindEndpointsSingleColor(EncodeResults &result, Color color, bo
result.color_mode = is_3color ? ColorMode::ThreeColor : ColorMode::FourColor;
result.error = match_r.error + match_g.error + match_b.error;
result.low = Color(match_r.low, match_g.low, match_b.low);
result.high = Color(match_r.high, match_g.high, match_b.high);
result.low = OldColor(match_r.low, match_g.low, match_b.low);
result.high = OldColor(match_r.high, match_g.high, match_b.high);
// selectors decided when writing, no point deciding them now
}
void BC1Encoder::FindEndpointsSingleColor(EncodeResults &result, const CBlock &pixels, Color color,
void BC1Encoder::FindEndpointsSingleColor(EncodeResults &result, const CBlock &pixels, OldColor color,
bool is_3color) const {
std::array<Color, 4> colors = _interpolator->InterpolateBC1(result.low, result.high, is_3color);
std::array<OldColor, 4> colors = _interpolator->InterpolateBC1(result.low, result.high, is_3color);
Vector4Int result_vector = (Vector4Int)colors[2];
FindEndpointsSingleColor(result, color, is_3color);
@ -498,7 +498,7 @@ void BC1Encoder::FindEndpoints(EncodeResults &result, const CBlock &pixels, cons
uint8_t fr5 = (uint8_t)scale8To5(fr);
uint8_t fr6 = (uint8_t)scale8To6(fr);
result.low = Color(fr5, fr6, fr5);
result.low = OldColor(fr5, fr6, fr5);
result.high = result.low;
} else {
uint8_t lr5 = scale8To5(metrics.min.r);
@ -507,12 +507,13 @@ void BC1Encoder::FindEndpoints(EncodeResults &result, const CBlock &pixels, cons
uint8_t hr5 = scale8To5(metrics.max.r);
uint8_t hr6 = scale8To6(metrics.max.r);
result.low = Color(lr5, lr6, lr5);
result.high = Color(hr5, hr6, hr5);
result.low = OldColor(lr5, lr6, lr5);
result.high = OldColor(hr5, hr6, hr5);
}
} else if (endpoint_mode == EndpointMode::LeastSquares) {
// 2D Least Squares approach from Humus's example, with added inset and optimal rounding.
Color diff = Color(metrics.max.r - metrics.min.r, metrics.max.g - metrics.min.g, metrics.max.b - metrics.min.b);
OldColor diff =
OldColor(metrics.max.r - metrics.min.r, metrics.max.g - metrics.min.g, metrics.max.b - metrics.min.b);
Vector4 l = {0, 0, 0};
Vector4 h = {0, 0, 0};
@ -567,8 +568,8 @@ void BC1Encoder::FindEndpoints(EncodeResults &result, const CBlock &pixels, cons
h[c] = ((h[c] - inset) / 255.0f);
}
result.low = Color::PreciseRound565(l);
result.high = Color::PreciseRound565(h);
result.low = OldColor::PreciseRound565(l);
result.high = OldColor::PreciseRound565(h);
} else if (endpoint_mode == EndpointMode::BoundingBox) {
// Algorithm from icbc.h compress_dxt1_fast()
Vector4 l, h;
@ -595,13 +596,13 @@ void BC1Encoder::FindEndpoints(EncodeResults &result, const CBlock &pixels, cons
if (icov_xz < 0) std::swap(l[0], h[0]);
if (icov_yz < 0) std::swap(l[1], h[1]);
result.low = Color::PreciseRound565(l);
result.high = Color::PreciseRound565(h);
result.low = OldColor::PreciseRound565(l);
result.high = OldColor::PreciseRound565(h);
} else if (endpoint_mode == EndpointMode::BoundingBoxInt) {
// Algorithm from icbc.h compress_dxt1_fast(), but converted to integer.
// TODO: handle constant blue channel better
Color min, max;
OldColor min, max;
// rescale and inset values
for (unsigned c = 0; c < 3; c++) {
@ -706,7 +707,7 @@ void BC1Encoder::FindSelectors(EncodeResults &result, const CBlock &pixels, Erro
const int color_count = (unsigned)M & 0x0F;
std::array<Color, 4> colors = _interpolator->InterpolateBC1(result.low, result.high, color_count == 3);
std::array<OldColor, 4> colors = _interpolator->InterpolateBC1(result.low, result.high, color_count == 3);
std::array<Vector4Int, 4> color_vectors;
if (color_count == 4) {
@ -816,7 +817,7 @@ bool BC1Encoder::RefineEndpointsLS(EncodeResults &result, const CBlock &pixels,
Vector4 matrix = Vector4(0);
for (int i = 0; i < 16; i++) {
const Color color = pixels.Get(i);
const OldColor color = pixels.Get(i);
const uint8_t sel = result.selectors[i];
if ((bool)(M & ColorMode::ThreeColorBlack) && color.IsBlack()) continue;
@ -847,8 +848,8 @@ bool BC1Encoder::RefineEndpointsLS(EncodeResults &result, const CBlock &pixels,
Vector4 high = (matrix[2] * q00) + (matrix[3] * q10);
result.color_mode = M;
result.low = Color::PreciseRound565(low);
result.high = Color::PreciseRound565(high);
result.low = OldColor::PreciseRound565(low);
result.high = OldColor::PreciseRound565(high);
return true;
}
@ -875,8 +876,8 @@ void BC1Encoder::RefineEndpointsLS(EncodeResults &result, std::array<Vector4, 17
Vector4 high = (matrix[2] * q00) + (matrix[3] * q10);
result.color_mode = M;
result.low = Color::PreciseRound565(low);
result.high = Color::PreciseRound565(high);
result.low = OldColor::PreciseRound565(low);
result.high = OldColor::PreciseRound565(high);
}
template <BC1Encoder::ColorMode M>

View File

@ -26,9 +26,9 @@
#include <memory>
#include <tuple>
#include "../../Color.h"
#include "../../ColorBlock.h"
#include "../../Encoder.h"
#include "../../OldColor.h"
#include "../../Texture.h"
#include "../interpolator/Interpolator.h"
#include "BC1Block.h"
@ -141,8 +141,8 @@ class BC1Encoder final : public BlockEncoder<BlockTexture<BC1Block>> {
// Unpacked BC1 block with metadata
struct EncodeResults {
Color low;
Color high;
OldColor low;
OldColor high;
std::array<uint8_t, 16> selectors = {0};
ColorMode color_mode = ColorMode::Incomplete;
bool solid = false;
@ -169,12 +169,12 @@ class BC1Encoder final : public BlockEncoder<BlockTexture<BC1Block>> {
unsigned _orderings4;
unsigned _orderings3;
BC1Block WriteBlockSolid(Color color) const;
BC1Block WriteBlockSolid(OldColor color) const;
BC1Block WriteBlock(EncodeResults &result) const;
void FindEndpoints(EncodeResults &result, const CBlock &pixels, const BlockMetrics &metrics, EndpointMode endpoint_mode, bool ignore_black = false) const;
void FindEndpointsSingleColor(EncodeResults &result, Color color, bool is_3color = false) const;
void FindEndpointsSingleColor(EncodeResults &result, const CBlock &pixels, Color color, bool is_3color) const;
void FindEndpointsSingleColor(EncodeResults &result, OldColor color, bool is_3color = false) const;
void FindEndpointsSingleColor(EncodeResults &result, const CBlock &pixels, OldColor color, bool is_3color) const;
template <ColorMode M> void FindSelectors(EncodeResults &result, const CBlock &pixels, ErrorMode error_mode) const;

View File

@ -50,7 +50,7 @@ void InitBC1(py::module_ &s3tc) {
bc1_block.doc() = "A single BC1 block.";
bc1_block.def(py::init<>());
bc1_block.def(py::init<Color, Color, BC1Block::SelectorArray>(), "color0"_a, "color1"_a, "selectors"_a, R"doc(
bc1_block.def(py::init<OldColor, OldColor, BC1Block::SelectorArray>(), "color0"_a, "color1"_a, "selectors"_a, R"doc(
Create a new BC1Block with the specified endpoints and selectors
:param color0: The first endpoint

View File

@ -22,8 +22,8 @@
#include <array> // for array
#include <cassert> // for assert
#include "../../Color.h"
#include "../../ColorBlock.h"
#include "../../OldColor.h"
#include "BC4Block.h"
namespace quicktex::s3tc {

View File

@ -23,8 +23,8 @@
#include <array>
#include <cstdint>
#include "../../Color.h"
#include "../../ColorBlock.h"
#include "../../OldColor.h"
#include "BC4Block.h"
namespace quicktex::s3tc {

View File

@ -24,8 +24,8 @@
#include <cstdint>
#include <stdexcept>
#include "../../OldColor.h"
#include "../../util.h"
#include "../../Color.h"
namespace quicktex::s3tc {
@ -50,20 +50,20 @@ uint8_t Interpolator::Interpolate6(uint8_t v0, uint8_t v1) const { return Interp
uint8_t Interpolator::InterpolateHalf5(uint8_t v0, uint8_t v1) const { return InterpolateHalf8(scale5To8(v0), scale5To8(v1)); }
uint8_t Interpolator::InterpolateHalf6(uint8_t v0, uint8_t v1) const { return InterpolateHalf8(scale6To8(v0), scale6To8(v1)); }
std::array<Color, 4> Interpolator::Interpolate565BC1(uint16_t low, uint16_t high, bool allow_3color) const {
std::array<OldColor, 4> Interpolator::Interpolate565BC1(uint16_t low, uint16_t high, bool allow_3color) const {
bool use_3color = allow_3color && (high >= low);
return InterpolateBC1(Color::Unpack565Unscaled(low), Color::Unpack565Unscaled(high), use_3color);
return InterpolateBC1(OldColor::Unpack565Unscaled(low), OldColor::Unpack565Unscaled(high), use_3color);
}
std::array<Color, 4> Interpolator::InterpolateBC1(Color low, Color high, bool use_3color) const {
auto colors = std::array<Color, 4>();
std::array<OldColor, 4> Interpolator::InterpolateBC1(OldColor low, OldColor high, bool use_3color) const {
auto colors = std::array<OldColor, 4>();
colors[0] = low.ScaleFrom565();
colors[1] = high.ScaleFrom565();
if (use_3color) {
// 3-color mode
colors[2] = InterpolateHalfColor24(colors[0], colors[1]);
colors[3] = Color(0, 0, 0, 0); // transparent black
colors[3] = OldColor(0, 0, 0, 0); // transparent black
} else {
// 4-color mode
colors[2] = InterpolateColor24(colors[0], colors[1]);
@ -108,9 +108,9 @@ uint8_t InterpolatorNvidia::InterpolateHalf6(uint8_t v0, uint8_t v1) const {
return static_cast<uint8_t>((256 * v0 + gdiff / 4 + 128 + gdiff * 128) >> 8);
}
std::array<Color, 4> InterpolatorNvidia::InterpolateBC1(Color low, Color high, bool use_3color) const {
std::array<OldColor, 4> InterpolatorNvidia::InterpolateBC1(OldColor low, OldColor high, bool use_3color) const {
// Nvidia is special and interpolation cant be done with 8-bit values, so we need to override the default behavior
std::array<Color, 4> colors;
std::array<OldColor, 4> colors;
colors[0] = low.ScaleFrom565();
colors[1] = high.ScaleFrom565();
@ -121,7 +121,7 @@ std::array<Color, 4> InterpolatorNvidia::InterpolateBC1(Color low, Color high, b
} else {
// 3-color mode
colors[2] = InterpolateHalfColor565(low, high);
colors[3] = Color(0, 0, 0, 0); // transparent black
colors[3] = OldColor(0, 0, 0, 0); // transparent black
}
return colors;

View File

@ -22,7 +22,7 @@
#include <cstdint> // for uint8_t, uint16_t
#include <memory> // for unique_ptr
#include "../../Color.h" // for Color
#include "../../OldColor.h" // for Color
namespace quicktex::s3tc {
@ -97,7 +97,7 @@ class Interpolator {
* @param allow_3color if true, a different interpolation mode will be used if high >= low
* @return an array of 4 Color values, with indices matching BC1 selectors
*/
std::array<Color, 4> Interpolate565BC1(uint16_t low, uint16_t high, bool allow_3color = true) const;
std::array<OldColor, 4> Interpolate565BC1(uint16_t low, uint16_t high, bool allow_3color = true) const;
/**
* Generates the 4 colors for a BC1 block from the given
@ -106,7 +106,7 @@ class Interpolator {
* @param use_3color if the 3-color interpolation mode should be used
* @return an array of 4 Color values, with indices matching BC1 selectors
*/
virtual std::array<Color, 4> InterpolateBC1(Color low, Color high, bool use_3color) const;
virtual std::array<OldColor, 4> InterpolateBC1(OldColor low, OldColor high, bool use_3color) const;
/**
* Gets the type of an interpolator
@ -126,12 +126,12 @@ class Interpolator {
}
private:
Color InterpolateColor24(const Color &c0, const Color &c1) const {
return Color(Interpolate8(c0.r, c1.r), Interpolate8(c0.g, c1.g), Interpolate8(c0.b, c1.b));
OldColor InterpolateColor24(const OldColor &c0, const OldColor &c1) const {
return OldColor(Interpolate8(c0.r, c1.r), Interpolate8(c0.g, c1.g), Interpolate8(c0.b, c1.b));
}
Color InterpolateHalfColor24(const Color &c0, const Color &c1) const {
return Color(InterpolateHalf8(c0.r, c1.r), InterpolateHalf8(c0.g, c1.g), InterpolateHalf8(c0.b, c1.b));
OldColor InterpolateHalfColor24(const OldColor &c0, const OldColor &c1) const {
return OldColor(InterpolateHalf8(c0.r, c1.r), InterpolateHalf8(c0.g, c1.g), InterpolateHalf8(c0.b, c1.b));
}
};
@ -152,18 +152,18 @@ class InterpolatorNvidia final : public Interpolator {
virtual uint8_t InterpolateHalf5(uint8_t v0, uint8_t v1) const override;
virtual uint8_t InterpolateHalf6(uint8_t v0, uint8_t v1) const override;
virtual std::array<Color, 4> InterpolateBC1(Color low, Color high, bool use_3color) const override;
virtual std::array<OldColor, 4> InterpolateBC1(OldColor low, OldColor high, bool use_3color) const override;
virtual Type GetType() const noexcept override { return Type::Nvidia; }
virtual bool CanInterpolate8Bit() const noexcept override { return false; }
private:
Color InterpolateColor565(const Color &c0, const Color &c1) const {
return Color(Interpolate5(c0.r, c1.r), Interpolate6(c0.g, c1.g), Interpolate5(c0.b, c1.b));
OldColor InterpolateColor565(const OldColor &c0, const OldColor &c1) const {
return OldColor(Interpolate5(c0.r, c1.r), Interpolate6(c0.g, c1.g), Interpolate5(c0.b, c1.b));
}
Color InterpolateHalfColor565(const Color &c0, const Color &c1) const {
return Color(InterpolateHalf5(c0.r, c1.r), InterpolateHalf6(c0.g, c1.g), InterpolateHalf5(c0.b, c1.b));
OldColor InterpolateHalfColor565(const OldColor &c0, const OldColor &c1) const {
return OldColor(InterpolateHalf5(c0.r, c1.r), InterpolateHalf6(c0.g, c1.g), InterpolateHalf5(c0.b, c1.b));
}
};