From patchwork Sat Apr 4 14:31:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaaira Gupta X-Patchwork-Id: 3402 Return-Path: Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7E725600F4 for ; Sat, 4 Apr 2020 16:31:32 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=es-iitr-ac-in.20150623.gappssmtp.com header.i=@es-iitr-ac-in.20150623.gappssmtp.com header.b="V/hKLa4x"; dkim-atps=neutral Received: by mail-pl1-x62e.google.com with SMTP id ay1so4016002plb.0 for ; Sat, 04 Apr 2020 07:31:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=es-iitr-ac-in.20150623.gappssmtp.com; s=20150623; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=Lagxp7mTksqiVxkl6zk7baQtxHoVesy3CdC9+MN5ZNI=; b=V/hKLa4xyahNoptxxpmMVTWUnrATrbFLWApY2UhAmxCcRMfdlGdqsD3Pect5uWnXsF uEfSElzIaLe0PiMDmbU966w8kACPl3JIjQg4SjwtLQtLh1Nwbo0PiO4k5cmCZB3NKWtl 80OR8dOq9vE+QWIvqq8NMDH5y8jvGnJDVVjEWNj5ZXIo+4895yupFPx2NJGMHIg2/F3b /SI+mj/XOOxAXu+3rzZ2Lg6DI7gmFXGMRNKZC7aaAgPk0aTDffJ0KFufhVKXSS2vYjDS SD3z64t6JuCP2Ab2yVsK3IfJCxfOdCNfBcVROAesvXSVHscZy8/5Ob8Qw0cJBcKyvyOO TF2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=Lagxp7mTksqiVxkl6zk7baQtxHoVesy3CdC9+MN5ZNI=; b=S5VmbyTcQkrswbtycw7nhsHZILoGwzqvWo6awZkMFXAFfqvA36BV3ig9AG15x/2VEz CMNbTkeyoySqUvYalAgp9wD7IOQ7licurWVTb2mXIkwgqkrO+5Up3/uQ4wmJL9idM/EY SKiZYaS/RRaufesiVs5a8daJ/RyyxqhnRJ3GoN43NGuAF5QYEPzddddx5fV7Kc27yEzI 0jLYVHBx3k+HtWA3GYAH/VyBzeQXXideG6D5nSat4dz8SvrzlP5cgSSbInD1RtbO7b9D uaiCZKbAVCDM2qbQsHtiISnNMAMs7NKzedDE+10lALVN4ec92sy5mjaT0lQoSHyoPMBm 5aLQ== X-Gm-Message-State: AGi0PuY4Y4XBZOEQT9g7Qb0M0frfKlmG/zPIQHi54zr67fn6O1rtCvJ2 bpA5a00P62qKK0aYCYAr3HCDmkwTJwGp0w== X-Google-Smtp-Source: APiQypJoWd6YCYisNOo7NXX5V11pdE8kyKQ59SWBRFmYtIdF6qKXxFdJFg8HmwkwD2K1oF6KR2EVIg== X-Received: by 2002:a17:90a:3606:: with SMTP id s6mr16360208pjb.195.1586010690689; Sat, 04 Apr 2020 07:31:30 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.154]) by smtp.gmail.com with ESMTPSA id d3sm7961831pjz.2.2020.04.04.07.31.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 04 Apr 2020 07:31:29 -0700 (PDT) Date: Sat, 4 Apr 2020 20:01:23 +0530 From: Kaaira Gupta To: libcamera-devel@lists.libcamera.org, Kieran Bingham , Helen Koike , Vaishali Thakkar Message-ID: <20200404143123.GA14635@kaaira-HP-Pavilion-Notebook> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Subject: [libcamera-devel] [PATCH v2] libcamera: PixelFormat: Replace hex with fourcc and modifiers X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Apr 2020 14:31:34 -0000 Print fourCC characters instead of the hex values in toString() as they are easier to comprehend. Also, print the corresponding modifiers of the DRM formats so that it can be more specific. Write the tests for them as well. Signed-off-by: Kaaira Gupta --- Changes since v1: - Replaced magic numbers with expressive values. - Re-wrote ARM vendor's modifiers - Re-wrote the vendors' map with a macro. - Changed the copyrights in test file. - Changed the tests. src/libcamera/pixelformats.cpp | 197 ++++++++++++++++++++++++++++++++- test/meson.build | 1 + test/pixel-format.cpp | 49 ++++++++ 3 files changed, 244 insertions(+), 3 deletions(-) create mode 100644 test/pixel-format.cpp diff --git a/src/libcamera/pixelformats.cpp b/src/libcamera/pixelformats.cpp index 1330dc5..81159ee 100644 --- a/src/libcamera/pixelformats.cpp +++ b/src/libcamera/pixelformats.cpp @@ -6,6 +6,17 @@ */ #include +#include +#include + +#define PIXELFORMAT_VENDOR(vendor) \ + { DRM_FORMAT_MOD_VENDOR_## vendor, #vendor } + +#define AFBC_FORMAT_MOD_BLOCK(afbcBlock) \ + { AFBC_FORMAT_MOD_## afbcBlock, #afbcBlock } + +#define AFBC_FORMAT_MOD(modifier, mod) \ + { modifier & (AFBC_FORMAT_MOD_## mod), #mod } /** * \file pixelformats.h @@ -108,9 +119,189 @@ bool PixelFormat::operator<(const PixelFormat &other) const */ std::string PixelFormat::toString() const { - char str[11]; - snprintf(str, 11, "0x%08x", fourcc_); - return str; + if (fourcc_ == DRM_FORMAT_INVALID) + return ""; + + char ss[8] = { static_cast(fourcc_ & 0x7f), + static_cast((fourcc_ >> 8) & 0x7f), + static_cast((fourcc_ >> 16) & 0x7f), + static_cast((fourcc_ >> 24) & 0x7f) }; + + for (unsigned int i = 0; i < 4; i++) { + if (!isprint(ss[i])) + ss[i] = '.'; + } + + if (fourcc_ & (1 << 31)) + strcat(ss, "-BE"); + + std::string modifier; + + if (modifier_ == DRM_FORMAT_MOD_INVALID) { + modifier = " - modifier"; + return ss + modifier; + } + + /* Map of all the vendors with their Ids: */ + std::map vendors = { + PIXELFORMAT_VENDOR(NONE), + PIXELFORMAT_VENDOR(INTEL), + PIXELFORMAT_VENDOR(AMD), + PIXELFORMAT_VENDOR(NVIDIA), + PIXELFORMAT_VENDOR(SAMSUNG), + PIXELFORMAT_VENDOR(QCOM), + PIXELFORMAT_VENDOR(VIVANTE), + PIXELFORMAT_VENDOR(BROADCOM), + PIXELFORMAT_VENDOR(ARM), + PIXELFORMAT_VENDOR(ALLWINNER), + PIXELFORMAT_VENDOR(MIPI) + }; + + std::map afbc_format_blocks = { + AFBC_FORMAT_MOD_BLOCK(BLOCK_SIZE_16x16), + AFBC_FORMAT_MOD_BLOCK(BLOCK_SIZE_32x8), + AFBC_FORMAT_MOD_BLOCK(BLOCK_SIZE_64x4), + AFBC_FORMAT_MOD_BLOCK(BLOCK_SIZE_32x8_64x4), + + }; + + std::map afbc_format_mod = { + AFBC_FORMAT_MOD(modifier_, YTR), + AFBC_FORMAT_MOD(modifier_, SPLIT), + AFBC_FORMAT_MOD(modifier_, SPARSE), + AFBC_FORMAT_MOD(modifier_, CBR), + AFBC_FORMAT_MOD(modifier_, TILED), + AFBC_FORMAT_MOD(modifier_, SC), + AFBC_FORMAT_MOD(modifier_, DB), + AFBC_FORMAT_MOD(modifier_, BCH), + }; + + /* Get the vendor name using its Id */ + long int vendorCode = (modifier_ >> 56) & 0xff; + std::string vendor = vendors[vendorCode]; + + uint64_t modifierValue = modifier_ & 0xff; + std::string vendorSpecification; + + switch (vendorCode) { + case DRM_FORMAT_MOD_VENDOR_NONE: { + if (modifierValue == 0) + vendorSpecification = "Linear Layout"; + break; + } + case DRM_FORMAT_MOD_VENDOR_INTEL: { + if (modifierValue == 1) + vendorSpecification = "X-tiled"; + else if (modifierValue == 2) + vendorSpecification = "Y-tiled"; + else if (modifierValue == 3) + vendorSpecification = "Yf-tiled"; + else if (modifierValue == 4) + vendorSpecification = "Y-tiled CCS"; + else if (modifierValue == 5) + vendorSpecification = "Yf-tiled CSS"; + else if (modifierValue == 8) + vendorSpecification = "Bayer packed"; + break; + } + case DRM_FORMAT_MOD_VENDOR_AMD: { + // no specifications + break; + } + case DRM_FORMAT_MOD_VENDOR_NVIDIA: { + if (modifierValue == 1) + vendorSpecification = "Tegra-tiled"; + else if (modifierValue == 0x10) + vendorSpecification = "ONE_GOB | v = 0"; + else if (modifierValue == 0x11) + vendorSpecification = "TWO_GOB | v = 1"; + else if (modifierValue == 0x12) + vendorSpecification = "FOUR_GOB | v = 2"; + else if (modifierValue == 0x13) + vendorSpecification = "EIGHT_GOB | v = 3"; + else if (modifierValue == 0x14) + vendorSpecification = "SIXTEEN_GOB | v = 4"; + else if (modifierValue == 0x15) + vendorSpecification = "THIRTYTWO_GOB | v = 5"; + break; + } + case DRM_FORMAT_MOD_VENDOR_SAMSUNG: { + if (modifierValue == 1) + vendorSpecification = "Tiled, 64 (pixels) x 32 (lines)"; + else if (modifierValue == 2) + vendorSpecification = "Tiled, 16 (pixels) x 16 (lines)"; + break; + } + case DRM_FORMAT_MOD_VENDOR_QCOM: { + if (modifierValue == 1) + vendorSpecification = "Compressed"; + break; + } + case DRM_FORMAT_MOD_VENDOR_VIVANTE: { + if (modifierValue == 1) + vendorSpecification = "4 x 4 tiled"; + else if (modifierValue == 2) + vendorSpecification = "64 x 64 super-tiled"; + else if (modifierValue == 3) + vendorSpecification = "4 x 4 split-tiled"; + else if (modifierValue == 4) + vendorSpecification = "64 x 64 split-super-tiled"; + break; + } + case DRM_FORMAT_MOD_VENDOR_BROADCOM: { + if (modifierValue == 1) + vendorSpecification = "VC4-T-Tiled"; + else if (modifierValue == 6) + vendorSpecification = "UIF"; + else if (modifierValue == 2) + vendorSpecification = "SAND32"; + else if (modifierValue == 3) + vendorSpecification = "SAND64"; + else if (modifierValue == 4) + vendorSpecification = "SAND128"; + else if (modifierValue == 5) + vendorSpecification = "SAND256"; + break; + } + case DRM_FORMAT_MOD_VENDOR_ARM: { + uint8_t block_size = modifier_ & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK; + + if (afbc_format_blocks.count(block_size)) { + vendorSpecification = afbc_format_blocks[block_size] + " | "; + }; + + std::map::iterator it; + for (it = afbc_format_mod.begin(); it != afbc_format_mod.end(); it++) { + if (it->first != 0) { + vendorSpecification += it->second + " | "; + } + } + break; + } + case DRM_FORMAT_MOD_VENDOR_ALLWINNER: { + if (modifierValue == 1) + vendorSpecification = "Tiled"; + break; + } + case DRM_FORMAT_MOD_VENDOR_MIPI: { + if (modifierValue == 1) + vendorSpecification = "CSI-2 packed"; + break; + } + default: + break; + } + + modifier = vendor + " : " + vendorSpecification; + std::string formatString(ss); + formatString = formatString + " - " + modifier; + + /* Trim last three characters of the string if last char is a space. */ + if (isspace(formatString.back())) { + formatString = formatString.substr(0, formatString.size() - 3); + } + + return formatString; } } /* namespace libcamera */ diff --git a/test/meson.build b/test/meson.build index 8ab58ac..3f97278 100644 --- a/test/meson.build +++ b/test/meson.build @@ -30,6 +30,7 @@ internal_tests = [ ['message', 'message.cpp'], ['object', 'object.cpp'], ['object-invoke', 'object-invoke.cpp'], + ['pixel-format', 'pixel-format.cpp'], ['signal-threads', 'signal-threads.cpp'], ['threads', 'threads.cpp'], ['timer', 'timer.cpp'], diff --git a/test/pixel-format.cpp b/test/pixel-format.cpp new file mode 100644 index 0000000..55cd916 --- /dev/null +++ b/test/pixel-format.cpp @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2020, Kaaira Gupta + * + * libcamera pixel format handling test + */ + +#include +#include + +#include "libcamera/pixelformats.h" + +#include "test.h" + +using namespace std; +using namespace libcamera; + +class PixelFormatTest : public Test +{ +protected: + int run() + { + std::vector> formats{ + { PixelFormat(DRM_FORMAT_SRGGB8, DRM_FORMAT_MOD_INVALID), "RGGB - modifier" }, + { PixelFormat(DRM_FORMAT_SRGGB8, DRM_FORMAT_MOD_LINEAR), "RGGB - NONE : Linear Layout" }, + { PixelFormat(DRM_FORMAT_C8, DRM_FORMAT_MOD_ARM_AFBC(4)), "C8 - ARM : BLOCK_SIZE_32x8_64x4" }, + { PixelFormat(DRM_FORMAT_YUV410, DRM_FORMAT_MOD_ARM_AFBC(4|1ULL << 11)), "YUV9 - ARM : BLOCK_SIZE_32x8_64x4 | BCH"}, + { PixelFormat(DRM_FORMAT_BIG_ENDIAN, DRM_FORMAT_MOD_ALLWINNER_TILED), "....-BE - ALLWINNER : Tiled" } + }; + for (const auto &format : formats) { + if ((format.first).toString() != format.second) { + cerr << "Failed to convert PixelFormat " + << format.first.fourcc() << " to string" + << endl; + return TestFail; + } + } + + if (PixelFormat().toString() != "") { + cerr << "Failed to convert default PixelFormat to string" + << endl; + return TestFail; + } + + return TestPass; + } +}; + +TEST_REGISTER(PixelFormatTest)