From patchwork Wed Dec 23 12:10:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Fricke X-Patchwork-Id: 10698 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id A1FBDC0F1A for ; Wed, 23 Dec 2020 12:11:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 717AC60529; Wed, 23 Dec 2020 13:11:17 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="X3r3K2iZ"; dkim-atps=neutral Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CABF460527 for ; Wed, 23 Dec 2020 13:11:15 +0100 (CET) Received: by mail-wm1-x331.google.com with SMTP id 3so5942526wmg.4 for ; Wed, 23 Dec 2020 04:11:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CAC/Tm4ejwSsZarJXbXK7kFPNNrqy+c4VbTAK8m4opA=; b=X3r3K2iZ3OVSKqVI/+okq46QaI1r0BtFYNCvhlZ1r6NxCP16cwEqYuqvewyph2vxfc TYSEjDQtXzeEJNg8lR3pKwiYhuqZZd2hkwdUnhsImQcSBSWMbhRR+bKrxr0LitL6GvV8 KHDfmEg90543mli2QPFfF68WdprYGq6YV88HGR5RzfPu8YmpFw1ukz66P2KsvYM2onzn Lk5g8DSBPF5X6tRpj0/VnZyKS/fSlyRi9szQa4g0elgEtACec2EWRedblVtMJWD7aTa8 Llz/fVURWRcqXofI0d5VmKq5FFRfvrkHJpbspfEDUDmwSEhQcvR3w+++kyiTdvw4OcNa HXfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CAC/Tm4ejwSsZarJXbXK7kFPNNrqy+c4VbTAK8m4opA=; b=f/ikVA5JbXv69MAKDGWo8odgggW1s9Jz5ixxpasaucjcbyGrI73Q50IprLZxcAV4g8 wmfsb/3oiAJ64Y1v5Mj6QpMuJDVXJBnB1GEMuhlCye0ITvkFpRezVUVx1REcyfVjnCB9 YIsrK1TBylMMmMfI+NEUMLcUURHx/3Bxfx4Iq4wH0+6t45BkHCT5OzSbmDbVUnrS/cdY h+4geNMskfxStU1eFndChWVCTRTF2QdNO+5lcrb2qcTSaev4wsHOxQjHzASIOhBxVXRM McpU8eWMsUt7IYHC6Ebu8GBZcdtKik3h7NQYRbxn7rOAwTRUYFqSPra8SeExr1ILROzM n/DQ== X-Gm-Message-State: AOAM531ndF1rFtAXVOEYxGWmp0Hb6oOMwObuYdFTbc1F5d/ZZPLNYHUe 5fPgvGtr/Axl2QWIUJt7WaD9dnrHIlWQpw== X-Google-Smtp-Source: ABdhPJxlj+iyaahbanRyrcrfryl88G27i0+JlsiGf0v4o6Ouhn2ebpTutKxSzYvM1joxZ50aGBpmFQ== X-Received: by 2002:a1c:6a10:: with SMTP id f16mr26279242wmc.106.1608725475651; Wed, 23 Dec 2020 04:11:15 -0800 (PST) Received: from basti.fritz.box (p200300d1ff2be200e1a8f8b471c12212.dip0.t-ipconnect.de. [2003:d1:ff2b:e200:e1a8:f8b4:71c1:2212]) by smtp.gmail.com with ESMTPSA id u6sm36787733wrm.90.2020.12.23.04.11.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Dec 2020 04:11:15 -0800 (PST) From: Sebastian Fricke To: libcamera-devel@lists.libcamera.org Date: Wed, 23 Dec 2020 13:10:54 +0100 Message-Id: <20201223121055.14178-2-sebastian.fricke.linux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201223121055.14178-1-sebastian.fricke.linux@gmail.com> References: <20201223121055.14178-1-sebastian.fricke.linux@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] libcamera: Add the fromV4L2PixelFormat method 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add the method to get the corresponding bayer-format from a given V4L2-pixel-format. Uses the existing mapping table. Signed-off-by: Sebastian Fricke --- include/libcamera/internal/bayer_format.h | 1 + src/libcamera/bayer_format.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h index 4280b76b..a8060029 100644 --- a/include/libcamera/internal/bayer_format.h +++ b/include/libcamera/internal/bayer_format.h @@ -48,6 +48,7 @@ public: std::string toString() const; V4L2PixelFormat toV4L2PixelFormat() const; + BayerFormat fromV4L2PixelFormat(V4L2PixelFormat v4l2Format) const; BayerFormat transform(Transform t) const; Order order; diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp index c42792ff..f4f0e8ca 100644 --- a/src/libcamera/bayer_format.cpp +++ b/src/libcamera/bayer_format.cpp @@ -217,6 +217,20 @@ V4L2PixelFormat BayerFormat::toV4L2PixelFormat() const return V4L2PixelFormat(); } +/** + * \brief Convert a V4L2PixelFormat into the corresponding BayerFormat + * \param[in] v4l2Format The raw format to convert into a BayerFormat + * \return The BayerFormat corresponding to the V4L2PixelFormat parameter + */ +BayerFormat BayerFormat::fromV4L2PixelFormat(V4L2PixelFormat v4l2Format) const +{ + const auto it = v4l2ToBayer.find(v4l2Format); + if (it != v4l2ToBayer.end()) + return it->second; + + return BayerFormat(); +} + /** * \brief Apply a transform to this BayerFormat * \param[in] t The transform to apply From patchwork Wed Dec 23 12:10:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Fricke X-Patchwork-Id: 10699 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 0AB5DC0F1A for ; Wed, 23 Dec 2020 12:11:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C9A1A615D2; Wed, 23 Dec 2020 13:11:18 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ojRcBXpa"; dkim-atps=neutral Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 17F8F60527 for ; Wed, 23 Dec 2020 13:11:18 +0100 (CET) Received: by mail-wr1-x42a.google.com with SMTP id y17so18399732wrr.10 for ; Wed, 23 Dec 2020 04:11:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Qg0t00pVXRsV+cmgeCBaO1VXuxMMdE09WxMARf1DwwU=; b=ojRcBXpa8RM+JhC4d44S65X2iWxP95sUsnjyLWFvgzweBGp3HpIfwvZxrJezjkfVE2 06+TachmrHYyXAVYe84lL5uxLiTQ8GtACsoDllCu++Q2LYW0QH9/weubZ7Ebust/vh4n 7RDs5YvB1esJg0qynWkmp5JfvjzU4bQoMl/cdMkEsVB+AksnUyju3sL//XMIofhC2Sqk B1YGmsPgeS3amnncEZPOu9wiq2lrZ+g0nJ6ktIP9ljF9AeZD4NX9zeiOq+EOI3a8jWci pqrFlw/2CZsd0KWw6m2CzuLOiGXYmtVASe5mKWCNSqiNPLMxRV0dBARI1oN59IzBoI6z tetg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Qg0t00pVXRsV+cmgeCBaO1VXuxMMdE09WxMARf1DwwU=; b=Wy+tf7XJg0DGiUKyCvAX83khwyTuR/nNs0s6upt4/0Idx72fLAQSUIxAy2tVneokpm C0S/CUrnwxgP1KJ1tZaILsWR7PS1Tyu5rcnRb9Sz2Kr+k9ik9VuMgdkp7tznaJJxOCnn 8lYlL7Owl+3r6uNPS6mIQzfgFQYM4Fzs/nWElZUK6IW2kGyYEgCC4qz7FpZagPsiEHjW ik3DHFvh0Au/y32qQWQTnZpFnXB0MUemrma55N7nVU9shdpYbVLHaEiyHWwy4SBHwa1l mLQrw7hhvbwalHpN9aODpl1AzwcYkFgrikA/hjio2z5zRzRWbD7rMT/qacumMIM/y9if WwcA== X-Gm-Message-State: AOAM531iPHHG85sgMlCcqFsyhz3mCVY2V2ur4x20WhIp9ODUw650vJOA tuYAkvVuFRgmNMZLGnGWf+gFHl2F6549xQ== X-Google-Smtp-Source: ABdhPJywjHGXpSOEjNX5bwNgGXrukB9TkqnKJUz9zDAtrD8+pNsuRiarKcmwW/GPbOd9WrruG15dZw== X-Received: by 2002:adf:e54a:: with SMTP id z10mr29462944wrm.1.1608725477848; Wed, 23 Dec 2020 04:11:17 -0800 (PST) Received: from basti.fritz.box (p200300d1ff2be200e1a8f8b471c12212.dip0.t-ipconnect.de. [2003:d1:ff2b:e200:e1a8:f8b4:71c1:2212]) by smtp.gmail.com with ESMTPSA id u6sm36787733wrm.90.2020.12.23.04.11.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Dec 2020 04:11:17 -0800 (PST) From: Sebastian Fricke To: libcamera-devel@lists.libcamera.org Date: Wed, 23 Dec 2020 13:10:55 +0100 Message-Id: <20201223121055.14178-3-sebastian.fricke.linux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201223121055.14178-1-sebastian.fricke.linux@gmail.com> References: <20201223121055.14178-1-sebastian.fricke.linux@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] test: Add unit tests for the BayerFormat class 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Test all of the present methods including the newly implemented `fromV4L2PixelFormat`. Signed-off-by: Sebastian Fricke --- test/bayer_format.cpp | 154 ++++++++++++++++++++++++++++++++++++++++++ test/meson.build | 1 + 2 files changed, 155 insertions(+) create mode 100644 test/bayer_format.cpp diff --git a/test/bayer_format.cpp b/test/bayer_format.cpp new file mode 100644 index 00000000..4d7c7ca1 --- /dev/null +++ b/test/bayer_format.cpp @@ -0,0 +1,154 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2020, Sebastian Fricke + * + * bayer_format.cpp - BayerFormat class tests + */ +#include +#include +#include + +#include "test.h" + +using namespace std; +using namespace libcamera; + +class BayerFormatTest : public Test +{ +protected: + int run() + { + /* + * TEST 1: A empty bayer format has to be invalid. + */ + BayerFormat bay_fmt = BayerFormat(); + if (bay_fmt.isValid()) { + cout << "TEST 1: FAIL: An empty bayer format " + << "has to be invalid." << endl; + return TestFail; + } + + /* + * TEST 2: A correct bayer format has to be valid. + */ + bay_fmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + if (!bay_fmt.isValid()) { + cout << "TEST 2: FAIL: A correct bayer format " + << "has to be valid." << endl; + return TestFail; + } + + /* + * TEST 3: Create a bayer format with a V4L2PixelFormat and + * check if we get the same format after converting + * back to the V4L2 Format. + */ + V4L2PixelFormat pix_fmt = V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8); + bay_fmt = BayerFormat(pix_fmt); + V4L2PixelFormat found_pix_fmt = bay_fmt.toV4L2PixelFormat(); + if (found_pix_fmt != pix_fmt) { + cout << "TEST 3: FAIL: expected: " + << pix_fmt.toString() << " got: " + << found_pix_fmt.toString() << endl; + return TestFail; + } + + /* + * TEST 4: Check if we get the expected bayer format BGGR8 + * when we convert the V4L2PixelFormat + * (V4L2_PIX_FMT_SBGGR8) to a bayer format. + */ + BayerFormat exp_bay_fmt = BayerFormat(BayerFormat::BGGR, 8, + BayerFormat::None); + BayerFormat found_bay_fmt = bay_fmt.fromV4L2PixelFormat( + pix_fmt); + if (found_bay_fmt.order != exp_bay_fmt.order || + found_bay_fmt.bitDepth != exp_bay_fmt.bitDepth || + found_bay_fmt.packing != exp_bay_fmt.packing) { + cout << "TEST 4: FAIL: Expected bayer format 'BGGR8'," + << "got: " << found_bay_fmt.toString() << endl; + return TestFail; + } + + /* TEST 5: Confirm that a V4L2PixelFormat that is not found in + * the conversion table, doesn't yield a bayer format. + */ + exp_bay_fmt = BayerFormat(); + found_bay_fmt = BayerFormat(); + V4L2PixelFormat unknownn_pix_fmt = V4L2PixelFormat( + V4L2_PIX_FMT_BGRA444); + found_bay_fmt = bay_fmt.fromV4L2PixelFormat(unknownn_pix_fmt); + if (found_bay_fmt.order != exp_bay_fmt.order || + found_bay_fmt.bitDepth != exp_bay_fmt.bitDepth || + found_bay_fmt.packing != exp_bay_fmt.packing) { + cout << "TEST 5: FAIL: expected empty bayer format got: " + << found_bay_fmt.toString() << endl; + return TestFail; + } + + /* + * TEST 6: Test if a valid bayer format can be converted to a + * string representation. + */ + if (bay_fmt.toString() != "BGGR-8") { + cout << "TEST 6: FAIL: String representation != 'BGGR8' (is: " + << bay_fmt.toString() << " ) " << endl; + return TestFail; + } + + /* + * TEST 7: Determine if an empty bayer format results in no + * string representation. + */ + bay_fmt = BayerFormat(); + if (bay_fmt.toString() != "INVALID") { + cout << "TEST 7: FAIL: String representation != 'INVALID' (is: " + << bay_fmt.toString() << " ) " << endl; + return TestFail; + } + + /* + * TEST 8: Perform a horizontal Flip and make sure that the + * order is adjusted accordingly. + */ + bay_fmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + BayerFormat h_flip_fmt = bay_fmt.transform(Transform::HFlip); + if (h_flip_fmt.toString() != "GBRG-8") { + cout << "TEST 8: FAIL: horizontal flip of 'BGGR-8' " + << "should result in 'GBRG-8', got: " + << h_flip_fmt.toString() << endl; + return TestFail; + } + + + /* + * TEST 9: Perform a horizontal Flip and make sure that the + * order is adjusted accordingly. + */ + bay_fmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + BayerFormat v_flip_fmt = bay_fmt.transform(Transform::VFlip); + if (v_flip_fmt.toString() != "GRBG-8") { + cout << "TEST 9: FAIL: vertical flip of 'BGGR-8' should " + << "result in 'GRBG-8', got: " + << v_flip_fmt.toString() << endl; + return TestFail; + } + + /* + * TEST 10: Perform a transposition and make sure that + * nothing changes. + */ + bay_fmt = BayerFormat(BayerFormat::BGGR, 8, BayerFormat::None); + BayerFormat t_fmt = bay_fmt.transform(Transform::Transpose); + if (t_fmt.toString() != "BGGR-8") { + cout << "TEST 10: FAIL: transposition not supported " + << "format should be 'BGGR-8', got: " + << t_fmt.toString() << endl; + return TestFail; + } + + return TestPass; + } +}; + +TEST_REGISTER(BayerFormatTest); diff --git a/test/meson.build b/test/meson.build index 0a1d434e..e985b0a0 100644 --- a/test/meson.build +++ b/test/meson.build @@ -23,6 +23,7 @@ public_tests = [ ] internal_tests = [ + ['bayer-format', 'bayer_format.cpp'], ['byte-stream-buffer', 'byte-stream-buffer.cpp'], ['camera-sensor', 'camera-sensor.cpp'], ['event', 'event.cpp'],