From 1a5c70c76e395c3d1a101d56137c500f85a33ca4 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 2 Jul 2011 07:15:23 +0000 Subject: [PATCH] - another small bugfix for water texture loading --- .../shared_lib/sources/graphics/PNGReader.cpp | 11 ++- .../shared_lib/sources/graphics/TGAReader.cpp | 20 +++--- source/shared_lib/sources/graphics/pixmap.cpp | 69 +------------------ 3 files changed, 22 insertions(+), 78 deletions(-) diff --git a/source/shared_lib/sources/graphics/PNGReader.cpp b/source/shared_lib/sources/graphics/PNGReader.cpp index d3deafef9..a8bc246ce 100644 --- a/source/shared_lib/sources/graphics/PNGReader.cpp +++ b/source/shared_lib/sources/graphics/PNGReader.cpp @@ -258,14 +258,19 @@ Pixmap3D* PNGReader3D::read(ifstream& is, const string& path, Pixmap3D* ret) con png_read_image(png_ptr, row_pointers); size_t fileComponents = info_ptr->rowbytes/info_ptr->width; 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; //picComponents = 4; //Copy image //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(); - if(ret->getSlice() > 0) { - pixels = &pixels[ret->getSlice()*width*height*picComponents]; + if(slice > 0) { + pixels = &pixels[slice*width*height*picComponents]; } const size_t rowbytes = info_ptr->rowbytes; diff --git a/source/shared_lib/sources/graphics/TGAReader.cpp b/source/shared_lib/sources/graphics/TGAReader.cpp index b7f519fc7..4c8f88ef8 100644 --- a/source/shared_lib/sources/graphics/TGAReader.cpp +++ b/source/shared_lib/sources/graphics/TGAReader.cpp @@ -89,17 +89,21 @@ Pixmap3D* TGAReader3D::read(ifstream& in, const string& path, Pixmap3D* ret) con const int h = fileHeader.height; const int w = fileHeader.width; + const int d = ret->getD(); + const int slice = ret->getSlice(); const int fileComponents= fileHeader.bitsPerPixel/8; 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; - ret->init(w,h,ret->getD(), picComponents); + if(ret->getPixels() == NULL){ + ret->init(w,h,d, picComponents); + } uint8* pixels = ret->getPixels(); - if(ret->getSlice() > 0) { - pixels = &pixels[ret->getSlice()*w*h*picComponents]; + if(slice > 0) { + pixels = &pixels[slice*w*h*picComponents]; } //read file for(int i=0; igetPixels(); //read file for(int i=0; ipath = path; - deletePixels(); - + //deletePixels(); Pixmap3D *pixmap = FileReader::readPath(path,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){ @@ -1354,37 +1316,10 @@ void Pixmap3D::loadSliceBmp(const string &path, int slice){ void Pixmap3D::loadSliceTga(const string &path, int slice){ this->path = path; - deletePixels(); + //deletePixels(); FileReader::readPath(path,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::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; plt.openRead(path);