- Timestamp:
- 01/24/12 15:34:02 (16 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/nvtt/NVTTImageProcessor.cpp
r12292 r12912 47 47 48 48 // Convert RGBA to BGRA : nvtt only accepts BGRA pixel format 49 void convertRGBAToBGRA( std::vector<unsigned char>& outputData, const unsigned char* inputData);49 void convertRGBAToBGRA( std::vector<unsigned char>& outputData, const osg::Image& image ); 50 50 51 51 // Convert RGB to BGRA : nvtt only accepts BGRA pixel format 52 void convertRGBToBGRA( std::vector<unsigned char>& outputData, const unsigned char* inputData);52 void convertRGBToBGRA( std::vector<unsigned char>& outputData, const osg::Image& image ); 53 53 54 54 }; … … 176 176 177 177 // Convert RGBA to BGRA : nvtt only accepts BGRA pixel format 178 void NVTTProcessor::convertRGBAToBGRA( std::vector<unsigned char>& outputData, const unsigned char* inputData ) 179 { 180 for (unsigned n=0; n<outputData.size(); n += 4) 181 { 182 outputData[n] = inputData[n+2]; 183 outputData[n+1] = inputData[n+1]; 184 outputData[n+2] = inputData[n]; 185 outputData[n+3] = inputData[n+3]; 178 void NVTTProcessor::convertRGBAToBGRA( std::vector<unsigned char>& outputData, const osg::Image& image ) 179 { 180 unsigned int n=0; 181 for(int row=0; row<image.t(); ++row) 182 { 183 const unsigned char* data = image.data(0,row); 184 for(int column=0; column<image.s(); ++column) 185 { 186 outputData[n] = data[column*4+2]; 187 outputData[n+1] = data[column*4+1]; 188 outputData[n+2] = data[column*4+n]; 189 outputData[n+3] = data[column*4+3]; 190 n+=4; 191 } 186 192 } 187 193 } 188 194 189 195 // Convert RGB to BGRA : nvtt only accepts BGRA pixel format 190 void NVTTProcessor::convertRGBToBGRA( std::vector<unsigned char>& outputData, const unsigned char* inputData ) 191 { 192 unsigned int numberOfPixels = outputData.size()/4; 193 for (unsigned n=0; n<numberOfPixels; n++) 194 { 195 outputData[4*n] = inputData[3*n+2]; 196 outputData[4*n+1] = inputData[3*n+1]; 197 outputData[4*n+2] = inputData[3*n]; 198 outputData[4*n+3] = 255; 196 void NVTTProcessor::convertRGBToBGRA( std::vector<unsigned char>& outputData, const osg::Image& image ) 197 { 198 unsigned int n=0; 199 for(int row=0; row<image.t(); ++row) 200 { 201 const unsigned char* data = image.data(0,row); 202 for(int column=0; column<image.s(); ++column) 203 { 204 outputData[n] = data[column*3+2]; 205 outputData[n+1] = data[column*3+1]; 206 outputData[n+2] = data[column*3+n]; 207 outputData[n+3] = 255; 208 n+=4; 209 } 199 210 } 200 211 } … … 228 239 if (image.getPixelFormat() == GL_RGB) 229 240 { 230 convertRGBToBGRA( imageData, image .data());241 convertRGBToBGRA( imageData, image ); 231 242 } 232 243 else 233 244 { 234 convertRGBAToBGRA( imageData, image .data());245 convertRGBAToBGRA( imageData, image ); 235 246 } 236 247 inputOptions.setMipmapData(&imageData[0],image.s(),image.t());
