From patchwork Sun Jun 16 22:28:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramiro Polla X-Patchwork-Id: 49952 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:9196:0:b0:460:55fa:d5ed with SMTP id s22csp1596655vqg; Sun, 16 Jun 2024 15:29:05 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVui3BJuwBraPkI/Ak7ymglWVCnUTgHxqhWnalC5Dr5HWbKhTD1Vi/m6r4DOrBQPlnJ2Yn5uc/dxSZURtrOqXxkFYZFDbjfuQa7cg== X-Google-Smtp-Source: AGHT+IG4b/2ERRQ7gWBMCJ8z666zca9Mjp2ndS0vGfC/nSe/rw+SKoke9RU+Kq6J6tKQRNqJB0Ce X-Received: by 2002:a05:651c:1025:b0:2ec:23b7:b8ff with SMTP id 38308e7fff4ca-2ec23b7ba3bmr27032931fa.10.1718576945330; Sun, 16 Jun 2024 15:29:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718576945; cv=none; d=google.com; s=arc-20160816; b=uWUGIZTYpX0Vkw0Cktwzb8xrYX9JfWJeBfPnV8XRDOqhJdNeLCbbw8U7mtB/kyCmdD 2h7ovtm+zh2lZSH9/UiSFjrjUr8hXB+KoTBWC3OcsHqIkraMJXkJAvX8ExzV8rU/oYtp PBmgdO5YVl8n0UAEvmWcnR9ubo7lkMgAu1V2R8JUbClVk8Exy0LaGN56Yxu6G3/Ikmg7 pQs7yhsNuxku7jTS7VJ6l1kdvREwOwieTTQONRjVYFqSB2iRCY7VUk6YjTmBG4ixVcVt 4Xz/7NnBDve5IXrW/wTqvUlAuocHUxsOqV1bM+USqYhha1WDAdBbJwTgb5Px0L04v8Lv dycw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=m1qEfqRTv6xoUSNwtktlAX0qNBUHAouMeXbzNKThVRg=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=t4QJIvt/eBeDqLnWwsAJBXUhj7KBQC+ul6/Y5McBQnmzG4eCDAsZirBKzz9YXuZyTT Cwrgyi7Jf+YQH0AoDyCjFRxHFP/eZ4Fvxowytx/DY1+9TDrBvOA8/iKb5L7aPIJ9fAn2 RgcYlDadqOiRNv2hpJkpmTsdYRLCy8bRph0iD3FOMha96BorDBBhCcRDwox3MQQ2s56b +Z38SfAjjAYjrmIVGlGEmdLF13+o9w8e01EiMx8wVoOSTp88e6wvAy5vnmPib+HXf8os fjZO9oylA5Hb5UhSfd+JqPkO5xLcw0MK/PR+9UbjZ4Ioc2SWBfZY8vemoddcEdZX8pF3 EipA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=YQn53bfS; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 38308e7fff4ca-2ec05c4b7c8si22529741fa.218.2024.06.16.15.29.04; Sun, 16 Jun 2024 15:29:05 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=YQn53bfS; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6757F68D73B; Mon, 17 Jun 2024 01:29:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7BAA168D602 for ; Mon, 17 Jun 2024 01:28:53 +0300 (EEST) Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-3609565a1bdso317530f8f.1 for ; Sun, 16 Jun 2024 15:28:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718576932; x=1719181732; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=zK1wb13zw6tu73uqec2CTVqHy2OT9m6F6sHn40nz83Q=; b=YQn53bfSjYTMWjaIjlwPPzzkBkgR/hm8cCQ/TmDxIt5pCJ5UPlPnT2hK6EW4pbma8x al6xtyKRJLUeOsRMQ6xJl09U+bMMP5bLgu09qGTHL0Dnu+v+nBm7eA7dtnw7X+gHvW8b gRQURRmSanU4cXII0J7HhRpivhASEj2M0mHNo2xQwKpsXQo0qLklfXxg/5p3NJYl2hpU prrkH5aiwH6eLwR4Ui3TLH9mYSOZw9DKik6gQx7x+maeh5nM84zVU0z34F2SvOj8V/bb 9t5V8PgZWZ2/4ml4nGglyXhL/gk1bG/V+y9PNk5clRLCB9UM8uujO034ZAobd7fKf2EA OmnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718576932; x=1719181732; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zK1wb13zw6tu73uqec2CTVqHy2OT9m6F6sHn40nz83Q=; b=krY/XSi7d/3EE5KLWszDlyEwOykXru/Qm8+d0iM2RyEGBIu9D+yz/gD0nuBCSAKJ+0 ZN25Rg2Y1JoJ0wrPB8NeH/XONOoNnIbFziwSPD2qpP+H8i82ebOJ40ZYmSQf55fVTalw E8qLFup6l+S/OoAXO2g8zLXGWcpCcEMmsM/vtcQwJQG9B9hcR9BUwklvrTHoWxlqp6nF Td3ZCjoTH4uaxNkQiGsAohZimt6g5cf36OdbrzojCj6de8IcfKyRqu0bqGdZaydwRdF2 f/ngWPwNelNibNJkNITq1hzW3A2ir9vbI+hFR6zPCpUlYzXDYnHyXVJyedBjHutUnDGu NDEg== X-Gm-Message-State: AOJu0YwSSW+9i5ofgH2vwMx12+49zGk0d8sfG4h0zcH6S6kC4RwLiyBz Jn3JSZIkzzAHL20oZMF1CEG3OcgYr9JQ/3UrRCAFnavC1DYlTZeBsaZFfA== X-Received: by 2002:adf:fd03:0:b0:35f:2760:aaa0 with SMTP id ffacd0b85a97d-3607a786b07mr6981492f8f.65.1718576931445; Sun, 16 Jun 2024 15:28:51 -0700 (PDT) Received: from localhost.localdomain (247.111-201-80.adsl-dyn.isp.belgacom.be. [80.201.111.247]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-360750ad082sm10349146f8f.59.2024.06.16.15.28.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 15:28:51 -0700 (PDT) From: Ramiro Polla To: ffmpeg-devel@ffmpeg.org Date: Mon, 17 Jun 2024 00:28:44 +0200 Message-Id: <20240616222849.420361-1-ramiro.polla@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/6] swscale/yuv2rgb: fix conversion for widths not aligned to 8 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 1onHTZsivBlx The C code for some pixel formats (rgb555, rgb565, rgb444, and monob) was not converting the last pixels on widths not aligned to 8. NOTE: the last pixel for odd widths is still not converted for any of the pixel formats in the C code for yuv2rgb except for monob. --- libswscale/yuv2rgb.c | 101 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 93 insertions(+), 8 deletions(-) diff --git a/libswscale/yuv2rgb.c b/libswscale/yuv2rgb.c index c1d6236f37..e641c765c7 100644 --- a/libswscale/yuv2rgb.c +++ b/libswscale/yuv2rgb.c @@ -172,10 +172,6 @@ const int *sws_getCoefficients(int colorspace) return srcSliceH; \ } -#define CLOSEYUV2RGBFUNC(dst_delta) \ - ENDYUV2RGBLINE(dst_delta, 0) \ - ENDYUV2RGBFUNC() - YUV2RGBFUNC(yuv2rgb_c_48, uint8_t, 0) LOADCHROMA(0); PUTRGB48(dst_1, py_1, 0); @@ -432,7 +428,27 @@ YUV2RGBFUNC(yuv2rgb_c_16_ordered_dither, uint16_t, 0) LOADCHROMA(3); PUTRGB16(dst_2, py_2, 3, 6 + 8); PUTRGB16(dst_1, py_1, 3, 6); -CLOSEYUV2RGBFUNC(8) +ENDYUV2RGBLINE(8, 0) + const uint8_t *d16 = ff_dither_2x2_8[y & 1]; + const uint8_t *e16 = ff_dither_2x2_4[y & 1]; + const uint8_t *f16 = ff_dither_2x2_8[(y & 1)^1]; + + LOADCHROMA(0); + PUTRGB16(dst_1, py_1, 0, 0); + PUTRGB16(dst_2, py_2, 0, 0 + 8); + + LOADCHROMA(1); + PUTRGB16(dst_2, py_2, 1, 2 + 8); + PUTRGB16(dst_1, py_1, 1, 2); +ENDYUV2RGBLINE(8, 1) + const uint8_t *d16 = ff_dither_2x2_8[y & 1]; + const uint8_t *e16 = ff_dither_2x2_4[y & 1]; + const uint8_t *f16 = ff_dither_2x2_8[(y & 1)^1]; + + LOADCHROMA(0); + PUTRGB16(dst_1, py_1, 0, 0); + PUTRGB16(dst_2, py_2, 0, 0 + 8); +ENDYUV2RGBFUNC() YUV2RGBFUNC(yuv2rgb_c_15_ordered_dither, uint16_t, 0) const uint8_t *d16 = ff_dither_2x2_8[y & 1]; @@ -462,7 +478,25 @@ YUV2RGBFUNC(yuv2rgb_c_15_ordered_dither, uint16_t, 0) LOADCHROMA(3); PUTRGB15(dst_2, py_2, 3, 6 + 8); PUTRGB15(dst_1, py_1, 3, 6); -CLOSEYUV2RGBFUNC(8) +ENDYUV2RGBLINE(8, 0) + const uint8_t *d16 = ff_dither_2x2_8[y & 1]; + const uint8_t *e16 = ff_dither_2x2_8[(y & 1)^1]; + + LOADCHROMA(0); + PUTRGB15(dst_1, py_1, 0, 0); + PUTRGB15(dst_2, py_2, 0, 0 + 8); + + LOADCHROMA(1); + PUTRGB15(dst_2, py_2, 1, 2 + 8); + PUTRGB15(dst_1, py_1, 1, 2); +ENDYUV2RGBLINE(8, 1) + const uint8_t *d16 = ff_dither_2x2_8[y & 1]; + const uint8_t *e16 = ff_dither_2x2_8[(y & 1)^1]; + + LOADCHROMA(0); + PUTRGB15(dst_1, py_1, 0, 0); + PUTRGB15(dst_2, py_2, 0, 0 + 8); +ENDYUV2RGBFUNC() // r, g, b, dst_1, dst_2 YUV2RGBFUNC(yuv2rgb_c_12_ordered_dither, uint16_t, 0) @@ -493,7 +527,23 @@ YUV2RGBFUNC(yuv2rgb_c_12_ordered_dither, uint16_t, 0) LOADCHROMA(3); PUTRGB12(dst_2, py_2, 3, 6 + 8); PUTRGB12(dst_1, py_1, 3, 6); -CLOSEYUV2RGBFUNC(8) +ENDYUV2RGBLINE(8, 0) + const uint8_t *d16 = ff_dither_4x4_16[y & 3]; + + LOADCHROMA(0); + PUTRGB12(dst_1, py_1, 0, 0); + PUTRGB12(dst_2, py_2, 0, 0 + 8); + + LOADCHROMA(1); + PUTRGB12(dst_2, py_2, 1, 2 + 8); + PUTRGB12(dst_1, py_1, 1, 2); +ENDYUV2RGBLINE(8, 1) + const uint8_t *d16 = ff_dither_4x4_16[y & 3]; + + LOADCHROMA(0); + PUTRGB12(dst_1, py_1, 0, 0); + PUTRGB12(dst_2, py_2, 0, 0 + 8); +ENDYUV2RGBFUNC() // r, g, b, dst_1, dst_2 YUV2RGBFUNC(yuv2rgb_c_8_ordered_dither, uint8_t, 0) @@ -672,7 +722,42 @@ YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0) dst_1[0] = out_1; dst_2[0] = out_2; -CLOSEYUV2RGBFUNC(1) + + py_1 += 8; + py_2 += 8; + dst_1 += 1; + dst_2 += 1; + } + if (c->dstW & 7) { + int av_unused Y, U, V; + int pixels_left = c->dstW & 7; + const uint8_t *d128 = ff_dither_8x8_220[yd & 7]; + char out_1 = 0, out_2 = 0; + g = c->table_gU[128 + YUVRGB_TABLE_HEADROOM] + c->table_gV[128 + YUVRGB_TABLE_HEADROOM]; + +#define PUTRGB1_OR00(out, src, i, o) \ + if (pixels_left) { \ + PUTRGB1(out, src, i, o) \ + pixels_left--; \ + } else { \ + out <<= 2; \ + } + + PUTRGB1_OR00(out_1, py_1, 0, 0); + PUTRGB1_OR00(out_2, py_2, 0, 0 + 8); + + PUTRGB1_OR00(out_2, py_2, 1, 2 + 8); + PUTRGB1_OR00(out_1, py_1, 1, 2); + + PUTRGB1_OR00(out_1, py_1, 2, 4); + PUTRGB1_OR00(out_2, py_2, 2, 4 + 8); + + PUTRGB1_OR00(out_2, py_2, 3, 6 + 8); + PUTRGB1_OR00(out_1, py_1, 3, 6); + + dst_1[0] = out_1; + dst_2[0] = out_2; +ENDYUV2RGBFUNC() SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c) {