From b38f69dc7882fd4b8e464bd22d04f58a20d1fdc2 Mon Sep 17 00:00:00 2001 From: samcake Date: Sat, 29 Oct 2016 22:43:42 -0700 Subject: [PATCH] stage 0 of fooling around with image compression.... --- libraries/gpu/src/gpu/Image.cpp | 9 +++-- libraries/gpu/src/gpu/Image.h | 49 ++++++++++++++---------- libraries/model/src/model/TextureMap.cpp | 22 +++++++++-- 3 files changed, 53 insertions(+), 27 deletions(-) diff --git a/libraries/gpu/src/gpu/Image.cpp b/libraries/gpu/src/gpu/Image.cpp index b3fcbe11eb..eddc1d60d7 100644 --- a/libraries/gpu/src/gpu/Image.cpp +++ b/libraries/gpu/src/gpu/Image.cpp @@ -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 = } } diff --git a/libraries/gpu/src/gpu/Image.h b/libraries/gpu/src/gpu/Image.h index ff106f65b6..c9969b8e15 100644 --- a/libraries/gpu/src/gpu/Image.h +++ b/libraries/gpu/src/gpu/Image.h @@ -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 bitVal() { return 1 << N; } + template int bitProduct() { return bitVal() * bitVal(); } + template T mix(const T x, const T y, const A a) { return T(((bitVal() - a) * x + a * y) / bitProduct()); } + + 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 bitVal() { return 1 << N; } - template int bitProduct() { return bitVal() * bitVal(); } - template T mix(const T x, const T y, const A a) { return T(((bitVal() - a) * x + a * y) / bitProduct()); } - + 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 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; using PixRGBA32 = Pixel; + template 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 (&pixels->raw); } }; class BC { @@ -104,6 +110,9 @@ namespace image { PixRGB565 color0; PixRGB565 color1; pixel::Byte4 table; + + + Byte }; struct BC4 { PixRGB565 color0; diff --git a/libraries/model/src/model/TextureMap.cpp b/libraries/model/src/model/TextureMap.cpp index bd1a4baf48..1cbff8bd21 100755 --- a/libraries/model/src/model/TextureMap.cpp +++ b/libraries/model/src/model/TextureMap.cpp @@ -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);