X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a8d9809fc0d3ac6a285bddeb6de44d334e38e011..7a4b8f27709c3dd59a5b447850389ca25f178047:/src/common/imagpnm.cpp?ds=sidebyside diff --git a/src/common/imagpnm.cpp b/src/common/imagpnm.cpp index ffbd4c1bd4..5352da9f4f 100644 --- a/src/common/imagpnm.cpp +++ b/src/common/imagpnm.cpp @@ -37,7 +37,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxPNMHandler,wxImageHandler) #if wxUSE_STREAMS - //#include // for cout +//#include // for cout void Skip_Comment(wxInputStream &stream) { @@ -64,10 +64,11 @@ bool wxPNMHandler::LoadFile( wxImage *image, wxInputStream& stream, bool WXUNUSE * Read the PNM header */ - wxTextInputStream text_stream(stream); + wxBufferedInputStream buf_stream(stream); + wxTextInputStream text_stream(buf_stream); - Skip_Comment(stream); - if (stream.GetC()==_T('P')) c=stream.GetC(); + Skip_Comment(buf_stream); + if (buf_stream.GetC()==_T('P')) c=buf_stream.GetC(); switch (c) { @@ -84,12 +85,12 @@ bool wxPNMHandler::LoadFile( wxImage *image, wxInputStream& stream, bool WXUNUSE } text_stream >> line; // for the \n - Skip_Comment(stream); + Skip_Comment(buf_stream); text_stream >> width >> height ; - Skip_Comment(stream); + Skip_Comment(buf_stream); text_stream >> maxval; - //cout << width << " " << height << " " << maxval << endl; + //cout << line << " " << width << " " << height << " " << maxval << endl; image->Create( width, height ); unsigned char *ptr = image->GetData(); if (!ptr) @@ -98,7 +99,7 @@ bool wxPNMHandler::LoadFile( wxImage *image, wxInputStream& stream, bool WXUNUSE return FALSE; } - if (c=='3') // Ascii RBG + if (c=='3') // Ascii RBG { wxUint32 value, size=3*width*height; for (wxUint32 i=0; iSetMask( FALSE ); - return (stream.LastError()==wxStream_NOERROR || stream.LastError()==wxStream_EOF); + return (buf_stream.LastError()==wxStream_NOERROR || buf_stream.LastError()==wxStream_EOF); } bool wxPNMHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool WXUNUSED(verbose) ) @@ -136,6 +137,25 @@ bool wxPNMHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool WXUNUS return (stream.LastError()==wxStream_NOERROR); } +bool wxPNMHandler::CanRead( wxInputStream& stream ) +{ + off_t pos=stream.TellI(); + + Skip_Comment(stream); + + if (stream.GetC()==_T('P')) + switch (stream.GetC()) + { + case _T('3'): case _T('6'): + stream.SeekI(pos); + return TRUE; + } + + stream.SeekI(pos); + return FALSE; +} + + #endif // wxUSE_STREAMS