tga file load speed improvement

This commit is contained in:
Mark Vejvoda
2013-06-12 07:21:16 +00:00
parent 80f25e8fff
commit cc4d650fad

View File

@@ -254,6 +254,7 @@ Pixmap2D* TGAReader::read(ifstream& in, const string& path, Pixmap2D* ret) const
//std::cout << "TGA-Components: Pic: " << picComponents << " old: " << (ret->getComponents()) << " File: " << fileComponents << std::endl; //std::cout << "TGA-Components: Pic: " << picComponents << " old: " << (ret->getComponents()) << " File: " << fileComponents << std::endl;
ret->init(w,h,picComponents); ret->init(w,h,picComponents);
uint8* pixels = ret->getPixels(); uint8* pixels = ret->getPixels();
//read file //read file
for(int i = 0; i < h*w*picComponents; i += picComponents) { for(int i = 0; i < h*w*picComponents; i += picComponents) {
uint8 r=0, g=0, b=0, a=0, l=0; uint8 r=0, g=0, b=0, a=0, l=0;
@@ -270,30 +271,52 @@ Pixmap2D* TGAReader::read(ifstream& in, const string& path, Pixmap2D* ret) const
a= 255; a= 255;
} }
else { else {
in.read((char*)&b, 1); uint8 bgra[4] = {0,0,0,0};
if(bigEndianSystem == true) { in.read((char*)&bgra[0], fileComponents);
b = Shared::PlatformByteOrder::fromCommonEndian(b); b = bgra[0];
} g = bgra[1];
r = bgra[2];
in.read((char*)&g, 1); a= 255;
if(bigEndianSystem == true) {
g = Shared::PlatformByteOrder::fromCommonEndian(g);
}
in.read((char*)&r, 1);
if(bigEndianSystem == true) {
r = Shared::PlatformByteOrder::fromCommonEndian(r);
}
if(fileComponents == 4) { if(fileComponents == 4) {
in.read((char*)&a, 1); a = bgra[3];
if(bigEndianSystem == true) {
a = Shared::PlatformByteOrder::fromCommonEndian(a);
} }
} else { if(bigEndianSystem == true) {
a= 255; b = Shared::PlatformByteOrder::fromCommonEndian(b);
g = Shared::PlatformByteOrder::fromCommonEndian(g);
r = Shared::PlatformByteOrder::fromCommonEndian(r);
if(fileComponents == 4) {
a = Shared::PlatformByteOrder::fromCommonEndian(a);
} }
}
// in.read((char*)&b, 1);
// if(bigEndianSystem == true) {
// b = Shared::PlatformByteOrder::fromCommonEndian(b);
// }
//
// in.read((char*)&g, 1);
// if(bigEndianSystem == true) {
// g = Shared::PlatformByteOrder::fromCommonEndian(g);
// }
//
// in.read((char*)&r, 1);
// if(bigEndianSystem == true) {
// r = Shared::PlatformByteOrder::fromCommonEndian(r);
// }
//
// if(fileComponents==4){
// in.read((char*)&a, 1);
// if(bigEndianSystem == true) {
// a = Shared::PlatformByteOrder::fromCommonEndian(a);
// }
//
// }
// else {
// a= 255;
// }
l = (r+g+b) / 3; l = (r+g+b) / 3;
} }
if (!in.good()) { if (!in.good()) {