X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c96ea65713a8dd58ae40b10718723b5c92a303e3..9cf99fc093f9c45b6b5d8d8b357699d826c9916a:/src/common/image.cpp diff --git a/src/common/image.cpp b/src/common/image.cpp index c19e9da9d7..51318de205 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -210,7 +210,14 @@ wxImage wxImage::Scale( int width, int height ) const wxCHECK_MSG( Ok(), image, wxT("invalid image") ); - wxCHECK_MSG( (width > 0) && (height > 0), image, wxT("invalid image size") ); + // can't scale to/from 0 size + wxCHECK_MSG( (width > 0) && (height > 0), image, + wxT("invalid new image size") ); + + long old_height = M_IMGDATA->m_height, + old_width = M_IMGDATA->m_width; + wxCHECK_MSG( (old_height > 0) && (old_width > 0), image, + wxT("invalid old image size") ); image.Create( width, height ); @@ -219,14 +226,39 @@ wxImage wxImage::Scale( int width, int height ) const wxCHECK_MSG( data, image, wxT("unable to create image") ); if (M_IMGDATA->m_hasMask) - image.SetMaskColour( M_IMGDATA->m_maskRed, M_IMGDATA->m_maskGreen, M_IMGDATA->m_maskBlue ); - - long old_height = M_IMGDATA->m_height; - long old_width = M_IMGDATA->m_width; + { + image.SetMaskColour( M_IMGDATA->m_maskRed, + M_IMGDATA->m_maskGreen, + M_IMGDATA->m_maskBlue ); + } char unsigned *source_data = M_IMGDATA->m_data; char unsigned *target_data = data; +#if 0 + // This is nonsense, RR. + + // We do (x, y) -> (x, y)*oldSize/newSize but the valid values of x and y + // are from 0 to size-1, hence all decrement the sizes + long old_old_width = old_width; + old_height--; + old_width--; + height--; + width--; + for ( long j = 0; j <= height; j++ ) + { + // don't crash for images with height == 1 + long y_offset = height ? (j * old_height / height)* old_old_width : 0; + + for ( long i = 0; i <= width; i++ ) + { + long x_offset = width ? (i * old_width) / width : 0; + + memcpy( target_data, source_data + 3*(y_offset + x_offset), 3 ); + target_data += 3; + } + } +#else for (long j = 0; j < height; j++) { long y_offset = (j * old_height / height) * old_width; @@ -239,6 +271,7 @@ wxImage wxImage::Scale( int width, int height ) const target_data += 3; } } +#endif return image; } @@ -414,31 +447,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; } @@ -1023,7 +1056,10 @@ wxImageHandler *wxImage::FindHandlerMime( const wxString& mimetype ) void wxImage::InitStandardHandlers() { - AddHandler( new wxBMPHandler ); + AddHandler(new wxBMPHandler); +#if wxUSE_XPM && !defined(__WXGTK__) && !defined(__WXMOTIF__) + AddHandler(new wxXPMHandler); +#endif } void wxImage::CleanUpHandlers() @@ -1140,7 +1176,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(); @@ -1174,7 +1211,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;