]> git.lizzy.rs Git - irrlicht.git/commitdiff
Merging r6120 through r6121 from trunk to ogl-es branch
authorcutealien <cutealien@dfc29bdd-3216-0410-991c-e03cc46cb475>
Sun, 14 Jun 2020 20:52:53 +0000 (20:52 +0000)
committercutealien <cutealien@dfc29bdd-3216-0410-991c-e03cc46cb475>
Sun, 14 Jun 2020 20:52:53 +0000 (20:52 +0000)
git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@6122 dfc29bdd-3216-0410-991c-e03cc46cb475

source/Irrlicht/CImage.cpp

index ffd23fcb53c9933e7dd13fcd037a8d3a8077238c..753262b772f569a4374185b8e6c0eee29e561da4 100644 (file)
@@ -216,13 +216,21 @@ void CImage::copyToScaling(void* target, u32 width, u32 height, ECOLOR_FORMAT fo
                }\r
        }\r
 \r
-       const f32 sourceXStep = (f32)Size.Width / (f32)width;\r
-       const f32 sourceYStep = (f32)Size.Height / (f32)height;\r
+       // NOTE: Scaling is coded to keep the border pixels intact.\r
+       // Alternatively we could for example work with first pixel being taken at half step-size.\r
+       // Then we have one more step here and it would be:\r
+       //     sourceXStep = (f32)(Size.Width-1) / (f32)(width);\r
+       //     And sx would start at 0.5f + sourceXStep / 2.f;\r
+       //     Similar for y.\r
+       // As scaling is done without any antialiasing it doesn't matter too much which outermost pixels we use and keeping\r
+       // border pixels intact is probably mostly better (with AA the other solution would be more correct).\r
+       const f32 sourceXStep = width > 1 ? (f32)(Size.Width-1) / (f32)(width-1) : 0.f;\r
+       const f32 sourceYStep = height > 1 ? (f32)(Size.Height-1) / (f32)(height-1) : 0.f;\r
        s32 yval=0, syval=0;\r
-       f32 sy = 0.5f;  // nearest pixel (used in float-int conversion below)\r
+       f32 sy = 0.5f;  // for rounding to nearest pixel\r
        for (u32 y=0; y<height; ++y)\r
        {\r
-               f32 sx = 0.5f;  // nearest pixel (used in float-int conversion below)\r
+               f32 sx = 0.5f;  // for rounding to nearest pixel\r
                for (u32 x=0; x<width; ++x)\r
                {\r
                        CColorConverter::convert_viaFormat(Data+ syval + ((s32)sx)*BytesPerPixel, Format, 1, ((u8*)target)+ yval + (x*bpp), format);\r