}\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