Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3631311pxb; Fri, 11 Feb 2022 04:28:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJy7HwgEJqMGLUWUtrquyWW7mMFnYTaPCBnU5sEK598Q/pLvq1u3Jr4tUe9Z2p4UPk3oHkx7 X-Received: by 2002:a17:903:22d0:: with SMTP id y16mr1385803plg.65.1644582488334; Fri, 11 Feb 2022 04:28:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644582488; cv=none; d=google.com; s=arc-20160816; b=H9xviBW1YCYb2l/u/k1Pl8tvtMqQFyVU9XGq3bTG0Gj/CrLSs5ZtqIXzIZXyCsgWCK nDZLsuZDYiAbVgwWvKU18k6ll2sYUmnFoXbQreStH3e0bWwv3zs+M87RJ9cAl3SdEPxe hzhAIR+pyERyN8Pb0s+M8jH9KS/+okB2Xzg/p2rQYQzU9MQIcivb6czy7oHf1T+y1m1z 8kWhlGXv3Ek4t12rGaLh8Jhha6uEaqP4R+U0XRJvHcW7XFoPFYL+0qFIadoSaqc4hDIk /tsO8sudUbLx0wMuN4TCGMdvujou9TT5nwTq7pwolGVAOA2vqA0ga/Kjhj3kVfUqOJEG llKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WfmTkAo8MbPeTvx/t6/qV64gOBcJ/r5gHdJT18TRKbc=; b=dine37cJyx2p2W1LqfYjxeZZPIceNI5fCp5s/fJqznWr39XuN063TZDaFsXph9YrbX lo9CVaaN+9O8JmVLfZOZbZmN3OLVPNxnIUbLI8H4wA0/M/jicWJy7jZo9+PH9bHwDKS1 djuKWNOdW7KF6F0Se8EVFFCix1+XfE7S1sfIbjZI6ayeuMyui6sBMA7a/BAycddt8C+F 2cD77BWdsPZxoSyBytvSE5qZsLDt1b1rswdMA+4QyMxZCubTvMT6Hrc7RyeLFDilk0nr 6eHPuyDYOE7QnUVu2mGvgk/1FjIgKxped1IeXpp1rCVlpfUcTK7yJpTcwrrIi6oaOZLg tjTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=J2ijK2Zo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i6si11057394pgo.770.2022.02.11.04.27.57; Fri, 11 Feb 2022 04:28:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=J2ijK2Zo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348455AbiBKJTr (ORCPT + 99 others); Fri, 11 Feb 2022 04:19:47 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:60292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348444AbiBKJTk (ORCPT ); Fri, 11 Feb 2022 04:19:40 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 71A4E337 for ; Fri, 11 Feb 2022 01:19:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644571179; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WfmTkAo8MbPeTvx/t6/qV64gOBcJ/r5gHdJT18TRKbc=; b=J2ijK2ZoaFlDPHBR6+6xlY759dBKPyWAwSU+3m+slcJvkV6QaZWOwzxMbpF0RzynVQNbjk m9scz3jRq+94C4S5zoKKS3/q1mlSRTT+1PWSc02DBHoUAv9cx5ee5g7sX6ga3iBEc6odwB cynqo1jpL9dpLB617qSwSDZM2Vca3Zs= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-577-xS8PV7yMOqKbB3AQ24MPlQ-1; Fri, 11 Feb 2022 04:19:38 -0500 X-MC-Unique: xS8PV7yMOqKbB3AQ24MPlQ-1 Received: by mail-wr1-f69.google.com with SMTP id g17-20020adfa591000000b001da86c91c22so3642236wrc.5 for ; Fri, 11 Feb 2022 01:19:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WfmTkAo8MbPeTvx/t6/qV64gOBcJ/r5gHdJT18TRKbc=; b=oRfuWLt9wkNegRBZNRmA1FhYD8KU19kzm125uIQIHgC04GXcK0n6MG91GuLJ/KFilP saoTeQDzkONCLmKcY8mopVeP0WYYLPB1+Wl5aXTTC3XZSzU8mjR3OMYygNNwqKwuUoKr we7QywYCbW48NnbZw3k0Qr1EtvdnPsUVjuzWsd22HbezEIPIIK3ZLStkZNoc3Hn8vzaf nHanLL59+iwKEOfqx4b0qbMhLbJwfSLrO/iE52TTMEA5adkd+wNaX0anO15NPPFOGv8e O2V2UFWFSEyne65ccuhG2rowNe3xK3RUko1KmQm1TbFtIjakat140bJhPUddIUyoqObO WJ7w== X-Gm-Message-State: AOAM531gLwSy+bjRYCK85f9TyJn2YPy6zlKZyPFyWLzOGl0zt2+Gvli0 2cXcr8E68ZzL08Hodx2ir4dZCmCN0drtiTGBS+Ja5Op1TKhc3SZqLGpbr/P32zO50EieUwFl6cE iploT1PF491G02Ue3OGxfLocvAQhAXdz1lzCW0lRrM7+gFr7O1kRHpluGjyHUdbPWw7dDkzPxt3 o= X-Received: by 2002:a05:600c:3514:: with SMTP id h20mr1321472wmq.164.1644571177393; Fri, 11 Feb 2022 01:19:37 -0800 (PST) X-Received: by 2002:a05:600c:3514:: with SMTP id h20mr1321436wmq.164.1644571177101; Fri, 11 Feb 2022 01:19:37 -0800 (PST) Received: from minerva.home ([92.176.231.205]) by smtp.gmail.com with ESMTPSA id r17sm3805578wmq.33.2022.02.11.01.19.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Feb 2022 01:19:36 -0800 (PST) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: linux-fbdev@vger.kernel.org, Geert Uytterhoeven , Andy Shevchenko , Maxime Ripard , Daniel Vetter , dri-devel@lists.freedesktop.org, Thomas Zimmermann , Sam Ravnborg , =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= , Javier Martinez Canillas , Daniel Vetter , David Airlie , Maarten Lankhorst , Maxime Ripard Subject: [PATCH v4 1/6] drm/format-helper: Add drm_fb_xrgb8888_to_gray8_line() Date: Fri, 11 Feb 2022 10:19:22 +0100 Message-Id: <20220211091927.2988283-2-javierm@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220211091927.2988283-1-javierm@redhat.com> References: <20220211091927.2988283-1-javierm@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Pull the per-line conversion logic into a separate helper function. This will allow to do line-by-line conversion in other helpers that convert to a gray8 format. Suggested-by: Thomas Zimmermann Signed-off-by: Javier Martinez Canillas --- (no changes since v3) Changes in v3: - Add a drm_fb_xrgb8888_to_gray8_line() helper function (Thomas Zimmermann) drivers/gpu/drm/drm_format_helper.c | 31 ++++++++++++++++++----------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_format_helper.c index 0f28dd2bdd72..b981712623d3 100644 --- a/drivers/gpu/drm/drm_format_helper.c +++ b/drivers/gpu/drm/drm_format_helper.c @@ -464,6 +464,21 @@ void drm_fb_xrgb8888_to_xrgb2101010_toio(void __iomem *dst, } EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb2101010_toio); +static void drm_fb_xrgb8888_to_gray8_line(u8 *dst, const u32 *src, unsigned int pixels) +{ + unsigned int x; + + for (x = 0; x < pixels; x++) { + u8 r = (*src & 0x00ff0000) >> 16; + u8 g = (*src & 0x0000ff00) >> 8; + u8 b = *src & 0x000000ff; + + /* ITU BT.601: Y = 0.299 R + 0.587 G + 0.114 B */ + *dst++ = (3 * r + 6 * g + b) / 10; + src++; + } +} + /** * drm_fb_xrgb8888_to_gray8 - Convert XRGB8888 to grayscale * @dst: 8-bit grayscale destination buffer @@ -484,8 +499,9 @@ EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb2101010_toio); void drm_fb_xrgb8888_to_gray8(void *dst, unsigned int dst_pitch, const void *vaddr, const struct drm_framebuffer *fb, const struct drm_rect *clip) { - unsigned int len = (clip->x2 - clip->x1) * sizeof(u32); - unsigned int x, y; + unsigned int linepixels = clip->x2 - clip->x1; + unsigned int len = linepixels * sizeof(u32); + unsigned int y; void *buf; u8 *dst8; u32 *src32; @@ -508,16 +524,7 @@ void drm_fb_xrgb8888_to_gray8(void *dst, unsigned int dst_pitch, const void *vad for (y = clip->y1; y < clip->y2; y++) { dst8 = dst; src32 = memcpy(buf, vaddr, len); - for (x = clip->x1; x < clip->x2; x++) { - u8 r = (*src32 & 0x00ff0000) >> 16; - u8 g = (*src32 & 0x0000ff00) >> 8; - u8 b = *src32 & 0x000000ff; - - /* ITU BT.601: Y = 0.299 R + 0.587 G + 0.114 B */ - *dst8++ = (3 * r + 6 * g + b) / 10; - src32++; - } - + drm_fb_xrgb8888_to_gray8_line(dst8, src32, linepixels); vaddr += fb->pitches[0]; dst += dst_pitch; } -- 2.34.1