- newRefData->m_width = M_IMGDATA->m_width;
- newRefData->m_height = M_IMGDATA->m_height;
- newRefData->m_data = data;
- newRefData->m_ok = TRUE;
- newRefData->m_maskRed = M_IMGDATA->m_maskRed;
- newRefData->m_maskGreen = M_IMGDATA->m_maskGreen;
- newRefData->m_maskBlue = M_IMGDATA->m_maskBlue;
- newRefData->m_hasMask = M_IMGDATA->m_hasMask;
-
- UnRef();
-
- m_refData = newRefData;
-}
-
-void wxImage::SetMaskColour( unsigned char r, unsigned char g, unsigned char b )
-{
- wxCHECK_RET( Ok(), wxT("invalid image") );
-
- M_IMGDATA->m_maskRed = r;
- M_IMGDATA->m_maskGreen = g;
- M_IMGDATA->m_maskBlue = b;
- M_IMGDATA->m_hasMask = TRUE;
-}
-
-unsigned char wxImage::GetMaskRed() const
-{
- wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
-
- return M_IMGDATA->m_maskRed;
-}
-
-unsigned char wxImage::GetMaskGreen() const
-{
- wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
-
- return M_IMGDATA->m_maskGreen;
-}
-
-unsigned char wxImage::GetMaskBlue() const
-{
- wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
-
- return M_IMGDATA->m_maskBlue;
-}
-
-void wxImage::SetMask( bool mask )
-{
- wxCHECK_RET( Ok(), wxT("invalid image") );
-
- M_IMGDATA->m_hasMask = mask;
-}
-
-bool wxImage::HasMask() const
-{
- wxCHECK_MSG( Ok(), FALSE, wxT("invalid image") );
-
- return M_IMGDATA->m_hasMask;
-}
-
-int wxImage::GetWidth() const
-{
- wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
-
- return M_IMGDATA->m_width;
-}
-
-int wxImage::GetHeight() const
-{
- wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
-
- return M_IMGDATA->m_height;
-}
-
-bool wxImage::LoadFile( const wxString& filename, long type )
-{
-#if wxUSE_STREAMS
- if (wxFileExists(filename))
- {
- wxFileInputStream stream(filename);
- wxBufferedInputStream bstream( stream );
- return LoadFile(bstream, type);
- }
- else
- {
- wxLogError( _("Can't load image from file '%s': file does not exist."), filename.c_str() );
-
- return FALSE;
- }
-#else // !wxUSE_STREAMS
- return FALSE;
-#endif // wxUSE_STREAMS
-}
-
-bool wxImage::LoadFile( const wxString& filename, const wxString& mimetype )
-{
-#if wxUSE_STREAMS
- if (wxFileExists(filename))
- {
- wxFileInputStream stream(filename);
- wxBufferedInputStream bstream( stream );
- return LoadFile(bstream, mimetype);
- }
- else
- {
- wxLogError( _("Can't load image from file '%s': file does not exist."), filename.c_str() );
-
- return FALSE;
- }
-#else // !wxUSE_STREAMS
- return FALSE;
-#endif // wxUSE_STREAMS
-}
-
-bool wxImage::SaveFile( const wxString& filename, int type )
-{
-#if wxUSE_STREAMS
- wxFileOutputStream stream(filename);
-
- if ( stream.LastError() == wxStream_NOERROR )
- {
- wxBufferedOutputStream bstream( stream );
- return SaveFile(bstream, type);
- }
- else
-#endif // wxUSE_STREAMS
- return FALSE;
-}
-
-bool wxImage::SaveFile( const wxString& filename, const wxString& mimetype )
-{
-#if wxUSE_STREAMS
- wxFileOutputStream stream(filename);
-
- if ( stream.LastError() == wxStream_NOERROR )
- {
- wxBufferedOutputStream bstream( stream );
- return SaveFile(bstream, mimetype);
- }
- else
-#endif // wxUSE_STREAMS
- return FALSE;
-}
-
-bool wxImage::CanRead( const wxString &name )
-{
-#if wxUSE_STREAMS
- wxFileInputStream stream(name);
- return CanRead(stream);
-#else
- return FALSE;
-#endif
-}
-
-#if wxUSE_STREAMS
-
-bool wxImage::CanRead( wxInputStream &stream )
-{
- wxList &list=GetHandlers();
-
- for ( wxList::Node *node = list.GetFirst(); node; node = node->GetNext() )
- {
- wxImageHandler *handler=(wxImageHandler*)node->GetData();
- if (handler->CanRead( stream ))
- return TRUE;
- }
-
- return FALSE;
-}
-
-bool wxImage::LoadFile( wxInputStream& stream, long type )
-{
- UnRef();
-
- m_refData = new wxImageRefData;
-
- wxImageHandler *handler;
-
- if (type==wxBITMAP_TYPE_ANY)
- {
- wxList &list=GetHandlers();
-
- for ( wxList::Node *node = list.GetFirst(); node; node = node->GetNext() )
- {
- handler=(wxImageHandler*)node->GetData();
- if (handler->CanRead( stream ))
- return handler->LoadFile( this, stream );
-
- }
-
- wxLogWarning( _("No handler found for image type.") );
- return FALSE;
- }
-
- handler = FindHandler(type);
-
- if (handler == NULL)
- {
- wxLogWarning( _("No image handler for type %d defined."), type );
-
- return FALSE;
- }
-
- return handler->LoadFile( this, stream );
-}
-
-bool wxImage::LoadFile( wxInputStream& stream, const wxString& mimetype )
-{
- UnRef();
-
- m_refData = new wxImageRefData;
-
- wxImageHandler *handler = FindHandlerMime(mimetype);
-
- if (handler == NULL)
- {
- wxLogWarning( _("No image handler for type %s defined."), mimetype.GetData() );
-
- return FALSE;
- }
-
- return handler->LoadFile( this, stream );
-}
-
-bool wxImage::SaveFile( wxOutputStream& stream, int type )
-{
- wxCHECK_MSG( Ok(), FALSE, wxT("invalid image") );
-
- wxImageHandler *handler = FindHandler(type);
-
- if (handler == NULL)
- {
- wxLogWarning( _("No image handler for type %d defined."), type );
-
- return FALSE;
- }
-
- return handler->SaveFile( this, stream );
-}
-
-bool wxImage::SaveFile( wxOutputStream& stream, const wxString& mimetype )
-{
- wxCHECK_MSG( Ok(), FALSE, wxT("invalid image") );
-
- wxImageHandler *handler = FindHandlerMime(mimetype);
-
- if (handler == NULL)
- {
- wxLogWarning( _("No image handler for type %s defined."), mimetype.GetData() );
-
- return FALSE;
- }
-
- return handler->SaveFile( this, stream );
-}
-#endif // wxUSE_STREAMS
-
-void wxImage::AddHandler( wxImageHandler *handler )
-{
- // make sure that the memory will be freed at the program end
- sm_handlers.DeleteContents(TRUE);
-
- sm_handlers.Append( handler );
-}
-
-void wxImage::InsertHandler( wxImageHandler *handler )
-{
- // make sure that the memory will be freed at the program end
- sm_handlers.DeleteContents(TRUE);
-
- sm_handlers.Insert( handler );
-}
-
-bool wxImage::RemoveHandler( const wxString& name )
-{
- wxImageHandler *handler = FindHandler(name);
- if (handler)
- {
- sm_handlers.DeleteObject(handler);
- return TRUE;
- }
- else
- return FALSE;
-}
-
-wxImageHandler *wxImage::FindHandler( const wxString& name )
-{
- wxNode *node = sm_handlers.First();
- while (node)
- {
- wxImageHandler *handler = (wxImageHandler*)node->Data();
- if (handler->GetName().Cmp(name) == 0) return handler;
-
- node = node->Next();
- }
- return (wxImageHandler *)NULL;
-}
-
-wxImageHandler *wxImage::FindHandler( const wxString& extension, long bitmapType )
-{
- wxNode *node = sm_handlers.First();
- while (node)
- {
- wxImageHandler *handler = (wxImageHandler*)node->Data();
- if ( (handler->GetExtension().Cmp(extension) == 0) &&
- (bitmapType == -1 || handler->GetType() == bitmapType) )
- return handler;
- node = node->Next();
- }
- return (wxImageHandler*)NULL;
-}
-
-wxImageHandler *wxImage::FindHandler( long bitmapType )
-{
- wxNode *node = sm_handlers.First();
- while (node)
- {
- wxImageHandler *handler = (wxImageHandler *)node->Data();
- if (handler->GetType() == bitmapType) return handler;
- node = node->Next();
- }
- return NULL;
-}
-
-wxImageHandler *wxImage::FindHandlerMime( const wxString& mimetype )
-{
- wxNode *node = sm_handlers.First();
- while (node)
- {
- wxImageHandler *handler = (wxImageHandler *)node->Data();
- if (handler->GetMimeType().IsSameAs(mimetype, FALSE)) return handler;
- node = node->Next();
- }
- return NULL;
-}
-
-void wxImage::InitStandardHandlers()
-{
- AddHandler( new wxBMPHandler );
-}
-
-void wxImage::CleanUpHandlers()
-{
- wxNode *node = sm_handlers.First();
- while (node)
- {
- wxImageHandler *handler = (wxImageHandler *)node->Data();
- wxNode *next = node->Next();
- delete handler;
- delete node;
- node = next;
- }
-}
-
-//-----------------------------------------------------------------------------
-// wxImageHandler
-//-----------------------------------------------------------------------------
-
-IMPLEMENT_ABSTRACT_CLASS(wxImageHandler,wxObject)
-
-#if wxUSE_STREAMS
-bool wxImageHandler::LoadFile( wxImage *WXUNUSED(image), wxInputStream& WXUNUSED(stream), bool WXUNUSED(verbose), int WXUNUSED(index) )
-{
- return FALSE;
-}
-
-bool wxImageHandler::SaveFile( wxImage *WXUNUSED(image), wxOutputStream& WXUNUSED(stream), bool WXUNUSED(verbose) )
-{
- return FALSE;
-}
-
-int wxImageHandler::GetImageCount( wxInputStream& WXUNUSED(stream) )
-{
- return 1;
-}
-
-bool wxImageHandler::CanRead( const wxString& name )
-{
- if (wxFileExists(name))
- {
- wxFileInputStream stream(name);
- return CanRead(stream);
- }
-
- else {
- wxLogError( _("Can't check image format of file '%s': file does not exist."), name.c_str() );
-
- return FALSE;
- }
-// return FALSE;
-}
-
-#endif // wxUSE_STREAMS
-
-//-----------------------------------------------------------------------------
-// MSW conversion routines
-//-----------------------------------------------------------------------------
-
-#ifdef __WXMSW__
-
-wxBitmap wxImage::ConvertToBitmap() const
-{
- if ( !Ok() )
- return wxNullBitmap;
-
- // sizeLimit is the MS upper limit for the DIB size
-#ifdef WIN32
- int sizeLimit = 1024*768*3;
-#else
- int sizeLimit = 0x7fff ;
-#endif
-
- // width and height of the device-dependent bitmap
- int width = GetWidth();
- int bmpHeight = GetHeight();
-
- // calc the number of bytes per scanline and padding
- int bytePerLine = width*3;
- int sizeDWORD = sizeof( DWORD );
- int lineBoundary = bytePerLine % sizeDWORD;
- int padding = 0;
- if( lineBoundary > 0 )
- {
- padding = sizeDWORD - lineBoundary;
- bytePerLine += padding;
- }
- // calc the number of DIBs and heights of DIBs
- int numDIB = 1;
- int hRemain = 0;
- int height = sizeLimit/bytePerLine;
- if( height >= bmpHeight )
- height = bmpHeight;
- else