X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f515c25a2cbf63596b03397a9d81705d3c464408..d0af5538d676fdc5f7620233ee24f43832b80bff:/src/common/image.cpp diff --git a/src/common/image.cpp b/src/common/image.cpp index 8778bb4289..5045805f8b 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -18,12 +18,17 @@ #pragma hdrstop #endif +#include "wx/defs.h" + +#if wxUSE_IMAGE + #include "wx/image.h" #include "wx/bitmap.h" #include "wx/debug.h" #include "wx/log.h" #include "wx/app.h" #include "wx/filefn.h" +#include "wx/filesys.h" #include "wx/wfstream.h" #include "wx/intl.h" #include "wx/module.h" @@ -225,12 +230,12 @@ wxImage wxImage::Scale( int width, int height ) const for (long j = 0; j < height; j++) { - long y_offset = (j * old_height / height) * old_width; + long y_offset = (j * (old_height-1) / (height-1)) * old_width; for (long i = 0; i < width; i++) { memcpy( target_data, - source_data + 3*(y_offset + ((i * old_width )/ width)), + source_data + 3*(y_offset + ((i * (old_width-1) )/ (width-1))), 3 ); target_data += 3; } @@ -410,31 +415,31 @@ void wxImage::Paste( const wxImage &image, int x, int y ) } return; } - + if (!HasMask() && image.HasMask()) { unsigned char r = image.GetMaskRed(); unsigned char g = image.GetMaskGreen(); unsigned char b = image.GetMaskBlue(); - + width *= 3; unsigned char* source_data = image.GetData() + xx*3 + yy*3*image.GetWidth(); int source_step = image.GetWidth()*3; unsigned char* target_data = GetData() + (x+xx)*3 + (y+yy)*3*M_IMGDATA->m_width; int target_step = M_IMGDATA->m_width*3; - + for (int j = 0; j < height; j++) { for (int i = 0; i < width; i+=3) { - if ((source_data[i] != r) && - (source_data[i+1] != g) && + if ((source_data[i] != r) && + (source_data[i+1] != g) && (source_data[i+2] != b)) { memcpy( target_data+i, source_data+i, 3 ); } - } + } source_data += source_step; target_data += target_step; } @@ -758,18 +763,19 @@ bool wxImage::HasOption(const wxString& name) const 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() ); - + // We want to use wxFileSystem for virtual FS compatibility + wxFileSystem fsys; + wxFSFile *file = fsys.OpenFile(filename); + if (!file) { + wxLogError(_("Can't open file '%s'"), filename); return FALSE; - } + } + wxInputStream *stream = file->GetStream(); + if (!stream) { + wxLogError(_("Can't open stream for file '%s'"), filename); + return FALSE; + } + return LoadFile(*stream, type); #else // !wxUSE_STREAMS return FALSE; #endif // wxUSE_STREAMS @@ -778,18 +784,19 @@ bool wxImage::LoadFile( const wxString& filename, long type ) 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() ); - + // We want to use wxFileSystem for virtual FS compatibility + wxFileSystem fsys; + wxFSFile *file = fsys.OpenFile(filename); + if (!file) { + wxLogError(_("Can't open file '%s'"), filename); return FALSE; - } + } + wxInputStream *stream = file->GetStream(); + if (!stream) { + wxLogError(_("Can't open stream for file '%s'"), filename); + return FALSE; + } + return LoadFile(*stream, mimetype); #else // !wxUSE_STREAMS return FALSE; #endif // wxUSE_STREAMS @@ -1019,7 +1026,10 @@ wxImageHandler *wxImage::FindHandlerMime( const wxString& mimetype ) void wxImage::InitStandardHandlers() { - AddHandler( new wxBMPHandler ); + AddHandler(new wxBMPHandler); +#if !defined(__WXGTK__) && !defined(__WXMOTIF__) + AddHandler(new wxXPMHandler); +#endif } void wxImage::CleanUpHandlers() @@ -1136,7 +1146,8 @@ unsigned long wxImage::CountColours( unsigned long stopafter ) { wxHashTable h; wxObject dummy; - unsigned char r, g, b, *p; + unsigned char r, g, b; + unsigned char *p; unsigned long size, nentries, key; p = GetData(); @@ -1170,7 +1181,8 @@ unsigned long wxImage::CountColours( unsigned long stopafter ) // unsigned long wxImage::ComputeHistogram( wxHashTable &h ) { - unsigned char r, g, b, *p; + unsigned char r, g, b; + unsigned char *p; unsigned long size, nentries, key; wxHNode *hnode; @@ -1460,3 +1472,4 @@ wxImage wxImage::Rotate(double angle, const wxPoint & centre_of_rotation, bool i return rotated; } +#endif // wxUSE_IMAGE