Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp574034img; Wed, 20 Mar 2019 06:41:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqymBHfb7107bjzDEkOAQOFrKJrJ6rDQQq4SCv13c8ibXFJz5+weGSXDi+2Eu6fkVFCj6evX X-Received: by 2002:a17:902:5ac9:: with SMTP id g9mr8125871plm.205.1553089273366; Wed, 20 Mar 2019 06:41:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553089273; cv=none; d=google.com; s=arc-20160816; b=vghxDNk1OayYm41XfCLVaInEdgxvKJXbk8ShqbDKmGhnS3LphRXCSNh/MRlpFfAi66 RrovpUFpYD/ISI1YcCFPIdJcjLkBcr4DpSewxvsMsZNLuNwvXRpLXZoBaUpVxiQwKMrM jIw7o/pMwtCHF9LNvWuEFwWDRnCcJlgPdUN+Wn/WdFHZHapGVdZVg7E41KPPMFWJt37+ 1xgFD2xNdyi9sGQtX3dAckcBdbtu+S6wweUQ/zdWhAZRTp9dXQEeWUuCelwVv2TJp2IG 9TNxSzWRX5IC2XKTKZMcJFyZ0QO3Vf0Lak2SLYkPtWIsy3Tg+MDCpLfWBIz66J2pu/6e 1vgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=gKnE2rKa4T6okKGvRLUZEC3HnX79YP81KNmCiZktQ1A=; b=S73zHXECS+eBHfh6Bpvss6xIJ55/ZtQPjjW629EiaIRtTcWrlcL68Cuefa/w+EYUaE 9uq9nOpwxbLpu/DOqEYLTWmcFMMgvsVW/7ivOLApKW0y6wdFp+Uyz+4dHfhB081meVfx FFXhvRqMuUZJbECy8udfe1QroQ3Oa0x2p0oTo6BF2tcLh/l9p3PaPxWDnlmb+4iww/h8 RT6mo/COSiP6bqHjPUTrC/lY0y09owDttzfJd8OgpkCFl4kWCGzM94HC7Q2Dn4D9hkIQ jCIr51a7muzhozb1BA+Y2zSD0PvixoeoNP6wAP0u4/LHQstKajwZaJFvdy5xTwRcGy4q JiUQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t2si1701610pgu.399.2019.03.20.06.40.57; Wed, 20 Mar 2019 06:41:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728058AbfCTNju (ORCPT + 99 others); Wed, 20 Mar 2019 09:39:50 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:44240 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726065AbfCTNju (ORCPT ); Wed, 20 Mar 2019 09:39:50 -0400 Received: from localhost (unknown [IPv6:2a01:e0a:2c:6930:5cf4:84a1:2763:fe0d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: bbrezillon) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 7C1CA281753; Wed, 20 Mar 2019 13:39:47 +0000 (GMT) Date: Wed, 20 Mar 2019 14:39:44 +0100 From: Boris Brezillon To: Maxime Ripard Cc: Daniel Vetter , David Airlie , Maarten Lankhorst , Sean Paul , Mauro Carvalho Chehab , Sakari Ailus , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , linux-media@vger.kernel.org Subject: Re: [RFC PATCH 06/20] lib: Add video format information library Message-ID: <20190320143944.10454b3b@collabora.com> In-Reply-To: References: Organization: Collabora X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 19 Mar 2019 22:57:11 +0100 Maxime Ripard wrote: > Move the DRM formats API to turn this into a more generic image formats API > to be able to leverage it into some other places of the kernel, such as > v4l2 drivers. > > Signed-off-by: Maxime Ripard > --- > include/linux/image-formats.h | 240 +++++++++++- > lib/Kconfig | 7 +- > lib/Makefile | 3 +- > lib/image-formats-selftests.c | 326 +++++++++++++++- > lib/image-formats.c | 760 +++++++++++++++++++++++++++++++++++- > 5 files changed, 1336 insertions(+) > create mode 100644 include/linux/image-formats.h > create mode 100644 lib/image-formats-selftests.c > create mode 100644 lib/image-formats.c > [...] > --- /dev/null > +++ b/lib/image-formats.c > @@ -0,0 +1,760 @@ > +#include > +#include > +#include > +#include > + > +#include > + > +static const struct image_format_info formats[] = { > + { ... > + }, > +}; > + > +#define __image_format_lookup(_field, _fmt) \ > + ({ \ > + const struct image_format_info *format = NULL; \ > + unsigned i; \ > + \ > + for (i = 0; i < ARRAY_SIZE(formats); i++) \ > + if (formats[i]._field == _fmt) \ > + format = &formats[i]; \ > + \ > + format; \ > + }) > + > +/** > + * __image_format_drm_lookup - query information for a given format > + * @drm: DRM fourcc pixel format (DRM_FORMAT_*) > + * > + * The caller should only pass a supported pixel format to this function. > + * > + * Returns: > + * The instance of struct image_format_info that describes the pixel format, or > + * NULL if the format is unsupported. > + */ > +const struct image_format_info *__image_format_drm_lookup(u32 drm) > +{ > + return __image_format_lookup(drm_fmt, drm); > +} > +EXPORT_SYMBOL(__image_format_drm_lookup); > + > +/** > + * image_format_drm_lookup - query information for a given format > + * @drm: DRM fourcc pixel format (DRM_FORMAT_*) > + * > + * The caller should only pass a supported pixel format to this function. > + * Unsupported pixel formats will generate a warning in the kernel log. > + * > + * Returns: > + * The instance of struct image_format_info that describes the pixel format, or > + * NULL if the format is unsupported. > + */ > +const struct image_format_info *image_format_drm_lookup(u32 drm) > +{ > + const struct image_format_info *format; > + > + format = __image_format_drm_lookup(drm); > + > + WARN_ON(!format); > + return format; > +} > +EXPORT_SYMBOL(image_format_drm_lookup); I think this function and the DRM formats table should be moved in drivers/gpu/drm/drm_image_format.c since they are DRM specific. The remaining functions can IMHO be placed in include/linux/image-formats.h as static inline funcs. This way you can get rid of lib/image-formats.c and the associated Kconfig entry. > + > +/** > + * image_format_plane_cpp - determine the bytes per pixel value > + * @format: pointer to the image_format > + * @plane: plane index > + * > + * Returns: > + * The bytes per pixel value for the specified plane. > + */ > +unsigned int image_format_plane_cpp(const struct image_format_info *format, > + int plane) > +{ > + if (!format || plane >= format->num_planes) > + return 0; > + > + return format->cpp[plane]; > +} > +EXPORT_SYMBOL(image_format_plane_cpp); > + > +/** > + * image_format_plane_width - width of the plane given the first plane > + * @format: pointer to the image_format > + * @width: width of the first plane > + * @plane: plane index > + * > + * Returns: > + * The width of @plane, given that the width of the first plane is @width. > + */ > +unsigned int image_format_plane_width(int width, > + const struct image_format_info *format, > + int plane) > +{ > + if (!format || plane >= format->num_planes) > + return 0; > + > + if (plane == 0) > + return width; > + > + return width / format->hsub; > +} > +EXPORT_SYMBOL(image_format_plane_width); > + > +/** > + * image_format_plane_height - height of the plane given the first plane > + * @format: pointer to the image_format > + * @height: height of the first plane > + * @plane: plane index > + * > + * Returns: > + * The height of @plane, given that the height of the first plane is @height. > + */ > +unsigned int image_format_plane_height(int height, > + const struct image_format_info *format, > + int plane) > +{ > + if (!format || plane >= format->num_planes) > + return 0; > + > + if (plane == 0) > + return height; > + > + return height / format->vsub; > +} > +EXPORT_SYMBOL(image_format_plane_height); > + > +/** > + * image_format_block_width - width in pixels of block. > + * @format: pointer to the image_format > + * @plane: plane index > + * > + * Returns: > + * The width in pixels of a block, depending on the plane index. > + */ > +unsigned int image_format_block_width(const struct image_format_info *format, > + int plane) > +{ > + if (!format || plane < 0 || plane >= format->num_planes) > + return 0; > + > + if (!format->block_w[plane]) > + return 1; > + > + return format->block_w[plane]; > +} > +EXPORT_SYMBOL(image_format_block_width); > + > +/** > + * image_format_block_height - height in pixels of a block > + * @info: pointer to the image_format > + * @plane: plane index > + * > + * Returns: > + * The height in pixels of a block, depending on the plane index. > + */ > +unsigned int image_format_block_height(const struct image_format_info *format, > + int plane) > +{ > + if (!format || plane < 0 || plane >= format->num_planes) > + return 0; > + > + if (!format->block_h[plane]) > + return 1; > + > + return format->block_h[plane]; > +} > +EXPORT_SYMBOL(image_format_block_height); > + > +/** > + * image_format_min_pitch - computes the minimum required pitch in bytes > + * @info: pixel format info > + * @plane: plane index > + * @buffer_width: buffer width in pixels > + * > + * Returns: > + * The minimum required pitch in bytes for a buffer by taking into consideration > + * the pixel format information and the buffer width. > + */ > +uint64_t image_format_min_pitch(const struct image_format_info *info, > + int plane, unsigned int buffer_width) > +{ > + if (!info || plane < 0 || plane >= info->num_planes) > + return 0; > + > + return DIV_ROUND_UP_ULL((u64)buffer_width * info->char_per_block[plane], > + image_format_block_width(info, plane) * > + image_format_block_height(info, plane)); > +} > +EXPORT_SYMBOL(image_format_min_pitch);