+ for (long y = 0; y < height; y++)
+ {
+ for (long x = 0; x < width; x++)
+ {
+ unsigned long avgRed = 0 ;
+ unsigned long avgGreen = 0;
+ unsigned long avgBlue = 0;
+ unsigned long counter = 0 ;
+ // determine average
+ for ( int y1 = 0 ; y1 < yFactor ; ++y1 )
+ {
+ long y_offset = (y * yFactor + y1) * old_width;
+ for ( int x1 = 0 ; x1 < xFactor ; ++x1 )
+ {
+ unsigned char *pixel = source_data + 3 * ( y_offset + x * xFactor + x1 ) ;
+ unsigned char red = pixel[0] ;
+ unsigned char green = pixel[1] ;
+ unsigned char blue = pixel[2] ;
+ if ( !hasMask || red != maskRed || green != maskGreen || blue != maskBlue )
+ {
+ avgRed += red ;
+ avgGreen += green ;
+ avgBlue += blue ;
+ counter++ ;
+ }
+ }
+ }
+ if ( counter == 0 )
+ {
+ *(target_data++) = M_IMGDATA->m_maskRed ;
+ *(target_data++) = M_IMGDATA->m_maskGreen ;
+ *(target_data++) = M_IMGDATA->m_maskBlue ;
+ }
+ else
+ {
+ *(target_data++) = (unsigned char)(avgRed / counter);
+ *(target_data++) = (unsigned char)(avgGreen / counter);
+ *(target_data++) = (unsigned char)(avgBlue / counter);
+ }
+ }
+ }
+
+ // In case this is a cursor, make sure the hotspot is scalled accordingly:
+ if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_X) )
+ image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X,
+ (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X))/xFactor);
+ if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y) )
+ image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y,
+ (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y))/yFactor);
+
+ return image;
+}
+
+wxImage wxImage::Scale( int width, int height ) const
+{
+ wxImage image;
+
+ wxCHECK_MSG( Ok(), image, wxT("invalid image") );
+
+ // 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") );
+
+ if ( old_width % width == 0 && old_width >= width &&
+ old_height % height == 0 && old_height >= height )