#if wxUSE_STREAMS
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
+
+ virtual bool CanRead( wxInputStream& stream );
+ virtual bool CanRead( const wxString& name );
#endif
inline void SetName(const wxString& name) { m_name = name; }
#if wxUSE_STREAMS
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
+ virtual bool CanRead( wxInputStream& stream );
#endif
};
#endif
#if wxUSE_STREAMS
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
+ virtual bool CanRead( wxInputStream& stream );
#endif
};
#endif
#if wxUSE_STREAMS
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
+ virtual bool CanRead( wxInputStream& stream );
#endif
};
#if wxUSE_STREAMS
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
+ virtual bool CanRead( wxInputStream& stream );
#endif
};
#if wxUSE_STREAMS
virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
+ virtual bool CanRead( wxInputStream& stream );
#endif
};
else
my_horse_png = new wxBitmap( image.ConvertToBitmap() );
- if ( !image.LoadFile( dir + wxString("horse.jpg"), wxBITMAP_TYPE_JPEG ) )
+ if ( !image.LoadFile( dir + wxString("horse.jpg") ) )
wxLogError("Can't load JPG image");
else
my_horse_jpeg = new wxBitmap( image.ConvertToBitmap() );
- if ( !image.LoadFile( dir + wxString("horse.gif"), wxBITMAP_TYPE_GIF ) )
+ if ( !image.LoadFile( dir + wxString("horse.gif") ) )
wxLogError("Can't load GIF image");
else
my_horse_gif = new wxBitmap( image.ConvertToBitmap() );
- if ( !image.LoadFile( dir + wxString("horse.bmp"), wxBITMAP_TYPE_BMP ) )
+ if ( !image.LoadFile( dir + wxString("horse.bmp") ) )
wxLogError("Can't load BMP image");
else
my_horse_bmp = new wxBitmap( image.ConvertToBitmap() );
- image.LoadFile( dir + wxString("test.png"), wxBITMAP_TYPE_PNG );
+ image.LoadFile( dir + wxString("test.png") );
my_square = new wxBitmap( image.ConvertToBitmap() );
CreateAntiAliasedBitmap();
return TRUE;
}
+bool wxBMPHandler::CanRead( wxInputStream& stream )
+{
+ unsigned char hdr[2];
+
+ stream.Read(&hdr, 2);
+ stream.SeekI(-2, wxFromCurrent);
+ return (hdr[0] == 'B' && hdr[1] == 'M');
+}
+
#endif // wxUSE_STREAMS
if (type==wxBITMAP_TYPE_ANY)
{
- // here we can try to guess the handler according the extension,
- // but we lose the stream name !?
- // Probably we should write methods such as
- // bool wxImageHandler::CanRead(wxString&)
- // bool wxImageHandler::CanRead(sxInputStream&&)
- // for png : see example.c
wxList &list=GetHandlers();
- off_t pos=stream.TellI();
-
- wxLogNull prevent_log;
for ( wxList::Node *node = list.GetFirst(); node; node = node->GetNext() )
{
handler=(wxImageHandler*)node->GetData();
- if (handler->LoadFile( this, stream, FALSE )) return TRUE;
+ if (handler->CanRead( stream ))
+ return handler->LoadFile( this, stream );
- stream.SeekI(pos);
}
wxLogWarning( _T("No handler found for this image.") );
{
return FALSE;
}
+
+bool wxImageHandler::CanRead( wxInputStream& stream )
+{
+ return FALSE;
+}
+
+bool wxImageHandler::CanRead( const wxString& name )
+{
+#if wxUSE_STREAMS
+ if (wxFileExists(name))
+ {
+ wxFileInputStream stream(name);
+ return CanRead(stream);
+ }
+
+ else {
+ wxLogError( _T("Can't check image format of file '%s': file does not exist."), name.c_str() );
+
+ return FALSE;
+ }
+#else // !wxUSE_STREAMS
+ return FALSE;
+#endif // wxUSE_STREAMS
+}
+
+
+
#endif // wxUSE_STREAMS
//-----------------------------------------------------------------------------
return FALSE;
}
+bool wxGIFHandler::CanRead( wxInputStream& stream )
+{
+ unsigned char hdr[5];
+
+ stream.Read(&hdr, 5);
+ stream.SeekI(-5, wxFromCurrent);
+ return (hdr[0] == 'G' && hdr[1] == 'I' && hdr[2] == 'F' && hdr[3] == '8' && hdr[4] == '9');
+}
+
#endif
return TRUE;
}
+
+bool wxJPEGHandler::CanRead( wxInputStream& stream )
+{
+ unsigned char hdr[2];
+
+ stream.Read(&hdr, 2);
+ stream.SeekI(-2, wxFromCurrent);
+ return (hdr[0] == 0xFF && hdr[1] == 0xD8);
+}
+
#endif
// wxUSE_STREAMS
return TRUE;
}
+bool wxPNGHandler::CanRead( wxInputStream& stream )
+{
+ unsigned char hdr[4];
+
+ stream.Read(&hdr, 4);
+ stream.SeekI(-4, wxFromCurrent);
+ return (hdr[0] == 0x89 && hdr[1] == 'P' && hdr[2] == 'N' && hdr[3] == 'G');
+}
+
#endif
// wxUSE_STREAMS
return (stream.LastError()==wxStream_NOERROR);
}
+bool wxPNMHandler::CanRead( wxInputStream& stream )
+{
+ return FALSE; // VS - temporary - FIXME
+}
+
+
#endif // wxUSE_STREAMS