#endif // wxUSE_STREAMS
wxImage::wxImage( const wxImage& image )
+ : wxObject()
{
Ref(image);
}
wxCHECK_MSG( data, image, wxT("unable to create image") );
- if (M_IMGDATA->m_hasMask)
- image.SetMaskColour( M_IMGDATA->m_maskRed, M_IMGDATA->m_maskGreen, M_IMGDATA->m_maskBlue );
+ image.SetMaskColour( M_IMGDATA->m_maskRed, M_IMGDATA->m_maskGreen, M_IMGDATA->m_maskBlue );
+ image.SetMask( M_IMGDATA->m_hasMask );
memcpy( data, GetData(), M_IMGDATA->m_width*M_IMGDATA->m_height*3 );
}
#endif
+ // In case this is a cursor, make sure the hotspot is scalled accordingly:
+ if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_X) )
+ image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X,
+ (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X)*width)/old_width);
+ if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y) )
+ image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y,
+ (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y)*height)/old_height);
+
return image;
}
bool wxImage::FindFirstUnusedColour(
unsigned char *r, unsigned char *g, unsigned char *b,
- unsigned char startR, unsigned char startG, unsigned char startB)
+ unsigned char startR, unsigned char startG, unsigned char startB) const
{
wxImageHistogram histogram;
unsigned long key;
#endif // wxUSE_STREAMS
}
-bool wxImage::SaveFile( const wxString& filename, int type )
+
+
+bool wxImage::SaveFile( const wxString& filename ) const
+{
+ wxString ext = filename.AfterLast('.').Lower();
+
+ wxImageHandler * pHandler = FindHandler(ext, -1);
+ if (pHandler)
+ {
+ SaveFile(filename, pHandler->GetType());
+ return TRUE;
+ }
+
+ wxLogError(_("Can't save image to file '%s': unknown extension."), filename.c_str());
+
+ return FALSE;
+}
+
+bool wxImage::SaveFile( const wxString& filename, int type ) const
{
#if wxUSE_STREAMS
+ ((wxImage*)this)->SetOption(wxIMAGE_OPTION_FILENAME, filename);
+
wxFileOutputStream stream(filename);
if ( stream.LastError() == wxStream_NOERROR )
return FALSE;
}
-bool wxImage::SaveFile( const wxString& filename, const wxString& mimetype )
+bool wxImage::SaveFile( const wxString& filename, const wxString& mimetype ) const
{
#if wxUSE_STREAMS
+ ((wxImage*)this)->SetOption(wxIMAGE_OPTION_FILENAME, filename);
+
wxFileOutputStream stream(filename);
if ( stream.LastError() == wxStream_NOERROR )
bool wxImage::CanRead( wxInputStream &stream )
{
- wxList &list=GetHandlers();
+ const wxList& list = GetHandlers();
for ( wxList::Node *node = list.GetFirst(); node; node = node->GetNext() )
{
return handler->LoadFile( this, stream, TRUE/*verbose*/, index );
}
-bool wxImage::SaveFile( wxOutputStream& stream, int type )
+bool wxImage::SaveFile( wxOutputStream& stream, int type ) const
{
wxCHECK_MSG( Ok(), FALSE, wxT("invalid image") );
return FALSE;
}
- return handler->SaveFile( this, stream );
+ return handler->SaveFile( (wxImage*)this, stream );
}
-bool wxImage::SaveFile( wxOutputStream& stream, const wxString& mimetype )
+bool wxImage::SaveFile( wxOutputStream& stream, const wxString& mimetype ) const
{
wxCHECK_MSG( Ok(), FALSE, wxT("invalid image") );
return FALSE;
}
- return handler->SaveFile( this, stream );
+ return handler->SaveFile( (wxImage*)this, stream );
}
#endif // wxUSE_STREAMS
return CanRead(stream);
}
- else {
- wxLogError( _("Can't check image format of file '%s': file does not exist."), name.c_str() );
+ wxLogError( _("Can't check image format of file '%s': file does not exist."), name.c_str() );
+ return FALSE;
+}
+
+bool wxImageHandler::CallDoCanRead(wxInputStream& stream)
+{
+ off_t posOld = stream.TellI();
+ if ( posOld == wxInvalidOffset )
+ {
+ // can't test unseekable stream
return FALSE;
}
-// return FALSE;
+
+ bool ok = DoCanRead(stream);
+
+ // restore the old position to be able to test other formats and so on
+ if ( stream.SeekI(posOld) == wxInvalidOffset )
+ {
+ wxLogDebug(_T("Failed to rewind the stream in wxImageHandler!"));
+
+ // reading would fail anyhow as we're not at the right position
+ return FALSE;
+ }
+
+ return ok;
}
#endif // wxUSE_STREAMS
//-----------------------------------------------------------------------------
-// wxBitmap convertion routines
+// Deprecated wxBitmap convertion routines
//-----------------------------------------------------------------------------
-#if wxUSE_GUI
+#if WXWIN_COMPATIBILITY_2_2 && wxUSE_GUI
#ifdef __WXGTK__
wxBitmap wxImage::ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue ) const
*this = bitmap.ConvertToImage();
}
-#endif
-
-
-
-// A module to allow wxImage initialization/cleanup
-// without calling these functions from app.cpp or from
-// the user's application.
-
-class wxImageModule: public wxModule
-{
-DECLARE_DYNAMIC_CLASS(wxImageModule)
-public:
- wxImageModule() {}
- bool OnInit() { wxImage::InitStandardHandlers(); return TRUE; };
- void OnExit() { wxImage::CleanUpHandlers(); };
-};
-
-IMPLEMENT_DYNAMIC_CLASS(wxImageModule, wxModule)
+#endif // WXWIN_COMPATIBILITY_2_2 && wxUSE_GUI
//-----------------------------------------------------------------------------
// less, in this case it would be invoked as CountColours(256)). Default
// value for stopafter is -1 (don't care).
//
-unsigned long wxImage::CountColours( unsigned long stopafter )
+unsigned long wxImage::CountColours( unsigned long stopafter ) const
{
wxHashTable h;
wxObject dummy;
}
-unsigned long wxImage::ComputeHistogram( wxImageHistogram &h )
+unsigned long wxImage::ComputeHistogram( wxImageHistogram &h ) const
{
unsigned char r, g, b;
unsigned char *p;
return rotated;
}
+
+
+
+
+// A module to allow wxImage initialization/cleanup
+// without calling these functions from app.cpp or from
+// the user's application.
+
+class wxImageModule: public wxModule
+{
+DECLARE_DYNAMIC_CLASS(wxImageModule)
+public:
+ wxImageModule() {}
+ bool OnInit() { wxImage::InitStandardHandlers(); return TRUE; };
+ void OnExit() { wxImage::CleanUpHandlers(); };
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxImageModule, wxModule)
+
+
#endif // wxUSE_IMAGE