tga file load speed improvement
This commit is contained in:
parent
80f25e8fff
commit
cc4d650fad
|
@ -254,11 +254,12 @@ 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;
|
||||||
|
|
||||||
if(fileComponents==1){
|
if(fileComponents == 1) {
|
||||||
in.read((char*)&l,1);
|
in.read((char*)&l,1);
|
||||||
if(bigEndianSystem == true) {
|
if(bigEndianSystem == true) {
|
||||||
l = Shared::PlatformByteOrder::fromCommonEndian(l);
|
l = Shared::PlatformByteOrder::fromCommonEndian(l);
|
||||||
|
@ -269,38 +270,60 @@ Pixmap2D* TGAReader::read(ifstream& in, const string& path, Pixmap2D* ret) const
|
||||||
b= l;
|
b= l;
|
||||||
a= 255;
|
a= 255;
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
in.read((char*)&b, 1);
|
uint8 bgra[4] = {0,0,0,0};
|
||||||
|
in.read((char*)&bgra[0], fileComponents);
|
||||||
|
b = bgra[0];
|
||||||
|
g = bgra[1];
|
||||||
|
r = bgra[2];
|
||||||
|
a= 255;
|
||||||
|
|
||||||
|
if(fileComponents == 4) {
|
||||||
|
a = bgra[3];
|
||||||
|
}
|
||||||
|
|
||||||
if(bigEndianSystem == true) {
|
if(bigEndianSystem == true) {
|
||||||
b = Shared::PlatformByteOrder::fromCommonEndian(b);
|
b = Shared::PlatformByteOrder::fromCommonEndian(b);
|
||||||
}
|
|
||||||
|
|
||||||
in.read((char*)&g, 1);
|
|
||||||
if(bigEndianSystem == true) {
|
|
||||||
g = Shared::PlatformByteOrder::fromCommonEndian(g);
|
g = Shared::PlatformByteOrder::fromCommonEndian(g);
|
||||||
}
|
|
||||||
|
|
||||||
in.read((char*)&r, 1);
|
|
||||||
if(bigEndianSystem == true) {
|
|
||||||
r = Shared::PlatformByteOrder::fromCommonEndian(r);
|
r = Shared::PlatformByteOrder::fromCommonEndian(r);
|
||||||
}
|
if(fileComponents == 4) {
|
||||||
|
|
||||||
if(fileComponents==4){
|
|
||||||
in.read((char*)&a, 1);
|
|
||||||
if(bigEndianSystem == true) {
|
|
||||||
a = Shared::PlatformByteOrder::fromCommonEndian(a);
|
a = Shared::PlatformByteOrder::fromCommonEndian(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
a= 255;
|
|
||||||
}
|
}
|
||||||
l= (r+g+b)/3;
|
|
||||||
|
// 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;
|
||||||
}
|
}
|
||||||
if (!in.good()) {
|
if (!in.good()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(picComponents){
|
switch(picComponents) {
|
||||||
case 1:
|
case 1:
|
||||||
pixels[i]= l;
|
pixels[i]= l;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user