{"id":3402,"url":"https://patchwork.libcamera.org/api/1.1/patches/3402/?format=json","web_url":"https://patchwork.libcamera.org/patch/3402/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200404143123.GA14635@kaaira-HP-Pavilion-Notebook>","date":"2020-04-04T14:31:23","name":"[libcamera-devel,v2] libcamera: PixelFormat: Replace hex with fourcc and modifiers","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"5cea22b689737071c2b051257fb2e83d78b1ce67","submitter":{"id":39,"url":"https://patchwork.libcamera.org/api/1.1/people/39/?format=json","name":"Kaaira Gupta","email":"kgupta@es.iitr.ac.in"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/3402/mbox/","series":[{"id":798,"url":"https://patchwork.libcamera.org/api/1.1/series/798/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=798","date":"2020-04-04T14:31:23","name":"[libcamera-devel,v2] libcamera: PixelFormat: Replace hex with fourcc and modifiers","version":2,"mbox":"https://patchwork.libcamera.org/series/798/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3402/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3402/checks/","tags":{},"headers":{"Return-Path":"<kgupta@es.iitr.ac.in>","Received":["from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com\n\t[IPv6:2607:f8b0:4864:20::62e])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7E725600F4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  4 Apr 2020 16:31:32 +0200 (CEST)","by mail-pl1-x62e.google.com with SMTP id ay1so4016002plb.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 04 Apr 2020 07:31:32 -0700 (PDT)","from kaaira-HP-Pavilion-Notebook ([103.113.213.154])\n\tby smtp.gmail.com with ESMTPSA id\n\td3sm7961831pjz.2.2020.04.04.07.31.27\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tSat, 04 Apr 2020 07:31:29 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=es-iitr-ac-in.20150623.gappssmtp.com\n\theader.i=@es-iitr-ac-in.20150623.gappssmtp.com header.b=\"V/hKLa4x\"; \n\tdkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=es-iitr-ac-in.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:subject:message-id:mime-version:content-disposition\n\t:user-agent; bh=Lagxp7mTksqiVxkl6zk7baQtxHoVesy3CdC9+MN5ZNI=;\n\tb=V/hKLa4xyahNoptxxpmMVTWUnrATrbFLWApY2UhAmxCcRMfdlGdqsD3Pect5uWnXsF\n\tuEfSElzIaLe0PiMDmbU966w8kACPl3JIjQg4SjwtLQtLh1Nwbo0PiO4k5cmCZB3NKWtl\n\t80OR8dOq9vE+QWIvqq8NMDH5y8jvGnJDVVjEWNj5ZXIo+4895yupFPx2NJGMHIg2/F3b\n\t/SI+mj/XOOxAXu+3rzZ2Lg6DI7gmFXGMRNKZC7aaAgPk0aTDffJ0KFufhVKXSS2vYjDS\n\tSD3z64t6JuCP2Ab2yVsK3IfJCxfOdCNfBcVROAesvXSVHscZy8/5Ob8Qw0cJBcKyvyOO\n\tTF2g==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:subject:message-id:mime-version\n\t:content-disposition:user-agent;\n\tbh=Lagxp7mTksqiVxkl6zk7baQtxHoVesy3CdC9+MN5ZNI=;\n\tb=S5VmbyTcQkrswbtycw7nhsHZILoGwzqvWo6awZkMFXAFfqvA36BV3ig9AG15x/2VEz\n\tCMNbTkeyoySqUvYalAgp9wD7IOQ7licurWVTb2mXIkwgqkrO+5Up3/uQ4wmJL9idM/EY\n\tSKiZYaS/RRaufesiVs5a8daJ/RyyxqhnRJ3GoN43NGuAF5QYEPzddddx5fV7Kc27yEzI\n\t0jLYVHBx3k+HtWA3GYAH/VyBzeQXXideG6D5nSat4dz8SvrzlP5cgSSbInD1RtbO7b9D\n\tuaiCZKbAVCDM2qbQsHtiISnNMAMs7NKzedDE+10lALVN4ec92sy5mjaT0lQoSHyoPMBm\n\t5aLQ==","X-Gm-Message-State":"AGi0PuY4Y4XBZOEQT9g7Qb0M0frfKlmG/zPIQHi54zr67fn6O1rtCvJ2\n\tbpA5a00P62qKK0aYCYAr3HCDmkwTJwGp0w==","X-Google-Smtp-Source":"APiQypJoWd6YCYisNOo7NXX5V11pdE8kyKQ59SWBRFmYtIdF6qKXxFdJFg8HmwkwD2K1oF6KR2EVIg==","X-Received":"by 2002:a17:90a:3606:: with SMTP id\n\ts6mr16360208pjb.195.1586010690689; \n\tSat, 04 Apr 2020 07:31:30 -0700 (PDT)","Date":"Sat, 4 Apr 2020 20:01:23 +0530","From":"Kaaira Gupta <kgupta@es.iitr.ac.in>","To":"libcamera-devel@lists.libcamera.org,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tHelen Koike <helen.koike@collabora.com>,\n\tVaishali Thakkar <vthakkar@vaishalithakkar.in>","Message-ID":"<20200404143123.GA14635@kaaira-HP-Pavilion-Notebook>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","User-Agent":"Mutt/1.9.4 (2018-02-28)","Subject":"[libcamera-devel] [PATCH v2] libcamera: PixelFormat: Replace hex\n\twith fourcc and modifiers","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Sat, 04 Apr 2020 14:31:34 -0000"},"content":"Print fourCC characters instead of the hex values in toString() as they\nare easier to comprehend. Also, print the corresponding modifiers of the\nDRM formats so that it can be more specific.\n\nWrite the tests for them as well.\n\nSigned-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in>\n---\n\nChanges since v1:\n        - Replaced magic numbers with expressive values.\n        - Re-wrote ARM vendor's modifiers\n        - Re-wrote the vendors' map with a macro.\n        - Changed the copyrights in test file.\n        - Changed the tests.\n\n src/libcamera/pixelformats.cpp | 197 ++++++++++++++++++++++++++++++++-\n test/meson.build               |   1 +\n test/pixel-format.cpp          |  49 ++++++++\n 3 files changed, 244 insertions(+), 3 deletions(-)\n create mode 100644 test/pixel-format.cpp","diff":"diff --git a/src/libcamera/pixelformats.cpp b/src/libcamera/pixelformats.cpp\nindex 1330dc5..81159ee 100644\n--- a/src/libcamera/pixelformats.cpp\n+++ b/src/libcamera/pixelformats.cpp\n@@ -6,6 +6,17 @@\n  */\n \n #include <libcamera/pixelformats.h>\n+#include <map>\n+#include <string.h>\n+\n+#define PIXELFORMAT_VENDOR(vendor)\t\t    \\\n+        { DRM_FORMAT_MOD_VENDOR_## vendor, #vendor }\n+\n+#define AFBC_FORMAT_MOD_BLOCK(afbcBlock)\t\t    \\\n+\t\t{ AFBC_FORMAT_MOD_## afbcBlock, #afbcBlock }\n+\n+#define AFBC_FORMAT_MOD(modifier, mod)\t\t\t     \\\n+\t\t{ modifier & (AFBC_FORMAT_MOD_## mod), #mod }\n \n /**\n  * \\file pixelformats.h\n@@ -108,9 +119,189 @@ bool PixelFormat::operator<(const PixelFormat &other) const\n  */\n std::string PixelFormat::toString() const\n {\n-\tchar str[11];\n-\tsnprintf(str, 11, \"0x%08x\", fourcc_);\n-\treturn str;\n+\tif (fourcc_ == DRM_FORMAT_INVALID)\n+\t\treturn \"<INVALID>\";\n+\n+\tchar ss[8] = { static_cast<char>(fourcc_ & 0x7f),\n+\t\t       static_cast<char>((fourcc_ >> 8) & 0x7f),\n+\t\t       static_cast<char>((fourcc_ >> 16) & 0x7f),\n+\t\t       static_cast<char>((fourcc_ >> 24) & 0x7f) };\n+\n+\tfor (unsigned int i = 0; i < 4; i++) {\n+\t\tif (!isprint(ss[i]))\n+\t\t\tss[i] = '.';\n+\t}\n+\n+\tif (fourcc_ & (1 << 31))\n+\t\tstrcat(ss, \"-BE\");\n+\n+\tstd::string modifier;\n+\n+\tif (modifier_ == DRM_FORMAT_MOD_INVALID) {\n+\t\tmodifier = \" - <INVALID> modifier\";\n+\t\treturn ss + modifier;\n+\t}\n+\n+\t/* Map of all the vendors with their Ids: */\n+\tstd::map<long int, std::string> vendors = {\n+\t\tPIXELFORMAT_VENDOR(NONE),\n+\t\tPIXELFORMAT_VENDOR(INTEL),\n+\t\tPIXELFORMAT_VENDOR(AMD),\n+\t\tPIXELFORMAT_VENDOR(NVIDIA),\n+\t\tPIXELFORMAT_VENDOR(SAMSUNG),\n+\t\tPIXELFORMAT_VENDOR(QCOM),\n+\t\tPIXELFORMAT_VENDOR(VIVANTE),\n+\t\tPIXELFORMAT_VENDOR(BROADCOM),\n+\t\tPIXELFORMAT_VENDOR(ARM),\n+\t\tPIXELFORMAT_VENDOR(ALLWINNER),\n+\t\tPIXELFORMAT_VENDOR(MIPI)\n+\t};\n+\n+\tstd::map<long int, std::string> afbc_format_blocks = {\n+\t\tAFBC_FORMAT_MOD_BLOCK(BLOCK_SIZE_16x16),\n+\t\tAFBC_FORMAT_MOD_BLOCK(BLOCK_SIZE_32x8),\n+\t\tAFBC_FORMAT_MOD_BLOCK(BLOCK_SIZE_64x4),\n+\t\tAFBC_FORMAT_MOD_BLOCK(BLOCK_SIZE_32x8_64x4),\n+\n+\t};\n+\n+\tstd::map<long int, std::string> afbc_format_mod = {\n+\t\tAFBC_FORMAT_MOD(modifier_, YTR),\n+\t\tAFBC_FORMAT_MOD(modifier_, SPLIT),\n+\t\tAFBC_FORMAT_MOD(modifier_, SPARSE),\n+\t\tAFBC_FORMAT_MOD(modifier_, CBR),\n+\t\tAFBC_FORMAT_MOD(modifier_, TILED),\n+\t\tAFBC_FORMAT_MOD(modifier_, SC),\n+\t\tAFBC_FORMAT_MOD(modifier_, DB),\n+\t\tAFBC_FORMAT_MOD(modifier_, BCH),\n+\t};\n+\n+\t/* Get the vendor name using its Id */\n+\tlong int vendorCode = (modifier_ >> 56) & 0xff;\n+\tstd::string vendor = vendors[vendorCode];\n+\n+\tuint64_t modifierValue = modifier_ & 0xff;\n+\tstd::string vendorSpecification;\n+\n+\tswitch (vendorCode) {\n+\tcase DRM_FORMAT_MOD_VENDOR_NONE: {\n+\t\tif (modifierValue == 0)\n+\t\t\tvendorSpecification = \"Linear Layout\";\n+\t\tbreak;\n+\t}\n+\tcase DRM_FORMAT_MOD_VENDOR_INTEL: {\n+\t\tif (modifierValue == 1)\n+\t\t\tvendorSpecification = \"X-tiled\";\n+\t\telse if (modifierValue == 2)\n+\t\t\tvendorSpecification = \"Y-tiled\";\n+\t\telse if (modifierValue == 3)\n+\t\t\tvendorSpecification = \"Yf-tiled\";\n+\t\telse if (modifierValue == 4)\n+\t\t\tvendorSpecification = \"Y-tiled CCS\";\n+\t\telse if (modifierValue == 5)\n+\t\t\tvendorSpecification = \"Yf-tiled CSS\";\n+\t\telse if (modifierValue == 8)\n+\t\t\tvendorSpecification = \"Bayer packed\";\n+\t\tbreak;\n+\t}\n+\tcase DRM_FORMAT_MOD_VENDOR_AMD: {\n+\t\t// no specifications\n+\t\tbreak;\n+\t}\n+\tcase DRM_FORMAT_MOD_VENDOR_NVIDIA: {\n+\t\tif (modifierValue == 1)\n+\t\t\tvendorSpecification = \"Tegra-tiled\";\n+\t\telse if (modifierValue == 0x10)\n+\t\t\tvendorSpecification = \"ONE_GOB | v = 0\";\n+\t\telse if (modifierValue == 0x11)\n+\t\t\tvendorSpecification = \"TWO_GOB | v = 1\";\n+\t\telse if (modifierValue == 0x12)\n+\t\t\tvendorSpecification = \"FOUR_GOB | v = 2\";\n+\t\telse if (modifierValue == 0x13)\n+\t\t\tvendorSpecification = \"EIGHT_GOB | v = 3\";\n+\t\telse if (modifierValue == 0x14)\n+\t\t\tvendorSpecification = \"SIXTEEN_GOB | v = 4\";\n+\t\telse if (modifierValue == 0x15)\n+\t\t\tvendorSpecification = \"THIRTYTWO_GOB | v = 5\";\n+\t\tbreak;\n+\t}\n+\tcase DRM_FORMAT_MOD_VENDOR_SAMSUNG: {\n+\t\tif (modifierValue == 1)\n+\t\t\tvendorSpecification = \"Tiled, 64 (pixels) x 32 (lines)\";\n+\t\telse if (modifierValue == 2)\n+\t\t\tvendorSpecification = \"Tiled, 16 (pixels) x 16 (lines)\";\n+\t\tbreak;\n+\t}\n+\tcase DRM_FORMAT_MOD_VENDOR_QCOM: {\n+\t\tif (modifierValue == 1)\n+\t\t\tvendorSpecification = \"Compressed\";\n+\t\tbreak;\n+\t}\n+\tcase DRM_FORMAT_MOD_VENDOR_VIVANTE: {\n+\t\tif (modifierValue == 1)\n+\t\t\tvendorSpecification = \"4 x 4 tiled\";\n+\t\telse if (modifierValue == 2)\n+\t\t\tvendorSpecification = \"64 x 64 super-tiled\";\n+\t\telse if (modifierValue == 3)\n+\t\t\tvendorSpecification = \"4 x 4 split-tiled\";\n+\t\telse if (modifierValue == 4)\n+\t\t\tvendorSpecification = \"64 x 64 split-super-tiled\";\n+\t\tbreak;\n+\t}\n+\tcase DRM_FORMAT_MOD_VENDOR_BROADCOM: {\n+\t\tif (modifierValue == 1)\n+\t\t\tvendorSpecification = \"VC4-T-Tiled\";\n+\t\telse if (modifierValue == 6)\n+\t\t\tvendorSpecification = \"UIF\";\n+\t\telse if (modifierValue == 2)\n+\t\t\tvendorSpecification = \"SAND32\";\n+\t\telse if (modifierValue == 3)\n+\t\t\tvendorSpecification = \"SAND64\";\n+\t\telse if (modifierValue == 4)\n+\t\t\tvendorSpecification = \"SAND128\";\n+\t\telse if (modifierValue == 5)\n+\t\t\tvendorSpecification = \"SAND256\";\n+\t\tbreak;\n+\t}\n+\tcase DRM_FORMAT_MOD_VENDOR_ARM: {\n+\t\tuint8_t block_size = modifier_ & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK;\n+\n+\t\tif (afbc_format_blocks.count(block_size)) {\n+\t\t\tvendorSpecification = afbc_format_blocks[block_size] + \" | \";\n+\t\t};\n+\n+\t\tstd::map<long int, std::string>::iterator it;\n+\t\tfor (it = afbc_format_mod.begin(); it != afbc_format_mod.end(); it++) {\n+\t\t\tif (it->first != 0) {\n+\t\t\t\tvendorSpecification += it->second + \" | \";\n+\t\t\t}\n+\t\t}\n+\t\tbreak;\n+\t}\n+\tcase DRM_FORMAT_MOD_VENDOR_ALLWINNER: {\n+\t\tif (modifierValue == 1)\n+\t\t\tvendorSpecification = \"Tiled\";\n+\t\tbreak;\n+\t}\n+\tcase DRM_FORMAT_MOD_VENDOR_MIPI: {\n+\t\tif (modifierValue == 1)\n+\t\t\tvendorSpecification = \"CSI-2 packed\";\n+\t\tbreak;\n+\t}\n+\tdefault:\n+\t\tbreak;\n+\t}\n+\n+\tmodifier = vendor + \" : \" + vendorSpecification;\n+\tstd::string formatString(ss);\n+\tformatString = formatString + \" - \" + modifier;\n+\n+\t/* Trim last three characters of the string if last char is a space. */\n+\tif (isspace(formatString.back())) {\n+\t\tformatString = formatString.substr(0, formatString.size() - 3);\n+\t}\n+\n+\treturn formatString;\n }\n \n } /* namespace libcamera */\ndiff --git a/test/meson.build b/test/meson.build\nindex 8ab58ac..3f97278 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -30,6 +30,7 @@ internal_tests = [\n     ['message',                         'message.cpp'],\n     ['object',                          'object.cpp'],\n     ['object-invoke',                   'object-invoke.cpp'],\n+    ['pixel-format',                    'pixel-format.cpp'],\n     ['signal-threads',                  'signal-threads.cpp'],\n     ['threads',                         'threads.cpp'],\n     ['timer',                           'timer.cpp'],\ndiff --git a/test/pixel-format.cpp b/test/pixel-format.cpp\nnew file mode 100644\nindex 0000000..55cd916\n--- /dev/null\n+++ b/test/pixel-format.cpp\n@@ -0,0 +1,49 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2020, Kaaira Gupta\n+ *\n+ * libcamera pixel format handling test\n+ */\n+\n+#include <iostream>\n+#include <vector>\n+\n+#include \"libcamera/pixelformats.h\"\n+\n+#include \"test.h\"\n+\n+using namespace std;\n+using namespace libcamera;\n+\n+class PixelFormatTest : public Test\n+{\n+protected:\n+\tint run()\n+\t{\n+\t\tstd::vector<std::pair<PixelFormat, const char *>> formats{\n+\t\t\t{ PixelFormat(DRM_FORMAT_SRGGB8, DRM_FORMAT_MOD_INVALID), \"RGGB - <INVALID> modifier\" },\n+\t\t\t{ PixelFormat(DRM_FORMAT_SRGGB8, DRM_FORMAT_MOD_LINEAR), \"RGGB - NONE : Linear Layout\" },\n+\t\t\t{ PixelFormat(DRM_FORMAT_C8, DRM_FORMAT_MOD_ARM_AFBC(4)), \"C8   - ARM : BLOCK_SIZE_32x8_64x4\" },\n+\t\t\t{ PixelFormat(DRM_FORMAT_YUV410, DRM_FORMAT_MOD_ARM_AFBC(4|1ULL << 11)), \"YUV9 - ARM : BLOCK_SIZE_32x8_64x4 | BCH\"},\n+\t\t\t{ PixelFormat(DRM_FORMAT_BIG_ENDIAN, DRM_FORMAT_MOD_ALLWINNER_TILED), \"....-BE - ALLWINNER : Tiled\" }\n+\t\t};\n+\t\tfor (const auto &format : formats) {\n+\t\t\tif ((format.first).toString() != format.second) {\n+\t\t\t\tcerr << \"Failed to convert PixelFormat \"\n+\t\t\t\t     << format.first.fourcc() << \" to string\"\n+\t\t\t\t     << endl;\n+\t\t\t\treturn TestFail;\n+\t\t\t}\n+\t\t}\n+\n+\t\tif (PixelFormat().toString() != \"<INVALID>\") {\n+\t\t\tcerr << \"Failed to convert default PixelFormat to string\"\n+\t\t\t     << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n+\t\treturn TestPass;\n+\t}\n+};\n+\n+TEST_REGISTER(PixelFormatTest)\n","prefixes":["libcamera-devel","v2"]}