+wxImage wxImage::Scale( int width, int height )
+{
+ wxImage image;
+
+ wxCHECK_MSG( Ok(), image, "invlaid image" );
+
+ wxCHECK_MSG( (width > 0) && (height > 0), image, "invalid image size" );
+
+ image.Create( width, height );
+
+ char unsigned *data = image.GetData();
+
+ wxCHECK_MSG( data, image, "unable to create image" );
+
+ if (M_IMGDATA->m_hasMask)
+ image.SetMaskColour( M_IMGDATA->m_maskRed, M_IMGDATA->m_maskGreen, M_IMGDATA->m_maskBlue );
+
+ double xscale = (double)width / (double)M_IMGDATA->m_width;
+ double yscale = (double)height / (double)M_IMGDATA->m_height;
+
+ for (int j = 0; j < height; j++)
+ {
+ for (int i = 0; i < width; i++)
+ {
+ int new_pos = 3*(j*width + i);
+ int old_pos = 3*((long)(j/yscale)*M_IMGDATA->m_width + (long)(i/xscale));
+ data[ new_pos ] = M_IMGDATA->m_data[ old_pos ];
+ data[ new_pos+1 ] = M_IMGDATA->m_data[ old_pos+1 ];
+ data[ new_pos+2 ] = M_IMGDATA->m_data[ old_pos+2 ];
+ }
+ }
+
+ return image;
+}
+