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
This commit is contained in:
Vadim Zeitlin
2008-06-11 00:28:23 +00:00
parent 54c49fab9e
commit 591d3fa210
4 changed files with 53 additions and 9 deletions

View File

@@ -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<wxImage> compilation (Leonardo Fernandes).
- Added wxImage::GetType() (troelsk).
wxGTK:

View File

@@ -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)
};

View File

@@ -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.

View File

@@ -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,14 +2230,10 @@ 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.") );
return false;
@@ -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