From patchwork Thu May 28 13:05:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaaira Gupta X-Patchwork-Id: 3870 Return-Path: Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 358A1603D3 for ; Thu, 28 May 2020 15:05:54 +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="uNG7qIBf"; dkim-atps=neutral Received: by mail-pl1-x636.google.com with SMTP id m7so11549132plt.5 for ; Thu, 28 May 2020 06:05:54 -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=C9bIOlFIYJCDsZT1GfV3LJzqxiq7iukGFxOiG3IbnLQ=; b=uNG7qIBf6Oy92GeI5ogghHd+iKL5m6O1vjr2/QjRl9HQWb+DCVCckmrbpg0vuUC2mD IgC/hjlDzl1Avz7gUlMqiHifk8PO6V1HSEBA5WHeVuHOXR+TjJWf6EctgmP5KcSF6kkD J+eZTjnwuT8UTY9lBxbmPLhq6MFufBjbIVfsj5i4zg+z8/+XkbCWHfDwwg/Mw6eHZ61m lBdYvGDFaMnW3VunDY2CZb3sjn/T+KlJwPxNH000hjAc1Tib1cvZ+K7lkNe5FDSar5/c VB5JVDHt1stJF1Yq1TzxwXBzYfIyoonej1nHvucF2dA6v6Q2l4+BD0Lj7SB75034fcJo f7HQ== 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=C9bIOlFIYJCDsZT1GfV3LJzqxiq7iukGFxOiG3IbnLQ=; b=J3BEu/JxLqCVgEo7f7YTWpvr0G0jE14GwGnaE3a+4ROF9egYn7t0pdk2dfiE63YccV Gelu1HKoiCnbxJPKOKsCja4hjcnTk96usXPzmsRPQc84Ld6C6S76dKnlM5Ltcb/AuzbS 6pV4zJ5FMrhX5L9cnesT0/3kWrDENG2GyakE4PUMMbIaVx+0rUOQrH6MhdJY6b6jo3Ez zwgmUpqWG0xbGYDgvXOb8v0dkxxr/cl1Q4pNV/s2JAET1aZDZ6Tl3FiHJoE52ypKlz9i fgHTZN0KOH7pJHb7xmdDKp90QWQfwKxACYAIyXC1HryOGxoP/hnS8oQTM+VtqoMPBHvI a/vQ== X-Gm-Message-State: AOAM532ZmFfm87/YI6jVaprCg8eLzl27rnyzBjUw478Al7Atch6LMDLO eNgoHT4Icr7DF+/OZXx7lKQJLzqprs4akA== X-Google-Smtp-Source: ABdhPJwJe/+2BxyrFg3Ywfn4jpz23IgK9XlMyZdL1fb3zPb5P9GRm4YkLMo99ZeJmjQhEVQunmm0Ag== X-Received: by 2002:a17:902:ea82:: with SMTP id x2mr3418419plb.174.1590671151825; Thu, 28 May 2020 06:05:51 -0700 (PDT) Received: from kaaira-HP-Pavilion-Notebook ([103.113.213.169]) by smtp.gmail.com with ESMTPSA id h35sm1663736pje.29.2020.05.28.06.05.49 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 May 2020 06:05:51 -0700 (PDT) Date: Thu, 28 May 2020 18:35:45 +0530 From: Kaaira Gupta To: libcamera-devel@lists.libcamera.org, Kieran Bingham Message-ID: <20200528130545.GA19932@kaaira-HP-Pavilion-Notebook> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Subject: [libcamera-devel] [PATCH v4] 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: Thu, 28 May 2020 13:05:54 -0000 Print fourCC characters instead of the hex values in toString() as they are easier to comprehend. Also, print the corresponding modifiers for MIPI vendor as it is mostly used in libcamera. Signed-off-by: Kaaira Gupta Reviewed-by: Kieran Bingham --- Changes since v3: -shortened the texts. -Removed default case as well. -changed commit message and tests to reflect the changes. Changes since v2: - Remove description for all vendors except for MIPI - Change commit message to reflect this change. - Change tests accordingly. 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 | 28 +++++++++++++++++--- test/meson.build | 1 + test/pixel-format.cpp | 47 ++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 test/pixel-format.cpp diff --git a/src/libcamera/pixelformats.cpp b/src/libcamera/pixelformats.cpp index 1330dc5..16aa7e4 100644 --- a/src/libcamera/pixelformats.cpp +++ b/src/libcamera/pixelformats.cpp @@ -6,6 +6,7 @@ */ #include +#include /** * \file pixelformats.h @@ -108,9 +109,30 @@ 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 fourcc[5] = { 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(fourcc[i])) + fourcc[i] = '.'; + } + + std::string formatString(fourcc); + + if (fourcc_ & (1 << 31)) + formatString += "-BE"; + + if (modifier_ == DRM_FORMAT_MOD_INVALID) + formatString += ": modifier"; + else if (modifier_ == MIPI_FORMAT_MOD_CSI2_PACKED) + formatString += ":packed"; + + return formatString; } } /* namespace libcamera */ diff --git a/test/meson.build b/test/meson.build index bd7da14..591d848 100644 --- a/test/meson.build +++ b/test/meson.build @@ -33,6 +33,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..84062b7 --- /dev/null +++ b/test/pixel-format.cpp @@ -0,0 +1,47 @@ +/* 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" }, + { PixelFormat(DRM_FORMAT_C8, DRM_FORMAT_MOD_SAMSUNG_64_32_TILE), "C8 " }, + { PixelFormat(DRM_FORMAT_BIG_ENDIAN, MIPI_FORMAT_MOD_CSI2_PACKED), "....-BE:packed" } + }; + 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)