mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 05:37:13 +02:00
Saving state before merge up
This commit is contained in:
parent
f077b9a6c0
commit
41109553eb
3 changed files with 118 additions and 54 deletions
|
@ -32,7 +32,7 @@ template <> void uncompress(const CB_BC1& src, PB_RGB32& dst) {
|
||||||
auto r = pixel::mix(
|
auto r = pixel::mix(
|
||||||
c0,
|
c0,
|
||||||
c1,
|
c1,
|
||||||
(pixel::Byte)bc1.table);
|
(Byte)bc1.table);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
Let s try compressing images
|
Let s try compressing images
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
#include "Forward.h"
|
#include "Forward.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,6 +13,20 @@ namespace image {
|
||||||
using Byte = uint8_t;
|
using Byte = uint8_t;
|
||||||
using Byte2 = uint16_t;
|
using Byte2 = uint16_t;
|
||||||
using Byte4 = uint32_t;
|
using Byte4 = uint32_t;
|
||||||
|
using Byte8 = uint64_t;
|
||||||
|
|
||||||
|
// Storage type selector based on size (sizeof of a type)
|
||||||
|
template<int size, typename T1 = Byte, typename T2 = Byte2, typename T4 = Byte4, typename T8 = Byte8>
|
||||||
|
struct storage { typedef T1 type; };
|
||||||
|
|
||||||
|
template<typename T1, typename T2, typename T4, typename T8>
|
||||||
|
struct storage<2, T1, T2, T4, T8> { typedef T2 type; };
|
||||||
|
|
||||||
|
template<typename T1, typename T2, typename T4, typename T8>
|
||||||
|
struct storage<4, T1, T2, T4, T8> { typedef T4 type; };
|
||||||
|
|
||||||
|
template<typename T1, typename T2, typename T4, typename T8>
|
||||||
|
struct storage<8, T1, T2, T4, T8> { typedef T8 type; };
|
||||||
|
|
||||||
static const Byte BLACK8 { 0 };
|
static const Byte BLACK8 { 0 };
|
||||||
static const Byte WHITE8 { 255 };
|
static const Byte WHITE8 { 255 };
|
||||||
|
@ -25,7 +41,6 @@ namespace image {
|
||||||
|
|
||||||
namespace pixel {
|
namespace pixel {
|
||||||
|
|
||||||
|
|
||||||
struct RGB32 {
|
struct RGB32 {
|
||||||
Byte r { BLACK8 };
|
Byte r { BLACK8 };
|
||||||
Byte g { BLACK8 };
|
Byte g { BLACK8 };
|
||||||
|
@ -40,7 +55,6 @@ namespace image {
|
||||||
Byte a { WHITE8 };
|
Byte a { WHITE8 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct RGB16_565 {
|
struct RGB16_565 {
|
||||||
Byte2 b : 5;
|
Byte2 b : 5;
|
||||||
Byte2 g : 6;
|
Byte2 g : 6;
|
||||||
|
@ -49,58 +63,66 @@ namespace image {
|
||||||
RGB16_565() : b(BLACK8), g(BLACK8), r(BLACK8) {}
|
RGB16_565() : b(BLACK8), g(BLACK8), r(BLACK8) {}
|
||||||
RGB16_565(Byte pR, Byte pG, Byte pB) : b(pB), g(pG), r(pR) {}
|
RGB16_565(Byte pR, Byte pG, Byte pB) : b(pB), g(pG), r(pR) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct R8 {
|
||||||
|
Byte r { BLACK8 };
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename P, typename S> const P mix(const P p0, const P p1, const S alpha) { return p0; }
|
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);
|
template <> const RGB16_565 mix(const RGB16_565 p0, const RGB16_565 p1, const Byte alpha);
|
||||||
|
|
||||||
};
|
template <typename F, typename S = typename storage<sizeof(F)>::type > class Pixel {
|
||||||
|
public:
|
||||||
template <typename F, typename S> class Pixel {
|
using Format = F;
|
||||||
public:
|
using Storage = S;
|
||||||
using Format = F;
|
|
||||||
using Storage = S;
|
union {
|
||||||
|
Storage raw;
|
||||||
union {
|
Format val{ Format() }; // Format last to be initialized by Format's default constructor
|
||||||
Storage raw;
|
};
|
||||||
Format val{ Format() }; // Format last to be initialized by Format's default constructor
|
|
||||||
|
Pixel() {};
|
||||||
|
Pixel(Format v) : val(v) {}
|
||||||
|
Pixel(Storage s) : raw(s) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Pixel() {};
|
template <typename P> class PixelBlock {
|
||||||
Pixel(Format v) : val(v) {}
|
public:
|
||||||
Pixel(Storage s) : raw(s) {}
|
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];
|
||||||
|
|
||||||
|
PixelBlock() {}
|
||||||
|
|
||||||
|
|
||||||
|
PixelBlock(const P* srcPixels) {
|
||||||
|
setPixels(srcPixels);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setPixels(const P* srcPixels) {
|
||||||
|
memcpy(pixels, srcPixels, getSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
const Storage* getStorage() const { return static_cast<const Storage*> (&pixels->raw); }
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
using PixRGB565 = Pixel<pixel::RGB16_565, pixel::Byte2>;
|
|
||||||
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 };
|
using PixRGB565 = pixel::Pixel<pixel::RGB16_565>;
|
||||||
static const uint32_t SIZE { WIDTH * HEIGHT };
|
using PixRGB32 = pixel::Pixel<pixel::RGB32>;
|
||||||
|
using PixRGBA32 = pixel::Pixel<pixel::RGBA32>;
|
||||||
uint32_t getSize() const { return SIZE * sizeof(P); }
|
using PixR8 = pixel::Pixel<pixel::R8>;
|
||||||
|
|
||||||
P pixels[SIZE];
|
|
||||||
|
|
||||||
PixelBlock() {}
|
|
||||||
|
|
||||||
|
|
||||||
PixelBlock(const P* srcPixels) {
|
|
||||||
setPixels(srcPixels);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setPixels(const P* srcPixels) {
|
|
||||||
memcpy(pixels, srcPixels, getSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
const Storage* getStorage() const { return static_cast<const Storage*> (&pixels->raw); }
|
|
||||||
};
|
|
||||||
|
|
||||||
class BC {
|
class BC {
|
||||||
public:
|
public:
|
||||||
|
@ -109,15 +131,13 @@ namespace image {
|
||||||
struct BC1 {
|
struct BC1 {
|
||||||
PixRGB565 color0;
|
PixRGB565 color0;
|
||||||
PixRGB565 color1;
|
PixRGB565 color1;
|
||||||
pixel::Byte4 table;
|
Byte4 table;
|
||||||
|
|
||||||
|
|
||||||
Byte
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BC4 {
|
struct BC4 {
|
||||||
PixRGB565 color0;
|
PixRGB565 color0;
|
||||||
PixRGB565 color1;
|
PixRGB565 color1;
|
||||||
pixel::Byte4 table;
|
Byte4 table;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -125,19 +145,20 @@ namespace image {
|
||||||
public:
|
public:
|
||||||
static const uint32_t SIZE { sizeof(T) };
|
static const uint32_t SIZE { sizeof(T) };
|
||||||
union {
|
union {
|
||||||
pixel::Byte bytes[SIZE];
|
Byte bytes[SIZE];
|
||||||
T bc;
|
T bc;
|
||||||
};
|
};
|
||||||
|
|
||||||
CompressedBlock() {}
|
CompressedBlock() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename PB, typename CB> void compress(const PB& srcBlock, CB& dstBlock) { }
|
template <typename PB, typename CB> void compress(const PB& srcBlock, CB& dstBlock) { }
|
||||||
template <typename PB, typename CB> void uncompress(const CB& srcBlock, PB& dstBlock) { }
|
template <typename PB, typename CB> void uncompress(const CB& srcBlock, PB& dstBlock) { }
|
||||||
|
|
||||||
|
|
||||||
using PB_RGB32 = PixelBlock<PixRGB32>;
|
using PB_RGB32 = pixel::PixelBlock<PixRGB32>;
|
||||||
using PB_RGBA32 = PixelBlock<PixRGBA32>;
|
using PB_RGBA32 = pixel::PixelBlock<PixRGBA32>;
|
||||||
|
|
||||||
using CB_BC1 = CompressedBlock<BC::BC1>;
|
using CB_BC1 = CompressedBlock<BC::BC1>;
|
||||||
using CB_BC4 = CompressedBlock<BC::BC4>;
|
using CB_BC4 = CompressedBlock<BC::BC4>;
|
||||||
|
@ -147,4 +168,44 @@ namespace image {
|
||||||
|
|
||||||
template <> void uncompress(const CB_BC1& src, PB_RGB32& dst);
|
template <> void uncompress(const CB_BC1& src, PB_RGB32& dst);
|
||||||
template <> void uncompress(const CB_BC4& src, PB_RGBA32& dst);
|
template <> void uncompress(const CB_BC4& src, PB_RGBA32& dst);
|
||||||
|
|
||||||
|
|
||||||
|
template <typename P, typename B>
|
||||||
|
class PixelBlockArray {
|
||||||
|
public:
|
||||||
|
using Pixel = P;
|
||||||
|
using Block = pixel::PixelBlock<Pixel>;
|
||||||
|
|
||||||
|
using Blocks = std::vector<Block>;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class Grid {
|
||||||
|
public:
|
||||||
|
using Coord = uint16_t;
|
||||||
|
using Coord2 = glm::u16vec2;
|
||||||
|
using Size = uint32_t;
|
||||||
|
|
||||||
|
Coord2 _block { 1, 1 };
|
||||||
|
Coord2 _surface { 1, 1 };
|
||||||
|
|
||||||
|
Coord width() const { return _surface.x; }
|
||||||
|
Coord height() const { return _surface.y; }
|
||||||
|
Size size() const { return width() * height(); }
|
||||||
|
|
||||||
|
Coord blockWidth() const { return _block.x; }
|
||||||
|
Coord blockHeight() const { return _block.y; }
|
||||||
|
Size blockSize() const { return blockWidth() * blockHeight(); }
|
||||||
|
|
||||||
|
Coord pixelWidth() const { return _surface.x * _block.x; }
|
||||||
|
Coordisd pixelHeight() const { return _surface.y * _block.y; }
|
||||||
|
Size pixelSize() const { return pixelWidth() * pixelHeight(); }
|
||||||
|
|
||||||
|
Coord2 pixelToBlock(const Coord2& coord) const {
|
||||||
|
auto blockX = coord.x / blockWidth();
|
||||||
|
auto blockY = coord.y / blockHeight();
|
||||||
|
return Coord2(blockX, blockY);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
}
|
}
|
|
@ -252,6 +252,8 @@ gpu::Texture* TextureUsage::process2DTextureColorFromImage(const QImage& srcImag
|
||||||
|
|
||||||
image::PixRGBA32 pix1;
|
image::PixRGBA32 pix1;
|
||||||
|
|
||||||
|
image::PixR8 pix2;
|
||||||
|
|
||||||
image::PixRGB565 pix3;
|
image::PixRGB565 pix3;
|
||||||
|
|
||||||
image::PB_RGB32 pb0;
|
image::PB_RGB32 pb0;
|
||||||
|
@ -260,6 +262,7 @@ gpu::Texture* TextureUsage::process2DTextureColorFromImage(const QImage& srcImag
|
||||||
|
|
||||||
auto pix0_s = sizeof(pix0);
|
auto pix0_s = sizeof(pix0);
|
||||||
auto pix1_s = sizeof(pix1);
|
auto pix1_s = sizeof(pix1);
|
||||||
|
auto pix2_s = sizeof(pix2);
|
||||||
auto pix3_s = sizeof(pix3);
|
auto pix3_s = sizeof(pix3);
|
||||||
|
|
||||||
auto pb0_s = sizeof(pb0);
|
auto pb0_s = sizeof(pb0);
|
||||||
|
|
Loading…
Reference in a new issue