From 9c5c2c803c54f2f2ebef4f9cb946117bc414a5fa Mon Sep 17 00:00:00 2001 From: neonloop Date: Sat, 16 Dec 2023 16:43:16 +0000 Subject: Blends pixels that would be missed during downscale Avoids entirely missing lines and pixels, improves downscale smoothness --- scale.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/scale.c b/scale.c index 842e4ae..5857589 100644 --- a/scale.c +++ b/scale.c @@ -186,7 +186,19 @@ static void scale_blend(unsigned w, unsigned h, size_t pitch, const void *src, v if (!lines) pnext -= (pitch / sizeof(uint16_t)); - if (dy > rat_dst_h - bh[0]) { + if (dy <= bh[0] && dy + rat_h > (rat_dst_h + rat_dst_h - bh[0])) { + /* Will miss next line, blend in instead */ + const uint32_t *src32 = (const uint32_t *)src; + const uint32_t *pnext32 = (const uint32_t *)pnext; + uint32_t *pblend32 = (uint32_t *)pblend; + int count = w / 2; + + while(count--) { + *pblend32++ = AVERAGE32(*src32, *pnext32); + src32++; + pnext32++; + } + } else if (dy > rat_dst_h - bh[0]) { pblend = pnext; } else if (dy <= bh[0]) { /* Drops const, won't get touched later though */ @@ -227,15 +239,17 @@ static void scale_blend(unsigned w, unsigned h, size_t pitch, const void *src, v while (dx < rat_dst_w) { if (a == b) { out = a; + } else if (dx <= bw[0] && dx + rat_w > (rat_dst_w + rat_dst_w - bw[0])) { + out = AVERAGE16_NOCHK(a, b); // will miss next pixel, blend in instead } else if (dx > rat_dst_w - bw[0]) { // top quintile, bbbb out = b; } else if (dx <= bw[0]) { // last quintile, aaaa out = a; } else { if (dx > rat_dst_w - bw[1]) { // 2nd quintile, abbb - a = AVERAGE16_NOCHK(a,b); + a = AVERAGE16_NOCHK(a, b); } else if (dx <= bw[1]) { // 4th quintile, aaab - b = AVERAGE16_NOCHK(a,b); + b = AVERAGE16_NOCHK(a, b); } out = AVERAGE16_NOCHK(a, b); // also 3rd quintile, aabb -- cgit v1.2.3