mirror of
https://github.com/glest/glest-source.git
synced 2025-08-19 14:41:23 +02:00
bugfixes for static init filereader concrete classes
This commit is contained in:
@@ -81,6 +81,7 @@ Pixmap2D* BMPReader::read(ifstream& in, const string& path, Pixmap2D* ret) const
|
||||
int h= infoHeader.height;
|
||||
int w= infoHeader.width;
|
||||
int components= (ret->getComponents() == -1)?3:ret->getComponents();
|
||||
std::cout << "BMP-Components: Pic: " << components << " old: " << (ret->getComponents()) << " File: " << 3 << std::endl;
|
||||
ret->init(w,h,components);
|
||||
uint8* pixels = ret->getPixels();
|
||||
for(int i=0; i<h*w*components; i+=components){
|
||||
|
@@ -65,9 +65,18 @@ Pixmap2D* JPGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const
|
||||
//Read file
|
||||
is.seekg(0, ios::end);
|
||||
size_t length = is.tellg();
|
||||
if (length < 8) {
|
||||
return NULL;
|
||||
}
|
||||
is.seekg(0, ios::beg);
|
||||
uint8 * buffer = new uint8[length];
|
||||
is.read((char*)buffer, length);
|
||||
//Check buffer (weak jpeg check)
|
||||
if (buffer[0] != 0x46 || buffer[1] != 0xA0) {
|
||||
delete[] buffer;
|
||||
std::cout << "Returning NULL jpeg" << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
struct jpeg_error_mgr jerr;
|
||||
@@ -112,6 +121,7 @@ Pixmap2D* JPGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const
|
||||
std::cout << "Color components per fixel: " << cinfo.num_components << std::endl;
|
||||
std::cout << "Color space: " << cinfo.jpeg_color_space << std::endl;*/
|
||||
const int picComponents = (ret->getComponents() == -1)?cinfo.num_components:ret->getComponents();
|
||||
std::cout << "JPG-Components: Pic: " << picComponents << " old: " << (ret->getComponents()) << " File: " << cinfo.num_components << std::endl;
|
||||
ret->init(cinfo.image_width, cinfo.image_height, picComponents);
|
||||
uint8* pixels = ret->getPixels();
|
||||
//TODO: Irrlicht has some special CMYK-handling - maybe needed too?
|
||||
|
@@ -108,6 +108,7 @@ Pixmap2D* PNGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const
|
||||
png_read_image(png_ptr, row_pointers);
|
||||
int fileComponents = info_ptr->rowbytes/info_ptr->width;
|
||||
int picComponents = (ret->getComponents()==-1)?fileComponents:ret->getComponents();
|
||||
std::cout << "PNG-Components: Pic: " << picComponents << " old: " << (ret->getComponents()) << " File: " << fileComponents << std::endl;
|
||||
//Copy image
|
||||
ret->init(width,height,picComponents);
|
||||
uint8* pixels = ret->getPixels();
|
||||
|
@@ -85,6 +85,7 @@ Pixmap2D* TGAReader::read(ifstream& in, const string& path, Pixmap2D* ret) const
|
||||
const int w = fileHeader.width;
|
||||
const int fileComponents= fileHeader.bitsPerPixel/8;
|
||||
const int picComponents = (ret->getComponents()==-1)?fileComponents:ret->getComponents();
|
||||
std::cout << "BMP-Components: Pic: " << picComponents << " old: " << (ret->getComponents()) << " File: " << fileComponents << std::endl;
|
||||
ret->init(w,h,picComponents);
|
||||
uint8* pixels = ret->getPixels();
|
||||
//read file
|
||||
|
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "opengl.h"
|
||||
#include "leak_dumper.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -47,6 +48,7 @@ GLint toFormatGl(Texture::Format format, int components){
|
||||
case 4:
|
||||
return GL_RGBA;
|
||||
default:
|
||||
std::cerr << "Components = " << (components) << std::endl;
|
||||
assert(false);
|
||||
return GL_RGBA;
|
||||
}
|
||||
|
Reference in New Issue
Block a user