From 7d067ca7981e0e0568474d9dec04ed0463e4ae79 Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Wed, 31 Dec 2025 19:21:56 +0200 Subject: [PATCH] imageviewer: jpegp: improve downscale quality Use simple area-averaging for smoother images. Change-Id: I7ac2db05262500041286404c97a615e4b3a43194 --- apps/plugins/imageviewer/jpegp/jpegp.c | 35 +++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/apps/plugins/imageviewer/jpegp/jpegp.c b/apps/plugins/imageviewer/jpegp/jpegp.c index d018f6cc16..eee5be8424 100644 --- a/apps/plugins/imageviewer/jpegp/jpegp.c +++ b/apps/plugins/imageviewer/jpegp/jpegp.c @@ -229,9 +229,38 @@ static int get_image(struct image_info *info, int frame, int ds) j->Components[2].du[j->Components[2].du_width * ((y / v2) / 8)] + 8 * ((y / v2) & 7); for (x = 0; x < max_x; x += ds) { - TCOEF c0 = C0[(x / h0 / 8) * 64 + ((x / h0) & 7)]; - TCOEF c1 = C1[(x / h1 / 8) * 64 + ((x / h1) & 7)]; - TCOEF c2 = C2[(x / h2 / 8) * 64 + ((x / h2) & 7)]; + int c0, c1, c2; + if (ds == 1) + { + c0 = C0[(x / h0 / 8) * 64 + ((x / h0) & 7)]; + c1 = C1[(x / h1 / 8) * 64 + ((x / h1) & 7)]; + c2 = C2[(x / h2 / 8) * 64 + ((x / h2) & 7)]; + } + else + { + /* Box filter downsampling (area averaging): + Average a ds*ds block of Y/U/V samples per output pixel + for simple anti-aliasing without extra buffers */ + int sumY = 0, sumU = 0, sumV = 0; + int dx, dy; + int area = ds * ds; + for (dy = 0; dy < ds; dy++) + { + TCOEF *C0_dy = j->Components[0].du[j->Components[0].du_width * (((y + dy) / v0) / 8)] + 8 * (((y + dy) / v0) & 7); + TCOEF *C1_dy = j->Components[1].du[j->Components[1].du_width * (((y + dy) / v1) / 8)] + 8 * (((y + dy) / v1) & 7); + TCOEF *C2_dy = j->Components[2].du[j->Components[2].du_width * (((y + dy) / v2) / 8)] + 8 * (((y + dy) / v2) & 7); + for (dx = 0; dx < ds; dx++) + { + int sx = x + dx; + sumY += C0_dy[((sx / h0 / 8) * 64) + ((sx / h0) & 7)]; + sumU += C1_dy[((sx / h1 / 8) * 64) + ((sx / h1) & 7)]; + sumV += C2_dy[((sx / h2 / 8) * 64) + ((sx / h2) & 7)]; + } + } + c0 = (sumY + area/2) / area; + c1 = (sumU + area/2) / area; + c2 = (sumV + area/2) / area; + } // ITU BT.601 full-range YUV-to-RGB integer approximation {