wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; }
#if wxUSE_STREAMS
- virtual bool LoadFile( wxImage *image, wxInputStream& stream );
- virtual bool SaveFile( wxImage *image, wxOutputStream& stream );
+ virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
+ virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
#endif
inline void SetName(const wxString& name) { m_name = name; }
};
#if wxUSE_STREAMS
- virtual bool LoadFile( wxImage *image, wxInputStream& stream );
- virtual bool SaveFile( wxImage *image, wxOutputStream& stream );
+ virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
+ virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
#endif
};
#endif
};
#if wxUSE_STREAMS
- virtual bool LoadFile( wxImage *image, wxInputStream& stream );
- virtual bool SaveFile( wxImage *image, wxOutputStream& stream );
+ virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
+ virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
#endif
};
#endif
};
#if wxUSE_STREAMS
- virtual bool LoadFile( wxImage *image, wxInputStream& stream );
+ virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
#endif
};
};
#if wxUSE_STREAMS
- virtual bool LoadFile( wxImage *image, wxInputStream& stream );
- virtual bool SaveFile( wxImage *image, wxOutputStream& stream );
+ virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
+ virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
#endif
};
wxImage();
wxImage( int width, int height );
- wxImage( const wxString& name, long type = wxBITMAP_TYPE_PNG );
- wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_PNG );
+ wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY );
+ wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY );
wxImage( const wxString& name, const wxString& mimetype );
wxImage( wxInputStream& stream, const wxString& mimetype );
unsigned char GetGreen( int x, int y );
unsigned char GetBlue( int x, int y );
- virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_PNG );
+ virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY );
virtual bool LoadFile( const wxString& name, const wxString& mimetype );
#if wxUSE_STREAMS
- virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_PNG );
+ virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY );
virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype );
#endif
#define poffset (line * width * 3 + column * 3)
-bool wxBMPHandler::LoadFile( wxImage *image, wxInputStream& stream )
+bool wxBMPHandler::LoadFile( wxImage *image, wxInputStream& stream, bool WXUNUSED(verbose) )
{
int rshift = 0, gshift = 0, bshift = 0;
wxUint8 aByte;
}
#if wxUSE_STREAMS
+//#include <stream.h>
+
bool wxImage::LoadFile( wxInputStream& stream, long type )
{
UnRef();
m_refData = new wxImageRefData;
- wxImageHandler *handler = FindHandler(type);
+ wxImageHandler *handler;
+
+ 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::IsAppropriate(wxString&)
+ // bool wxImageHandler::IsAppropriate(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();
+ //cout << handler->GetExtension() << endl;
+ if (handler->LoadFile( this, stream, FALSE )) return TRUE;
+ stream.SeekI(pos);
+ }
+
+ return FALSE;
+ }
+
+ handler = FindHandler(type);
if (handler == NULL)
{
void wxImage::InitStandardHandlers()
{
- AddHandler( new wxBMPHandler );
+ AddHandler( new wxBMPHandler );
}
void wxImage::CleanUpHandlers()
#endif
#if wxUSE_STREAMS
-bool wxImageHandler::LoadFile( wxImage *WXUNUSED(image), wxInputStream& WXUNUSED(stream) )
+bool wxImageHandler::LoadFile( wxImage *WXUNUSED(image), wxInputStream& WXUNUSED(stream), bool WXUNUSED(verbose) )
{
return FALSE;
}
-bool wxImageHandler::SaveFile( wxImage *WXUNUSED(image), wxOutputStream& WXUNUSED(stream) )
+bool wxImageHandler::SaveFile( wxImage *WXUNUSED(image), wxOutputStream& WXUNUSED(stream), bool WXUNUSED(verbose) )
{
return FALSE;
}
// wxGIFHandler
//-----------------------------------------------------------------------------
-bool wxGIFHandler::LoadFile( wxImage *image, wxInputStream& stream )
+bool wxGIFHandler::LoadFile( wxImage *image, wxInputStream& stream, bool WXUNUSED(verbose) )
{
unsigned char *ptr, *src, *pal;
IMAGEN igif;
}
bool wxGIFHandler::SaveFile( wxImage * WXUNUSED(image),
- wxOutputStream& WXUNUSED(stream) )
+ wxOutputStream& WXUNUSED(stream), bool verbose )
{
- wxLogDebug(_T("wxGIFHandler is read-only!!"));
+ if (verbose) wxLogDebug(_T("wxGIFHandler is read-only!!"));
return FALSE;
}
/* Always display the message. */
/* We could postpone this until after returning, if we chose. */
- (*cinfo->err->output_message) (cinfo);
+ if (cinfo->err->output_message) (*cinfo->err->output_message) (cinfo);
/* Return control to the setjmp point */
longjmp(myerr->setjmp_buffer, 1);
-bool wxJPEGHandler::LoadFile( wxImage *image, wxInputStream& stream )
+bool wxJPEGHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose )
{
struct jpeg_decompress_struct cinfo;
struct my_error_mgr jerr;
cinfo.err = jpeg_std_error( &jerr.pub );
jerr.pub.error_exit = my_error_exit;
+ if (!verbose) cinfo.err->output_message=NULL;
+
/* Establish the setjmp return context for my_error_exit to use. */
if (setjmp(jerr.setjmp_buffer)) {
/* If we get here, the JPEG code has signaled an error.
* We need to clean up the JPEG object, close the input file, and return.
*/
- wxLogError(_("Couldn't load a JPEG image - probably file is corrupted."));
+ if (verbose) wxLogError(_("Couldn't load a JPEG image - probably file is corrupted."));
jpeg_destroy_decompress(&cinfo);
if (image->Ok()) image->Destroy();
return FALSE;
dest->stream = &outfile;
}
-bool wxJPEGHandler::SaveFile( wxImage *image, wxOutputStream& stream )
+bool wxJPEGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbose )
{
struct jpeg_compress_struct cinfo;
struct my_error_mgr jerr;
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
+ if (!verbose) cinfo.err->output_message=NULL;
+
/* Establish the setjmp return context for my_error_exit to use. */
if (setjmp(jerr.setjmp_buffer)) {
/* If we get here, the JPEG code has signaled an error.
* We need to clean up the JPEG object, close the input file, and return.
*/
- wxLogError(_("Couldn't save a JPEG image - probably file is corrupted."));
+ if (verbose) wxLogError(_("Couldn't save a JPEG image - probably file is corrupted."));
jpeg_destroy_compress(&cinfo);
return FALSE;
}
((wxOutputStream*) png_get_io_ptr( png_ptr )) -> Write(data, length);
}
-bool wxPNGHandler::LoadFile( wxImage *image, wxInputStream& stream )
+// from pngerror.c
+// so that the libpng doesn't send anything on stderr
+void
+png_silent_error(png_structp png_ptr, png_const_charp WXUNUSED(message))
+{
+#ifdef USE_FAR_KEYWORD
+ {
+ jmp_buf jmpbuf;
+ png_memcpy(jmpbuf,png_ptr->jmpbuf,sizeof(jmp_buf));
+ longjmp(jmpbuf, 1);
+ }
+#else
+ longjmp(png_ptr->jmpbuf, 1);
+#endif
+}
+
+void
+png_silent_warning(png_structp WXUNUSED(png_ptr), png_const_charp WXUNUSED(message))
+{
+}
+
+bool wxPNGHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbose)
{
// VZ: as this function uses setjmp() the only fool proof error handling
// method is to use goto (setjmp is not really C++ dtors friendly...)
if (!png_ptr)
goto error_nolines;
+ // the file example.c explain how to guess if the stream is a png image
+ if (!verbose) png_set_error_fn(png_ptr, (png_voidp)NULL, png_silent_error, png_silent_warning);
+
info_ptr = png_create_info_struct( png_ptr );
if (!info_ptr)
goto error_nolines;
}
-bool wxPNGHandler::SaveFile( wxImage *image, wxOutputStream& stream )
+bool wxPNGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbose )
{
{
png_structp png_ptr = png_create_write_struct( PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
return FALSE;
}
+ if (!verbose) png_set_error_fn(png_ptr, (png_voidp)NULL, png_silent_error, png_silent_warning);
+
png_infop info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
{