I changed my mind.

also fixed a bunch of things mangled by find-and-replace
faster-single-tables
Andrew Cassidy 3 years ago
parent 840da38081
commit 0c6846f630

@ -18,106 +18,106 @@ As used herein, “this License” refers to version 3 of the GNU Lesser
General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License, and the “GNU GPL” refers to version 3 of the GNU
General Public License. General Public License.
“The Library” refers to A() covered work governed by this License, “The Library” refers to a covered work governed by this License,
other than an Application or A() Combined Work as defined below. other than an Application or a Combined Work as defined below.
An “Application” is any work that makes use of an interface provided An “Application” is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library. by the Library, but which is not otherwise based on the Library.
Defining A() subclass of A() class defined by the Library is deemed A() mode Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library. of using an interface provided by the Library.
A “Combined Work” is A() work produced by combining or linking an A “Combined Work” is a work produced by combining or linking an
Application with the Library. The particular version of the Library Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the “Linked with which the Combined Work was made is also called the “Linked
Version”. Version”.
The “Minimal Corresponding Source” for A() Combined Work means the The “Minimal Corresponding Source” for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version. based on the Application, and not on the Linked Version.
The “Corresponding Application Code” for A() Combined Work means the The “Corresponding Application Code” for a Combined Work means the
object code and/or source code for the Application, including any data object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work. Application, but excluding the System Libraries of the Combined Work.
### 1. Exception to Section 3 of the GNU GPL ### 1. Exception to Section 3 of the GNU GPL
You may convey A() covered work under sections 3 and 4 of this License You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL. without being bound by section 3 of the GNU GPL.
### 2. Conveying Modified Versions ### 2. Conveying Modified Versions
If you modify a copy of the Library, and, in your modifications, A() If you modify a copy of the Library, and, in your modifications, a
facility refers to A() function or data to be supplied by an Application facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified facility is invoked), then you may convey a copy of the modified
version: version:
* **A())** under this License, provided that you make A() good faith effort to * **a)** under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or whatever part of its purpose remains meaningful, or
* **B())** under the GNU GPL, with none of the additional permissions of * **b)** under the GNU GPL, with none of the additional permissions of
this License applicable to that copy. this License applicable to that copy.
### 3. Object Code Incorporating Material from Library Header Files ### 3. Object Code Incorporating Material from Library Header Files
The object code form of an Application may incorporate material from The object code form of an Application may incorporate material from
A() header file that is part of the Library. You may convey such object a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following: (ten or fewer lines in length), you do both of the following:
* **A())** Give prominent notice with each copy of the object code that the * **a)** Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are Library is used in it and that the Library and its use are
covered by this License. covered by this License.
* **B())** Accompany the object code with a copy of the GNU GPL and this license * **b)** Accompany the object code with a copy of the GNU GPL and this license
document. document.
### 4. Combined Works ### 4. Combined Works
You may convey A() Combined Work under terms of your choice that, You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of engineering for debugging such modifications, if you also do each of
the following: the following:
* **A())** Give prominent notice with each copy of the Combined Work that * **a)** Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are the Library is used in it and that the Library and its use are
covered by this License. covered by this License.
* **B())** Accompany the Combined Work with a copy of the GNU GPL and this license * **b)** Accompany the Combined Work with a copy of the GNU GPL and this license
document. document.
* **c)** For A() Combined Work that displays copyright notices during * **c)** For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among execution, include the copyright notice for the Library among
these notices, as well as A() reference directing the user to the these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document. copies of the GNU GPL and this license document.
* **d)** Do one of the following: * **d)** Do one of the following:
- **0)** Convey the Minimal Corresponding Source under the terms of this - **0)** Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in A() form License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to suitable for, and under terms that permit, the user to
recombine or relink the Application with A() modified version of recombine or relink the Application with a modified version of
the Linked Version to produce A() modified Combined Work, in the the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying manner specified by section 6 of the GNU GPL for conveying
Corresponding Source. Corresponding Source.
- **1)** Use A() suitable shared library mechanism for linking with the - **1)** Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that **(A())** uses at run time Library. A suitable mechanism is one that **(a)** uses at run time
a copy of the Library already present on the user's computer a copy of the Library already present on the user's computer
system, and **(B())** will operate properly with A() modified version system, and **(b)** will operate properly with a modified version
of the Library that is interface-compatible with the Linked of the Library that is interface-compatible with the Linked
Version. Version.
* **e)** Provide Installation Information, but only if you would otherwise * **e)** Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is GNU GPL, and only to the extent that such information is
necessary to install and execute A() modified version of the necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the Combined Work produced by recombining or relinking the
Application with A() modified version of the Linked Version. (If Application with a modified version of the Linked Version. (If
you use option **4d0**, the Installation Information must accompany you use option **4d0**, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application the Minimal Corresponding Source and Corresponding Application
Code. If you use option **4d1**, you must provide the Installation Code. If you use option **4d1**, you must provide the Installation
@ -126,17 +126,17 @@ the following:
### 5. Combined Libraries ### 5. Combined Libraries
You may place library facilities that are A() work based on the You may place library facilities that are a work based on the
Library side by side in A() single library together with other library Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this facilities that are not Applications and are not covered by this
License, and convey such A() combined library under terms of your License, and convey such a combined library under terms of your
choice, if you do both of the following: choice, if you do both of the following:
* **A())** Accompany the combined library with a copy of the same work based * **a)** Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities, on the Library, uncombined with any other library facilities,
conveyed under the terms of this License. conveyed under the terms of this License.
* **B())** Give prominent notice with the combined library that part of it * **b)** Give prominent notice with the combined library that part of it
is A() work based on the Library, and explaining where to find the is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work. accompanying uncombined form of the same work.
### 6. Revised Versions of the GNU Lesser General Public License ### 6. Revised Versions of the GNU Lesser General Public License
@ -146,17 +146,17 @@ of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns. differ in detail to address new problems or concerns.
Each version is given A() distinguishing version number. If the Each version is given a distinguishing version number. If the
Library as you received it specifies that A() certain numbered version Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License “or any later version” of the GNU Lesser General Public License “or any later version”
applies to it, you have the option of following the terms and applies to it, you have the option of following the terms and
conditions either of that published version or of any later version conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you published by the Free Software Foundation. If the Library as you
received it does not specify A() version number of the GNU Lesser received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation. General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that A() proxy can decide If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the permanent authorization for you to choose that version for the

@ -34,7 +34,7 @@ void BC1Decoder::DecodeBlock(Color4x4 dest, BC1Block *const block) const {
const auto selector = selectors[y][x]; const auto selector = selectors[y][x];
const auto color = colors[selector]; const auto color = colors[selector];
assert(selector < 4); assert(selector < 4);
assert((color.A() == 0 && selector == 3 && l <= h) || color.A() == UINT8_MAX); assert((color.a == 0 && selector == 3 && l <= h) || color.a == UINT8_MAX);
if (_write_alpha) { if (_write_alpha) {
dest[y][x].SetRGBA(color); dest[y][x].SetRGBA(color);
} else { } else {

@ -55,27 +55,27 @@ Color Color::Unpack565Unscaled(uint16_t Packed) {
} }
void Color::SetRGBA(uint8_t vr, uint8_t vg, uint8_t vb, uint8_t va = 0xFF) { void Color::SetRGBA(uint8_t vr, uint8_t vg, uint8_t vb, uint8_t va = 0xFF) {
_channels[0] = vr; r = vr;
_channels[1] = vg; g = vg;
_channels[2] = vb; b = vb;
_channels[3] = va; a = va;
} }
void Color::SetRGB(uint8_t vr, uint8_t vg, uint8_t vb) { void Color::SetRGB(uint8_t vr, uint8_t vg, uint8_t vb) {
_channels[0] = vr; r = vr;
_channels[1] = vg; g = vg;
_channels[2] = vb; b = vb;
} }
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])); } 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])); }
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])); } 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])); }
uint16_t Color::pack565() { return Pack565(_channels[0], _channels[1], _channels[2]); } uint16_t Color::pack565() { return Pack565(r, g, b); }
uint16_t Color::pack565Unscaled() { return Pack565Unscaled(_channels[0], _channels[1], _channels[2]); } uint16_t Color::pack565Unscaled() { return Pack565Unscaled(r, g, b); }
Color Color::ScaleTo565() const { return Color(scale8To5(_channels[0]), scale8To6(_channels[1]), scale8To5(_channels[2])); } Color Color::ScaleTo565() const { return Color(scale8To5(r), scale8To6(g), scale8To5(b)); }
Color Color::ScaleFrom565() const { return Color(scale5To8(_channels[0]), scale6To8(_channels[1]), scale5To8(_channels[2])); } Color Color::ScaleFrom565() const { return Color(scale5To8(r), scale6To8(g), scale5To8(b)); }
// endregion // endregion

@ -23,10 +23,12 @@
#pragma pack(push, 1) #pragma pack(push, 1)
class Color { class Color {
private:
std::array<uint8_t, 4> _channels;
public: public:
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
Color(); Color();
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 0xFF); Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 0xFF);
@ -37,39 +39,22 @@ class Color {
static Color Unpack565Unscaled(uint16_t Packed); static Color Unpack565Unscaled(uint16_t Packed);
static Color Unpack565(uint16_t Packed); static Color Unpack565(uint16_t Packed);
bool operator==(const Color &Rhs) const { return R() == Rhs.R() && G() == Rhs.G() && B() == Rhs.B() && A() == Rhs.A(); } bool operator==(const Color &Rhs) const { return r == Rhs.r && g == Rhs.g && b == Rhs.b && a == Rhs.a; }
uint8_t operator[](size_t index) const { uint8_t operator[](size_t index) const {
assert(index < 4); assert(index < 4);
return _channels[index]; return reinterpret_cast<const uint8_t *>(this)[index];
} }
uint8_t &operator[](size_t index) { uint8_t &operator[](size_t index) {
assert(index < 4); assert(index < 4);
return _channels[index]; return reinterpret_cast<uint8_t *>(this)[index];
} }
// more readable versions of index operator for each channel
uint8_t &R() { return _channels[0]; }
uint8_t &G() { return _channels[1]; }
uint8_t &B() { return _channels[2]; }
uint8_t &A() { return _channels[3]; }
uint8_t R() const { return _channels[0]; }
uint8_t G() const { return _channels[1]; }
uint8_t B() const { return _channels[2]; }
uint8_t A() const { return _channels[3]; }
// Assignment functions
void SetR(uint8_t r) { _channels[0] = r; }
void SetG(uint8_t g) { _channels[1] = g; }
void SetB(uint8_t b) { _channels[2] = b; }
void SetA(uint8_t a) { _channels[3] = a; }
void SetRGBA(uint8_t vr, uint8_t vg, uint8_t vb, uint8_t va); void SetRGBA(uint8_t vr, uint8_t vg, uint8_t vb, uint8_t va);
void SetRGBA(const Color &other) { SetRGBA(other.R(), other.G(), other.B(), other.A()); } void SetRGBA(const Color &other) { SetRGBA(other.r, other.g, other.b, other.a); }
void SetRGB(uint8_t vr, uint8_t vg, uint8_t vb); 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 Color &other) { SetRGB(other.r, other.g, other.a); }
uint16_t pack565(); uint16_t pack565();
uint16_t pack565Unscaled(); uint16_t pack565Unscaled();
@ -80,6 +65,6 @@ class Color {
static Color min(const Color &A, const Color &B); static Color min(const Color &A, const Color &B);
static Color max(const Color &A, const Color &B); static Color max(const Color &A, const Color &B);
unsigned get_luma() const { return (13938U * R() + 46869U * G() + 4729U * B() + 32768U) >> 16U; } // REC709 weightings unsigned get_luma() const { return (13938U * r + 46869U * g + 4729U * b + 32768U) >> 16U; } // REC709 weightings
}; };
#pragma pack(pop) #pragma pack(pop)

@ -38,7 +38,7 @@ class Interpolator {
virtual ~Interpolator() noexcept = default; virtual ~Interpolator() noexcept = default;
/** /**
* Performs A() 2/3 interpolation of A() pair of 5-bit values to produce an 8-bit value * Performs a 2/3 interpolation of a pair of 5-bit values to produce an 8-bit value
* Output is approximately (2v0 + v1)/3, with v0 and v1 first extended to 8 bits. * Output is approximately (2v0 + v1)/3, with v0 and v1 first extended to 8 bits.
* @param v0 The first 5-bit value * @param v0 The first 5-bit value
* @param v1 The second 5-bit value * @param v1 The second 5-bit value
@ -47,7 +47,7 @@ class Interpolator {
virtual uint8_t Interpolate5(uint8_t v0, uint8_t v1) const; virtual uint8_t Interpolate5(uint8_t v0, uint8_t v1) const;
/** /**
* Performs A() 2/3 interpolation of A() pair of 5-bit values to produce an 8-bit value * Performs a 2/3 interpolation of a pair of 5-bit values to produce an 8-bit value
* Output is approximately (2v0 + v1)/3, with v0 and v1 first extended to 8 bits. * Output is approximately (2v0 + v1)/3, with v0 and v1 first extended to 8 bits.
* @param v0 The first 5-bit value * @param v0 The first 5-bit value
* @param v1 The second 5-bit value * @param v1 The second 5-bit value
@ -56,7 +56,7 @@ class Interpolator {
virtual uint8_t Interpolate6(uint8_t v0, uint8_t v1) const; virtual uint8_t Interpolate6(uint8_t v0, uint8_t v1) const;
/** /**
* Performs A() 1/2 interpolation of A() pair of 5-bit values to produce an 8-bit value * Performs a 1/2 interpolation of a pair of 5-bit values to produce an 8-bit value
* Output is approximately (v0 + v1)/2, with v0 and v1 first extended to 8 bits. * Output is approximately (v0 + v1)/2, with v0 and v1 first extended to 8 bits.
* @param v0 The first 5-bit value * @param v0 The first 5-bit value
* @param v1 The second 5-bit value * @param v1 The second 5-bit value
@ -65,7 +65,7 @@ class Interpolator {
virtual uint8_t InterpolateHalf5(uint8_t v0, uint8_t v1) const; virtual uint8_t InterpolateHalf5(uint8_t v0, uint8_t v1) const;
/** /**
* Performs A() 1/2 interpolation of A() pair of 6-bit values to produce an 8-bit value * Performs a 1/2 interpolation of a pair of 6-bit values to produce an 8-bit value
* Output is approximately (v0 + v1)/2, with v0 and v1 first extended to 8 bits. * Output is approximately (v0 + v1)/2, with v0 and v1 first extended to 8 bits.
* @param v0 The first 6-bit value * @param v0 The first 6-bit value
* @param v1 The second 6-bit value * @param v1 The second 6-bit value
@ -74,7 +74,7 @@ class Interpolator {
virtual uint8_t InterpolateHalf6(uint8_t v0, uint8_t v1) const; virtual uint8_t InterpolateHalf6(uint8_t v0, uint8_t v1) const;
/** /**
* Generates the 4 colors for A() BC1 block from the given 5:6:5-packed colors * Generates the 4 colors for a BC1 block from the given 5:6:5-packed colors
* @param low first 5:6:5 color for the block * @param low first 5:6:5 color for the block
* @param high second 5:6:5 color for the block * @param high second 5:6:5 color for the block
* @return and array of 4 Color values, with indices matching BC1 selectors * @return and array of 4 Color values, with indices matching BC1 selectors
@ -113,11 +113,11 @@ class Interpolator {
// const MatchListPtr _single_match6_half = {std::make_shared<MatchList>()}; // const MatchListPtr _single_match6_half = {std::make_shared<MatchList>()};
Color InterpolateColor24(const Color &c0, const Color &c1) const { 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())); return Color(Interpolate8(c0.r, c1.r), Interpolate8(c0.g, c1.g), Interpolate8(c0.b, c1.b));
} }
Color InterpolateHalfColor24(const Color &c0, const Color &c1) const { 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())); return Color(InterpolateHalf8(c0.r, c1.r), InterpolateHalf8(c0.g, c1.g), InterpolateHalf8(c0.b, c1.b));
} }
// virtual constexpr bool useExpandedInMatch() noexcept { return true; } // virtual constexpr bool useExpandedInMatch() noexcept { return true; }
@ -149,11 +149,11 @@ class InterpolatorNvidia : public Interpolator {
private: private:
Color InterpolateColor565(const Color &c0, const Color &c1) const { 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())); return Color(Interpolate5(c0.r, c1.r), Interpolate6(c0.g, c1.g), Interpolate5(c0.b, c1.b));
} }
Color InterpolateHalfColor565(const Color &c0, const Color &c1) const { 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())); return Color(InterpolateHalf5(c0.r, c1.r), InterpolateHalf6(c0.g, c1.g), InterpolateHalf5(c0.b, c1.b));
} }
}; };

@ -685,10 +685,10 @@ static inline void bc1_find_sels4_noerr(const Color *pSrc_pixels, uint32_t lr, u
static const uint8_t s_sels[4] = {3, 2, 1, 0}; static const uint8_t s_sels[4] = {3, 2, 1, 0};
for (uint32_t i = 0; i < 16; i += 4) { for (uint32_t i = 0; i < 16; i += 4) {
const int d0 = pSrc_pixels[i + 0].R() * ar + pSrc_pixels[i + 0].G() * ag + pSrc_pixels[i + 0].B() * ab; const int d0 = pSrc_pixels[i + 0].r * ar + pSrc_pixels[i + 0].g * ag + pSrc_pixels[i + 0].b * ab;
const int d1 = pSrc_pixels[i + 1].R() * ar + pSrc_pixels[i + 1].G() * ag + pSrc_pixels[i + 1].B() * ab; const int d1 = pSrc_pixels[i + 1].r * ar + pSrc_pixels[i + 1].g * ag + pSrc_pixels[i + 1].b * ab;
const int d2 = pSrc_pixels[i + 2].R() * ar + pSrc_pixels[i + 2].G() * ag + pSrc_pixels[i + 2].B() * ab; const int d2 = pSrc_pixels[i + 2].r * ar + pSrc_pixels[i + 2].g * ag + pSrc_pixels[i + 2].b * ab;
const int d3 = pSrc_pixels[i + 3].R() * ar + pSrc_pixels[i + 3].G() * ag + pSrc_pixels[i + 3].B() * ab; const int d3 = pSrc_pixels[i + 3].r * ar + pSrc_pixels[i + 3].g * ag + pSrc_pixels[i + 3].b * ab;
sels[i + 0] = s_sels[(d0 <= t0) + (d0 < t1) + (d0 < t2)]; sels[i + 0] = s_sels[(d0 <= t0) + (d0 < t1) + (d0 < t2)];
sels[i + 1] = s_sels[(d1 <= t0) + (d1 < t1) + (d1 < t2)]; sels[i + 1] = s_sels[(d1 <= t0) + (d1 < t1) + (d1 < t2)];
@ -718,10 +718,10 @@ static inline uint32_t bc1_find_sels4_fasterr(const Color *pSrc_pixels, uint32_t
uint32_t total_err = 0; uint32_t total_err = 0;
for (uint32_t i = 0; i < 16; i += 4) { for (uint32_t i = 0; i < 16; i += 4) {
const int d0 = pSrc_pixels[i + 0].R() * ar + pSrc_pixels[i + 0].G() * ag + pSrc_pixels[i + 0].B() * ab; const int d0 = pSrc_pixels[i + 0].r * ar + pSrc_pixels[i + 0].g * ag + pSrc_pixels[i + 0].b * ab;
const int d1 = pSrc_pixels[i + 1].R() * ar + pSrc_pixels[i + 1].G() * ag + pSrc_pixels[i + 1].B() * ab; const int d1 = pSrc_pixels[i + 1].r * ar + pSrc_pixels[i + 1].g * ag + pSrc_pixels[i + 1].b * ab;
const int d2 = pSrc_pixels[i + 2].R() * ar + pSrc_pixels[i + 2].G() * ag + pSrc_pixels[i + 2].B() * ab; const int d2 = pSrc_pixels[i + 2].r * ar + pSrc_pixels[i + 2].g * ag + pSrc_pixels[i + 2].b * ab;
const int d3 = pSrc_pixels[i + 3].R() * ar + pSrc_pixels[i + 3].G() * ag + pSrc_pixels[i + 3].B() * ab; const int d3 = pSrc_pixels[i + 3].r * ar + pSrc_pixels[i + 3].g * ag + pSrc_pixels[i + 3].b * ab;
uint8_t sel0 = s_sels[(d0 <= t0) + (d0 < t1) + (d0 < t2)]; uint8_t sel0 = s_sels[(d0 <= t0) + (d0 < t1) + (d0 < t2)];
uint8_t sel1 = s_sels[(d1 <= t0) + (d1 < t1) + (d1 < t2)]; uint8_t sel1 = s_sels[(d1 <= t0) + (d1 < t1) + (d1 < t2)];
@ -734,13 +734,13 @@ static inline uint32_t bc1_find_sels4_fasterr(const Color *pSrc_pixels, uint32_t
sels[i + 3] = sel3; sels[i + 3] = sel3;
total_err += total_err +=
squarei(pSrc_pixels[i + 0].R() - block_r[sel0]) + squarei(pSrc_pixels[i + 0].G() - block_g[sel0]) + squarei(pSrc_pixels[i + 0].B() - block_b[sel0]); squarei(pSrc_pixels[i + 0].r - block_r[sel0]) + squarei(pSrc_pixels[i + 0].g - block_g[sel0]) + squarei(pSrc_pixels[i + 0].b - block_b[sel0]);
total_err += total_err +=
squarei(pSrc_pixels[i + 1].R() - block_r[sel1]) + squarei(pSrc_pixels[i + 1].G() - block_g[sel1]) + squarei(pSrc_pixels[i + 1].B() - block_b[sel1]); squarei(pSrc_pixels[i + 1].r - block_r[sel1]) + squarei(pSrc_pixels[i + 1].g - block_g[sel1]) + squarei(pSrc_pixels[i + 1].b - block_b[sel1]);
total_err += total_err +=
squarei(pSrc_pixels[i + 2].R() - block_r[sel2]) + squarei(pSrc_pixels[i + 2].G() - block_g[sel2]) + squarei(pSrc_pixels[i + 2].B() - block_b[sel2]); squarei(pSrc_pixels[i + 2].r - block_r[sel2]) + squarei(pSrc_pixels[i + 2].g - block_g[sel2]) + squarei(pSrc_pixels[i + 2].b - block_b[sel2]);
total_err += total_err +=
squarei(pSrc_pixels[i + 3].R() - block_r[sel3]) + squarei(pSrc_pixels[i + 3].G() - block_g[sel3]) + squarei(pSrc_pixels[i + 3].B() - block_b[sel3]); squarei(pSrc_pixels[i + 3].r - block_r[sel3]) + squarei(pSrc_pixels[i + 3].g - block_g[sel3]) + squarei(pSrc_pixels[i + 3].b - block_b[sel3]);
if (total_err >= cur_err) break; if (total_err >= cur_err) break;
} }
@ -760,9 +760,9 @@ static inline uint32_t bc1_find_sels4_check2_err(const Color *pSrc_pixels, uint3
uint32_t total_err = 0; uint32_t total_err = 0;
for (uint32_t i = 0; i < 16; i++) { for (uint32_t i = 0; i < 16; i++) {
const int r = pSrc_pixels[i].R(); const int r = pSrc_pixels[i].r;
const int g = pSrc_pixels[i].G(); const int g = pSrc_pixels[i].g;
const int b = pSrc_pixels[i].B(); const int b = pSrc_pixels[i].b;
int sel = (int)((float)((r - (int)block_r[0]) * dr + (g - (int)block_g[0]) * dg + (b - (int)block_b[0]) * db) * f + .5f); int sel = (int)((float)((r - (int)block_r[0]) * dr + (g - (int)block_g[0]) * dg + (b - (int)block_b[0]) * db) * f + .5f);
sel = clampi(sel, 1, 3); sel = clampi(sel, 1, 3);
@ -797,9 +797,9 @@ static inline uint32_t bc1_find_sels4_fullerr(const Color *pSrc_pixels, uint32_t
uint32_t total_err = 0; uint32_t total_err = 0;
for (uint32_t i = 0; i < 16; i++) { for (uint32_t i = 0; i < 16; i++) {
const int r = pSrc_pixels[i].R(); const int r = pSrc_pixels[i].r;
const int g = pSrc_pixels[i].G(); const int g = pSrc_pixels[i].g;
const int b = pSrc_pixels[i].B(); const int b = pSrc_pixels[i].b;
uint32_t best_err = squarei((int)block_r[0] - (int)r) + squarei((int)block_g[0] - (int)g) + squarei((int)block_b[0] - (int)b); uint32_t best_err = squarei((int)block_r[0] - (int)r) + squarei((int)block_g[0] - (int)g) + squarei((int)block_b[0] - (int)b);
uint8_t best_sel = 0; uint8_t best_sel = 0;
@ -843,9 +843,9 @@ static inline uint32_t bc1_find_sels3_fullerr(bool use_black, const Color *pSrc_
uint32_t total_err = 0; uint32_t total_err = 0;
for (uint32_t i = 0; i < 16; i++) { for (uint32_t i = 0; i < 16; i++) {
const int r = pSrc_pixels[i].R(); const int r = pSrc_pixels[i].r;
const int g = pSrc_pixels[i].G(); const int g = pSrc_pixels[i].g;
const int b = pSrc_pixels[i].B(); const int b = pSrc_pixels[i].b;
uint32_t best_err = squarei((int)block_r[0] - (int)r) + squarei((int)block_g[0] - (int)g) + squarei((int)block_b[0] - (int)b); uint32_t best_err = squarei((int)block_r[0] - (int)r) + squarei((int)block_g[0] - (int)g) + squarei((int)block_b[0] - (int)b);
uint32_t best_sel = 0; uint32_t best_sel = 0;
@ -1019,7 +1019,7 @@ static bool try_3color_block_useblack(const Color *pSrc_pixels, uint32_t flags,
int min_r = 255, min_g = 255, min_b = 255; int min_r = 255, min_g = 255, min_b = 255;
int total_pixels = 0; int total_pixels = 0;
for (uint32_t i = 0; i < 16; i++) { for (uint32_t i = 0; i < 16; i++) {
const int r = pSrc_pixels[i].R(), g = pSrc_pixels[i].G(), b = pSrc_pixels[i].B(); const int r = pSrc_pixels[i].r, g = pSrc_pixels[i].g, b = pSrc_pixels[i].b;
if ((r | g | b) < 4) continue; if ((r | g | b) < 4) continue;
max_r = std::max(max_r, r); max_r = std::max(max_r, r);
@ -1046,9 +1046,9 @@ static bool try_3color_block_useblack(const Color *pSrc_pixels, uint32_t flags,
int icov[6] = {0, 0, 0, 0, 0, 0}; int icov[6] = {0, 0, 0, 0, 0, 0};
for (uint32_t i = 0; i < 16; i++) { for (uint32_t i = 0; i < 16; i++) {
int r = (int)pSrc_pixels[i].R(); int r = (int)pSrc_pixels[i].r;
int g = (int)pSrc_pixels[i].G(); int g = (int)pSrc_pixels[i].g;
int b = (int)pSrc_pixels[i].B(); int b = (int)pSrc_pixels[i].b;
if ((r | g | b) < 4) continue; if ((r | g | b) < 4) continue;
@ -1095,7 +1095,7 @@ static bool try_3color_block_useblack(const Color *pSrc_pixels, uint32_t flags,
int low_dot = INT_MAX, high_dot = INT_MIN; int low_dot = INT_MAX, high_dot = INT_MIN;
for (uint32_t i = 0; i < 16; i++) { for (uint32_t i = 0; i < 16; i++) {
int r = (int)pSrc_pixels[i].R(), g = (int)pSrc_pixels[i].G(), b = (int)pSrc_pixels[i].B(); int r = (int)pSrc_pixels[i].r, g = (int)pSrc_pixels[i].g, b = (int)pSrc_pixels[i].b;
if ((r | g | b) < 4) continue; if ((r | g | b) < 4) continue;
@ -1110,13 +1110,13 @@ static bool try_3color_block_useblack(const Color *pSrc_pixels, uint32_t flags,
} }
} }
int lr = scale8To5(pSrc_pixels[low_c].R()); int lr = scale8To5(pSrc_pixels[low_c].r);
int lg = scale8To6(pSrc_pixels[low_c].G()); int lg = scale8To6(pSrc_pixels[low_c].g);
int lb = scale8To5(pSrc_pixels[low_c].B()); int lb = scale8To5(pSrc_pixels[low_c].b);
int hr = scale8To5(pSrc_pixels[high_c].R()); int hr = scale8To5(pSrc_pixels[high_c].r);
int hg = scale8To6(pSrc_pixels[high_c].G()); int hg = scale8To6(pSrc_pixels[high_c].g);
int hb = scale8To5(pSrc_pixels[high_c].B()); int hb = scale8To5(pSrc_pixels[high_c].b);
uint8_t trial_sels[16]; uint8_t trial_sels[16];
uint32_t trial_err = bc1_find_sels3_fullerr(true, pSrc_pixels, lr, lg, lb, hr, hg, hb, trial_sels, UINT32_MAX); uint32_t trial_err = bc1_find_sels3_fullerr(true, pSrc_pixels, lr, lg, lb, hr, hg, hb, trial_sels, UINT32_MAX);
@ -1237,9 +1237,9 @@ static bool try_3color_block(const Color *pSrc_pixels, uint32_t flags, uint32_t
int dots[16]; int dots[16];
for (uint32_t i = 0; i < 16; i++) { for (uint32_t i = 0; i < 16; i++) {
int r = pSrc_pixels[i].R(); int r = pSrc_pixels[i].r;
int g = pSrc_pixels[i].G(); int g = pSrc_pixels[i].g;
int b = pSrc_pixels[i].B(); int b = pSrc_pixels[i].b;
int d = 0x1000000 + (r * ar + g * ag + b * ab); int d = 0x1000000 + (r * ar + g * ag + b * ab);
assert(d >= 0); assert(d >= 0);
dots[i] = (d << 4) + i; dots[i] = (d << 4) + i;
@ -1256,9 +1256,9 @@ static bool try_3color_block(const Color *pSrc_pixels, uint32_t flags, uint32_t
g_sum[i] = g; g_sum[i] = g;
b_sum[i] = b; b_sum[i] = b;
r += pSrc_pixels[p].R(); r += pSrc_pixels[p].r;
g += pSrc_pixels[p].G(); g += pSrc_pixels[p].g;
b += pSrc_pixels[p].B(); b += pSrc_pixels[p].b;
} }
r_sum[16] = total_r; r_sum[16] = total_r;
@ -1339,11 +1339,11 @@ void encode_bc1(uint32_t level, void *pDst, const uint8_t *pPixels, bool allow_3
flags = cEncodeBC1BoundingBoxInt; flags = cEncodeBC1BoundingBoxInt;
break; break;
case 1: case 1:
// Faster/higher quality than stb_dxt default. A() bit higher average quality vs. mode 0. // Faster/higher quality than stb_dxt default. a bit higher average quality vs. mode 0.
flags = cEncodeBC1Use2DLS; flags = cEncodeBC1Use2DLS;
break; break;
case 2: case 2:
// On average mode 2 is A() little weaker than modes 0/1, but it's stronger on outliers (very tough textures). // On average mode 2 is a little weaker than modes 0/1, but it's stronger on outliers (very tough textures).
// Slightly stronger than stb_dxt. // Slightly stronger than stb_dxt.
flags = 0; flags = 0;
break; break;
@ -1458,9 +1458,9 @@ static inline void encode_bc1_pick_initial(const Color *pSrc_pixels, uint32_t fl
int max_g, int max_b, int avg_r, int avg_g, int avg_b, int total_r, int total_g, int total_b, int &lr, int &lg, int max_g, int max_b, int avg_r, int avg_g, int avg_b, int total_r, int total_g, int total_b, int &lr, int &lg,
int &lb, int &hr, int &hg, int &hb) { int &lb, int &hr, int &hg, int &hb) {
if (grayscale_flag) { if (grayscale_flag) {
const int fr = pSrc_pixels[0].R(); const int fr = pSrc_pixels[0].r;
// Grayscale blocks are A() common enough case to specialize. // Grayscale blocks are a common enough case to specialize.
if ((max_r - min_r) < 2) { if ((max_r - min_r) < 2) {
lr = lb = hr = hb = scale8To5(fr); lr = lb = hr = hb = scale8To5(fr);
lg = hg = scale8To6(fr); lg = hg = scale8To6(fr);
@ -1482,7 +1482,7 @@ static inline void encode_bc1_pick_initial(const Color *pSrc_pixels, uint32_t fl
vec3F l, h; vec3F l, h;
if (big_chan == 0) { if (big_chan == 0) {
for (uint32_t i = 0; i < 16; i++) { for (uint32_t i = 0; i < 16; i++) {
const int r = pSrc_pixels[i].R(), g = pSrc_pixels[i].G(), b = pSrc_pixels[i].B(); const int r = pSrc_pixels[i].r, g = pSrc_pixels[i].g, b = pSrc_pixels[i].b;
sum_xy_r += r * r, sum_xy_g += r * g, sum_xy_b += r * b; sum_xy_r += r * r, sum_xy_g += r * g, sum_xy_b += r * b;
} }
@ -1523,7 +1523,7 @@ static inline void encode_bc1_pick_initial(const Color *pSrc_pixels, uint32_t fl
h.c[0] = fmax_chan_val; h.c[0] = fmax_chan_val;
} else if (big_chan == 1) { } else if (big_chan == 1) {
for (uint32_t i = 0; i < 16; i++) { for (uint32_t i = 0; i < 16; i++) {
const int r = pSrc_pixels[i].R(), g = pSrc_pixels[i].G(), b = pSrc_pixels[i].B(); const int r = pSrc_pixels[i].r, g = pSrc_pixels[i].g, b = pSrc_pixels[i].b;
sum_xy_r += g * r, sum_xy_g += g * g, sum_xy_b += g * b; sum_xy_r += g * r, sum_xy_g += g * g, sum_xy_b += g * b;
} }
@ -1564,7 +1564,7 @@ static inline void encode_bc1_pick_initial(const Color *pSrc_pixels, uint32_t fl
h.c[1] = fmax_chan_val; h.c[1] = fmax_chan_val;
} else { } else {
for (uint32_t i = 0; i < 16; i++) { for (uint32_t i = 0; i < 16; i++) {
const int r = pSrc_pixels[i].R(), g = pSrc_pixels[i].G(), b = pSrc_pixels[i].B(); const int r = pSrc_pixels[i].r, g = pSrc_pixels[i].g, b = pSrc_pixels[i].b;
sum_xy_r += b * r, sum_xy_g += b * g, sum_xy_b += b * b; sum_xy_r += b * r, sum_xy_g += b * g, sum_xy_b += b * b;
} }
@ -1632,9 +1632,9 @@ static inline void encode_bc1_pick_initial(const Color *pSrc_pixels, uint32_t fl
int icov_xz = 0, icov_yz = 0; int icov_xz = 0, icov_yz = 0;
for (uint32_t i = 0; i < 16; i++) { for (uint32_t i = 0; i < 16; i++) {
int r = (int)pSrc_pixels[i].R() - avg_r; int r = (int)pSrc_pixels[i].r - avg_r;
int g = (int)pSrc_pixels[i].G() - avg_g; int g = (int)pSrc_pixels[i].g - avg_g;
int b = (int)pSrc_pixels[i].B() - avg_b; int b = (int)pSrc_pixels[i].b - avg_b;
icov_xz += r * b; icov_xz += r * b;
icov_yz += g * b; icov_yz += g * b;
} }
@ -1670,9 +1670,9 @@ static inline void encode_bc1_pick_initial(const Color *pSrc_pixels, uint32_t fl
int icov_xz = 0, icov_yz = 0; int icov_xz = 0, icov_yz = 0;
for (uint32_t i = 0; i < 16; i++) { for (uint32_t i = 0; i < 16; i++) {
int r = (int)pSrc_pixels[i].R() - avg_r; int r = (int)pSrc_pixels[i].r - avg_r;
int g = (int)pSrc_pixels[i].G() - avg_g; int g = (int)pSrc_pixels[i].g - avg_g;
int b = (int)pSrc_pixels[i].B() - avg_b; int b = (int)pSrc_pixels[i].b - avg_b;
icov_xz += r * b; icov_xz += r * b;
icov_yz += g * b; icov_yz += g * b;
} }
@ -1682,7 +1682,7 @@ static inline void encode_bc1_pick_initial(const Color *pSrc_pixels, uint32_t fl
int x1 = max_r; int x1 = max_r;
int y1 = max_g; int y1 = max_g;
// swap R() and G() min and max to align principal axis // swap r and g min and max to align principal axis
if (icov_xz < 0) std::swap(x0, x1); if (icov_xz < 0) std::swap(x0, x1);
if (icov_yz < 0) std::swap(y0, y1); if (icov_yz < 0) std::swap(y0, y1);
@ -1695,14 +1695,14 @@ static inline void encode_bc1_pick_initial(const Color *pSrc_pixels, uint32_t fl
hg = scale8To6(y1); hg = scale8To6(y1);
hb = scale8To5(max_b); hb = scale8To5(max_b);
} else { } else {
// Select 2 colors along the principle axis. (There must be A() faster/simpler way.) // Select 2 colors along the principle axis. (There must be a faster/simpler way.)
uint32_t low_c = 0, high_c = 0; uint32_t low_c = 0, high_c = 0;
int icov[6] = {0, 0, 0, 0, 0, 0}; int icov[6] = {0, 0, 0, 0, 0, 0};
for (uint32_t i = 0; i < 16; i++) { for (uint32_t i = 0; i < 16; i++) {
int r = (int)pSrc_pixels[i].R() - avg_r; int r = (int)pSrc_pixels[i].r - avg_r;
int g = (int)pSrc_pixels[i].G() - avg_g; int g = (int)pSrc_pixels[i].g - avg_g;
int b = (int)pSrc_pixels[i].B() - avg_b; int b = (int)pSrc_pixels[i].b - avg_b;
icov[0] += r * r; icov[0] += r * r;
icov[1] += r * g; icov[1] += r * g;
icov[2] += r * b; icov[2] += r * b;
@ -1749,10 +1749,10 @@ static inline void encode_bc1_pick_initial(const Color *pSrc_pixels, uint32_t fl
saxis_b = (int)((uint32_t)saxis_b << 4U); saxis_b = (int)((uint32_t)saxis_b << 4U);
for (uint32_t i = 0; i < 16; i += 4) { for (uint32_t i = 0; i < 16; i += 4) {
int dot0 = ((pSrc_pixels[i].R() * saxis_r + pSrc_pixels[i].G() * saxis_g + pSrc_pixels[i].B() * saxis_b) & ~0xF) + i; int dot0 = ((pSrc_pixels[i].r * saxis_r + pSrc_pixels[i].g * saxis_g + pSrc_pixels[i].b * saxis_b) & ~0xF) + i;
int dot1 = ((pSrc_pixels[i + 1].R() * saxis_r + pSrc_pixels[i + 1].G() * saxis_g + pSrc_pixels[i + 1].B() * saxis_b) & ~0xF) + i + 1; int dot1 = ((pSrc_pixels[i + 1].r * saxis_r + pSrc_pixels[i + 1].g * saxis_g + pSrc_pixels[i + 1].b * saxis_b) & ~0xF) + i + 1;
int dot2 = ((pSrc_pixels[i + 2].R() * saxis_r + pSrc_pixels[i + 2].G() * saxis_g + pSrc_pixels[i + 2].B() * saxis_b) & ~0xF) + i + 2; int dot2 = ((pSrc_pixels[i + 2].r * saxis_r + pSrc_pixels[i + 2].g * saxis_g + pSrc_pixels[i + 2].b * saxis_b) & ~0xF) + i + 2;
int dot3 = ((pSrc_pixels[i + 3].R() * saxis_r + pSrc_pixels[i + 3].G() * saxis_g + pSrc_pixels[i + 3].B() * saxis_b) & ~0xF) + i + 3; int dot3 = ((pSrc_pixels[i + 3].r * saxis_r + pSrc_pixels[i + 3].g * saxis_g + pSrc_pixels[i + 3].b * saxis_b) & ~0xF) + i + 3;
int min_d01 = std::min(dot0, dot1); int min_d01 = std::min(dot0, dot1);
int max_d01 = std::max(dot0, dot1); int max_d01 = std::max(dot0, dot1);
@ -1769,13 +1769,13 @@ static inline void encode_bc1_pick_initial(const Color *pSrc_pixels, uint32_t fl
low_c = low_dot & 15; low_c = low_dot & 15;
high_c = high_dot & 15; high_c = high_dot & 15;
lr = scale8To5(pSrc_pixels[low_c].R()); lr = scale8To5(pSrc_pixels[low_c].r);
lg = scale8To6(pSrc_pixels[low_c].G()); lg = scale8To6(pSrc_pixels[low_c].g);
lb = scale8To5(pSrc_pixels[low_c].B()); lb = scale8To5(pSrc_pixels[low_c].b);
hr = scale8To5(pSrc_pixels[high_c].R()); hr = scale8To5(pSrc_pixels[high_c].r);
hg = scale8To6(pSrc_pixels[high_c].G()); hg = scale8To6(pSrc_pixels[high_c].g);
hb = scale8To5(pSrc_pixels[high_c].B()); hb = scale8To5(pSrc_pixels[high_c].b);
} }
} }
@ -1860,11 +1860,11 @@ void encode_bc1(void *pDst, const uint8_t *pPixels, uint32_t flags, uint32_t tot
int avg_r, avg_g, avg_b, min_r, min_g, min_b, max_r, max_g, max_b; int avg_r, avg_g, avg_b, min_r, min_g, min_b, max_r, max_g, max_b;
const uint32_t fr = pSrc_pixels[0].R(), fg = pSrc_pixels[0].G(), fb = pSrc_pixels[0].B(); const uint32_t fr = pSrc_pixels[0].r, fg = pSrc_pixels[0].g, fb = pSrc_pixels[0].b;
uint32_t j; uint32_t j;
for (j = 15; j >= 1; --j) for (j = 15; j >= 1; --j)
if ((pSrc_pixels[j].R() != fr) || (pSrc_pixels[j].G() != fg) || (pSrc_pixels[j].B() != fb)) break; if ((pSrc_pixels[j].r != fr) || (pSrc_pixels[j].g != fg) || (pSrc_pixels[j].b != fb)) break;
if (j == 0) { if (j == 0) {
encode_bc1_solid_block(pDst, fr, fg, fb, (flags & (cEncodeBC1Use3ColorBlocks | cEncodeBC1Use3ColorBlocksForBlackPixels)) != 0); encode_bc1_solid_block(pDst, fr, fg, fb, (flags & (cEncodeBC1Use3ColorBlocks | cEncodeBC1Use3ColorBlocksForBlackPixels)) != 0);
@ -1880,7 +1880,7 @@ void encode_bc1(void *pDst, const uint8_t *pPixels, uint32_t flags, uint32_t tot
uint32_t any_black_pixels = (fr | fg | fb) < 4; uint32_t any_black_pixels = (fr | fg | fb) < 4;
for (uint32_t i = 1; i < 16; i++) { for (uint32_t i = 1; i < 16; i++) {
const int r = pSrc_pixels[i].R(), g = pSrc_pixels[i].G(), b = pSrc_pixels[i].B(); const int r = pSrc_pixels[i].r, g = pSrc_pixels[i].g, b = pSrc_pixels[i].b;
grayscale_flag &= ((r == g) && (r == b)); grayscale_flag &= ((r == g) && (r == b));
any_black_pixels |= ((r | g | b) < 4); any_black_pixels |= ((r | g | b) < 4);
@ -1929,7 +1929,7 @@ void encode_bc1(void *pDst, const uint8_t *pPixels, uint32_t flags, uint32_t tot
vec3F xl, xh; vec3F xl, xh;
if (!compute_least_squares_endpoints4_rgb(pSrc_pixels, sels, &xl, &xh, total_r, total_g, total_b)) { if (!compute_least_squares_endpoints4_rgb(pSrc_pixels, sels, &xl, &xh, total_r, total_g, total_b)) {
// All selectors equal - treat it as A() solid block which should always be equal or better. // All selectors equal - treat it as a solid block which should always be equal or better.
trial_lr = g_bc1_match5_equals_1[avg_r].m_hi; trial_lr = g_bc1_match5_equals_1[avg_r].m_hi;
trial_lg = g_bc1_match6_equals_1[avg_g].m_hi; trial_lg = g_bc1_match6_equals_1[avg_g].m_hi;
trial_lb = g_bc1_match5_equals_1[avg_b].m_hi; trial_lb = g_bc1_match5_equals_1[avg_b].m_hi;
@ -1982,7 +1982,7 @@ void encode_bc1(void *pDst, const uint8_t *pPixels, uint32_t flags, uint32_t tot
vec3F xl, xh; vec3F xl, xh;
if (!compute_least_squares_endpoints4_rgb(pSrc_pixels, round_sels, &xl, &xh, total_r, total_g, total_b)) { if (!compute_least_squares_endpoints4_rgb(pSrc_pixels, round_sels, &xl, &xh, total_r, total_g, total_b)) {
// All selectors equal - treat it as A() solid block which should always be equal or better. // All selectors equal - treat it as a solid block which should always be equal or better.
trial_lr = g_bc1_match5_equals_1[avg_r].m_hi; trial_lr = g_bc1_match5_equals_1[avg_r].m_hi;
trial_lg = g_bc1_match6_equals_1[avg_g].m_hi; trial_lg = g_bc1_match6_equals_1[avg_g].m_hi;
trial_lb = g_bc1_match5_equals_1[avg_b].m_hi; trial_lb = g_bc1_match5_equals_1[avg_b].m_hi;
@ -2069,9 +2069,9 @@ void encode_bc1(void *pDst, const uint8_t *pPixels, uint32_t flags, uint32_t tot
int dots[16]; int dots[16];
for (uint32_t i = 0; i < 16; i++) { for (uint32_t i = 0; i < 16; i++) {
int r = pSrc_pixels[i].R(); int r = pSrc_pixels[i].r;
int g = pSrc_pixels[i].G(); int g = pSrc_pixels[i].g;
int b = pSrc_pixels[i].B(); int b = pSrc_pixels[i].b;
int d = 0x1000000 + (r * ar + g * ag + b * ab); int d = 0x1000000 + (r * ar + g * ag + b * ab);
assert(d >= 0); assert(d >= 0);
dots[i] = (d << 4) + i; dots[i] = (d << 4) + i;
@ -2088,9 +2088,9 @@ void encode_bc1(void *pDst, const uint8_t *pPixels, uint32_t flags, uint32_t tot
g_sum[i] = g; g_sum[i] = g;
b_sum[i] = b; b_sum[i] = b;
r += pSrc_pixels[p].R(); r += pSrc_pixels[p].r;
g += pSrc_pixels[p].G(); g += pSrc_pixels[p].g;
b += pSrc_pixels[p].B(); b += pSrc_pixels[p].b;
} }
r_sum[16] = total_r; r_sum[16] = total_r;
@ -2456,7 +2456,7 @@ bool unpack_bc3(const void *pBlock_bits, void *pPixels, bc1_approx_mode mode) {
if (unpack_bc1((const uint8_t *)pBlock_bits + sizeof(BC4Block), pDst_pixels, true, mode)) success = false; if (unpack_bc1((const uint8_t *)pBlock_bits + sizeof(BC4Block), pDst_pixels, true, mode)) success = false;
unpack_bc4(pBlock_bits, &pDst_pixels[0].A(), sizeof(Color)); unpack_bc4(pBlock_bits, &pDst_pixels[0].a, sizeof(Color));
return success; return success;
} }

@ -28,6 +28,8 @@ The manual and changelog are in the header file "lodepng.h"
Rename this file to lodepng.cpp to use it for C++, or to lodepng.c to use it for C. Rename this file to lodepng.cpp to use it for C++, or to lodepng.c to use it for C.
*/ */
#pragma GCC diagnostic ignored "-Weverything"
#include "lodepng.h" #include "lodepng.h"
#include <limits.h> #include <limits.h>

@ -2,6 +2,7 @@
#ifdef _MSC_VER #ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS
#endif #endif
#pragma GCC diagnostic ignored "-Weverything"
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
@ -18,6 +19,7 @@
#include "../blocks.h" #include "../blocks.h"
#include "../rgbcx.h" #include "../rgbcx.h"
#include "../rgbcxDecoders.h"
#include "../util.h" #include "../util.h"
#include "bc7decomp.h" #include "bc7decomp.h"
#include "bc7enc.h" #include "bc7enc.h"
@ -66,7 +68,7 @@ static int print_usage() {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
/*
struct color_quad_u8 { struct color_quad_u8 {
uint8_t m_c[4]; uint8_t m_c[4];
@ -100,7 +102,8 @@ struct color_quad_u8 {
} }
inline int get_luma() const { return (13938U * m_c[0] + 46869U * m_c[1] + 4729U * m_c[2] + 32768U) >> 16U; } // REC709 weightings inline int get_luma() const { return (13938U * m_c[0] + 46869U * m_c[1] + 4729U * m_c[2] + 32768U) >> 16U; } // REC709 weightings
}; };*/
using color_quad_u8 = Color;
typedef std::vector<color_quad_u8> color_quad_u8_vec; typedef std::vector<color_quad_u8> color_quad_u8_vec;
class image_u8 { class image_u8 {
@ -112,6 +115,10 @@ class image_u8 {
inline const color_quad_u8_vec &get_pixels() const { return m_pixels; } inline const color_quad_u8_vec &get_pixels() const { return m_pixels; }
inline color_quad_u8_vec &get_pixels() { return m_pixels; } inline color_quad_u8_vec &get_pixels() { return m_pixels; }
void set_pixels(const color_quad_u8_vec &pixels) {
m_pixels = pixels;
}
inline uint32_t width() const { return m_width; } inline uint32_t width() const { return m_width; }
inline uint32_t height() const { return m_height; } inline uint32_t height() const { return m_height; }
inline uint32_t total_pixels() const { return m_width * m_height; } inline uint32_t total_pixels() const { return m_width * m_height; }
@ -833,7 +840,7 @@ int main(int argc, char *argv[]) {
image_u8 unpacked_image_alpha(unpacked_image); image_u8 unpacked_image_alpha(unpacked_image);
for (uint32_t y = 0; y < unpacked_image_alpha.height(); y++) for (uint32_t y = 0; y < unpacked_image_alpha.height(); y++)
for (uint32_t x = 0; x < unpacked_image_alpha.width(); x++) { for (uint32_t x = 0; x < unpacked_image_alpha.width(); x++) {
uint8_t alpha = unpacked_image_alpha(x, y).A(); uint8_t alpha = unpacked_image_alpha(x, y).a;
unpacked_image_alpha(x, y).SetRGBA(alpha, alpha, alpha, 255); } unpacked_image_alpha(x, y).SetRGBA(alpha, alpha, alpha, 255); }
if (!save_png(png_alpha_output_filename.c_str(), unpacked_image_alpha, false)) if (!save_png(png_alpha_output_filename.c_str(), unpacked_image_alpha, false))

@ -85,16 +85,14 @@ template <typename I, typename O, size_t S, size_t C> constexpr auto Pack(const
static_assert(std::numeric_limits<I>::digits >= S, "Unpacked input type must be big enough to represent the number of bits"); static_assert(std::numeric_limits<I>::digits >= S, "Unpacked input type must be big enough to represent the number of bits");
static_assert(std::numeric_limits<O>::digits >= (C * S), "Packed output type must be big enough to represent the number of bits multiplied by count"); static_assert(std::numeric_limits<O>::digits >= (C * S), "Packed output type must be big enough to represent the number of bits multiplied by count");
constexpr I max_input = (1U << S) - 1U; // maximum value representable by S bits O packed = 0; // output value of type O
constexpr O max_output = (static_cast<O>(1U) << (C * S)) - 1U; // maximum value representable by S * C bits
O packed = 0; // output value of type O
for (unsigned i = 0; i < C; i++) { for (unsigned i = 0; i < C; i++) {
assert(vals[i] <= max_input); assert(vals[i] <= (1U << S) - 1U);
packed |= static_cast<O>(vals[i]) << (i * S); packed |= static_cast<O>(vals[i]) << (i * S);
} }
assert(packed <= max_output); assert(packed <= (static_cast<O>(1U) << (C * S)) - 1U);
return packed; return packed;
} }

Loading…
Cancel
Save