Designing IMage

This commit is contained in:
samcake 2016-10-24 18:35:15 -07:00
parent 4ac0c29d9b
commit 07d1daaa9b
3 changed files with 47 additions and 13 deletions

View file

@ -1,17 +1,29 @@
#include "TextureUtils.h" #include "Image.h"
int image::Pixel::cpp { 0 }; int image::Pixel::cpp { 0 };
namespace image { namespace image {
template <> void compress(const PB_RGB32& src, CB_8& dst) {
template <> void compress(const PB_RGB32& src, CB_8& dst) {
for (auto& b : dst.bytes) { for (auto& b : dst.bytes) {
b = 12; b = 12;
} }
} }
template <> void uncompress(const CB_8& src, PB_RGB32& dst) {
for (auto& b : dst.bytes) {
b = 12;
}
}
template <> void compress(const PB_RGBA32& src, CB_8& dst) { template <> void compress(const PB_RGBA32& src, CB_8& dst) {
} }
template <> void uncompress(const CB_8& src, PB_RGBA32& dst) {
}
} }

View file

@ -10,9 +10,13 @@ namespace image {
class Pixel { class Pixel {
public: public:
using Byte = uint8_t; using Byte = uint8_t;
static const Byte BLACK { 0 }; using Byte2 = uint16_t;
static const Byte WHITE { 255 }; using Byte4 = uint32_t;
static const Byte BLACK8 { 0 };
static const Byte WHITE8 { 255 };
struct RGB32 { struct RGB32 {
Byte r { BLACK }; Byte r { BLACK };
Byte g { BLACK }; Byte g { BLACK };
@ -26,8 +30,14 @@ namespace image {
Byte b { BLACK }; Byte b { BLACK };
Byte a { WHITE }; Byte a { WHITE };
}; };
struct RGB16_565 {
Byte2 b : 5;
Byte2 g : 6;
Byte2 r : 5;
};
static int cpp; static int cpp;
}; };
@ -36,7 +46,7 @@ namespace image {
static const uint32_t WIDTH { 4 }; static const uint32_t WIDTH { 4 };
static const uint32_t HEIGHT { WIDTH }; static const uint32_t HEIGHT { WIDTH };
static const uint32_t SIZE { WIDTH * HEIGHT }; static const uint32_t SIZE { WIDTH * HEIGHT };
constexpr uint32_t getByteSize() const { return SIZE * sizeof(P); } uint32_t getByteSize() const { return SIZE * sizeof(P); }
P pixels[SIZE]; P pixels[SIZE];
@ -50,7 +60,6 @@ namespace image {
void setPixels(const P* srcPixels) { void setPixels(const P* srcPixels) {
memcpy(pixels, srcPixels, getByteSize()); memcpy(pixels, srcPixels, getByteSize());
} }
}; };
template <int Size> class CompressedBlock { template <int Size> class CompressedBlock {
@ -58,7 +67,19 @@ namespace image {
uint8_t bytes[Size]; uint8_t bytes[Size];
}; };
template <typename PB, typename CB> void compress(const PB& srcPixelBlock, CB& dstBlock) { } class BC {
public:
struct BC1 {
Pixel::RGB16_565 color_0;
Pixel::RGB16_565 color_1;
Pixel::Byte4 table;
};
};
template <typename PB, typename CB> void compress(const PB& srcBlock, CB& dstBlock) { }
template <typename PB, typename CB> void uncompress(const CB& srcBlock, PB& dstBlock) { }
using PB_RGB32 = PixelBlock<Pixel::RGB32>; using PB_RGB32 = PixelBlock<Pixel::RGB32>;
using PB_RGBA32 = PixelBlock<Pixel::RGBA32>; using PB_RGBA32 = PixelBlock<Pixel::RGBA32>;
@ -68,6 +89,7 @@ namespace image {
template <> void compress(const PB_RGB32& src, CB_8& dst); template <> void compress(const PB_RGB32& src, CB_8& dst);
template <> void compress(const PB_RGBA32& src, CB_8& dst); template <> void compress(const PB_RGBA32& src, CB_8& dst);
template <> void uncompress(const CB_8& src, PB_RGB32& dst);
template <> void uncompress(const CB_8& src, PB_RGBA32& dst);
} }

View file

@ -15,7 +15,7 @@
#include <QDebug> #include <QDebug>
#include "ModelLogging.h" #include "ModelLogging.h"
#include <gpu/TextureUtils.h> #include <gpu/Image.cpp>
using namespace model; using namespace model;
using namespace gpu; using namespace gpu;