mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 01:24:03 +02:00
stage 0 of fooling around with image compression....
This commit is contained in:
parent
c65269e72d
commit
b38f69dc78
3 changed files with 53 additions and 27 deletions
|
@ -23,15 +23,16 @@ template <> void compress(const PB_RGB32& src, CB_BC1& dst) {
|
|||
|
||||
template <> void uncompress(const CB_BC1& src, PB_RGB32& dst) {
|
||||
auto bc1 = src.bc;
|
||||
auto c0 = bc1.color0;
|
||||
auto c1 = bc1.color1;
|
||||
|
||||
for (auto& p : dst.pixels) {
|
||||
auto c0 = bc1.color0.val;
|
||||
auto c1 = bc1.color1.val;
|
||||
|
||||
for (int i = 0; i < PB_RGB32::SIZE; ++i) {
|
||||
//dst.pixels[i] = ;
|
||||
auto r = pixel::mix(
|
||||
c0,
|
||||
c1,
|
||||
(pixel::Byte)bc1.table);
|
||||
///p.val =
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,19 +7,25 @@
|
|||
|
||||
namespace image {
|
||||
|
||||
// Storage types
|
||||
using Byte = uint8_t;
|
||||
using Byte2 = uint16_t;
|
||||
using Byte4 = uint32_t;
|
||||
|
||||
static const Byte BLACK8 { 0 };
|
||||
static const Byte WHITE8 { 255 };
|
||||
|
||||
template <int N> int bitVal() { return 1 << N; }
|
||||
template <int Tn, int An> int bitProduct() { return bitVal<Tn>() * bitVal<An>(); }
|
||||
template <int Tn, int An, typename T = Byte, typename A = T> T mix(const T x, const T y, const A a) { return T(((bitVal<An>() - a) * x + a * y) / bitProduct<Tn, An>()); }
|
||||
|
||||
Byte mix5_4(const Byte x, const Byte y, const Byte a) { return mix<5, 4>(x, y, a); }
|
||||
Byte mix6_4(const Byte x, const Byte y, const Byte a) { return mix<6, 4>(x, y, a); }
|
||||
|
||||
|
||||
namespace pixel {
|
||||
|
||||
using Byte = uint8_t;
|
||||
using Byte2 = uint16_t;
|
||||
using Byte4 = uint32_t;
|
||||
|
||||
static const Byte BLACK8 { 0 };
|
||||
static const Byte WHITE8 { 255 };
|
||||
|
||||
template <int N> int bitVal() { return 1 << N; }
|
||||
template <int Tn, int An> int bitProduct() { return bitVal<Tn>() * bitVal<An>(); }
|
||||
template <int Tn, int An, typename T = Byte, typename A = T> T mix(const T x, const T y, const A a) { return T(((bitVal<An>() - a) * x + a * y) / bitProduct<Tn, An>()); }
|
||||
|
||||
|
||||
struct RGB32 {
|
||||
Byte r { BLACK8 };
|
||||
Byte g { BLACK8 };
|
||||
|
@ -43,16 +49,9 @@ namespace image {
|
|||
RGB16_565() : b(BLACK8), g(BLACK8), r(BLACK8) {}
|
||||
RGB16_565(Byte pR, Byte pG, Byte pB) : b(pB), g(pG), r(pR) {}
|
||||
};
|
||||
|
||||
|
||||
Byte mix5_4(const Byte x, const Byte y, const Byte a) { return mix<5, 4>(x, y, a); }
|
||||
Byte mix6_4(const Byte x, const Byte y, const Byte a) { return mix<6, 4>(x, y, a); }
|
||||
|
||||
|
||||
|
||||
template <typename P, typename S> const P mix(const P p0, const P p1, const S alpha) { return p0; }
|
||||
|
||||
template <> const RGB16_565 mix(const RGB16_565 p0, const RGB16_565 p1, const Byte alpha);
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
@ -62,8 +61,8 @@ namespace image {
|
|||
using Storage = S;
|
||||
|
||||
union {
|
||||
Format val;
|
||||
Storage raw;
|
||||
Format val{ Format() }; // Format last to be initialized by Format's default constructor
|
||||
};
|
||||
|
||||
Pixel() {};
|
||||
|
@ -75,11 +74,16 @@ namespace image {
|
|||
using PixRGB32 = Pixel<pixel::RGB32, pixel::Byte4>;
|
||||
using PixRGBA32 = Pixel<pixel::RGBA32, pixel::Byte4>;
|
||||
|
||||
|
||||
template <typename P> class PixelBlock {
|
||||
public:
|
||||
using Format = typename P::Format;
|
||||
using Storage = typename P::Storage;
|
||||
|
||||
static const uint32_t WIDTH { 4 };
|
||||
static const uint32_t HEIGHT { WIDTH };
|
||||
static const uint32_t SIZE { WIDTH * HEIGHT };
|
||||
|
||||
uint32_t getSize() const { return SIZE * sizeof(P); }
|
||||
|
||||
P pixels[SIZE];
|
||||
|
@ -94,6 +98,8 @@ namespace image {
|
|||
void setPixels(const P* srcPixels) {
|
||||
memcpy(pixels, srcPixels, getSize());
|
||||
}
|
||||
|
||||
const Storage* getStorage() const { return static_cast<const Storage*> (&pixels->raw); }
|
||||
};
|
||||
|
||||
class BC {
|
||||
|
@ -104,6 +110,9 @@ namespace image {
|
|||
PixRGB565 color0;
|
||||
PixRGB565 color1;
|
||||
pixel::Byte4 table;
|
||||
|
||||
|
||||
Byte
|
||||
};
|
||||
struct BC4 {
|
||||
PixRGB565 color0;
|
||||
|
|
|
@ -248,10 +248,26 @@ gpu::Texture* TextureUsage::process2DTextureColorFromImage(const QImage& srcImag
|
|||
|
||||
theTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits());
|
||||
|
||||
image::PB_RGB32 pb;
|
||||
image::CB_BC1 cb;
|
||||
image::PixRGB32 pix0;
|
||||
|
||||
image::compress(pb, cb);
|
||||
image::PixRGBA32 pix1;
|
||||
|
||||
image::PixRGB565 pix3;
|
||||
|
||||
image::PB_RGB32 pb0;
|
||||
image::CB_BC1 cb;
|
||||
image::PB_RGB32 pb1;
|
||||
|
||||
auto pix0_s = sizeof(pix0);
|
||||
auto pix1_s = sizeof(pix1);
|
||||
auto pix3_s = sizeof(pix3);
|
||||
|
||||
auto pb0_s = sizeof(pb0);
|
||||
auto cb_s = sizeof(cb);
|
||||
|
||||
auto cb_bytes = pb0.getStorage();
|
||||
image::compress(pb0, cb);
|
||||
image::uncompress(cb, pb1);
|
||||
|
||||
if (generateMips) {
|
||||
::generateMips(theTexture, image, formatMip);
|
||||
|
|
Loading…
Reference in a new issue