Removed LastError() from wxFilterStream

Added a better Peek() to wxBufferedInputStream
Fixed wxPNMHandler (it is a lot faster on text PNM now)
Image sample loads a PNM


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3525 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Guilhem Lavaux 1999-08-29 19:48:03 +00:00
parent 6cc24024d6
commit 6319afe332
4 changed files with 43 additions and 11 deletions

View File

@ -170,7 +170,6 @@ class WXDLLEXPORT wxFilterInputStream: public wxInputStream {
char Peek() { return m_parent_i_stream->Peek(); }
wxStreamError LastError() const { return m_parent_i_stream->LastError(); }
size_t GetSize() const { return m_parent_i_stream->GetSize(); }
protected:
@ -183,7 +182,6 @@ class WXDLLEXPORT wxFilterOutputStream: public wxOutputStream {
wxFilterOutputStream(wxOutputStream& stream);
~wxFilterOutputStream();
wxStreamError LastError() const { return m_parent_o_stream->LastError(); }
size_t GetSize() const { return m_parent_o_stream->GetSize(); }
protected:
@ -216,6 +214,7 @@ class WXDLLEXPORT wxStreamBuffer {
size_t Write(const void *buffer, size_t size);
size_t Write(wxStreamBuffer *buf);
char Peek();
char GetChar();
void PutChar(char c);
off_t Tell() const;
@ -273,6 +272,7 @@ class wxBufferedInputStream: public wxFilterInputStream {
wxBufferedInputStream(wxInputStream& stream);
~wxBufferedInputStream();
char Peek();
wxInputStream& Read(void *buffer, size_t size);
// Position functions

View File

@ -43,6 +43,7 @@ public:
wxBitmap *my_horse_gif;
wxBitmap *my_horse_bmp;
wxBitmap *my_horse_pcx;
wxBitmap *my_horse_pnm;
wxBitmap *my_square;
wxBitmap *my_anti;
@ -148,6 +149,11 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
else
my_horse_bmp = new wxBitmap( image.ConvertToBitmap() );
if ( !image.LoadFile( dir + wxString("horse.pnm"), wxBITMAP_TYPE_PNM ) )
wxLogError("Can't load PNM image");
else
my_horse_pnm = new wxBitmap( image.ConvertToBitmap() );
image.LoadFile( dir + wxString("test.png") );
my_square = new wxBitmap( image.ConvertToBitmap() );
@ -156,6 +162,7 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
MyCanvas::~MyCanvas()
{
delete my_horse_pnm;
delete my_horse_png;
delete my_horse_jpeg;
delete my_horse_gif;
@ -194,6 +201,9 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
dc.DrawText( "BMP handler", 30, 1055 );
if (my_horse_bmp && my_horse_bmp->Ok()) dc.DrawBitmap( *my_horse_bmp, 30, 1070 );
dc.DrawText( "PNM handler", 30, 1285 );
if (my_horse_pnm && my_horse_pnm->Ok()) dc.DrawBitmap( *my_horse_pnm, 30, 1300 );
}
void MyCanvas::CreateAntiAliasedBitmap()
@ -277,7 +287,7 @@ MyFrame::MyFrame()
m_canvas = new MyCanvas( this, -1, wxPoint(0,0), wxSize(10,10) );
// 500 width * 1300 height
m_canvas->SetScrollbars( 10, 10, 50, 130 );
m_canvas->SetScrollbars( 10, 10, 50, 152 );
}
void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
@ -309,6 +319,7 @@ bool MyApp::OnInit()
wxImage::AddHandler( new wxGIFHandler );
wxImage::AddHandler( new wxPCXHandler );
wxImage::AddHandler( new wxPNMHandler );
wxFrame *frame = new MyFrame();
frame->Show( TRUE );

View File

@ -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,9 +85,9 @@ 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 << line << " " << width << " " << height << " " << maxval << endl;
@ -98,8 +99,6 @@ bool wxPNMHandler::LoadFile( wxImage *image, wxInputStream& stream, bool WXUNUSE
return FALSE;
}
wxBufferedInputStream buf_stream(stream);
if (c=='3') // Ascii RBG
{
wxUint32 value, size=3*width*height;

View File

@ -195,6 +195,23 @@ void wxStreamBuffer::PutChar(char c)
m_stream->m_lastcount = 1;
}
char wxStreamBuffer::Peek()
{
char c;
wxASSERT(m_stream != NULL && m_buffer_size != 0);
if (!GetDataLeft()) {
CHECK_ERROR(wxStream_READ_ERR);
return 0;
}
GetFromBuffer(&c, 1);
m_buffer_pos--;
return c;
}
char wxStreamBuffer::GetChar()
{
char c;
@ -248,7 +265,7 @@ size_t wxStreamBuffer::Read(void *buffer, size_t size)
buffer = (char *)buffer + buf_left; // ANSI C++ violation.
if (!FillBuffer()) {
CHECK_ERROR(wxStream_READ_ERR);
CHECK_ERROR(wxStream_EOF);
return (m_stream->m_lastcount = orig_size-size);
}
} else {
@ -743,6 +760,11 @@ wxBufferedInputStream::~wxBufferedInputStream()
delete m_i_streambuf;
}
char wxBufferedInputStream::Peek()
{
return m_i_streambuf->Peek();
}
wxInputStream& wxBufferedInputStream::Read(void *buffer, size_t size)
{
size_t retsize;