- more detailed error handling for bad textures and/or models and sounds
This commit is contained in:
parent
8ba5524f35
commit
1966710628
|
@ -20,7 +20,6 @@ using std::runtime_error;
|
||||||
|
|
||||||
namespace Shared{ namespace Graphics{
|
namespace Shared{ namespace Graphics{
|
||||||
|
|
||||||
/**Copied from pixmap.cpp*/
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// Structs used for BMP-reading
|
// Structs used for BMP-reading
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
@ -91,7 +90,7 @@ Pixmap2D* BMPReader::read(ifstream& in, const string& path, Pixmap2D* ret) const
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fileHeader.type1!='B' || fileHeader.type2!='M'){
|
if(fileHeader.type1!='B' || fileHeader.type2!='M'){
|
||||||
throw megaglest_runtime_error(path +" is not a bitmap");
|
throw megaglest_runtime_error(path +" is not a bitmap",true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//read info header
|
//read info header
|
||||||
|
@ -112,7 +111,7 @@ Pixmap2D* BMPReader::read(ifstream& in, const string& path, Pixmap2D* ret) const
|
||||||
}
|
}
|
||||||
|
|
||||||
if(infoHeader.bitCount!=24){
|
if(infoHeader.bitCount!=24){
|
||||||
throw megaglest_runtime_error(path+" is not a 24 bit bitmap");
|
throw megaglest_runtime_error(path+" is not a 24 bit bitmap",true);
|
||||||
}
|
}
|
||||||
|
|
||||||
int h= infoHeader.height;
|
int h= infoHeader.height;
|
||||||
|
|
|
@ -24,8 +24,6 @@
|
||||||
using std::runtime_error;
|
using std::runtime_error;
|
||||||
using std::ios;
|
using std::ios;
|
||||||
|
|
||||||
/**Used things from CImageLoaderJPG.cpp from Irrlicht*/
|
|
||||||
|
|
||||||
namespace Shared{ namespace Graphics{
|
namespace Shared{ namespace Graphics{
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
@ -92,7 +90,7 @@ Pixmap2D* JPGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const
|
||||||
if (buffer[0] != 0xFF || buffer[1] != 0xD8) {
|
if (buffer[0] != 0xFF || buffer[1] != 0xD8) {
|
||||||
std::cout << "0 = [" << std::hex << (int)buffer[0] << "] 1 = [" << std::hex << (int)buffer[1] << "]" << std::endl;
|
std::cout << "0 = [" << std::hex << (int)buffer[0] << "] 1 = [" << std::hex << (int)buffer[1] << "]" << std::endl;
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
return NULL;
|
throw megaglest_runtime_error(path +" is not a jpeg",true);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct jpeg_decompress_struct cinfo;
|
struct jpeg_decompress_struct cinfo;
|
||||||
|
@ -116,7 +114,7 @@ Pixmap2D* JPGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const
|
||||||
if (row_pointer[0] != NULL) {
|
if (row_pointer[0] != NULL) {
|
||||||
delete[] row_pointer[0];
|
delete[] row_pointer[0];
|
||||||
}
|
}
|
||||||
return NULL;
|
throw megaglest_runtime_error(path +" is a corrupt(1) jpeg",true);
|
||||||
}
|
}
|
||||||
|
|
||||||
source.init_source = init_source;
|
source.init_source = init_source;
|
||||||
|
@ -129,7 +127,7 @@ Pixmap2D* JPGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const
|
||||||
if (jpeg_read_header( &cinfo, TRUE ) != JPEG_HEADER_OK) {
|
if (jpeg_read_header( &cinfo, TRUE ) != JPEG_HEADER_OK) {
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
jpeg_destroy_decompress(&cinfo);
|
jpeg_destroy_decompress(&cinfo);
|
||||||
return NULL;
|
throw megaglest_runtime_error(path +" is a corrupt(1) jpeg",true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
using std::runtime_error;
|
using std::runtime_error;
|
||||||
using std::ios;
|
using std::ios;
|
||||||
|
|
||||||
/**Used things from CImageLoaderJPG.cpp from Irrlicht*/
|
|
||||||
|
|
||||||
namespace Shared{ namespace Graphics{
|
namespace Shared{ namespace Graphics{
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
@ -79,24 +77,26 @@ Pixmap2D* PNGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const
|
||||||
|
|
||||||
if (png_sig_cmp(buffer, 0, 8) != 0) {
|
if (png_sig_cmp(buffer, 0, 8) != 0) {
|
||||||
delete [] buffer;
|
delete [] buffer;
|
||||||
return NULL; //This is not a PNG file - could be used for fast checking whether file is supported or not
|
//This is not a PNG file - could be used for fast checking whether file is supported or not
|
||||||
|
throw megaglest_runtime_error(path +" is not a png",true);
|
||||||
}
|
}
|
||||||
|
|
||||||
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||||
if (!png_ptr) {
|
if (!png_ptr) {
|
||||||
delete [] buffer;
|
delete [] buffer;
|
||||||
return NULL;
|
throw megaglest_runtime_error(path +" is a corrupt(1) png",true);
|
||||||
}
|
}
|
||||||
png_infop info_ptr = png_create_info_struct(png_ptr);
|
png_infop info_ptr = png_create_info_struct(png_ptr);
|
||||||
if (!info_ptr) {
|
if (!info_ptr) {
|
||||||
png_destroy_read_struct(&png_ptr, (png_infopp)NULL,(png_infopp)NULL);
|
png_destroy_read_struct(&png_ptr, (png_infopp)NULL,(png_infopp)NULL);
|
||||||
delete [] buffer;
|
delete [] buffer;
|
||||||
return NULL;
|
throw megaglest_runtime_error(path +" is a corrupt(2) png",true);
|
||||||
}
|
}
|
||||||
if (setjmp(png_jmpbuf(png_ptr))) {
|
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||||
png_destroy_read_struct(&png_ptr, &info_ptr,(png_infopp)NULL);
|
png_destroy_read_struct(&png_ptr, &info_ptr,(png_infopp)NULL);
|
||||||
delete [] buffer;
|
delete [] buffer;
|
||||||
return NULL; //Error during init_io
|
//Error during init_io
|
||||||
|
throw megaglest_runtime_error(path +" is a corrupt(3) png",true);
|
||||||
}
|
}
|
||||||
png_set_read_fn(png_ptr, &is, user_read_data);
|
png_set_read_fn(png_ptr, &is, user_read_data);
|
||||||
png_set_sig_bytes(png_ptr, 8);
|
png_set_sig_bytes(png_ptr, 8);
|
||||||
|
@ -127,7 +127,8 @@ Pixmap2D* PNGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const
|
||||||
if (setjmp(png_jmpbuf(png_ptr))) {
|
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||||
delete[] row_pointers;
|
delete[] row_pointers;
|
||||||
delete [] buffer;
|
delete [] buffer;
|
||||||
return NULL; //error during read_image
|
//error during read_image
|
||||||
|
throw megaglest_runtime_error(path +" is a corrupt(4) png",true);
|
||||||
}
|
}
|
||||||
for (int y = 0; y < height; ++y) {
|
for (int y = 0; y < height; ++y) {
|
||||||
row_pointers[y] = new png_byte[png_get_rowbytes(png_ptr, info_ptr)];
|
row_pointers[y] = new png_byte[png_get_rowbytes(png_ptr, info_ptr)];
|
||||||
|
@ -224,24 +225,26 @@ Pixmap3D* PNGReader3D::read(ifstream& is, const string& path, Pixmap3D* ret) con
|
||||||
|
|
||||||
if (png_sig_cmp(buffer, 0, 8) != 0) {
|
if (png_sig_cmp(buffer, 0, 8) != 0) {
|
||||||
delete [] buffer;
|
delete [] buffer;
|
||||||
return NULL; //This is not a PNG file - could be used for fast checking whether file is supported or not
|
//This is not a PNG file - could be used for fast checking whether file is supported or not
|
||||||
|
throw megaglest_runtime_error(path +" is not a png(2)",true);
|
||||||
}
|
}
|
||||||
|
|
||||||
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||||
if (!png_ptr) {
|
if (!png_ptr) {
|
||||||
delete [] buffer;
|
delete [] buffer;
|
||||||
return NULL;
|
throw megaglest_runtime_error(path +" is a corrupt(5) png",true);
|
||||||
}
|
}
|
||||||
png_infop info_ptr = png_create_info_struct(png_ptr);
|
png_infop info_ptr = png_create_info_struct(png_ptr);
|
||||||
if (!info_ptr) {
|
if (!info_ptr) {
|
||||||
png_destroy_read_struct(&png_ptr, (png_infopp)NULL,(png_infopp)NULL);
|
png_destroy_read_struct(&png_ptr, (png_infopp)NULL,(png_infopp)NULL);
|
||||||
delete [] buffer;
|
delete [] buffer;
|
||||||
return NULL;
|
throw megaglest_runtime_error(path +" is a corrupt(6) png",true);
|
||||||
}
|
}
|
||||||
if (setjmp(png_jmpbuf(png_ptr))) {
|
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||||
png_destroy_read_struct(&png_ptr, &info_ptr,(png_infopp)NULL);
|
png_destroy_read_struct(&png_ptr, &info_ptr,(png_infopp)NULL);
|
||||||
delete [] buffer;
|
delete [] buffer;
|
||||||
return NULL; //Error during init_io
|
//Error during init_io
|
||||||
|
throw megaglest_runtime_error(path +" is a corrupt(7) png",true);
|
||||||
}
|
}
|
||||||
png_set_read_fn(png_ptr, &is, user_read_data);
|
png_set_read_fn(png_ptr, &is, user_read_data);
|
||||||
png_set_sig_bytes(png_ptr, 8);
|
png_set_sig_bytes(png_ptr, 8);
|
||||||
|
@ -271,7 +274,8 @@ Pixmap3D* PNGReader3D::read(ifstream& is, const string& path, Pixmap3D* ret) con
|
||||||
if (setjmp(png_jmpbuf(png_ptr))) {
|
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||||
delete[] row_pointers;
|
delete[] row_pointers;
|
||||||
delete [] buffer;
|
delete [] buffer;
|
||||||
return NULL; //error during read_image
|
//error during read_image
|
||||||
|
throw megaglest_runtime_error(path +" is a corrupt(8) png",true);
|
||||||
}
|
}
|
||||||
for (int y = 0; y < height; ++y) {
|
for (int y = 0; y < height; ++y) {
|
||||||
row_pointers[y] = new png_byte[png_get_rowbytes(png_ptr, info_ptr)];
|
row_pointers[y] = new png_byte[png_get_rowbytes(png_ptr, info_ptr)];
|
||||||
|
|
|
@ -419,13 +419,13 @@ void Mesh::loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *tex
|
||||||
if(meshHeader.normalFrameCount != meshHeader.vertexFrameCount) {
|
if(meshHeader.normalFrameCount != meshHeader.vertexFrameCount) {
|
||||||
char szBuf[8096]="";
|
char szBuf[8096]="";
|
||||||
snprintf(szBuf,8096,"Old v2 model: vertex frame count different from normal frame count [v = %d, n = %d] meshIndex = %d modelFile [%s]",meshHeader.vertexFrameCount,meshHeader.normalFrameCount,meshIndex,modelFile.c_str());
|
snprintf(szBuf,8096,"Old v2 model: vertex frame count different from normal frame count [v = %d, n = %d] meshIndex = %d modelFile [%s]",meshHeader.vertexFrameCount,meshHeader.normalFrameCount,meshIndex,modelFile.c_str());
|
||||||
throw megaglest_runtime_error(szBuf);
|
throw megaglest_runtime_error(szBuf,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(meshHeader.texCoordFrameCount != 1) {
|
if(meshHeader.texCoordFrameCount != 1) {
|
||||||
char szBuf[8096]="";
|
char szBuf[8096]="";
|
||||||
snprintf(szBuf,8096,"Old v2 model: texture coord frame count is not 1 [t = %d] meshIndex = %d modelFile [%s]",meshHeader.texCoordFrameCount,meshIndex,modelFile.c_str());
|
snprintf(szBuf,8096,"Old v2 model: texture coord frame count is not 1 [t = %d] meshIndex = %d modelFile [%s]",meshHeader.texCoordFrameCount,meshIndex,modelFile.c_str());
|
||||||
throw megaglest_runtime_error(szBuf);
|
throw megaglest_runtime_error(szBuf,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//init
|
//init
|
||||||
|
@ -556,7 +556,7 @@ void Mesh::loadV3(int meshIndex, const string &dir, FILE *f,
|
||||||
if(meshHeader.normalFrameCount != meshHeader.vertexFrameCount) {
|
if(meshHeader.normalFrameCount != meshHeader.vertexFrameCount) {
|
||||||
char szBuf[8096]="";
|
char szBuf[8096]="";
|
||||||
snprintf(szBuf,8096,"Old v3 model: vertex frame count different from normal frame count [v = %d, n = %d] meshIndex = %d modelFile [%s]",meshHeader.vertexFrameCount,meshHeader.normalFrameCount,meshIndex,modelFile.c_str());
|
snprintf(szBuf,8096,"Old v3 model: vertex frame count different from normal frame count [v = %d, n = %d] meshIndex = %d modelFile [%s]",meshHeader.vertexFrameCount,meshHeader.normalFrameCount,meshIndex,modelFile.c_str());
|
||||||
throw megaglest_runtime_error(szBuf);
|
throw megaglest_runtime_error(szBuf,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//init
|
//init
|
||||||
|
@ -1153,7 +1153,7 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad,
|
||||||
#endif
|
#endif
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
printf("In [%s::%s] cannot load file = [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,path.c_str());
|
printf("In [%s::%s] cannot load file = [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,path.c_str());
|
||||||
throw megaglest_runtime_error("Error opening g3d model file [" + path + "]");
|
throw megaglest_runtime_error("Error opening g3d model file [" + path + "]",true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(loadedFileList) {
|
if(loadedFileList) {
|
||||||
|
@ -1177,7 +1177,7 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad,
|
||||||
fclose(f);
|
fclose(f);
|
||||||
f = NULL;
|
f = NULL;
|
||||||
printf("In [%s::%s] file = [%s] fileheader.id = [%s][%c]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,path.c_str(),reinterpret_cast<char*>(fileHeader.id),fileHeader.id[0]);
|
printf("In [%s::%s] file = [%s] fileheader.id = [%s][%c]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,path.c_str(),reinterpret_cast<char*>(fileHeader.id),fileHeader.id[0]);
|
||||||
throw megaglest_runtime_error("Not a valid G3D model");
|
throw megaglest_runtime_error("Not a valid G3D model",true);
|
||||||
}
|
}
|
||||||
fileVersion= fileHeader.version;
|
fileVersion= fileHeader.version;
|
||||||
|
|
||||||
|
|
|
@ -110,13 +110,13 @@ PixmapIoTga::~PixmapIoTga() {
|
||||||
void PixmapIoTga::openRead(const string &path) {
|
void PixmapIoTga::openRead(const string &path) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
file= _wfopen(utf8_decode(path).c_str(), L"rb");
|
file= _wfopen(utf8_decode(path).c_str(), L"rb");
|
||||||
#else
|
#else
|
||||||
file= fopen(path.c_str(),"rb");
|
file= fopen(path.c_str(),"rb");
|
||||||
#endif
|
#endif
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
throw megaglest_runtime_error("Can't open TGA file: "+ path);
|
throw megaglest_runtime_error("Can't open TGA file: "+ path,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//read header
|
//read header
|
||||||
|
@ -142,29 +142,32 @@ void PixmapIoTga::openRead(const string &path) {
|
||||||
}
|
}
|
||||||
//check that we can load this tga file
|
//check that we can load this tga file
|
||||||
if(fileHeader.idLength != 0) {
|
if(fileHeader.idLength != 0) {
|
||||||
throw megaglest_runtime_error(path + ": id field is not 0");
|
throw megaglest_runtime_error(path + ": id field is not 0",true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fileHeader.dataTypeCode != tgaUncompressedRgb && fileHeader.dataTypeCode != tgaUncompressedBw) {
|
if(fileHeader.dataTypeCode != tgaUncompressedRgb && fileHeader.dataTypeCode != tgaUncompressedBw) {
|
||||||
throw megaglest_runtime_error(path + ": only uncompressed BW and RGB targa images are supported");
|
throw megaglest_runtime_error(path + ": only uncompressed BW and RGB targa images are supported",true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//check bits per pixel
|
//check bits per pixel
|
||||||
if(fileHeader.bitsPerPixel != 8 && fileHeader.bitsPerPixel != 24 && fileHeader.bitsPerPixel !=32) {
|
if(fileHeader.bitsPerPixel != 8 && fileHeader.bitsPerPixel != 24 && fileHeader.bitsPerPixel !=32) {
|
||||||
throw megaglest_runtime_error(path + ": only 8, 24 and 32 bit targa images are supported");
|
throw megaglest_runtime_error(path + ": only 8, 24 and 32 bit targa images are supported",true);
|
||||||
}
|
}
|
||||||
|
|
||||||
h= fileHeader.height;
|
h= fileHeader.height;
|
||||||
w= fileHeader.width;
|
w= fileHeader.width;
|
||||||
components= fileHeader.bitsPerPixel / 8;
|
components= fileHeader.bitsPerPixel / 8;
|
||||||
|
}
|
||||||
|
catch(megaglest_runtime_error& ex) {
|
||||||
|
char szBuf[8096]="";
|
||||||
|
snprintf(szBuf,8096,"Error in [%s] on line: %d msg: %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,ex.what());
|
||||||
|
throw megaglest_runtime_error(szBuf,!ex.wantStackTrace());
|
||||||
}
|
}
|
||||||
catch(exception& ex) {
|
catch(exception& ex) {
|
||||||
char szBuf[8096]="";
|
char szBuf[8096]="";
|
||||||
snprintf(szBuf,8096,"Error in [%s] on line: %d msg: %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,ex.what());
|
snprintf(szBuf,8096,"Error in [%s] on line: %d msg: %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,ex.what());
|
||||||
throw megaglest_runtime_error(szBuf);
|
throw megaglest_runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixmapIoTga::read(uint8 *pixels) {
|
void PixmapIoTga::read(uint8 *pixels) {
|
||||||
|
@ -259,14 +262,17 @@ void PixmapIoTga::read(uint8 *pixels, int components) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch(megaglest_runtime_error& ex) {
|
||||||
|
char szBuf[8096]="";
|
||||||
|
snprintf(szBuf,8096,"Error in [%s] on line: %d msg: %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,ex.what());
|
||||||
|
throw megaglest_runtime_error(szBuf,!ex.wantStackTrace());
|
||||||
}
|
}
|
||||||
catch(exception& ex) {
|
catch(exception& ex) {
|
||||||
char szBuf[8096]="";
|
char szBuf[8096]="";
|
||||||
snprintf(szBuf,8096,"Error in [%s] on line: %d msg: %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,ex.what());
|
snprintf(szBuf,8096,"Error in [%s] on line: %d msg: %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,ex.what());
|
||||||
throw megaglest_runtime_error(szBuf);
|
throw megaglest_runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixmapIoTga::openWrite(const string &path, int w, int h, int components) {
|
void PixmapIoTga::openWrite(const string &path, int w, int h, int components) {
|
||||||
|
@ -280,7 +286,7 @@ void PixmapIoTga::openWrite(const string &path, int w, int h, int components) {
|
||||||
file= fopen(path.c_str(),"wb");
|
file= fopen(path.c_str(),"wb");
|
||||||
#endif
|
#endif
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
throw megaglest_runtime_error("Can't open TGA file: "+ path);
|
throw megaglest_runtime_error("Can't open TGA file: "+ path,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TargaFileHeader fileHeader;
|
TargaFileHeader fileHeader;
|
||||||
|
@ -357,7 +363,7 @@ void PixmapIoBmp::openRead(const string &path){
|
||||||
file= fopen(path.c_str(),"rb");
|
file= fopen(path.c_str(),"rb");
|
||||||
#endif
|
#endif
|
||||||
if (file==NULL){
|
if (file==NULL){
|
||||||
throw megaglest_runtime_error("Can't open BMP file: "+ path);
|
throw megaglest_runtime_error("Can't open BMP file: "+ path,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//read file header
|
//read file header
|
||||||
|
@ -379,7 +385,7 @@ void PixmapIoBmp::openRead(const string &path){
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fileHeader.type1!='B' || fileHeader.type2!='M'){
|
if(fileHeader.type1!='B' || fileHeader.type2!='M'){
|
||||||
throw megaglest_runtime_error(path +" is not a bitmap");
|
throw megaglest_runtime_error(path +" is not a bitmap",true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//read info header
|
//read info header
|
||||||
|
@ -404,7 +410,7 @@ void PixmapIoBmp::openRead(const string &path){
|
||||||
infoHeader.yPelsPerMeter = Shared::PlatformByteOrder::fromCommonEndian(infoHeader.yPelsPerMeter);
|
infoHeader.yPelsPerMeter = Shared::PlatformByteOrder::fromCommonEndian(infoHeader.yPelsPerMeter);
|
||||||
}
|
}
|
||||||
if(infoHeader.bitCount!=24){
|
if(infoHeader.bitCount!=24){
|
||||||
throw megaglest_runtime_error(path+" is not a 24 bit bitmap");
|
throw megaglest_runtime_error(path+" is not a 24 bit bitmap",true);
|
||||||
}
|
}
|
||||||
|
|
||||||
h= infoHeader.height;
|
h= infoHeader.height;
|
||||||
|
@ -593,31 +599,7 @@ void PixmapIoPng::openWrite(const string &path, int w, int h, int components) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixmapIoPng::write(uint8 *pixels) {
|
void PixmapIoPng::write(uint8 *pixels) {
|
||||||
|
|
||||||
// initialize stuff
|
// initialize stuff
|
||||||
/*
|
|
||||||
std::auto_ptr<png_byte*> imrow(new png_byte*[h]);
|
|
||||||
for(int i = 0; i < h; ++i) {
|
|
||||||
imrow.get()[i] = pixels+(h-1-i) * w * components;
|
|
||||||
}
|
|
||||||
|
|
||||||
png_structp imgp = png_create_write_struct(PNG_LIBPNG_VER_STRING,0,0,0);
|
|
||||||
png_infop infop = png_create_info_struct(imgp);
|
|
||||||
png_init_io(imgp, file);
|
|
||||||
|
|
||||||
int color_type = PNG_COLOR_TYPE_RGB;
|
|
||||||
if(components == 4) {
|
|
||||||
color_type = PNG_COLOR_TYPE_RGBA;
|
|
||||||
}
|
|
||||||
png_set_IHDR(imgp, infop, w, h,
|
|
||||||
8, color_type, PNG_INTERLACE_NONE,
|
|
||||||
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
|
||||||
|
|
||||||
// write file
|
|
||||||
png_write_info(imgp, infop);
|
|
||||||
png_write_image(imgp, imrow.get());
|
|
||||||
png_write_end(imgp, NULL);
|
|
||||||
*/
|
|
||||||
png_bytep *imrow = new png_bytep[h];
|
png_bytep *imrow = new png_bytep[h];
|
||||||
//png_bytep *imrow = (png_bytep*) malloc(sizeof(png_bytep) * height);
|
//png_bytep *imrow = (png_bytep*) malloc(sizeof(png_bytep) * height);
|
||||||
for(int i = 0; i < h; ++i) {
|
for(int i = 0; i < h; ++i) {
|
||||||
|
@ -642,128 +624,8 @@ void PixmapIoPng::write(uint8 *pixels) {
|
||||||
png_write_end(imgp, NULL);
|
png_write_end(imgp, NULL);
|
||||||
|
|
||||||
delete [] imrow;
|
delete [] imrow;
|
||||||
|
|
||||||
/*
|
|
||||||
// Allocate write & info structures
|
|
||||||
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
|
||||||
if(!png_ptr) {
|
|
||||||
fclose(file);
|
|
||||||
throw megaglest_runtime_error("OpenGlDevice::saveImageAsPNG() - out of memory creating write structure");
|
|
||||||
}
|
|
||||||
|
|
||||||
png_infop info_ptr = png_create_info_struct(png_ptr);
|
|
||||||
if(!info_ptr) {
|
|
||||||
png_destroy_write_struct(&png_ptr,
|
|
||||||
(png_infopp)NULL);
|
|
||||||
fclose(file);
|
|
||||||
throw megaglest_runtime_error("OpenGlDevice::saveImageAsPNG() - out of memery creating info structure");
|
|
||||||
}
|
|
||||||
|
|
||||||
// setjmp() must be called in every function that calls a PNG-writing
|
|
||||||
// libpng function, unless an alternate error handler was installed--
|
|
||||||
// but compatible error handlers must either use longjmp() themselves
|
|
||||||
// (as in this program) or exit immediately, so here we go:
|
|
||||||
|
|
||||||
if(setjmp(png_jmpbuf(png_ptr))) {
|
|
||||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
|
||||||
fclose(file);
|
|
||||||
throw megaglest_runtime_error("OpenGlDevice::saveImageAsPNG() - setjmp problem");
|
|
||||||
}
|
|
||||||
|
|
||||||
// make sure outfile is (re)opened in BINARY mode
|
|
||||||
png_init_io(png_ptr, file);
|
|
||||||
|
|
||||||
// set the compression levels--in general, always want to leave filtering
|
|
||||||
// turned on (except for palette images) and allow all of the filters,
|
|
||||||
// which is the default; want 32K zlib window, unless entire image buffer
|
|
||||||
// is 16K or smaller (unknown here)--also the default; usually want max
|
|
||||||
// compression (NOT the default); and remaining compression flags should
|
|
||||||
// be left alone
|
|
||||||
|
|
||||||
//png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
|
|
||||||
png_set_compression_level(png_ptr, Z_DEFAULT_COMPRESSION);
|
|
||||||
|
|
||||||
//
|
|
||||||
// this is default for no filtering; Z_FILTERED is default otherwise:
|
|
||||||
// png_set_compression_strategy(png_ptr, Z_DEFAULT_STRATEGY);
|
|
||||||
// these are all defaults:
|
|
||||||
// png_set_compression_mem_level(png_ptr, 8);
|
|
||||||
// png_set_compression_window_bits(png_ptr, 15);
|
|
||||||
// png_set_compression_method(png_ptr, 8);
|
|
||||||
|
|
||||||
|
|
||||||
// Set some options: color_type, interlace_type
|
|
||||||
int color_type=0, interlace_type=0, numChannels=0;
|
|
||||||
|
|
||||||
// color_type = PNG_COLOR_TYPE_GRAY;
|
|
||||||
// color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
|
|
||||||
color_type = PNG_COLOR_TYPE_RGBA;
|
|
||||||
numChannels = 4;
|
|
||||||
// color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
|
||||||
|
|
||||||
interlace_type = PNG_INTERLACE_NONE;
|
|
||||||
// interlace_type = PNG_INTERLACE_ADAM7;
|
|
||||||
|
|
||||||
int bit_depth = 8;
|
|
||||||
png_set_IHDR(png_ptr, info_ptr, this->w, this->h,
|
|
||||||
bit_depth,
|
|
||||||
color_type,
|
|
||||||
interlace_type,
|
|
||||||
PNG_COMPRESSION_TYPE_BASE,
|
|
||||||
PNG_FILTER_TYPE_BASE);
|
|
||||||
|
|
||||||
// Optional gamma chunk is strongly suggested if you have any guess
|
|
||||||
// as to the correct gamma of the image. (we don't have a guess)
|
|
||||||
//
|
|
||||||
// png_set_gAMA(png_ptr, info_ptr, image_gamma);
|
|
||||||
//png_set_strip_alpha(png_ptr);
|
|
||||||
|
|
||||||
// write all chunks up to (but not including) first IDAT
|
|
||||||
png_write_info(png_ptr, info_ptr);
|
|
||||||
|
|
||||||
//png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL );
|
|
||||||
|
|
||||||
|
|
||||||
// set up the row pointers for the image so we can use png_write_image
|
|
||||||
png_bytep* row_pointers = new png_bytep[this->h];
|
|
||||||
if (row_pointers == 0) {
|
|
||||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
|
||||||
fclose(file);
|
|
||||||
throw megaglest_runtime_error("OpenGlDevice::failed to allocate memory for row pointers");
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int row_stride = this->w * numChannels;
|
|
||||||
unsigned char *rowptr = (unsigned char*) pixels;
|
|
||||||
for (int row = this->h-1; row >=0 ; row--) {
|
|
||||||
row_pointers[row] = rowptr;
|
|
||||||
rowptr += row_stride;
|
|
||||||
}
|
|
||||||
|
|
||||||
// now we just write the whole image; libpng takes care of interlacing for us
|
|
||||||
png_write_image(png_ptr, row_pointers);
|
|
||||||
|
|
||||||
// since that's it, we also close out the end of the PNG file now--if we
|
|
||||||
// had any text or time info to write after the IDATs, second argument
|
|
||||||
// would be info_ptr, but we optimize slightly by sending NULL pointer:
|
|
||||||
|
|
||||||
png_write_end(png_ptr, info_ptr);
|
|
||||||
|
|
||||||
//
|
|
||||||
// clean up after the write
|
|
||||||
// free any memory allocated & close the file
|
|
||||||
//
|
|
||||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
|
||||||
|
|
||||||
delete [] row_pointers;
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class PixmapIoJpg
|
// class PixmapIoJpg
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
@ -780,7 +642,6 @@ PixmapIoJpg::~PixmapIoJpg() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PixmapIoJpg::openRead(const string &path) {
|
void PixmapIoJpg::openRead(const string &path) {
|
||||||
|
|
||||||
throw megaglest_runtime_error("PixmapIoJpg::openRead not implemented!");
|
throw megaglest_runtime_error("PixmapIoJpg::openRead not implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ void WavSoundFileLoader::open(const string &path, SoundInfo *soundInfo){
|
||||||
f.open(path.c_str(), ios_base::in | ios_base::binary);
|
f.open(path.c_str(), ios_base::in | ios_base::binary);
|
||||||
|
|
||||||
if(!f.is_open()){
|
if(!f.is_open()){
|
||||||
throw megaglest_runtime_error("Error opening wav file: "+ string(path));
|
throw megaglest_runtime_error("Error opening wav file: "+ string(path),true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//RIFF chunk - Id
|
//RIFF chunk - Id
|
||||||
|
@ -53,7 +53,7 @@ void WavSoundFileLoader::open(const string &path, SoundInfo *soundInfo){
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strcmp(chunkId, "RIFF")!=0){
|
if(strcmp(chunkId, "RIFF")!=0){
|
||||||
throw megaglest_runtime_error("Not a valid wav file (first four bytes are not RIFF):" + path);
|
throw megaglest_runtime_error("Not a valid wav file (first four bytes are not RIFF):" + path,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//RIFF chunk - Size
|
//RIFF chunk - Size
|
||||||
|
@ -71,7 +71,7 @@ void WavSoundFileLoader::open(const string &path, SoundInfo *soundInfo){
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strcmp(chunkId, "WAVE")!=0){
|
if(strcmp(chunkId, "WAVE")!=0){
|
||||||
throw megaglest_runtime_error("Not a valid wav file (wave data don't start by WAVE): " + path);
|
throw megaglest_runtime_error("Not a valid wav file (wave data don't start by WAVE): " + path,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// === HEADER ===
|
// === HEADER ===
|
||||||
|
@ -85,7 +85,7 @@ void WavSoundFileLoader::open(const string &path, SoundInfo *soundInfo){
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strcmp(chunkId, "fmt ")!=0){
|
if(strcmp(chunkId, "fmt ")!=0){
|
||||||
throw megaglest_runtime_error("Not a valid wav file (first sub-chunk Id is not fmt): "+ path);
|
throw megaglest_runtime_error("Not a valid wav file (first sub-chunk Id is not fmt): "+ path,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//first sub-chunk (header) - Size
|
//first sub-chunk (header) - Size
|
||||||
|
@ -139,7 +139,7 @@ void WavSoundFileLoader::open(const string &path, SoundInfo *soundInfo){
|
||||||
soundInfo->setBitRate(soundInfo->getSamplesPerSecond() * soundInfo->getChannels() * soundInfo->getBitsPerSample() / 8);
|
soundInfo->setBitRate(soundInfo->getSamplesPerSecond() * soundInfo->getChannels() * soundInfo->getBitsPerSample() / 8);
|
||||||
|
|
||||||
if (soundInfo->getBitsPerSample() != 8 && soundInfo->getBitsPerSample()!=16){
|
if (soundInfo->getBitsPerSample() != 8 && soundInfo->getBitsPerSample()!=16){
|
||||||
throw megaglest_runtime_error("Bits per sample must be 8 or 16: " + path);
|
throw megaglest_runtime_error("Bits per sample must be 8 or 16: " + path,true);
|
||||||
}
|
}
|
||||||
bytesPerSecond= soundInfo->getBitsPerSample()*8*soundInfo->getSamplesPerSecond()*soundInfo->getChannels();
|
bytesPerSecond= soundInfo->getBitsPerSample()*8*soundInfo->getSamplesPerSecond()*soundInfo->getChannels();
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ void WavSoundFileLoader::open(const string &path, SoundInfo *soundInfo){
|
||||||
while(strncmp(chunkId, "data", 4)!=0 && count<maxDataRetryCount);
|
while(strncmp(chunkId, "data", 4)!=0 && count<maxDataRetryCount);
|
||||||
|
|
||||||
if(f.bad() || count==maxDataRetryCount){
|
if(f.bad() || count==maxDataRetryCount){
|
||||||
throw megaglest_runtime_error("Error reading samples: "+ path);
|
throw megaglest_runtime_error("Error reading samples: "+ path,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
dataOffset= (uint32)f.tellg();
|
dataOffset= (uint32)f.tellg();
|
||||||
|
@ -210,19 +210,19 @@ void OggSoundFileLoader::open(const string &path, SoundInfo *soundInfo){
|
||||||
f= fopen(path.c_str(), "rb");
|
f= fopen(path.c_str(), "rb");
|
||||||
#endif
|
#endif
|
||||||
if(f==NULL){
|
if(f==NULL){
|
||||||
throw megaglest_runtime_error("Can't open ogg file: "+path);
|
throw megaglest_runtime_error("Can't open ogg file: "+path,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
vf= new OggVorbis_File();
|
vf= new OggVorbis_File();
|
||||||
if(vf==NULL) {
|
if(vf==NULL) {
|
||||||
throw megaglest_runtime_error("Can't create ogg object for file: "+path);
|
throw megaglest_runtime_error("Can't create ogg object for file: "+path,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
ov_open(f, vf, NULL, 0);
|
ov_open(f, vf, NULL, 0);
|
||||||
|
|
||||||
vorbis_info *vi= ov_info(vf, -1);
|
vorbis_info *vi= ov_info(vf, -1);
|
||||||
if(vi==NULL) {
|
if(vi==NULL) {
|
||||||
throw megaglest_runtime_error("Can't read ogg header info for file: "+path);
|
throw megaglest_runtime_error("Can't read ogg header info for file: "+path,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 samples = static_cast<uint32>(ov_pcm_total(vf, -1));
|
uint32 samples = static_cast<uint32>(ov_pcm_total(vf, -1));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user