Changeset 3300 for OpenSceneGraph/trunk/src/osg/dxtctool.cpp
- Timestamp:
- 08/17/04 21:42:45 (9 years ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osg/dxtctool.cpp (modified) (6 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
