- another small bugfix for water texture loading

This commit is contained in:
Mark Vejvoda
2011-07-02 07:15:23 +00:00
parent f9ad27f655
commit 1a5c70c76e
3 changed files with 22 additions and 78 deletions

View File

@@ -258,14 +258,19 @@ Pixmap3D* PNGReader3D::read(ifstream& is, const string& path, Pixmap3D* ret) con
png_read_image(png_ptr, row_pointers); png_read_image(png_ptr, row_pointers);
size_t fileComponents = info_ptr->rowbytes/info_ptr->width; size_t fileComponents = info_ptr->rowbytes/info_ptr->width;
size_t picComponents = (ret->getComponents()==-1)?fileComponents:ret->getComponents(); size_t picComponents = (ret->getComponents()==-1)?fileComponents:ret->getComponents();
const int d = ret->getD();
const int slice = ret->getSlice();
if(ret->getPixels() == NULL){
ret->init(width,height,d, (int)picComponents);
}
//std::cout << "PNG-Components: Pic: " << picComponents << " old: " << (ret->getComponents()) << " File: " << fileComponents << std::endl; //std::cout << "PNG-Components: Pic: " << picComponents << " old: " << (ret->getComponents()) << " File: " << fileComponents << std::endl;
//picComponents = 4; //picComponents = 4;
//Copy image //Copy image
//printf("pixmap3d loading path [%s] w = %d h = %d d = %d comp = %d\n",path.c_str(),width,height,ret->getD(),picComponents); //printf("pixmap3d loading path [%s] w = %d h = %d d = %d comp = %d\n",path.c_str(),width,height,ret->getD(),picComponents);
ret->init(width,height,ret->getD(),(int)picComponents);
uint8* pixels = ret->getPixels(); uint8* pixels = ret->getPixels();
if(ret->getSlice() > 0) { if(slice > 0) {
pixels = &pixels[ret->getSlice()*width*height*picComponents]; pixels = &pixels[slice*width*height*picComponents];
} }
const size_t rowbytes = info_ptr->rowbytes; const size_t rowbytes = info_ptr->rowbytes;

View File

@@ -89,17 +89,21 @@ Pixmap3D* TGAReader3D::read(ifstream& in, const string& path, Pixmap3D* ret) con
const int h = fileHeader.height; const int h = fileHeader.height;
const int w = fileHeader.width; const int w = fileHeader.width;
const int d = ret->getD();
const int slice = ret->getSlice();
const int fileComponents= fileHeader.bitsPerPixel/8; const int fileComponents= fileHeader.bitsPerPixel/8;
const int picComponents = (ret->getComponents()==-1)?fileComponents:ret->getComponents(); const int picComponents = (ret->getComponents()==-1)?fileComponents:ret->getComponents();
//std::cout << "TGA-Components: Pic: " << picComponents << " old: " << (ret->getComponents()) << " File: " << fileComponents << " slice:" << ret->getSlice() << std::endl; //std::cout << "TGA-Components: Pic: " << picComponents << " old: " << (ret->getComponents()) << " File: " << fileComponents << " slice:" << ret->getSlice() << std::endl;
ret->init(w,h,ret->getD(), picComponents); if(ret->getPixels() == NULL){
ret->init(w,h,d, picComponents);
}
uint8* pixels = ret->getPixels(); uint8* pixels = ret->getPixels();
if(ret->getSlice() > 0) { if(slice > 0) {
pixels = &pixels[ret->getSlice()*w*h*picComponents]; pixels = &pixels[slice*w*h*picComponents];
} }
//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, g, b, a, l; 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);
@@ -119,9 +123,9 @@ Pixmap3D* TGAReader3D::read(ifstream& in, const string& path, Pixmap3D* ret) con
} }
l= (r+g+b)/3; l= (r+g+b)/3;
} }
if (!in.good()) { //if (!in.good()) {
return NULL; // return NULL;
} //}
switch(picComponents){ switch(picComponents){
case 1: case 1:
@@ -191,7 +195,7 @@ Pixmap2D* TGAReader::read(ifstream& in, const string& path, Pixmap2D* ret) const
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, g, b, a, l; 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);

View File

@@ -1288,47 +1288,9 @@ void Pixmap3D::loadSlice(const string &path, int slice) {
void Pixmap3D::loadSlicePng(const string &path, int slice) { void Pixmap3D::loadSlicePng(const string &path, int slice) {
this->path = path; this->path = path;
deletePixels(); //deletePixels();
Pixmap3D *pixmap = FileReader<Pixmap3D>::readPath(path,this); Pixmap3D *pixmap = FileReader<Pixmap3D>::readPath(path,this);
//printf("Loading 3D pixmap PNG [%s] pixmap [%p] this [%p]\n",path.c_str(),pixmap, this); //printf("Loading 3D pixmap PNG [%s] pixmap [%p] this [%p]\n",path.c_str(),pixmap, this);
// if(pixmap != NULL) {
// this->path = path;
//
// w= pixmap->getW();
// h= pixmap->getH();
// if(components==-1){
// components= pixmap->getComponents();
// }
//
// if(pixels==NULL) {
// pixels= new uint8[(std::size_t)pixmap->getPixelByteCount()];
// }
//
// for(unsigned int i = 0; i < pixmap->getPixelByteCount(); ++i) {
// pixels[i] = pixmap->getPixels()[i];
// }
// }
// PixmapIoP plt;
// plt.openRead(path);
//
// //header
// int fileComponents= plt.getComponents();
//
// //init
// w= plt.getW();
// h= plt.getH();
// if(components==-1){
// components= fileComponents;
// }
// if(pixels==NULL){
// pixels= new uint8[(std::size_t)getPixelByteCount()];
// }
//
// //read data
// plt.read(&pixels[slice*w*h*components], components);
} }
void Pixmap3D::loadSliceBmp(const string &path, int slice){ void Pixmap3D::loadSliceBmp(const string &path, int slice){
@@ -1354,37 +1316,10 @@ void Pixmap3D::loadSliceBmp(const string &path, int slice){
void Pixmap3D::loadSliceTga(const string &path, int slice){ void Pixmap3D::loadSliceTga(const string &path, int slice){
this->path = path; this->path = path;
deletePixels(); //deletePixels();
FileReader<Pixmap3D>::readPath(path,this); FileReader<Pixmap3D>::readPath(path,this);
//printf("Loading 3D pixmap TGA [%s] this [%p]\n",path.c_str(),this); //printf("Loading 3D pixmap TGA [%s] this [%p]\n",path.c_str(),this);
// Pixmap3D *pixmap = new Pixmap3D();
// pixmap->h = this->h;
// pixmap->w = this->w;
// pixmap->d = this->d;
// pixmap->components = this->components;
// pixmap->slice = this->slice;
// FileReader<Pixmap3D>::readPath(path,pixmap);
// printf("Loading 3D pixmap TGA [%s] pixmap [%p] this [%p]\n",path.c_str(),pixmap, this);
//
// //init
// w= pixmap->getW();
// h= pixmap->getH();
// if(components==-1){
// components= pixmap->getComponents();
// }
// if(pixels==NULL){
// pixels= new uint8[(std::size_t)getPixelByteCount()];
// }
//
// //read data
// for(unsigned int i = slice*w*h*components; i < h*w*components; ++i) {
// pixels[i] = pixmap->getPixels()[i];
// }
//
// delete pixmap;
/* /*
PixmapIoTga plt; PixmapIoTga plt;
plt.openRead(path); plt.openRead(path);