X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/deb2fec01e097102e2799d7d0797f66dbae4f0c4..275abf24e140159f2ac19b64b76737a6903b1319:/src/common/image.cpp?ds=sidebyside diff --git a/src/common/image.cpp b/src/common/image.cpp index a67a7445ac..ab36e52be6 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -189,6 +189,43 @@ wxImage wxImage::Scale( int width, int height ) const return image; } +wxImage wxImage::GetSubImage( const wxRect &rect ) const +{ + wxImage image; + + wxCHECK_MSG( Ok(), image, _T("invalid image") ); + + wxCHECK_MSG( (rect.GetLeft()>=0) && (rect.GetTop()>=0) && (rect.GetRight()<=GetWidth()) && (rect.GetBottom()<=GetHeight()) + , image, _T("invalid subimage size") ); + + int subwidth=rect.GetWidth(); + const int subheight=rect.GetHeight(); + + image.Create( subwidth, subheight ); + + char unsigned *subdata = image.GetData(), *data=GetData(); + + wxCHECK_MSG( subdata, image, _T("unable to create image") ); + + if (M_IMGDATA->m_hasMask) + image.SetMaskColour( M_IMGDATA->m_maskRed, M_IMGDATA->m_maskGreen, M_IMGDATA->m_maskBlue ); + + const int subleft=3*rect.GetLeft(); + const int width=3*GetWidth(); + subwidth*=3; + + data+=rect.GetTop()*width+subleft; + + for (long j = 0; j < subheight; ++j) + { + memcpy( subdata, data, subwidth); + subdata+=subwidth; + data+=width; + } + + return image; +} + void wxImage::SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b ) { wxCHECK_RET( Ok(), _T("invalid image") ); @@ -263,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 ) @@ -388,7 +438,6 @@ bool wxImage::SaveFile( const wxString& filename, const wxString& mimetype ) } #if wxUSE_STREAMS -//#include bool wxImage::LoadFile( wxInputStream& stream, long type ) { @@ -400,25 +449,17 @@ 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::IsAppropriate(wxString&) - // bool wxImageHandler::IsAppropriate(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(); - //cout << handler->GetExtension() << endl; - if (handler->LoadFile( this, stream, FALSE )) return TRUE; - stream.SeekI(pos); + { + handler=(wxImageHandler*)node->GetData(); + if (handler->CanRead( stream )) + return handler->LoadFile( this, stream ); + } + wxLogWarning( _T("No handler found for this image.") ); return FALSE; } @@ -600,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 //----------------------------------------------------------------------------- @@ -614,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();