diff options
Diffstat (limited to 'source/blender/imbuf/intern/dds')
-rw-r--r-- | source/blender/imbuf/intern/dds/BlockDXT.cpp | 42 | ||||
-rw-r--r-- | source/blender/imbuf/intern/dds/BlockDXT.h | 58 | ||||
-rw-r--r-- | source/blender/imbuf/intern/dds/ColorBlock.cpp | 15 | ||||
-rw-r--r-- | source/blender/imbuf/intern/dds/ColorBlock.h | 2 | ||||
-rw-r--r-- | source/blender/imbuf/intern/dds/DirectDrawSurface.cpp | 15 |
5 files changed, 86 insertions, 46 deletions
diff --git a/source/blender/imbuf/intern/dds/BlockDXT.cpp b/source/blender/imbuf/intern/dds/BlockDXT.cpp index 24a090d93f6..06a0cd9336b 100644 --- a/source/blender/imbuf/intern/dds/BlockDXT.cpp +++ b/source/blender/imbuf/intern/dds/BlockDXT.cpp @@ -277,7 +277,7 @@ void BlockDXT3::flip2() void AlphaBlockDXT5::evaluatePalette(uint8 alpha[8]) const { - if (alpha0 > alpha1) { + if (alpha0() > alpha1()) { evaluatePalette8(alpha); } else { @@ -289,8 +289,8 @@ void AlphaBlockDXT5::evaluatePalette8(uint8 alpha[8]) const { // 8-alpha block: derive the other six alphas. // Bit code 000 = alpha0, 001 = alpha1, others are interpolated. - alpha[0] = alpha0; - alpha[1] = alpha1; + alpha[0] = alpha0(); + alpha[1] = alpha1(); alpha[2] = (6 * alpha[0] + 1 * alpha[1]) / 7; // bit code 010 alpha[3] = (5 * alpha[0] + 2 * alpha[1]) / 7; // bit code 011 alpha[4] = (4 * alpha[0] + 3 * alpha[1]) / 7; // bit code 100 @@ -303,8 +303,8 @@ void AlphaBlockDXT5::evaluatePalette6(uint8 alpha[8]) const { // 6-alpha block. // Bit code 000 = alpha0, 001 = alpha1, others are interpolated. - alpha[0] = alpha0; - alpha[1] = alpha1; + alpha[0] = alpha0(); + alpha[1] = alpha1(); alpha[2] = (4 * alpha[0] + 1 * alpha[1]) / 5; // Bit code 010 alpha[3] = (3 * alpha[0] + 2 * alpha[1]) / 5; // Bit code 011 alpha[4] = (2 * alpha[0] + 3 * alpha[1]) / 5; // Bit code 100 @@ -315,22 +315,22 @@ void AlphaBlockDXT5::evaluatePalette6(uint8 alpha[8]) const void AlphaBlockDXT5::indices(uint8 index_array[16]) const { - index_array[0x0] = bits0; - index_array[0x1] = bits1; - index_array[0x2] = bits2; - index_array[0x3] = bits3; - index_array[0x4] = bits4; - index_array[0x5] = bits5; - index_array[0x6] = bits6; - index_array[0x7] = bits7; - index_array[0x8] = bits8; - index_array[0x9] = bits9; - index_array[0xA] = bitsA; - index_array[0xB] = bitsB; - index_array[0xC] = bitsC; - index_array[0xD] = bitsD; - index_array[0xE] = bitsE; - index_array[0xF] = bitsF; + index_array[0x0] = bits0(); + index_array[0x1] = bits1(); + index_array[0x2] = bits2(); + index_array[0x3] = bits3(); + index_array[0x4] = bits4(); + index_array[0x5] = bits5(); + index_array[0x6] = bits6(); + index_array[0x7] = bits7(); + index_array[0x8] = bits8(); + index_array[0x9] = bits9(); + index_array[0xA] = bitsA(); + index_array[0xB] = bitsB(); + index_array[0xC] = bitsC(); + index_array[0xD] = bitsD(); + index_array[0xE] = bitsE(); + index_array[0xF] = bitsF(); } uint AlphaBlockDXT5::index(uint index) const diff --git a/source/blender/imbuf/intern/dds/BlockDXT.h b/source/blender/imbuf/intern/dds/BlockDXT.h index 5c232201f0c..ae640f6b5cc 100644 --- a/source/blender/imbuf/intern/dds/BlockDXT.h +++ b/source/blender/imbuf/intern/dds/BlockDXT.h @@ -143,29 +143,51 @@ struct BlockDXT3 /// DXT5 alpha block. struct AlphaBlockDXT5 { + // uint64 unions do not compile on all platforms + /* union { struct { - unsigned int alpha0 : 8; // 8 - unsigned int alpha1 : 8; // 16 - unsigned int bits0 : 3; // 3 - 19 - unsigned int bits1 : 3; // 6 - 22 - unsigned int bits2 : 3; // 9 - 25 - unsigned int bits3 : 3; // 12 - 28 - unsigned int bits4 : 3; // 15 - 31 - unsigned int bits5 : 3; // 18 - 34 - unsigned int bits6 : 3; // 21 - 37 - unsigned int bits7 : 3; // 24 - 40 - unsigned int bits8 : 3; // 27 - 43 - unsigned int bits9 : 3; // 30 - 46 - unsigned int bitsA : 3; // 33 - 49 - unsigned int bitsB : 3; // 36 - 52 - unsigned int bitsC : 3; // 39 - 55 - unsigned int bitsD : 3; // 42 - 58 - unsigned int bitsE : 3; // 45 - 61 - unsigned int bitsF : 3; // 48 - 64 + uint64 alpha0 : 8; // 8 + uint64 alpha1 : 8; // 16 + uint64 bits0 : 3; // 3 - 19 + uint64 bits1 : 3; // 6 - 22 + uint64 bits2 : 3; // 9 - 25 + uint64 bits3 : 3; // 12 - 28 + uint64 bits4 : 3; // 15 - 31 + uint64 bits5 : 3; // 18 - 34 + uint64 bits6 : 3; // 21 - 37 + uint64 bits7 : 3; // 24 - 40 + uint64 bits8 : 3; // 27 - 43 + uint64 bits9 : 3; // 30 - 46 + uint64 bitsA : 3; // 33 - 49 + uint64 bitsB : 3; // 36 - 52 + uint64 bitsC : 3; // 39 - 55 + uint64 bitsD : 3; // 42 - 58 + uint64 bitsE : 3; // 45 - 61 + uint64 bitsF : 3; // 48 - 64 }; uint64 u; }; + */ + uint64 u; + uint8 alpha0() const { return u & 0xffLL; }; + uint8 alpha1() const { return (u >> 8) & 0xffLL; }; + uint8 bits0() const { return (u >> 16) & 0x7LL; }; + uint8 bits1() const { return (u >> 19) & 0x7LL; }; + uint8 bits2() const { return (u >> 22) & 0x7LL; }; + uint8 bits3() const { return (u >> 25) & 0x7LL; }; + uint8 bits4() const { return (u >> 28) & 0x7LL; }; + uint8 bits5() const { return (u >> 31) & 0x7LL; }; + uint8 bits6() const { return (u >> 34) & 0x7LL; }; + uint8 bits7() const { return (u >> 37) & 0x7LL; }; + uint8 bits8() const { return (u >> 40) & 0x7LL; }; + uint8 bits9() const { return (u >> 43) & 0x7LL; }; + uint8 bitsA() const { return (u >> 46) & 0x7LL; }; + uint8 bitsB() const { return (u >> 49) & 0x7LL; }; + uint8 bitsC() const { return (u >> 52) & 0x7LL; }; + uint8 bitsD() const { return (u >> 55) & 0x7LL; }; + uint8 bitsE() const { return (u >> 58) & 0x7LL; }; + uint8 bitsF() const { return (u >> 61) & 0x7LL; }; void evaluatePalette(uint8 alpha[8]) const; void evaluatePalette8(uint8 alpha[8]) const; diff --git a/source/blender/imbuf/intern/dds/ColorBlock.cpp b/source/blender/imbuf/intern/dds/ColorBlock.cpp index 0199d15ada7..761501b1225 100644 --- a/source/blender/imbuf/intern/dds/ColorBlock.cpp +++ b/source/blender/imbuf/intern/dds/ColorBlock.cpp @@ -103,7 +103,7 @@ void ColorBlock::swizzleDXT5n() for(int i = 0; i < 16; i++) { Color32 c = m_color[i]; - m_color[i] = Color32(0, c.g, 0, c.r); + m_color[i] = Color32(0xFF, c.g, 0, c.r); } } @@ -125,6 +125,19 @@ void ColorBlock::splatY() } } +/// Returns true if the block has a single color. +bool ColorBlock::isSingleColor() const +{ + for(int i = 1; i < 16; i++) + { + if (m_color[0] != m_color[i]) + { + return false; + } + } + + return true; +} /// Count number of unique colors in this color block. uint ColorBlock::countUniqueColors() const diff --git a/source/blender/imbuf/intern/dds/ColorBlock.h b/source/blender/imbuf/intern/dds/ColorBlock.h index 72049be5f3c..1feaed4d659 100644 --- a/source/blender/imbuf/intern/dds/ColorBlock.h +++ b/source/blender/imbuf/intern/dds/ColorBlock.h @@ -53,6 +53,7 @@ struct ColorBlock void splatX(); void splatY(); + bool isSingleColor() const; uint countUniqueColors() const; Color32 averageColor() const; bool hasAlpha() const; @@ -61,7 +62,6 @@ struct ColorBlock void luminanceRange(Color32 * start, Color32 * end) const; void boundsRange(Color32 * start, Color32 * end) const; void boundsRangeAlpha(Color32 * start, Color32 * end) const; - void bestFitRange(Color32 * start, Color32 * end) const; void sortColorsByAbsoluteValue(); diff --git a/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp b/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp index f842c756ce1..702f87dfe25 100644 --- a/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp +++ b/source/blender/imbuf/intern/dds/DirectDrawSurface.cpp @@ -496,9 +496,9 @@ void DDSHeader::setPixelFormat(uint bitcount, uint rmask, uint gmask, uint bmask } // Align to 8. - if (bitcount < 8) bitcount = 8; - else if (bitcount < 16) bitcount = 16; - else if (bitcount < 24) bitcount = 24; + if (bitcount <= 8) bitcount = 8; + else if (bitcount <= 16) bitcount = 16; + else if (bitcount <= 24) bitcount = 24; else bitcount = 32; this->pf.fourcc = 0; //findD3D9Format(bitcount, rmask, gmask, bmask, amask); @@ -606,7 +606,7 @@ bool DirectDrawSurface::isSupported() const uint DirectDrawSurface::mipmapCount() const { if (header.flags & DDSD_MIPMAPCOUNT) return header.mipmapcount; - else return 0; + else return 1; } @@ -770,7 +770,7 @@ static Color32 buildNormal(uint8 x, uint8 y) float nx = 2 * (x / 255.0f) - 1; float ny = 2 * (y / 255.0f) - 1; float nz = 0.0f; - if (1 - nx*nx - ny*ny > 0) nz = sqrt(1 - nx*nx - ny*ny); + if (1 - nx*nx - ny*ny > 0) nz = sqrtf(1 - nx*nx - ny*ny); uint8 z = clamp(int(255.0f * (nz + 1) / 2.0f), 0, 255); return Color32(x, y, z); @@ -921,6 +921,11 @@ uint DirectDrawSurface::offset(const uint face, const uint mipmap) { uint size = 128; //sizeof(DDSHeader); + if (header.hasDX10Header()) + { + size += 20; // sizeof(DDSHeader10); + } + if (face != 0) { size += face * faceSize(); |