mirror of
https://github.com/glest/glest-source.git
synced 2025-08-19 22:51:24 +02:00
Bugfix for incorrect header check for jpg textures
This commit is contained in:
@@ -3,9 +3,9 @@
|
|||||||
//
|
//
|
||||||
// Copyright (C) 2001-2010 Martiño Figueroa and others
|
// Copyright (C) 2001-2010 Martiño Figueroa and others
|
||||||
//
|
//
|
||||||
// You can redistribute this code and/or modify it under
|
// You can redistribute this code and/or modify it under
|
||||||
// the terms of the GNU General Public License as published
|
// the terms of the GNU General Public License as published
|
||||||
// by the Free Software Foundation; either version 2 of the
|
// by the Free Software Foundation; either version 2 of the
|
||||||
// License, or (at your option) any later version
|
// License, or (at your option) any later version
|
||||||
// ==============================================================
|
// ==============================================================
|
||||||
|
|
||||||
@@ -72,7 +72,10 @@ Pixmap2D* JPGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const
|
|||||||
uint8 * buffer = new uint8[length];
|
uint8 * buffer = new uint8[length];
|
||||||
is.read((char*)buffer, length);
|
is.read((char*)buffer, length);
|
||||||
//Check buffer (weak jpeg check)
|
//Check buffer (weak jpeg check)
|
||||||
if (buffer[0] != 0x46 || buffer[1] != 0xA0) {
|
//if (buffer[0] != 0x46 || buffer[1] != 0xA0) {
|
||||||
|
// Proper header check found from: http://www.fastgraph.com/help/jpeg_header_format.html
|
||||||
|
if (buffer[0] != 0xFF || buffer[1] != 0xD8) {
|
||||||
|
std::cout << "0 = [" << std::hex << (int)buffer[0] << "] 1 = [" << std::hex << (int)buffer[1] << "]" << std::endl;
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
std::cout << "Returning NULL jpeg" << std::endl;
|
std::cout << "Returning NULL jpeg" << std::endl;
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -80,12 +83,12 @@ Pixmap2D* JPGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const
|
|||||||
|
|
||||||
struct jpeg_decompress_struct cinfo;
|
struct jpeg_decompress_struct cinfo;
|
||||||
struct jpeg_error_mgr jerr;
|
struct jpeg_error_mgr jerr;
|
||||||
|
|
||||||
JSAMPROW row_pointer[1];
|
JSAMPROW row_pointer[1];
|
||||||
row_pointer[0] = NULL;
|
row_pointer[0] = NULL;
|
||||||
cinfo.err = jpeg_std_error( &jerr ); //Standard error handler
|
cinfo.err = jpeg_std_error( &jerr ); //Standard error handler
|
||||||
jpeg_create_decompress( &cinfo ); //Create decompressing structure
|
jpeg_create_decompress( &cinfo ); //Create decompressing structure
|
||||||
struct jpeg_source_mgr source;
|
struct jpeg_source_mgr source;
|
||||||
|
|
||||||
jmp_buf error_buffer; //Used for saving/restoring context
|
jmp_buf error_buffer; //Used for saving/restoring context
|
||||||
// Set up data pointer
|
// Set up data pointer
|
||||||
@@ -155,7 +158,7 @@ Pixmap2D* JPGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const
|
|||||||
g = row_pointer[0][xFile+1];
|
g = row_pointer[0][xFile+1];
|
||||||
b = row_pointer[0][xFile+2];
|
b = row_pointer[0][xFile+2];
|
||||||
l = (r+g+b+2)/3;
|
l = (r+g+b+2)/3;
|
||||||
a = row_pointer[0][xFile+3];
|
a = row_pointer[0][xFile+3];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
//TODO: Error
|
//TODO: Error
|
||||||
|
Reference in New Issue
Block a user