]> git.saurik.com Git - wxWidgets.git/commitdiff
Changed wxImage.ResampleBox to always use a box size of at least 2 by 2 pixels.
authorDimitri Schoolwerth <dimitri.schoolwerth@gmail.com>
Tue, 15 Mar 2011 16:37:04 +0000 (16:37 +0000)
committerDimitri Schoolwerth <dimitri.schoolwerth@gmail.com>
Tue, 15 Mar 2011 16:37:04 +0000 (16:37 +0000)
Previously when resizing by more than 50% (for example resizing from 100x100 to 51x51 or 140x140) a box size of 1x1 would be used which effectively would give the same result as using nearest neighbour. Make sure that at least a box size of 2x2 pixels is always used.

Patch by scottb, see also #12845.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67202 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/image.cpp

index 6b431715c3a21721c267c74e418d47d30fff7325..a055858d4d21fcc0796aaed7e7195fbd9f9cb2d4 100644 (file)
@@ -589,16 +589,16 @@ wxImage wxImage::ResampleBox(int width, int height) const
             averaged_pixels = 0;
             sum_r = sum_g = sum_b = sum_a = 0.0;
 
-            for ( int j = int(src_y - scale_factor_y/2.0 + 1);
-                  j <= int(src_y + scale_factor_y_2);
+            for ( int j = int(src_y - scale_factor_y/2.0 + 1), k = j;
+                  j <= int(src_y + scale_factor_y_2) || j < k + 2;
                   j++ )
             {
                 // We don't care to average pixels that don't exist (edges)
                 if ( j < 0 || j > M_IMGDATA->m_height - 1 )
                     continue;
 
-                for ( int i = int(src_x - scale_factor_x/2.0 + 1);
-                      i <= src_x + scale_factor_x_2;
+                for ( int i = int(src_x - scale_factor_x/2.0 + 1), e = i;
+                      i <= src_x + scale_factor_x_2 || i < e + 2;
                       i++ )
                 {
                     // Don't average edge pixels