#endif
//-----------------------------------------------------------------------------
-// wxImage
+// global data
+//-----------------------------------------------------------------------------
+
+wxList wxImage::sm_handlers;
+wxImage wxNullImage;
+
+//-----------------------------------------------------------------------------
+// wxImageRefData
//-----------------------------------------------------------------------------
class wxImageRefData: public wxObjectRefData
wxArrayString m_optionNames;
wxArrayString m_optionValues;
- DECLARE_NO_COPY_CLASS(wxImageRefData)
+ wxDECLARE_NO_COPY_CLASS(wxImageRefData);
};
wxImageRefData::wxImageRefData()
free( m_alpha );
}
-wxList wxImage::sm_handlers;
-
-wxImage wxNullImage;
+//-----------------------------------------------------------------------------
+// wxImage
//-----------------------------------------------------------------------------
#define M_IMGDATA static_cast<wxImageRefData*>(m_refData)
IMPLEMENT_DYNAMIC_CLASS(wxImage, wxObject)
-wxImage::wxImage( int width, int height, bool clear )
-{
- Create( width, height, clear );
-}
-
-wxImage::wxImage( int width, int height, unsigned char* data, bool static_data )
-{
- Create( width, height, data, static_data );
-}
-
-wxImage::wxImage( int width, int height, unsigned char* data, unsigned char* alpha, bool static_data )
-{
- Create( width, height, data, alpha, static_data );
-}
-
-wxImage::wxImage( const wxString& name, wxBitmapType type, int index )
-{
- LoadFile( name, type, index );
-}
-
-wxImage::wxImage( const wxString& name, const wxString& mimetype, int index )
-{
- LoadFile( name, mimetype, index );
-}
-
-#if wxUSE_STREAMS
-wxImage::wxImage( wxInputStream& stream, wxBitmapType type, int index )
-{
- LoadFile( stream, type, index );
-}
-
-wxImage::wxImage( wxInputStream& stream, const wxString& mimetype, int index )
-{
- LoadFile( stream, mimetype, index );
-}
-#endif // wxUSE_STREAMS
-
-wxImage::wxImage(const char* const* xpmData)
-{
- Create(xpmData);
-}
-
bool wxImage::Create(const char* const* xpmData)
{
#if wxUSE_XPM
return false;
}
- if (clear)
- memset(M_IMGDATA->m_data, 0, width*height*3);
-
M_IMGDATA->m_width = width;
M_IMGDATA->m_height = height;
M_IMGDATA->m_ok = true;
+ if (clear)
+ {
+ Clear();
+ }
+
return true;
}
UnRef();
}
+void wxImage::Clear(unsigned char value)
+{
+ memset(M_IMGDATA->m_data, value, M_IMGDATA->m_width*M_IMGDATA->m_height*3);
+}
+
wxObjectRefData* wxImage::CreateRefData() const
{
return new wxImageRefData;
bool wxImage::ConvertAlphaToMask(unsigned char threshold)
{
- if (!HasAlpha())
+ if ( !HasAlpha() )
return true;
unsigned char mr, mg, mb;
- if (!FindFirstUnusedColour(&mr, &mg, &mb))
+ if ( !FindFirstUnusedColour(&mr, &mg, &mb) )
{
wxLogError( _("No unused colour in image being masked.") );
return false;
}
+ ConvertAlphaToMask(mr, mg, mb, threshold);
+ return true;
+}
+
+void wxImage::ConvertAlphaToMask(unsigned char mr,
+ unsigned char mg,
+ unsigned char mb,
+ unsigned char threshold)
+{
+ if ( !HasAlpha() )
+ return;
+
AllocExclusive();
SetMask(true);
}
}
- if( !M_IMGDATA->m_staticAlpha )
+ if ( !M_IMGDATA->m_staticAlpha )
free(M_IMGDATA->m_alpha);
M_IMGDATA->m_alpha = NULL;
M_IMGDATA->m_staticAlpha = false;
-
- return true;
}
// ----------------------------------------------------------------------------
while (node)
{
wxImageHandler *handler = (wxImageHandler*)node->GetData();
- if ( (handler->GetExtension().Cmp(extension) == 0) &&
- ( (bitmapType == wxBITMAP_TYPE_ANY) || (handler->GetType() == bitmapType)) )
+ if ((bitmapType == wxBITMAP_TYPE_ANY) || (handler->GetType() == bitmapType))
{
- return handler;
+ if (handler->GetExtension() == extension)
+ return handler;
+ if (handler->GetAltExtensions().Index(extension, false) != wxNOT_FOUND)
+ return handler;
}
node = node->GetNext();
}
{
wxImageHandler* Handler = (wxImageHandler*)Node->GetData();
fmts += wxT("*.") + Handler->GetExtension();
+ for (size_t i = 0; i < Handler->GetAltExtensions().size(); i++)
+ fmts += wxT(";*.") + Handler->GetAltExtensions()[i];
Node = Node->GetNext();
if ( Node ) fmts += wxT(";");
}
IMPLEMENT_ABSTRACT_CLASS(wxImageHandler,wxObject)
#if wxUSE_STREAMS
-bool wxImageHandler::LoadFile( wxImage *WXUNUSED(image), wxInputStream& WXUNUSED(stream), bool WXUNUSED(verbose), int WXUNUSED(index) )
+int wxImageHandler::GetImageCount( wxInputStream& stream )
{
- return false;
-}
+ // NOTE: this code is the same of wxAnimationDecoder::CanRead and
+ // wxImageHandler::CallDoCanRead
-bool wxImageHandler::SaveFile( wxImage *WXUNUSED(image), wxOutputStream& WXUNUSED(stream), bool WXUNUSED(verbose) )
-{
- return false;
-}
+ if ( !stream.IsSeekable() )
+ return false; // can't test unseekable stream
-int wxImageHandler::GetImageCount( wxInputStream& WXUNUSED(stream) )
-{
- return 1;
+ wxFileOffset posOld = stream.TellI();
+ int n = DoGetImageCount(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 n;
}
bool wxImageHandler::CanRead( const wxString& name )
bool wxImageHandler::CallDoCanRead(wxInputStream& stream)
{
- wxFileOffset posOld = stream.TellI();
- if ( posOld == wxInvalidOffset )
- {
- // can't test unseekable stream
- return false;
- }
+ // NOTE: this code is the same of wxAnimationDecoder::CanRead and
+ // wxImageHandler::GetImageCount
+
+ if ( !stream.IsSeekable() )
+ return false; // can't test unseekable stream
+ wxFileOffset posOld = stream.TellI();
bool ok = DoCanRead(stream);
// restore the old position to be able to test other formats and so on