Fix Image nearest and cubic resizing bias

This commit is contained in:
LuoZhihao 2025-07-30 23:53:59 +08:00
parent 2d113cc224
commit a32b59622f

View file

@ -801,13 +801,13 @@ static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_
for (uint32_t y = 0; y < p_dst_height; y++) {
// Y coordinates
oy = (double)y * yfac - 0.5f;
oy = (double)(y + 0.5) * yfac - 0.5;
oy1 = (int)oy;
dy = oy - (double)oy1;
for (uint32_t x = 0; x < p_dst_width; x++) {
// X coordinates
ox = (double)x * xfac - 0.5f;
ox = (double)(x + 0.5) * xfac - 0.5;
ox1 = (int)ox;
dx = ox - (double)ox1;
@ -815,10 +815,7 @@ static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_
T *__restrict dst = ((T *)p_dst) + (y * p_dst_width + x) * CC;
double color[CC];
for (int i = 0; i < CC; i++) {
color[i] = 0;
}
double color[CC] = {};
for (int n = -1; n < 3; n++) {
// get Y coefficient
@ -961,11 +958,11 @@ static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict
template <int CC, typename T>
static void _scale_nearest(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) {
for (uint32_t i = 0; i < p_dst_height; i++) {
uint32_t src_yofs = i * p_src_height / p_dst_height;
uint32_t src_yofs = (i + 0.5) * p_src_height / p_dst_height;
uint32_t y_ofs = src_yofs * p_src_width * CC;
for (uint32_t j = 0; j < p_dst_width; j++) {
uint32_t src_xofs = j * p_src_width / p_dst_width;
uint32_t src_xofs = (j + 0.5) * p_src_width / p_dst_width;
src_xofs *= CC;
for (uint32_t l = 0; l < CC; l++) {