{"id":3870,"url":"https://patchwork.libcamera.org/api/1.1/patches/3870/?format=json","web_url":"https://patchwork.libcamera.org/patch/3870/","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":"<20200528130545.GA19932@kaaira-HP-Pavilion-Notebook>","date":"2020-05-28T13:05:45","name":"[libcamera-devel,v4] libcamera: PixelFormat: Replace hex with fourcc and modifiers","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"89098c2fb8aea9373ec36331fba5ebfa9bfdd5ab","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/3870/mbox/","series":[{"id":933,"url":"https://patchwork.libcamera.org/api/1.1/series/933/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=933","date":"2020-05-28T13:05:45","name":"[libcamera-devel,v4] libcamera: PixelFormat: Replace hex with fourcc and modifiers","version":4,"mbox":"https://patchwork.libcamera.org/series/933/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3870/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3870/checks/","tags":{},"headers":{"Return-Path":"<kgupta@es.iitr.ac.in>","Received":["from mail-pl1-x636.google.com (mail-pl1-x636.google.com\n\t[IPv6:2607:f8b0:4864:20::636])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 358A1603D3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 28 May 2020 15:05:54 +0200 (CEST)","by mail-pl1-x636.google.com with SMTP id m7so11549132plt.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 28 May 2020 06:05:54 -0700 (PDT)","from kaaira-HP-Pavilion-Notebook ([103.113.213.169])\n\tby smtp.gmail.com with ESMTPSA id\n\th35sm1663736pje.29.2020.05.28.06.05.49\n\t(version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256);\n\tThu, 28 May 2020 06:05:51 -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=\"uNG7qIBf\"; \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=C9bIOlFIYJCDsZT1GfV3LJzqxiq7iukGFxOiG3IbnLQ=;\n\tb=uNG7qIBf6Oy92GeI5ogghHd+iKL5m6O1vjr2/QjRl9HQWb+DCVCckmrbpg0vuUC2mD\n\tIgC/hjlDzl1Avz7gUlMqiHifk8PO6V1HSEBA5WHeVuHOXR+TjJWf6EctgmP5KcSF6kkD\n\tJ+eZTjnwuT8UTY9lBxbmPLhq6MFufBjbIVfsj5i4zg+z8/+XkbCWHfDwwg/Mw6eHZ61m\n\tlBdYvGDFaMnW3VunDY2CZb3sjn/T+KlJwPxNH000hjAc1Tib1cvZ+K7lkNe5FDSar5/c\n\tVB5JVDHt1stJF1Yq1TzxwXBzYfIyoonej1nHvucF2dA6v6Q2l4+BD0Lj7SB75034fcJo\n\tf7HQ==","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=C9bIOlFIYJCDsZT1GfV3LJzqxiq7iukGFxOiG3IbnLQ=;\n\tb=J3BEu/JxLqCVgEo7f7YTWpvr0G0jE14GwGnaE3a+4ROF9egYn7t0pdk2dfiE63YccV\n\tGelu1HKoiCnbxJPKOKsCja4hjcnTk96usXPzmsRPQc84Ld6C6S76dKnlM5Ltcb/AuzbS\n\t6pV4zJ5FMrhX5L9cnesT0/3kWrDENG2GyakE4PUMMbIaVx+0rUOQrH6MhdJY6b6jo3Ez\n\tzwgmUpqWG0xbGYDgvXOb8v0dkxxr/cl1Q4pNV/s2JAET1aZDZ6Tl3FiHJoE52ypKlz9i\n\tfgHTZN0KOH7pJHb7xmdDKp90QWQfwKxACYAIyXC1HryOGxoP/hnS8oQTM+VtqoMPBHvI\n\ta/vQ==","X-Gm-Message-State":"AOAM532ZmFfm87/YI6jVaprCg8eLzl27rnyzBjUw478Al7Atch6LMDLO\n\teNgoHT4Icr7DF+/OZXx7lKQJLzqprs4akA==","X-Google-Smtp-Source":"ABdhPJwJe/+2BxyrFg3Ywfn4jpz23IgK9XlMyZdL1fb3zPb5P9GRm4YkLMo99ZeJmjQhEVQunmm0Ag==","X-Received":"by 2002:a17:902:ea82:: with SMTP id\n\tx2mr3418419plb.174.1590671151825; \n\tThu, 28 May 2020 06:05:51 -0700 (PDT)","Date":"Thu, 28 May 2020 18:35:45 +0530","From":"Kaaira Gupta <kgupta@es.iitr.ac.in>","To":"libcamera-devel@lists.libcamera.org,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<20200528130545.GA19932@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 v4] 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":"Thu, 28 May 2020 13:05:54 -0000"},"content":"Print fourCC characters instead of the hex values in toString() as they\nare easier to comprehend. Also, print the corresponding modifiers for\nMIPI vendor as it is mostly used in libcamera.\n\nSigned-off-by: Kaaira Gupta <kgupta@es.iitr.ac.in>\n---\n\nChanges since v3:\n\t-shortened the texts.\n\t-Removed default case as well.\n\t-changed commit message and tests to reflect the changes.\n\nChanges since v2:\n        - Remove description for all vendors except for MIPI\n        - Change commit message to reflect this change.\n        - Change tests accordingly.\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 | 28 +++++++++++++++++---\n test/meson.build               |  1 +\n test/pixel-format.cpp          | 47 ++++++++++++++++++++++++++++++++++\n 3 files changed, 73 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..16aa7e4 100644\n--- a/src/libcamera/pixelformats.cpp\n+++ b/src/libcamera/pixelformats.cpp\n@@ -6,6 +6,7 @@\n  */\n \n #include <libcamera/pixelformats.h>\n+#include <string.h>\n \n /**\n  * \\file pixelformats.h\n@@ -108,9 +109,30 @@ 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 fourcc[5] = { static_cast<char>(fourcc_ & 0x7f),\n+\t\t\t   static_cast<char>((fourcc_ >> 8) & 0x7f),\n+\t\t\t   static_cast<char>((fourcc_ >> 16) & 0x7f),\n+\t\t\t   static_cast<char>((fourcc_ >> 24) & 0x7f) };\n+\n+\tfor (unsigned int i = 0; i < 4; i++) {\n+\t\tif (!isprint(fourcc[i]))\n+\t\t\tfourcc[i] = '.';\n+\t}\n+\n+\tstd::string formatString(fourcc);\n+\n+\tif (fourcc_ & (1 << 31))\n+\t\tformatString += \"-BE\";\n+\n+\tif (modifier_ == DRM_FORMAT_MOD_INVALID)\n+\t\tformatString += \":<INVALID> modifier\";\n+\telse if (modifier_ == MIPI_FORMAT_MOD_CSI2_PACKED)\n+\t\tformatString += \":packed\";\n+\n+\treturn formatString;\n }\n \n } /* namespace libcamera */\ndiff --git a/test/meson.build b/test/meson.build\nindex bd7da14..591d848 100644\n--- a/test/meson.build\n+++ b/test/meson.build\n@@ -33,6 +33,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..84062b7\n--- /dev/null\n+++ b/test/pixel-format.cpp\n@@ -0,0 +1,47 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2020, Kaaira Gupta\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\" },\n+\t\t\t{ PixelFormat(DRM_FORMAT_C8, DRM_FORMAT_MOD_SAMSUNG_64_32_TILE), \"C8  \" },\n+\t\t\t{ PixelFormat(DRM_FORMAT_BIG_ENDIAN, MIPI_FORMAT_MOD_CSI2_PACKED), \"....-BE:packed\" }\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","v4"]}