Split up blocks file

faster-single-tables
Andrew Cassidy 3 years ago
parent 36bd624273
commit a3cc69db64

@ -36,7 +36,7 @@ set_project_warnings(test_rgbcx)
if (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -fsanitize=undefined")
set(PROJECT_WARNINGS ${CLANG_WARNINGS})
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set_property(TARGET python_rgbcx test_rgbcx PROPERTY OSX_ARCHITECTURES_RELEASE x86_64 arm64) #Mach-O fat binary for arm and x86

@ -0,0 +1,85 @@
/* Python-rgbcx Texture Compression Library
Copyright (C) 2021 Andrew Cassidy <drewcassidy@me.com>
Partially derived from rgbcx.h written by Richard Geldreich <richgel99@gmail.com>
and licenced under the public domain
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
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/>.
*/
#pragma once
#include <array>
#include <cassert>
#include <cstdint>
#include <cstdlib>
#include "../Color.h"
#include "../util.h"
namespace rgbcx {
#pragma pack(push, 1)
class BC1Block {
public:
using UnpackedSelectors = std::array<std::array<uint8_t, 4>, 4>;
uint16_t GetLowColor() const { return static_cast<uint16_t>(_low_color[0] | (_low_color[1] << 8U)); }
uint16_t GetHighColor() const { return static_cast<uint16_t>(_high_color[0] | (_high_color[1] << 8U)); }
Color GetLowColor32() const { return Color::Unpack565(GetLowColor()); }
Color GetHighColor32() const { return Color::Unpack565(GetHighColor()); }
bool Is3Color() const { return GetLowColor() <= GetHighColor(); }
void SetLowColor(uint16_t c) {
_low_color[0] = c & 0xFF;
_low_color[1] = (c >> 8) & 0xFF;
}
void SetHighColor(uint16_t c) {
_high_color[0] = c & 0xFF;
_high_color[1] = (c >> 8) & 0xFF;
}
uint32_t GetSelector(uint32_t x, uint32_t y) const {
assert((x < 4U) && (y < 4U));
return (selectors[y] >> (x * SelectorBits)) & SelectorMask;
}
void SetSelector(uint32_t x, uint32_t y, uint32_t val) {
assert((x < 4U) && (y < 4U) && (val < 4U));
selectors[y] &= (~(SelectorMask << (x * SelectorBits)));
selectors[y] |= (val << (x * SelectorBits));
}
UnpackedSelectors UnpackSelectors() const {
UnpackedSelectors unpacked;
for (unsigned i = 0; i < 4; i++) { unpacked[i] = Unpack<uint8_t, uint8_t, 2, 4>(selectors[i]); }
return unpacked;
}
void PackSelectors(const UnpackedSelectors& unpacked) {
for (unsigned i = 0; i < 4; i++) { selectors[i] = Pack<uint8_t, uint8_t, 2, 4>(unpacked[i]); }
}
constexpr static inline size_t EndpointSize = 2;
constexpr static inline size_t SelectorSize = 4;
constexpr static inline uint8_t SelectorBits = 2;
constexpr static inline uint8_t SelectorValues = 1 << SelectorBits;
constexpr static inline uint8_t SelectorMask = SelectorValues - 1;
private:
std::array<uint8_t, EndpointSize> _low_color;
std::array<uint8_t, EndpointSize> _high_color;
public:
std::array<uint8_t, 4> selectors;
};
#pragma pack(pop)
} // namespace rgbcx

@ -21,12 +21,14 @@
#include <assert.h>
#include <stdint.h>
#include <array>
#include "../ColorBlock.h"
#include "../blocks.h"
#include "../Color.h"
#include "../ColorBlock.h"
#include "../interpolator.h"
#include "../ndebug.h"
#include "BC1Block.h"
namespace rgbcx {
void BC1Decoder::DecodeBlock(Color4x4 dest, BC1Block *const block) const noexcept(ndebug) {

@ -23,9 +23,9 @@
#include "../BlockDecoder.h"
#include "../ColorBlock.h"
#include "../blocks.h"
#include "../interpolator.h"
#include "../ndebug.h"
#include "BC1Block.h"
namespace rgbcx {
class BC1Decoder final : public BlockDecoder<BC1Block, 4, 4> {

@ -0,0 +1,34 @@
/* Python-rgbcx Texture Compression Library
Copyright (C) 2021 Andrew Cassidy <drewcassidy@me.com>
Partially derived from rgbcx.h written by Richard Geldreich <richgel99@gmail.com>
and licenced under the public domain
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
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/>.
*/
#pragma once
#include "../BC1/BC1Block.h"
#include "../BC4/BC4Block.h"
namespace rgbcx {
#pragma pack(push, 1)
class BC3Block {
public:
BC4Block alpha_block;
BC1Block color_block;
};
#pragma pack(pop)
} // namespace rgbcx

@ -22,7 +22,6 @@
#include "../BC1/BC1Decoder.h"
#include "../BC4/BC4Decoder.h"
#include "../ColorBlock.h"
#include "../blocks.h"
#include "../ndebug.h"
namespace rgbcx {

@ -25,9 +25,9 @@
#include "../BC4/BC4Decoder.h"
#include "../BlockDecoder.h"
#include "../ColorBlock.h"
#include "../blocks.h"
#include "../interpolator.h"
#include "../ndebug.h"
#include "BC3Block.h"
namespace rgbcx {
class BC3Decoder : public BlockDecoder<BC3Block, 4, 4> {

@ -1,6 +1,6 @@
/* Python-rgbcx Texture Compression Library
Copyright (C) 2021 Andrew Cassidy <drewcassidy@me.com>
Partially derived from rgbcx.h written by Richard Geldreich 2020 <richgel99@gmail.com>
Partially derived from rgbcx.h written by Richard Geldreich <richgel99@gmail.com>
and licenced under the public domain
This program is free software: you can redistribute it and/or modify
@ -24,62 +24,13 @@
#include <cstdint>
#include <cstdlib>
#include "Color.h"
#include "util.h"
#include "../BC1/BC1Block.h"
#include "../Color.h"
#include "../util.h"
#pragma pack(push, 1)
class BC1Block {
public:
using UnpackedSelectors = std::array<std::array<uint8_t, 4>, 4>;
uint16_t GetLowColor() const { return static_cast<uint16_t>(_low_color[0] | (_low_color[1] << 8U)); }
uint16_t GetHighColor() const { return static_cast<uint16_t>(_high_color[0] | (_high_color[1] << 8U)); }
Color GetLowColor32() const { return Color::Unpack565(GetLowColor()); }
Color GetHighColor32() const { return Color::Unpack565(GetHighColor()); }
bool Is3Color() const { return GetLowColor() <= GetHighColor(); }
void SetLowColor(uint16_t c) {
_low_color[0] = c & 0xFF;
_low_color[1] = (c >> 8) & 0xFF;
}
void SetHighColor(uint16_t c) {
_high_color[0] = c & 0xFF;
_high_color[1] = (c >> 8) & 0xFF;
}
uint32_t GetSelector(uint32_t x, uint32_t y) const {
assert((x < 4U) && (y < 4U));
return (selectors[y] >> (x * SelectorBits)) & SelectorMask;
}
void SetSelector(uint32_t x, uint32_t y, uint32_t val) {
assert((x < 4U) && (y < 4U) && (val < 4U));
selectors[y] &= (~(SelectorMask << (x * SelectorBits)));
selectors[y] |= (val << (x * SelectorBits));
}
UnpackedSelectors UnpackSelectors() const {
UnpackedSelectors unpacked;
for (unsigned i = 0; i < 4; i++) { unpacked[i] = Unpack<uint8_t, uint8_t, 2, 4>(selectors[i]); }
return unpacked;
}
void PackSelectors(const UnpackedSelectors& unpacked) {
for (unsigned i = 0; i < 4; i++) { selectors[i] = Pack<uint8_t, uint8_t, 2, 4>(unpacked[i]); }
}
constexpr static inline size_t EndpointSize = 2;
constexpr static inline size_t SelectorSize = 4;
constexpr static inline uint8_t SelectorBits = 2;
constexpr static inline uint8_t SelectorValues = 1 << SelectorBits;
constexpr static inline uint8_t SelectorMask = SelectorValues - 1;
private:
std::array<uint8_t, EndpointSize> _low_color;
std::array<uint8_t, EndpointSize> _high_color;
public:
std::array<uint8_t, 4> selectors;
};
namespace rgbcx {
#pragma pack(push, 1)
class BC4Block {
public:
using UnpackedSelectors = std::array<std::array<uint8_t, 4>, 4>;
@ -156,22 +107,11 @@ class BC4Block {
constexpr static inline uint8_t SelectorBits = 3;
constexpr static inline uint8_t SelectorValues = 1 << SelectorBits;
constexpr static inline uint8_t SelectorMask = SelectorValues - 1;
constexpr static inline uint64_t SelectorBitsMax = (1UL << (8U * SelectorSize)) - 1U;
constexpr static inline uint64_t SelectorBitsMax = (1ULL << (8U * SelectorSize)) - 1U;
uint8_t low_alpha;
uint8_t high_alpha;
std::array<uint8_t, SelectorSize> selectors;
};
class BC3Block {
public:
BC4Block alpha_block;
BC1Block color_block;
};
class BC5Block {
public:
BC4Block chan0_block;
BC4Block chan1_block;
};
#pragma pack(pop)
#pragma pack(pop)
} // namespace rgbcx

@ -25,8 +25,8 @@
#include "../Color.h" // for Color
#include "../ColorBlock.h" // for ColorBlock
#include "../blocks.h" // for BC4Block
#include "../ndebug.h" // for ndebug
#include "BC4Block.h"
void rgbcx::BC4Decoder::DecodeBlock(Color4x4 dest, BC4Block *const block, size_t channel) const noexcept(ndebug) {
auto l = block->GetLowAlpha();

@ -23,8 +23,8 @@
#include "../BlockDecoder.h"
#include "../ColorBlock.h"
#include "../blocks.h"
#include "../ndebug.h"
#include "BC4Block.h"
namespace rgbcx {
class BC4Decoder : public BlockDecoder<BC4Block, 4, 4> {

@ -0,0 +1,33 @@
/* Python-rgbcx Texture Compression Library
Copyright (C) 2021 Andrew Cassidy <drewcassidy@me.com>
Partially derived from rgbcx.h written by Richard Geldreich <richgel99@gmail.com>
and licenced under the public domain
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
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/>.
*/
#pragma once
#include "../BC4/BC4Block.h"
namespace rgbcx {
#pragma pack(push, 1)
class BC5Block {
public:
BC4Block chan0_block;
BC4Block chan1_block;
};
#pragma pack(pop)
} // namespace rgbcx

@ -21,7 +21,6 @@
#include "../BC4/BC4Decoder.h"
#include "../ColorBlock.h"
#include "../blocks.h"
#include "../ndebug.h"
namespace rgbcx {

@ -25,8 +25,8 @@
#include "../BC4/BC4Decoder.h"
#include "../BlockDecoder.h"
#include "../ColorBlock.h"
#include "../blocks.h"
#include "../ndebug.h"
#include "BC5Block.h"
namespace rgbcx {
class BC5Decoder : public BlockDecoder<BC5Block, 4, 4> {

@ -25,7 +25,7 @@
#include <cstdio>
#include <vector>
#include "blocks.h"
#include "Color.h"
template <size_t N> class ColorRow {
public:

@ -12,8 +12,8 @@
#include <cstring>
#include <type_traits>
#include "BC1/BC1Block.h"
#include "Color.h"
#include "blocks.h"
#include "tables.h"
#include "util.h"

@ -55,7 +55,10 @@
#include <cstdint>
#include "blocks.h"
#include "BC1/BC1Block.h"
#include "BC3/BC3Block.h"
#include "BC4/BC4Block.h"
#include "BC5/BC5Block.h"
#include "interpolator.h"
// By default, the table used to accelerate cluster fit on 4 color blocks uses a 969x128 entry table.

@ -17,7 +17,6 @@
#include <type_traits>
#include <vector>
#include "../blocks.h"
#include "../rgbcx.h"
#include "../rgbcxDecoders.h"
#include "../util.h"
@ -26,6 +25,8 @@
#include "dds_defs.h"
#include "lodepng.h"
using namespace rgbcx;
const int MAX_UBER_LEVEL = 5;
static int print_usage() {

Loading…
Cancel
Save