X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7b2471a060f4f79481a2de8e6341571ad1674ff1..45fcbf3b7a7c9cfd96e67278e4eaa12e8e015651:/src/common/image.cpp diff --git a/src/common/image.cpp b/src/common/image.cpp index 2ee0a4c1bb..ab36e52be6 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -300,7 +300,20 @@ void wxImage::SetData( char unsigned *data ) { wxCHECK_RET( Ok(), _T("invalid image") ); - memcpy(M_IMGDATA->m_data, data, M_IMGDATA->m_width * M_IMGDATA->m_height * 3); + wxImageRefData *newRefData = new wxImageRefData(); + + 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 ) @@ -436,23 +449,14 @@ bool wxImage::LoadFile( wxInputStream& stream, long type ) if (type==wxBITMAP_TYPE_ANY) { - // here we can try to guess the handler according the extension, - // but we lose the stream name !? - // Probably we should write methods such as - // bool wxImageHandler::CanRead(wxString&) - // bool wxImageHandler::CanRead(sxInputStream&&) - // for png : see example.c wxList &list=GetHandlers(); - off_t pos=stream.TellI(); - - wxLogNull prevent_log; for ( wxList::Node *node = list.GetFirst(); node; node = node->GetNext() ) { handler=(wxImageHandler*)node->GetData(); - if (handler->LoadFile( this, stream, FALSE )) return TRUE; + if (handler->CanRead( stream )) + return handler->LoadFile( this, stream ); - stream.SeekI(pos); } wxLogWarning( _T("No handler found for this image.") ); @@ -637,6 +641,33 @@ bool wxImageHandler::SaveFile( wxImage *WXUNUSED(image), wxOutputStream& WXUNUSE { return FALSE; } + +bool wxImageHandler::CanRead( wxInputStream& stream ) +{ + return FALSE; +} + +bool wxImageHandler::CanRead( const wxString& name ) +{ +#if wxUSE_STREAMS + if (wxFileExists(name)) + { + wxFileInputStream stream(name); + return CanRead(stream); + } + + else { + wxLogError( _T("Can't check image format of file '%s': file does not exist."), name.c_str() ); + + return FALSE; + } +#else // !wxUSE_STREAMS + return FALSE; +#endif // wxUSE_STREAMS +} + + + #endif // wxUSE_STREAMS //----------------------------------------------------------------------------- @@ -651,7 +682,11 @@ wxBitmap wxImage::ConvertToBitmap() const 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();