From patchwork Tue Mar 31 21:05:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaaira Gupta X-Patchwork-Id: 3363 Return-Path: Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A742C6040B for ; Tue, 31 Mar 2020 23:05:34 +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="wN/8lz3W"; dkim-atps=neutral Received: by mail-pf1-x444.google.com with SMTP id i13so10967695pfe.3 for ; Tue, 31 Mar 2020 14:05:34 -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:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=72OodayrexomeTKqPJI/QpUisRU/qxfloIjQNgGTjxc=; b=wN/8lz3We5ywi1uNqvbCJYsg+M0XYv/Cup/9yfZhxSrYupV4M1nhm0GB0oR+0AeurL AD3wp7I+KeXEQmDxk4+vOJ6d9olHMZxInQgAXM1ceD9mD8oTmyocErCtYpi6Qnh09RxC OsXJDnrg7jg/8vJRv5PbSad5n7nBlLZxCmZJ06Kw8zS5UV8PuKKzShuQ0BszV+GkvnK2 dYweCfbgIQYzbhG8ItovCZyM7MnBMTcBSvyaDg4E9gnfe/uDNgr+Rd/AE46iyFAAF1u3 GUpRb3m+AZDtgscwY4zJvHzjLSbqReWaWiIuJgpVIk1SUeZDM7IXRsTDJG/BROSyZ8gS ZI4w== 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:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=72OodayrexomeTKqPJI/QpUisRU/qxfloIjQNgGTjxc=; b=aRTRJM7waPCnhPqgqzXLEgKMCv9EBx7Z0ia+oxtyNbvitFWZGnA6TWyo+185xBWUWv VdnZKQcifoTaL0qtON5whMFykiSOFjMfqg/x4WBRs4lZwH4hjqUjlFsHtOZ68AyXVthp eXx3wgV8ES/JRKSkzEI1Tudv4gk8uCuKz/tWirQ68kh9Y3P5sJLjTuKaEfStUudFmrwm HMY3mrhbDIG4Cdo15tUigQQk3pFqXmTIoCtwH0gzNW9FtyOC+hTyJy8WXRXAr2xADnbp C8Yx0kkRFf2/KEa9iR7w63IqUiAKsfIg4CQeI1C/snLuekCrdm4YX9piVMaAorapFHPA 4bxQ== X-Gm-Message-State: ANhLgQ0TQ+8hngmIvHGFkyQRVSBxDZ/d71O+XDT6kqm30A6z4iL2IskT Dx4/QCTUToiz7qUcZrsgvfh5g7GTM88Yfg== X-Google-Smtp-Source: ADFU+vtD8Jj3Fqgru7aBNCtE/gDlqAf8bRZhNByb/XyI/zoStqCqPDdbn0OTcFlhgwBI+Fmq1PUkBQ== X-Received: by 2002:a63:4282:: with SMTP id p124mr20325959pga.59.1585688732731; Tue, 31 Mar 2020 14:05:32 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.154]) by smtp.gmail.com with ESMTPSA id q19sm12382393pgn.93.2020.03.31.14.05.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 31 Mar 2020 14:05:32 -0700 (PDT) Date: Wed, 1 Apr 2020 02:35:25 +0530 From: Kaaira Gupta To: libcamera-devel@lists.libcamera.org, Kieran Bingham , Helen Koike , Vaishali Thakkar Cc: kgupta@es.iitr.ac.in Message-ID: <20200331210525.GA4378@kaaira-HP-Pavilion-Notebook> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Subject: [libcamera-devel] [PATCH] 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: Tue, 31 Mar 2020 21:05:37 -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 --- src/libcamera/pixelformats.cpp | 192 ++++++++++++++++++++++++++++++++- test/meson.build | 1 + test/pixel-format.cpp | 55 ++++++++++ 3 files changed, 245 insertions(+), 3 deletions(-) create mode 100644 test/pixel-format.cpp diff --git a/src/libcamera/pixelformats.cpp b/src/libcamera/pixelformats.cpp index 87557d9..398dbb2 100644 --- a/src/libcamera/pixelformats.cpp +++ b/src/libcamera/pixelformats.cpp @@ -6,6 +6,8 @@ */ #include +#include +#include /** * \file pixelformats.h @@ -108,9 +110,193 @@ 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_ == 0) + 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 (*modifiers_.begin() == 72057594037927935) { + modifier = " modifier"; + return ss + modifier; + } + + if (*modifiers_.begin() == 0xf) { + modifier = " AFBC_FORMAT_MOD_BLOCK_SIZE_MASK"; + return ss + modifier; + } else if (*modifiers_.begin() == 1ULL) { + modifier = "AFBC_FORMAT_MOD_BLOCK_SIZE_16x16"; + return ss + modifier; + } else if (*modifiers_.begin() == 2ULL) { + modifier = " AFBC_FORMAT_MOD_BLOCK_SIZE_32x8"; + return ss + modifier; + } else if (*modifiers_.begin() == 3ULL) { + modifier = " AFBC_FORMAT_MOD_BLOCK_SIZE_64x4"; + return ss + modifier; + } else if (*modifiers_.begin() == 4ULL) { + modifier = " AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4"; + return ss + modifier; + } else if (*modifiers_.begin() == (1ULL << 4)) { + modifier = " AFBC_FORMAT_MOD_YTR"; + return ss + modifier; + } else if (*modifiers_.begin() == (1ULL << 5)) { + modifier = " AFBC_FORMAT_MOD_SPLIT"; + return ss + modifier; + } else if (*modifiers_.begin() == (1ULL << 6)) { + modifier = " AFBC_FORMAT_MOD_SPARS"; + return ss + modifier; + } else if (*modifiers_.begin() == (1ULL << 7)) { + modifier = " AFBC_FORMAT_MOD_CBR"; + return ss + modifier; + } else if (*modifiers_.begin() == (1ULL << 8)) { + modifier = " AFBC_FORMAT_MOD_TILED"; + return ss + modifier; + } else if (*modifiers_.begin() == (1ULL << 9)) { + modifier = " AFBC_FORMAT_MOD_SC"; + return ss + modifier; + } else if (*modifiers_.begin() == (1ULL << 10)) { + modifier = " AFBC_FORMAT_MOD_DB"; + return ss + modifier; + } else if (*modifiers_.begin() == (1ULL << 11)) { + modifier = " AFBC_FORMAT_MOD_BCH"; + return ss + modifier; + } + + std::map vendors = { + { 0, "NONE" }, + { 0x01, "INTEL" }, + { 0x02, "AMD" }, + { 0x03, "NVIDIA" }, + { 0x04, "SAMSUNG" }, + { 0x05, "QCOM" }, + { 0x06, "VIVANTE" }, + { 0x07, "BROADCOM" }, + { 0x08, "ARM" }, + { 0x09, "ALLWINNER" }, + { 0x0a, "MIPI" } + }; + + long int vendorCode = (*modifiers_.begin() >> 56) & 0xff; + + std::string vendor = vendors[vendorCode]; + + int modifierValue = *modifiers_.begin() & 0xff; + std::string vendorSpecification; + + switch (vendorCode) { + case 0: { + if (modifierValue == 0) + vendorSpecification = "Linear Layout"; + break; + } + case 0x01: { + 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 0x02: { + // no specifications + break; + } + case 0x03: { + 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 0x04: { + if (modifierValue == 1) + vendorSpecification = "Tiled, 64 (pixels) x 32 (lines)"; + else if (modifierValue == 2) + vendorSpecification = "Tiled, 16 (pixels) x 16 (lines)"; + break; + } + case 0x05: { + if (modifierValue == 1) + vendorSpecification = "Compressed"; + break; + } + case 0x06: { + 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 0x07: { + 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 0x08: { + vendorSpecification = "DRM_FORMAT_MOD_ARM_AFBC(" + modifierValue; + break; + } + case 0x09: { + if (modifierValue == 1) + vendorSpecification = "Tiled"; + break; + } + case 0x0a: { + if (modifierValue == 1) + vendorSpecification = "CSI-2 packed"; + break; + } + default: + break; + } + + modifier = vendor + ' ' + vendorSpecification; + std::string formatString(ss); + + return formatString + ' ' + modifier; } } /* 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..9676f27 --- /dev/null +++ b/test/pixel-format.cpp @@ -0,0 +1,55 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * libcamera pixel format handling test + */ + +#include +#include + +#include "libcamera/pixelformats.h" +#include "utils.h" + +#include "test.h" + +using namespace std; +using namespace libcamera; + +class PixelFormatTest : public Test +{ +protected: + int run() + { + std::vector> formats{ + { PixelFormat(0, { DRM_FORMAT_MOD_INVALID }), "" }, + { PixelFormat(DRM_FORMAT_SRGGB8, { DRM_FORMAT_MOD_LINEAR }), + "RGGB NONE Linear Layout" }, + { PixelFormat(DRM_FORMAT_C8, + { DRM_FORMAT_MOD_BROADCOM_SAND32_COL_HEIGHT(0) }), + "C8 BROADCOM SAND32" }, + { PixelFormat(DRM_FORMAT_YUV410, { AFBC_FORMAT_MOD_SPLIT }), + "YUV9 AFBC_FORMAT_MOD_SPLIT" }, + { PixelFormat(DRM_FORMAT_BIG_ENDIAN, { DRM_FORMAT_MOD_INVALID }), + "....-BE modifier" } + }; + 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)