diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-11-13 00:16:53 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-11-13 00:16:53 +0300 |
commit | bdfe7d89e2f1292644577972c716931b4ce3c6c3 (patch) | |
tree | d00eb50b749cb001e2b08272c91791e66740b05d /source/blender/imbuf/intern/dds/BlockDXT.cpp | |
parent | 78a1c27c4a6abe0ed31ca93ad21910f3df04da56 (diff) | |
parent | 7e4db234cee71ead34ee81a12e27da4bd548eb4b (diff) |
Merge of trunk into blender 2.5:
svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r12987:17416
Issues:
* GHOST/X11 had conflicting changes. Some code was added in 2.5, which was
later added in trunk also, but reverted partially, specifically revision
16683. I have left out this reversion in the 2.5 branch since I think it is
needed there.
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16683
* Scons had various conflicting changes, I decided to go with trunk version
for everything except priorities and some library renaming.
* In creator.c, there were various fixes and fixes for fixes related to the -w
-W and -p options. In 2.5 -w and -W is not coded yet, and -p is done
differently. Since this is changed so much, and I don't think those fixes
would be needed in 2.5, I've left them out.
* Also in creator.c: there was code for a python bugfix where the screen was not
initialized when running with -P. The code that initializes the screen there
I had to disable, that can't work in 2.5 anymore but left it commented as a
reminder.
Further I had to disable some new function calls. using src/ and python/, as
was done already in this branch, disabled function calls:
* bpath.c: error reporting
* BME_conversions.c: editmesh conversion functions.
* SHD_dynamic: disabled almost completely, there is no python/.
* KX_PythonInit.cpp and Ketsji/ build files: Mathutils is not there, disabled.
* text.c: clipboard copy call.
* object.c: OB_SUPPORT_MATERIAL.
* DerivedMesh.c and subsurf_ccg, stipple_quarttone.
Still to be done:
* Go over files and functions that were moved to a different location but could
still use changes that were done in trunk.
Diffstat (limited to 'source/blender/imbuf/intern/dds/BlockDXT.cpp')
-rw-r--r-- | source/blender/imbuf/intern/dds/BlockDXT.cpp | 214 |
1 files changed, 141 insertions, 73 deletions
diff --git a/source/blender/imbuf/intern/dds/BlockDXT.cpp b/source/blender/imbuf/intern/dds/BlockDXT.cpp index 44435317f69..2a8a2c470c4 100644 --- a/source/blender/imbuf/intern/dds/BlockDXT.cpp +++ b/source/blender/imbuf/intern/dds/BlockDXT.cpp @@ -61,7 +61,7 @@ BlockDXT1 ----------------------------------------------------------------------------*/ -unsigned int BlockDXT1::evaluatePalette(Color32 color_array[4]) const +uint BlockDXT1::evaluatePalette(Color32 color_array[4]) const { // Does bit expansion before interpolation. color_array[0].b = (col0.b << 3) | (col0.b >> 2); @@ -176,9 +176,9 @@ void BlockDXT1::decodeBlock(ColorBlock * block) const evaluatePalette(color_array); // Write color block. - for( unsigned int j = 0; j < 4; j++ ) { - for( unsigned int i = 0; i < 4; i++ ) { - unsigned int idx = (row[j] >> (2 * i)) & 3; + for( uint j = 0; j < 4; j++ ) { + for( uint i = 0; i < 4; i++ ) { + uint idx = (row[j] >> (2 * i)) & 3; block->color(i, j) = color_array[idx]; } } @@ -187,7 +187,7 @@ void BlockDXT1::decodeBlock(ColorBlock * block) const void BlockDXT1::setIndices(int * idx) { indices = 0; - for(unsigned int i = 0; i < 16; i++) { + for(uint i = 0; i < 16; i++) { indices |= (idx[i] & 3) << (2 * i); } } @@ -196,16 +196,14 @@ void BlockDXT1::setIndices(int * idx) /// Flip DXT1 block vertically. inline void BlockDXT1::flip4() { - unsigned char tmp; - swap(row[0], row[3], tmp); - swap(row[1], row[2], tmp); + swap(row[0], row[3]); + swap(row[1], row[2]); } /// Flip half DXT1 block vertically. inline void BlockDXT1::flip2() { - unsigned char tmp; - swap(row[0], row[1], tmp); + swap(row[0], row[1]); } @@ -245,16 +243,14 @@ void AlphaBlockDXT3::decodeBlock(ColorBlock * block) const /// Flip DXT3 alpha block vertically. void AlphaBlockDXT3::flip4() { - unsigned short tmp; - swap(row[0], row[3], tmp); - swap(row[1], row[2], tmp); + swap(row[0], row[3]); + swap(row[1], row[2]); } /// Flip half DXT3 alpha block vertically. void AlphaBlockDXT3::flip2() { - unsigned short tmp; - swap(row[0], row[1], tmp); + swap(row[0], row[1]); } /// Flip DXT3 block vertically. @@ -276,9 +272,9 @@ void BlockDXT3::flip2() BlockDXT5 ----------------------------------------------------------------------------*/ -void AlphaBlockDXT5::evaluatePalette(unsigned char alpha[8]) const +void AlphaBlockDXT5::evaluatePalette(uint8 alpha[8]) const { - if (alpha0 > alpha1) { + if (alpha0() > alpha1()) { evaluatePalette8(alpha); } else { @@ -286,100 +282,100 @@ void AlphaBlockDXT5::evaluatePalette(unsigned char alpha[8]) const } } -void AlphaBlockDXT5::evaluatePalette8(unsigned char alpha[8]) const +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[2] = (6 * alpha0 + 1 * alpha1) / 7; // bit code 010 - alpha[3] = (5 * alpha0 + 2 * alpha1) / 7; // bit code 011 - alpha[4] = (4 * alpha0 + 3 * alpha1) / 7; // bit code 100 - alpha[5] = (3 * alpha0 + 4 * alpha1) / 7; // bit code 101 - alpha[6] = (2 * alpha0 + 5 * alpha1) / 7; // bit code 110 - alpha[7] = (1 * alpha0 + 6 * alpha1) / 7; // bit code 111 + 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 + alpha[5] = (3 * alpha[0] + 4 * alpha[1]) / 7; // bit code 101 + alpha[6] = (2 * alpha[0] + 5 * alpha[1]) / 7; // bit code 110 + alpha[7] = (1 * alpha[0] + 6 * alpha[1]) / 7; // bit code 111 } -void AlphaBlockDXT5::evaluatePalette6(unsigned char alpha[8]) const +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[2] = (4 * alpha0 + 1 * alpha1) / 5; // Bit code 010 - alpha[3] = (3 * alpha0 + 2 * alpha1) / 5; // Bit code 011 - alpha[4] = (2 * alpha0 + 3 * alpha1) / 5; // Bit code 100 - alpha[5] = (1 * alpha0 + 4 * alpha1) / 5; // Bit code 101 + 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 + alpha[5] = (1 * alpha[0] + 4 * alpha[1]) / 5; // Bit code 101 alpha[6] = 0x00; // Bit code 110 alpha[7] = 0xFF; // Bit code 111 } -void AlphaBlockDXT5::indices(unsigned char index_array[16]) 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(); } -unsigned int AlphaBlockDXT5::index(unsigned int index) const +uint AlphaBlockDXT5::index(uint index) const { int offset = (3 * index + 16); - return (this->u >> offset) & 0x7; + return uint((this->u >> offset) & 0x7); } -void AlphaBlockDXT5::setIndex(unsigned int index, unsigned int value) +void AlphaBlockDXT5::setIndex(uint index, uint value) { int offset = (3 * index + 16); - unsigned long long mask = ((unsigned long long)(0x7)) << offset; - this->u = (this->u & ~mask) | (((unsigned long long)(value)) << offset); + uint64 mask = uint64(0x7) << offset; + this->u = (this->u & ~mask) | (uint64(value) << offset); } void AlphaBlockDXT5::decodeBlock(ColorBlock * block) const { - unsigned char alpha_array[8]; + uint8 alpha_array[8]; evaluatePalette(alpha_array); - unsigned char index_array[16]; + uint8 index_array[16]; indices(index_array); - for(unsigned int i = 0; i < 16; i++) { + for(uint i = 0; i < 16; i++) { block->color(i).a = alpha_array[index_array[i]]; } } void AlphaBlockDXT5::flip4() { - unsigned long long * b = (unsigned long long *)this; + uint64 * b = (uint64 *)this; // @@ The masks might have to be byte swapped. - unsigned long long tmp = (*b & (unsigned long long)(0x000000000000FFFFLL)); - tmp |= (*b & (unsigned long long)(0x000000000FFF0000LL)) << 36; - tmp |= (*b & (unsigned long long)(0x000000FFF0000000LL)) << 12; - tmp |= (*b & (unsigned long long)(0x000FFF0000000000LL)) >> 12; - tmp |= (*b & (unsigned long long)(0xFFF0000000000000LL)) >> 36; + uint64 tmp = (*b & (uint64)(0x000000000000FFFFLL)); + tmp |= (*b & (uint64)(0x000000000FFF0000LL)) << 36; + tmp |= (*b & (uint64)(0x000000FFF0000000LL)) << 12; + tmp |= (*b & (uint64)(0x000FFF0000000000LL)) >> 12; + tmp |= (*b & (uint64)(0xFFF0000000000000LL)) >> 36; *b = tmp; } void AlphaBlockDXT5::flip2() { - unsigned int * b = (unsigned int *)this; + uint * b = (uint *)this; // @@ The masks might have to be byte swapped. - unsigned int tmp = (*b & 0xFF000000); + uint tmp = (*b & 0xFF000000); tmp |= (*b & 0x00000FFF) << 12; tmp |= (*b & 0x00FFF000) >> 12; @@ -393,6 +389,7 @@ void BlockDXT5::decodeBlock(ColorBlock * block) const // Decode alpha. alpha.decodeBlock(block); + } /// Flip DXT5 block vertically. @@ -413,13 +410,13 @@ void BlockDXT5::flip2() /// Decode ATI1 block. void BlockATI1::decodeBlock(ColorBlock * block) const { - unsigned char alpha_array[8]; + uint8 alpha_array[8]; alpha.evaluatePalette(alpha_array); - unsigned char index_array[16]; + uint8 index_array[16]; alpha.indices(index_array); - for(unsigned int i = 0; i < 16; i++) { + for(uint i = 0; i < 16; i++) { Color32 & c = block->color(i); c.b = c.g = c.r = alpha_array[index_array[i]]; c.a = 255; @@ -442,13 +439,13 @@ void BlockATI1::flip2() /// Decode ATI2 block. void BlockATI2::decodeBlock(ColorBlock * block) const { - unsigned char alpha_array[8]; - unsigned char index_array[16]; + uint8 alpha_array[8]; + uint8 index_array[16]; x.evaluatePalette(alpha_array); x.indices(index_array); - for(unsigned int i = 0; i < 16; i++) { + for(uint i = 0; i < 16; i++) { Color32 & c = block->color(i); c.r = alpha_array[index_array[i]]; } @@ -456,7 +453,7 @@ void BlockATI2::decodeBlock(ColorBlock * block) const y.evaluatePalette(alpha_array); y.indices(index_array); - for(unsigned int i = 0; i < 16; i++) { + for(uint i = 0; i < 16; i++) { Color32 & c = block->color(i); c.g = alpha_array[index_array[i]]; c.b = 0; @@ -478,6 +475,68 @@ void BlockATI2::flip2() y.flip2(); } + +void BlockCTX1::evaluatePalette(Color32 color_array[4]) const +{ + // Does bit expansion before interpolation. + color_array[0].b = 0x00; + color_array[0].g = col0[1]; + color_array[0].r = col0[0]; + color_array[0].a = 0xFF; + + color_array[1].r = 0x00; + color_array[1].g = col0[1]; + color_array[1].b = col1[0]; + color_array[1].a = 0xFF; + + color_array[2].r = 0x00; + color_array[2].g = (2 * color_array[0].g + color_array[1].g) / 3; + color_array[2].b = (2 * color_array[0].b + color_array[1].b) / 3; + color_array[2].a = 0xFF; + + color_array[3].r = 0x00; + color_array[3].g = (2 * color_array[1].g + color_array[0].g) / 3; + color_array[3].b = (2 * color_array[1].b + color_array[0].b) / 3; + color_array[3].a = 0xFF; +} + +void BlockCTX1::decodeBlock(ColorBlock * block) const +{ + // Decode color block. + Color32 color_array[4]; + evaluatePalette(color_array); + + // Write color block. + for( uint j = 0; j < 4; j++ ) { + for( uint i = 0; i < 4; i++ ) { + uint idx = (row[j] >> (2 * i)) & 3; + block->color(i, j) = color_array[idx]; + } + } +} + +void BlockCTX1::setIndices(int * idx) +{ + indices = 0; + for(uint i = 0; i < 16; i++) { + indices |= (idx[i] & 3) << (2 * i); + } +} + + +/// Flip CTX1 block vertically. +inline void BlockCTX1::flip4() +{ + swap(row[0], row[3]); + swap(row[1], row[2]); +} + +/// Flip half CTX1 block vertically. +inline void BlockCTX1::flip2() +{ + swap(row[0], row[1]); +} + void mem_read(Stream & mem, BlockDXT1 & block) { mem_read(mem, block.col0.u); @@ -518,3 +577,12 @@ void mem_read(Stream & mem, BlockATI2 & block) mem_read(mem, block.y); } +void mem_read(Stream & mem, BlockCTX1 & block) +{ + mem_read(mem, block.col0[0]); + mem_read(mem, block.col0[1]); + mem_read(mem, block.col1[0]); + mem_read(mem, block.col1[1]); + mem_read(mem, block.indices); +} + |