From 591d3fa2106eae93a22829c7b2665dec524b4c00 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 11 Jun 2008 00:28:23 +0000 Subject: [PATCH] remember the last type used for loading or saving the image and return it from GetType() (#9551) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54086 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/image.h | 13 +++++++++++++ interface/image.h | 6 ++++++ src/common/image.cpp | 42 +++++++++++++++++++++++++++++++++--------- 4 files changed, 53 insertions(+), 9 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 0f9625d963..dd87546c1c 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -364,6 +364,7 @@ All (GUI): - Fix appending items to sorted wxComboCtrl after creation (Jaakko Salli) - Don't blit area larger than necessary in wxBufferedDC::UnMask (Liang Jian) - Fixed wxPixelData compilation (Leonardo Fernandes). +- Added wxImage::GetType() (troelsk). wxGTK: diff --git a/include/wx/image.h b/include/wx/image.h index 07fe116d72..60aff69ce6 100644 --- a/include/wx/image.h +++ b/include/wx/image.h @@ -352,6 +352,9 @@ public: int GetWidth() const; int GetHeight() const; + // Gets the type of image found by LoadFile or specified with SaveFile + wxBitmapType GetType() const; + // these functions provide fastest access to wxImage data but should be // used carefully as no checks are done unsigned char *GetData() const; @@ -440,6 +443,16 @@ protected: private: friend class WXDLLIMPEXP_FWD_CORE wxImageHandler; +#if wxUSE_STREAMS + // read the image from the specified stream updating image type if + // successful + bool DoLoad(wxImageHandler& handler, wxInputStream& stream, int index); + + // write the image to the specified stream and also update the image type + // if successful + bool DoSave(wxImageHandler& handler, wxOutputStream& stream) const; +#endif // wxUSE_STREAMS + DECLARE_DYNAMIC_CLASS(wxImage) }; diff --git a/interface/image.h b/interface/image.h index fd1fbc2081..ef66408ff0 100644 --- a/interface/image.h +++ b/interface/image.h @@ -626,6 +626,12 @@ public: */ wxImage GetSubImage(const wxRect& rect) const; + /** + Gets the type of image found by LoadFile or specified with SaveFile + @since 2.9.0 + */ + wxBitmapType GetType() const; + /** Gets the width of the image in pixels. diff --git a/src/common/image.cpp b/src/common/image.cpp index b29070e431..b41fee58f6 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -64,6 +64,7 @@ public: int m_width; int m_height; + wxBitmapType m_type; unsigned char *m_data; bool m_hasMask; @@ -94,6 +95,7 @@ wxImageRefData::wxImageRefData() { m_width = 0; m_height = 0; + m_type = wxBITMAP_TYPE_INVALID; m_data = m_alpha = (unsigned char *) NULL; @@ -1459,6 +1461,13 @@ int wxImage::GetHeight() const return M_IMGDATA->m_height; } +wxBitmapType wxImage::GetType() const +{ + wxCHECK_MSG( IsOk(), wxBITMAP_TYPE_INVALID, wxT("invalid image") ); + + return M_IMGDATA->m_type; +} + long wxImage::XYToIndex(int x, int y) const { if ( Ok() && @@ -2196,6 +2205,15 @@ int wxImage::GetImageCount( wxInputStream &stream, wxBitmapType type ) } } +bool wxImage::DoLoad(wxImageHandler& handler, wxInputStream& stream, int index) +{ + if ( !handler.LoadFile(this, stream, true/*verbose*/, index) ) + return false; + + M_IMGDATA->m_type = handler.GetType(); + return true; +} + bool wxImage::LoadFile( wxInputStream& stream, wxBitmapType type, int index ) { UnRef(); @@ -2212,12 +2230,8 @@ bool wxImage::LoadFile( wxInputStream& stream, wxBitmapType type, int index ) node = node->GetNext() ) { handler = (wxImageHandler*)node->GetData(); - if ( handler->CanRead(stream) && - handler->LoadFile(this, stream, true/*verbose*/, index) ) - { + if ( handler->CanRead(stream) && DoLoad(*handler, stream, index) ) return true; - } - } wxLogWarning( _("No handler found for image type.") ); @@ -2239,7 +2253,7 @@ bool wxImage::LoadFile( wxInputStream& stream, wxBitmapType type, int index ) return false; } - return handler->LoadFile(this, stream, true/*verbose*/, index); + return DoLoad(*handler, stream, index); } bool wxImage::LoadFile( wxInputStream& stream, const wxString& mimetype, int index ) @@ -2262,7 +2276,17 @@ bool wxImage::LoadFile( wxInputStream& stream, const wxString& mimetype, int ind return false; } - return handler->LoadFile( this, stream, true/*verbose*/, index ); + return DoLoad(*handler, stream, index); +} + +bool wxImage::DoSave(wxImageHandler& handler, wxOutputStream& stream) const +{ + wxImage * const self = wx_const_cast(wxImage *, this); + if ( !handler.SaveFile(self, stream) ) + return false; + + M_IMGDATA->m_type = handler.GetType(); + return true; } bool wxImage::SaveFile( wxOutputStream& stream, wxBitmapType type ) const @@ -2276,7 +2300,7 @@ bool wxImage::SaveFile( wxOutputStream& stream, wxBitmapType type ) const return false; } - return handler->SaveFile( (wxImage*)this, stream ); + return DoSave(*handler, stream); } bool wxImage::SaveFile( wxOutputStream& stream, const wxString& mimetype ) const @@ -2289,7 +2313,7 @@ bool wxImage::SaveFile( wxOutputStream& stream, const wxString& mimetype ) const wxLogWarning( _("No image handler for type %s defined."), mimetype.GetData() ); } - return handler->SaveFile( (wxImage*)this, stream ); + return DoSave(*handler, stream); } #endif // wxUSE_STREAMS -- 2.45.2