Changeset 3300
- Timestamp:
- 08/17/04 21:42:45 (9 years ago)
- Location:
- OpenSceneGraph/trunk/src/osg
- Files:
-
- 2 modified
-
dxtctool.cpp (modified) (6 diffs)
-
dxtctool.h (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osg/dxtctool.cpp
r3286 r3300 12 12 namespace dxtc_tool { 13 13 14 15 14 const size_t dxtc_pixels::BSIZE_DXT1 = 8; 15 const size_t dxtc_pixels::BSIZE_DXT3 = 16; 16 const size_t dxtc_pixels::BSIZE_DXT5 = 16; 17 const size_t dxtc_pixels::BSIZE_ALPHA_DXT3 = 8; 18 const size_t dxtc_pixels::BSIZE_ALPHA_DXT5 = 8; 16 19 17 20 ////////////////////////////////////////////////////////////////////// … … 27 30 bool dxtc_pixels::OpenGLSize() const 28 31 { 29 size_t Width = m_Width;30 size_t Height = m_Height;31 // size_t TotalTrueBits = 0;32 size_t Width = m_Width; 33 size_t Height = m_Height; 34 // size_t TotalTrueBits = 0; 32 35 33 if ((Width == 0) || (Height == 0))34 return false;36 if ((Width == 0) || (Height == 0)) 37 return false; 35 38 36 for (; (Width % 2) == 0; Width /= 2);37 for (; (Height % 2) == 0; Height /= 2);39 for (; (Width % 2) == 0; Width /= 2); 40 for (; (Height % 2) == 0; Height /= 2); 38 41 39 if ((Width != 1) || (Height != 1))40 return false;41 else42 return true;42 if ((Width != 1) || (Height != 1)) 43 return false; 44 else 45 return true; 43 46 } 44 47 … … 47 50 bool dxtc_pixels::VFlip() const 48 51 { 49 // Check that the given dimentions are 2^x, 2^y50 if (! OpenGLSize())51 return false;52 // Check that the given dimentions are 2^x, 2^y 53 if (! OpenGLSize()) 54 return false; 52 55 53 // Check that the given format are supported54 if (! SupportedFormat())55 return false;56 // Check that the given format are supported 57 if (! SupportedFormat()) 58 return false; 56 59 57 // Nothing to do if Height == 158 if (m_Height == 1)59 return true;60 61 if (DXT1())62 VFlip_DXT1();63 else if (DXT3())64 VFlip_DXT3();65 else if (DXT5())66 VFlip_DXT5();67 else68 return false; // We should never get there60 // Nothing to do if Height == 1 61 if (m_Height == 1) 62 return true; 63 64 if (DXT1()) 65 VFlip_DXT1(); 66 else if (DXT3()) 67 VFlip_DXT3(); 68 else if (DXT5()) 69 VFlip_DXT5(); 70 else 71 return false; // We should never get there 69 72 70 return true;73 return true; 71 74 } 72 75 … … 75 78 void dxtc_pixels::VFlip_DXT1() const 76 79 { 77 // const size_t Size = ((m_Width + 3) / 4) * ((m_Height + 3) / 4) * BSIZE_DXT1;78 __int8 * const pPixels = (__int8 * const) m_pPixels;80 // const size_t Size = ((m_Width + 3) / 4) * ((m_Height + 3) / 4) * BSIZE_DXT1; 81 __int8 * const pPixels = (__int8 * const) m_pPixels; 79 82 80 if (m_Height == 2)81 for (size_t j = 0; j < (m_Width + 3) / 4; ++j)82 BVF_Color_H2(pPixels + j * BSIZE_DXT1);83 if (m_Height == 2) 84 for (size_t j = 0; j < (m_Width + 3) / 4; ++j) 85 BVF_Color_H2(pPixels + j * BSIZE_DXT1); 83 86 84 if (m_Height == 4)85 for (size_t j = 0; j < (m_Width + 3) / 4; ++j)86 BVF_Color_H4(pPixels + j * BSIZE_DXT1);87 if (m_Height == 4) 88 for (size_t j = 0; j < (m_Width + 3) / 4; ++j) 89 BVF_Color_H4(pPixels + j * BSIZE_DXT1); 87 90 88 if (m_Height > 4)89 for (size_t i = 0; i < ((m_Height + 7) / 8); ++i)90 for (size_t j = 0; j < (m_Width + 3) / 4; ++j) {91 const size_t TargetRow = ((m_Height + 3) / 4) - (i + 1);92 BVF_Color(GetBlock(i, j, BSIZE_DXT1), GetBlock(TargetRow, j, BSIZE_DXT1));93 }91 if (m_Height > 4) 92 for (size_t i = 0; i < ((m_Height + 7) / 8); ++i) 93 for (size_t j = 0; j < (m_Width + 3) / 4; ++j) { 94 const size_t TargetRow = ((m_Height + 3) / 4) - (i + 1); 95 BVF_Color(GetBlock(i, j, BSIZE_DXT1), GetBlock(TargetRow, j, BSIZE_DXT1)); 96 } 94 97 } 95 98 … … 98 101 void dxtc_pixels::VFlip_DXT3() const 99 102 { 100 // const size_t Size = ((m_Width + 3) / 4) * ((m_Height + 3) / 4) * BSIZE_DXT3;101 // __int8 * const pPixels = (__int8 * const) m_pPixels;103 // const size_t Size = ((m_Width + 3) / 4) * ((m_Height + 3) / 4) * BSIZE_DXT3; 104 // __int8 * const pPixels = (__int8 * const) m_pPixels; 102 105 103 if (m_Height == 2)104 for (size_t j = 0; j < (m_Width + 3) / 4; ++j) {105 BVF_Alpha_DXT3_H2(((__int8 * const) m_pPixels) + (j * BSIZE_DXT3));106 BVF_Color_H2(((__int8 * const) m_pPixels) + (j * BSIZE_DXT3 + BSIZE_ALPHA_DXT3));107 }106 if (m_Height == 2) 107 for (size_t j = 0; j < (m_Width + 3) / 4; ++j) { 108 BVF_Alpha_DXT3_H2(((__int8 * const) m_pPixels) + (j * BSIZE_DXT3)); 109 BVF_Color_H2(((__int8 * const) m_pPixels) + (j * BSIZE_DXT3 + BSIZE_ALPHA_DXT3)); 110 } 108 111 109 if (m_Height == 4)110 for (size_t j = 0; j < (m_Width + 3) / 4; ++j) {111 BVF_Alpha_DXT3_H4(((__int8 * const) m_pPixels) + (j * BSIZE_DXT3));112 BVF_Color_H4(((__int8 * const) m_pPixels) + (j * BSIZE_DXT3 + BSIZE_ALPHA_DXT3));113 }112 if (m_Height == 4) 113 for (size_t j = 0; j < (m_Width + 3) / 4; ++j) { 114 BVF_Alpha_DXT3_H4(((__int8 * const) m_pPixels) + (j * BSIZE_DXT3)); 115 BVF_Color_H4(((__int8 * const) m_pPixels) + (j * BSIZE_DXT3 + BSIZE_ALPHA_DXT3)); 116 } 114 117 115 if (m_Height > 4)116 for (size_t i = 0; i < ((m_Height + 7) / 8); ++i)117 for (size_t j = 0; j < (m_Width + 3) / 4; ++j) {118 const size_t TargetRow = ((m_Height + 3) / 4) - (i + 1);119 BVF_Alpha_DXT3(GetBlock(i, j, BSIZE_DXT3), GetBlock(TargetRow, j, BSIZE_DXT3));120 BVF_Color(((__int8 * const) GetBlock(i, j, BSIZE_DXT3)) + BSIZE_ALPHA_DXT3,121 ((__int8 * const) GetBlock(TargetRow, j, BSIZE_DXT3)) + BSIZE_ALPHA_DXT3);122 }118 if (m_Height > 4) 119 for (size_t i = 0; i < ((m_Height + 7) / 8); ++i) 120 for (size_t j = 0; j < (m_Width + 3) / 4; ++j) { 121 const size_t TargetRow = ((m_Height + 3) / 4) - (i + 1); 122 BVF_Alpha_DXT3(GetBlock(i, j, BSIZE_DXT3), GetBlock(TargetRow, j, BSIZE_DXT3)); 123 BVF_Color(((__int8 * const) GetBlock(i, j, BSIZE_DXT3)) + BSIZE_ALPHA_DXT3, 124 ((__int8 * const) GetBlock(TargetRow, j, BSIZE_DXT3)) + BSIZE_ALPHA_DXT3); 125 } 123 126 } 124 127 … … 127 130 void dxtc_pixels::VFlip_DXT5() const 128 131 { 129 // const size_t Size = ((m_Width + 3) / 4) * ((m_Height + 3) / 4) * BSIZE_DXT5;130 // __int8 * const pPixels = (__int8 * const) m_pPixels;132 // const size_t Size = ((m_Width + 3) / 4) * ((m_Height + 3) / 4) * BSIZE_DXT5; 133 // __int8 * const pPixels = (__int8 * const) m_pPixels; 131 134 132 if (m_Height == 2)133 for (size_t j = 0; j < (m_Width + 3) / 4; ++j) {134 BVF_Alpha_DXT5_H2(((__int8 * const) m_pPixels) + (j * BSIZE_DXT5));135 BVF_Color_H2(((__int8 * const) m_pPixels) + (j * BSIZE_DXT5 + BSIZE_ALPHA_DXT5));136 }135 if (m_Height == 2) 136 for (size_t j = 0; j < (m_Width + 3) / 4; ++j) { 137 BVF_Alpha_DXT5_H2(((__int8 * const) m_pPixels) + (j * BSIZE_DXT5)); 138 BVF_Color_H2(((__int8 * const) m_pPixels) + (j * BSIZE_DXT5 + BSIZE_ALPHA_DXT5)); 139 } 137 140 138 if (m_Height == 4)139 for (size_t j = 0; j < (m_Width + 3) / 4; ++j) {140 BVF_Alpha_DXT5_H4(((__int8 * const) m_pPixels) + (j * BSIZE_DXT5));141 BVF_Color_H4(((__int8 * const) m_pPixels) + (j * BSIZE_DXT5 + BSIZE_ALPHA_DXT5));142 }141 if (m_Height == 4) 142 for (size_t j = 0; j < (m_Width + 3) / 4; ++j) { 143 BVF_Alpha_DXT5_H4(((__int8 * const) m_pPixels) + (j * BSIZE_DXT5)); 144 BVF_Color_H4(((__int8 * const) m_pPixels) + (j * BSIZE_DXT5 + BSIZE_ALPHA_DXT5)); 145 } 143 146 144 if (m_Height > 4)145 for (size_t i = 0; i < ((m_Height + 7) / 8); ++i)146 for (size_t j = 0; j < (m_Width + 3) / 4; ++j) {147 const size_t TargetRow = ((m_Height + 3) / 4) - (i + 1);148 BVF_Alpha_DXT5(GetBlock(i, j, BSIZE_DXT5), GetBlock(TargetRow, j, BSIZE_DXT5));149 BVF_Color(((__int8 * const) GetBlock(i, j, BSIZE_DXT5)) + BSIZE_ALPHA_DXT5,150 ((__int8 * const) GetBlock(TargetRow, j, BSIZE_DXT5)) + BSIZE_ALPHA_DXT5);151 }147 if (m_Height > 4) 148 for (size_t i = 0; i < ((m_Height + 7) / 8); ++i) 149 for (size_t j = 0; j < (m_Width + 3) / 4; ++j) { 150 const size_t TargetRow = ((m_Height + 3) / 4) - (i + 1); 151 BVF_Alpha_DXT5(GetBlock(i, j, BSIZE_DXT5), GetBlock(TargetRow, j, BSIZE_DXT5)); 152 BVF_Color(((__int8 * const) GetBlock(i, j, BSIZE_DXT5)) + BSIZE_ALPHA_DXT5, 153 ((__int8 * const) GetBlock(TargetRow, j, BSIZE_DXT5)) + BSIZE_ALPHA_DXT5); 154 } 152 155 } 153 156 -
OpenSceneGraph/trunk/src/osg/dxtctool.h
r3290 r3300 26 26 ////////////////////////////////////////////////////////////////////// 27 27 // 28 // DXTC Tools: Vertical Flip.29 // *************************28 // DXTC Tools: Vertical Flip. 29 // ************************* 30 30 // 31 31 // Current version: 1.00 BETA 1 (27/08/2002) … … 81 81 { 82 82 public: 83 dxtc_pixels(size_t Width, size_t Height, GLenum Format, void * pPixels);84 85 // Vertically flip the whole picture86 bool VFlip() const;83 dxtc_pixels(size_t Width, size_t Height, GLenum Format, void * pPixels); 84 85 // Vertically flip the whole picture 86 bool VFlip() const; 87 87 88 88 protected: 89 89 90 // Limitation check functions91 bool DXT1() const;92 bool DXT3() const;93 bool DXT5() const;94 bool OpenGLSize() const;95 bool SupportedFormat() const;96 97 // Vertical flipping functions98 void VFlip_DXT1() const; 99 void VFlip_DXT3() const;100 void VFlip_DXT5() const;101 102 // Block vertical flipping functions103 void BVF_Color_H2(void * const pBlock) const;// V. flip one color block with its virtual height == 2104 void BVF_Color_H4(void * const pBlock) const;// V. flip one color block with its virtual height == 4105 void BVF_Color(void * const pBlock1, void * const pBlock2) const;// V. flip and swap two color blocks, with their virtual height == 4106 void BVF_Alpha_DXT3_H2(void * const pBlock) const;// V. flip one alpha (DXT3) block with its virtual height == 2107 void BVF_Alpha_DXT3_H4(void * const pBlock) const;// V. flip one alpha (DXT3) block with its virtual height == 4108 void BVF_Alpha_DXT3(void * const pBlock1, void * const pBlock2) const;// V. flip and swap two alpha (DXT3) blocks, with their virtual height == 4109 void BVF_Alpha_DXT5_H2(void * const pBlock) const;// V. flip one alpha (DXT5) block with its virtual height == 2110 void BVF_Alpha_DXT5_H4(void * const pBlock) const;// V. flip one alpha (DXT5) block with its virtual height == 4111 void BVF_Alpha_DXT5(void * const pBlock1, void * const pBlock2) const;// V. flip and swap two alpha (DXT5) blocks, with their virtual height == 4112 113 // Block localization functions114 void * GetBlock(size_t i, size_t j, size_t BlockSize) const;115 116 // mighty const and var117 static const size_t BSIZE_DXT1 = 8;118 static const size_t BSIZE_DXT3 = 16;119 static const size_t BSIZE_DXT5 = 16;120 static const size_t BSIZE_ALPHA_DXT3 = 8;121 static const size_t BSIZE_ALPHA_DXT5 = 8;122 123 const size_tm_Width;124 const size_tm_Height;125 const GLenumm_Format;126 void * constm_pPixels;90 // Limitation check functions 91 bool DXT1() const; 92 bool DXT3() const; 93 bool DXT5() const; 94 bool OpenGLSize() const; 95 bool SupportedFormat() const; 96 97 // Vertical flipping functions 98 void VFlip_DXT1() const; 99 void VFlip_DXT3() const; 100 void VFlip_DXT5() const; 101 102 // Block vertical flipping functions 103 void BVF_Color_H2(void * const pBlock) const; // V. flip one color block with its virtual height == 2 104 void BVF_Color_H4(void * const pBlock) const; // V. flip one color block with its virtual height == 4 105 void BVF_Color(void * const pBlock1, void * const pBlock2) const; // V. flip and swap two color blocks, with their virtual height == 4 106 void BVF_Alpha_DXT3_H2(void * const pBlock) const; // V. flip one alpha (DXT3) block with its virtual height == 2 107 void BVF_Alpha_DXT3_H4(void * const pBlock) const; // V. flip one alpha (DXT3) block with its virtual height == 4 108 void BVF_Alpha_DXT3(void * const pBlock1, void * const pBlock2) const; // V. flip and swap two alpha (DXT3) blocks, with their virtual height == 4 109 void BVF_Alpha_DXT5_H2(void * const pBlock) const; // V. flip one alpha (DXT5) block with its virtual height == 2 110 void BVF_Alpha_DXT5_H4(void * const pBlock) const; // V. flip one alpha (DXT5) block with its virtual height == 4 111 void BVF_Alpha_DXT5(void * const pBlock1, void * const pBlock2) const; // V. flip and swap two alpha (DXT5) blocks, with their virtual height == 4 112 113 // Block localization functions 114 void * GetBlock(size_t i, size_t j, size_t BlockSize) const; 115 116 // mighty const and var 117 static const size_t BSIZE_DXT1; 118 static const size_t BSIZE_DXT3; 119 static const size_t BSIZE_DXT5; 120 static const size_t BSIZE_ALPHA_DXT3; 121 static const size_t BSIZE_ALPHA_DXT5; 122 123 const size_t m_Width; 124 const size_t m_Height; 125 const GLenum m_Format; 126 void * const m_pPixels; 127 127 }; 128 128 … … 135 135 136 136 inline bool VerticalFlip(size_t Width, size_t Height, GLenum Format, void * pPixels) { 137 return (dxtc_pixels(Width, Height, Format, pPixels)).VFlip();137 return (dxtc_pixels(Width, Height, Format, pPixels)).VFlip(); 138 138 } 139 139 … … 145 145 146 146 inline dxtc_pixels::dxtc_pixels(size_t Width, size_t Height, GLenum Format, void * pPixels) : 147 m_Width(Width), m_Height(Height), m_Format(Format), m_pPixels(pPixels) { }147 m_Width(Width), m_Height(Height), m_Format(Format), m_pPixels(pPixels) { } 148 148 149 149 150 150 inline bool dxtc_pixels::DXT1() const { 151 return ((m_Format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) || (m_Format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT));151 return ((m_Format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) || (m_Format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT)); 152 152 } 153 153 154 154 155 155 inline bool dxtc_pixels::DXT3() const { 156 return (m_Format == GL_COMPRESSED_RGBA_S3TC_DXT3_EXT);156 return (m_Format == GL_COMPRESSED_RGBA_S3TC_DXT3_EXT); 157 157 } 158 158 159 159 160 160 inline bool dxtc_pixels::DXT5() const { 161 return (m_Format == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT);161 return (m_Format == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT); 162 162 } 163 163 164 164 165 165 inline bool dxtc_pixels::SupportedFormat() const { 166 return (DXT1() || DXT3() || DXT5());166 return (DXT1() || DXT3() || DXT5()); 167 167 } 168 168 169 169 170 170 inline void dxtc_pixels::BVF_Color_H2(void * const pBlock) const { 171 // Swap the two first row of pixels172 __int8 * const pP = ((__int8 * const) pBlock) + 4;173 174 std::swap(pP[0], pP[1]);171 // Swap the two first row of pixels 172 __int8 * const pP = ((__int8 * const) pBlock) + 4; 173 174 std::swap(pP[0], pP[1]); 175 175 } 176 176 177 177 178 178 inline void dxtc_pixels::BVF_Color_H4(void * const pBlock) const { 179 // Swap the the first row of pixels with the last one, then the 2 middle row of pixels180 __int8 * const pP = ((__int8 * const) pBlock) + 4;181 182 std::swap(pP[0], pP[3]);183 std::swap(pP[1], pP[2]);179 // Swap the the first row of pixels with the last one, then the 2 middle row of pixels 180 __int8 * const pP = ((__int8 * const) pBlock) + 4; 181 182 std::swap(pP[0], pP[3]); 183 std::swap(pP[1], pP[2]); 184 184 } 185 185 186 186 187 187 inline void dxtc_pixels::BVF_Color(void * const pBlock1, void * const pBlock2) const { 188 // Swap the "2 colors" header (32bits each header)189 __int32 * const pHdr1 = (__int32 * const) pBlock1;190 __int32 * const pHdr2 = (__int32 * const) pBlock2;191 192 std::swap(* pHdr1, * pHdr2);193 194 // Now swap the pixel values195 __int8 * const pP1 = ((__int8 * const) pBlock1) + 4;196 __int8 * const pP2 = ((__int8 * const) pBlock2) + 4;197 198 std::swap(pP1[0], pP2[3]);199 std::swap(pP1[1], pP2[2]);200 std::swap(pP1[2], pP2[1]);201 std::swap(pP1[3], pP2[0]);188 // Swap the "2 colors" header (32bits each header) 189 __int32 * const pHdr1 = (__int32 * const) pBlock1; 190 __int32 * const pHdr2 = (__int32 * const) pBlock2; 191 192 std::swap(* pHdr1, * pHdr2); 193 194 // Now swap the pixel values 195 __int8 * const pP1 = ((__int8 * const) pBlock1) + 4; 196 __int8 * const pP2 = ((__int8 * const) pBlock2) + 4; 197 198 std::swap(pP1[0], pP2[3]); 199 std::swap(pP1[1], pP2[2]); 200 std::swap(pP1[2], pP2[1]); 201 std::swap(pP1[3], pP2[0]); 202 202 } 203 203 204 204 205 205 inline void dxtc_pixels::BVF_Alpha_DXT3_H2(void * const pBlock) const { 206 // Swap the two first row of pixels207 __int16 * const pP = (__int16 * const) pBlock;208 209 std::swap(pP[0], pP[1]);206 // Swap the two first row of pixels 207 __int16 * const pP = (__int16 * const) pBlock; 208 209 std::swap(pP[0], pP[1]); 210 210 } 211 211 212 212 213 213 inline void dxtc_pixels::BVF_Alpha_DXT3_H4(void * const pBlock) const { 214 // Swap the the first row of pixels with the last one, then the 2 middle row of pixels215 __int16 * const pP = (__int16 * const) pBlock;216 217 std::swap(pP[0], pP[3]);218 std::swap(pP[1], pP[2]);214 // Swap the the first row of pixels with the last one, then the 2 middle row of pixels 215 __int16 * const pP = (__int16 * const) pBlock; 216 217 std::swap(pP[0], pP[3]); 218 std::swap(pP[1], pP[2]); 219 219 } 220 220 221 221 222 222 inline void dxtc_pixels::BVF_Alpha_DXT3(void * const pBlock1, void * const pBlock2) const { 223 // Swap all the pixel values224 __int16 * const pP1 = (__int16 * const) pBlock1;225 __int16 * const pP2 = (__int16 * const) pBlock2;226 227 std::swap(pP1[0], pP2[3]);228 std::swap(pP1[1], pP2[2]);229 std::swap(pP1[2], pP2[1]);230 std::swap(pP1[3], pP2[0]);223 // Swap all the pixel values 224 __int16 * const pP1 = (__int16 * const) pBlock1; 225 __int16 * const pP2 = (__int16 * const) pBlock2; 226 227 std::swap(pP1[0], pP2[3]); 228 std::swap(pP1[1], pP2[2]); 229 std::swap(pP1[2], pP2[1]); 230 std::swap(pP1[3], pP2[0]); 231 231 } 232 232 233 233 234 234 inline void dxtc_pixels::BVF_Alpha_DXT5_H2(void * const pBlock) const { 235 // Swap the two first row of pixels (kinda tricky with DXT5 unaligned encoding)236 __int32 * const pP = (__int32 * const) (((__int8 * const) pBlock) + 2);237 238 __int32 TmpDWord = (pP[0] & 0xFF000000);239 TmpDWord |=(pP[0] & 0x00000FFF) << 12;240 TmpDWord |= (pP[0] & 0x00FFF000) >> 12;241 pP[0] = TmpDWord;235 // Swap the two first row of pixels (kinda tricky with DXT5 unaligned encoding) 236 __int32 * const pP = (__int32 * const) (((__int8 * const) pBlock) + 2); 237 238 __int32 TmpDWord = (pP[0] & 0xFF000000); 239 TmpDWord |= (pP[0] & 0x00000FFF) << 12; 240 TmpDWord |= (pP[0] & 0x00FFF000) >> 12; 241 pP[0] = TmpDWord; 242 242 } 243 243 … … 248 248 249 249 inline void dxtc_pixels::BVF_Alpha_DXT5_H4(void * const pBlock) const { 250 // Swap the the first row of pixels with the last one, then the 2 middle row of pixels (tricky again)251 __int64 * const pB = (__int64 * const) pBlock;252 253 __int64 TmpQWord = (pB[0] & HEX_0x000000000000FFFF);254 TmpQWord |= (pB[0] & HEX_0x000000000FFF0000) << 36;255 TmpQWord |= (pB[0] & HEX_0x000000FFF0000000) << 12;256 TmpQWord |= (pB[0] & HEX_0x000FFF0000000000) >> 12;257 TmpQWord |= (pB[0] & HEX_0xFFF0000000000000) >> 36;258 pB[0] = TmpQWord;250 // Swap the the first row of pixels with the last one, then the 2 middle row of pixels (tricky again) 251 __int64 * const pB = (__int64 * const) pBlock; 252 253 __int64 TmpQWord = (pB[0] & HEX_0x000000000000FFFF); 254 TmpQWord |= (pB[0] & HEX_0x000000000FFF0000) << 36; 255 TmpQWord |= (pB[0] & HEX_0x000000FFF0000000) << 12; 256 TmpQWord |= (pB[0] & HEX_0x000FFF0000000000) >> 12; 257 TmpQWord |= (pB[0] & HEX_0xFFF0000000000000) >> 36; 258 pB[0] = TmpQWord; 259 259 } 260 260 261 261 262 262 inline void dxtc_pixels::BVF_Alpha_DXT5(void * const pBlock1, void * const pBlock2) const { 263 // Swap all the pixel values (same trick for DXT5)264 __int64 * const pB1 = (__int64 * const) pBlock1;265 __int64 * const pB2 = (__int64 * const) pBlock2;266 267 __int64 TmpQWord1 = (pB1[0] & HEX_0x000000000000FFFF);268 TmpQWord1 |= (pB1[0] & HEX_0x000000000FFF0000) << 36;269 TmpQWord1 |= (pB1[0] & HEX_0x000000FFF0000000) << 12;270 TmpQWord1 |= (pB1[0] & HEX_0x000FFF0000000000) >> 12;271 TmpQWord1 |= (pB1[0] & HEX_0xFFF0000000000000) >> 36;272 273 __int64 TmpQWord2 = (pB2[0] & HEX_0x000000000000FFFF);274 TmpQWord2 |= (pB2[0] & HEX_0x000000000FFF0000) << 36;275 TmpQWord2 |= (pB2[0] & HEX_0x000000FFF0000000) << 12;276 TmpQWord2 |= (pB2[0] & HEX_0x000FFF0000000000) >> 12;277 TmpQWord2 |= (pB2[0] & HEX_0xFFF0000000000000) >> 36;278 279 pB1[0] = TmpQWord2;280 pB2[0] = TmpQWord1;263 // Swap all the pixel values (same trick for DXT5) 264 __int64 * const pB1 = (__int64 * const) pBlock1; 265 __int64 * const pB2 = (__int64 * const) pBlock2; 266 267 __int64 TmpQWord1 = (pB1[0] & HEX_0x000000000000FFFF); 268 TmpQWord1 |= (pB1[0] & HEX_0x000000000FFF0000) << 36; 269 TmpQWord1 |= (pB1[0] & HEX_0x000000FFF0000000) << 12; 270 TmpQWord1 |= (pB1[0] & HEX_0x000FFF0000000000) >> 12; 271 TmpQWord1 |= (pB1[0] & HEX_0xFFF0000000000000) >> 36; 272 273 __int64 TmpQWord2 = (pB2[0] & HEX_0x000000000000FFFF); 274 TmpQWord2 |= (pB2[0] & HEX_0x000000000FFF0000) << 36; 275 TmpQWord2 |= (pB2[0] & HEX_0x000000FFF0000000) << 12; 276 TmpQWord2 |= (pB2[0] & HEX_0x000FFF0000000000) >> 12; 277 TmpQWord2 |= (pB2[0] & HEX_0xFFF0000000000000) >> 36; 278 279 pB1[0] = TmpQWord2; 280 pB2[0] = TmpQWord1; 281 281 } 282 282 283 283 284 284 inline void * dxtc_pixels::GetBlock(size_t i, size_t j, size_t BlockSize) const { 285 const __int8 * pPixels = (const __int8 *) m_pPixels;286 287 return (void *) (pPixels + i * ((m_Width + 3) / 4) * BlockSize + j * BlockSize);285 const __int8 * pPixels = (const __int8 *) m_pPixels; 286 287 return (void *) (pPixels + i * ((m_Width + 3) / 4) * BlockSize + j * BlockSize); 288 288 } 289 289
