mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
use putback() instead of seekg()
This commit is contained in:
parent
af97bce709
commit
4e256ae596
@ -83,6 +83,8 @@ public:
|
||||
pixval R[256]; /* reds */
|
||||
pixval G[256]; /* greens */
|
||||
pixval B[256]; /* blues */
|
||||
|
||||
bool _is_valid;
|
||||
};
|
||||
|
||||
class Writer : public PNMWriter {
|
||||
|
@ -256,8 +256,19 @@ PNMFileTypeJPG::Reader::
|
||||
Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number) :
|
||||
PNMReader(type, file, owns_file)
|
||||
{
|
||||
// Put the magic number bytes back into the file
|
||||
file->seekg(0);
|
||||
// Hope we can putback() more than one character.
|
||||
for (string::reverse_iterator mi = magic_number.rbegin();
|
||||
mi != magic_number.rend();
|
||||
mi++) {
|
||||
_file->putback(*mi);
|
||||
}
|
||||
if (_file->fail()) {
|
||||
pnmimage_jpg_cat.error()
|
||||
<< "Unable to put back magic number.\n";
|
||||
_is_valid = false;
|
||||
return;
|
||||
}
|
||||
_is_valid = true;
|
||||
|
||||
/* Step 1: allocate and initialize JPEG decompression object */
|
||||
|
||||
@ -302,8 +313,11 @@ Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number) :
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PNMFileTypeJPG::Reader::
|
||||
~Reader(void) {
|
||||
jpeg_destroy_decompress(&_cinfo);
|
||||
~Reader() {
|
||||
if (_is_valid) {
|
||||
jpeg_destroy_decompress(&_cinfo);
|
||||
_is_valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -321,6 +335,9 @@ PNMFileTypeJPG::Reader::
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int PNMFileTypeJPG::Reader::
|
||||
read_data(xel *array, xelval *) {
|
||||
if (!_is_valid) {
|
||||
return 0;
|
||||
}
|
||||
JSAMPARRAY buffer; /* Output row buffer */
|
||||
int row_stride; /* physical row width in output buffer */
|
||||
|
||||
|
@ -318,7 +318,7 @@ Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number) :
|
||||
unsigned short* greencolormap;
|
||||
unsigned short* bluecolormap;
|
||||
|
||||
// Hope we can ungetc() more than one character.
|
||||
// Hope we can putback() more than one character.
|
||||
for (string::reverse_iterator mi = magic_number.rbegin();
|
||||
mi != magic_number.rend();
|
||||
mi++) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user