From patchwork Wed Oct 27 09:27:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 14358 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 D9801BDB1C for ; Wed, 27 Oct 2021 09:28:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6E05B64892; Wed, 27 Oct 2021 11:28:16 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="pg8rgFZr"; dkim-atps=neutral Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 852CF64885 for ; Wed, 27 Oct 2021 11:28:10 +0200 (CEST) Received: by mail-wr1-x434.google.com with SMTP id o14so2927055wra.12 for ; Wed, 27 Oct 2021 02:28:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dqhDVpcqqWaGNFNTkUlgCHkGNjN4Xyh6MA+fZBZUJt8=; b=pg8rgFZrPIi/gDYYZ0XrtCrBw5pkXqR/kjRZBWHe6Mk56sJUINJZtDUUQABCbPT++l LU8OmjpGUm0CxDC9BCB0VqojVd0Lal2YIEudo0kBwhTB7zBzab7YhJxDxSGCyayTiZeG r6a1vI00iN/pJ22YDO9DeFMt6hUWBxB2jpaeixxAOqJ78JYDZlCqDfzS6SZzl8QjFwd4 9YYBUtSdWfllJV/YyWofNh5oKKGx+hwPjX6OW6FvX28A4+Y9jPkH/+70/lylvK9mZyC9 wTuffXwpq4dD/+1+Y1YbDLKjTNIpu69A/WQLqgEgGA3gWvRhDFMPcXjiMSQ4QzGFLDIb 0XYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dqhDVpcqqWaGNFNTkUlgCHkGNjN4Xyh6MA+fZBZUJt8=; b=YGCE6sXaZ+XyKcUrIYxARL2xLNVXKbJV8DCNaEyIvInjpF5kHZlpgm/FIZrzppjih7 6vCsZ1ZX7XiupRmX/JzI/Ykgf1jOrZtRTp9AHR6TcSL3Xl5er8lcTiTgw9oYTAExxeUp neuTzzUjC+9I27IGvFH3dmRoUjGaBkatVsG6WPRx4abE25UXyR1q7v/WGf88WSxxrOrf vmvTvnW4hNh1J5MWvkkM2VsLJajPr3Ixbz2qdLcqJc5TAWaAVwJp+x+PuOhoLPUZqGwG i1wGaQe59y3LHYb+atJfR26zMyTaGp1/M3o5g6USNXdbdJDCoxXktgAT0tOHgZCFqzra pohA== X-Gm-Message-State: AOAM530EqyUyafx11fHsK+QCm67Kqs3KJrFU4xXcNw87ZodaJ79TDg0h DTjz1unZtJLEBMZDoQKrmL4Ht1kU0o7u7j55 X-Google-Smtp-Source: ABdhPJz6ZDMIfcpYWTHKoVL0A9dpa11Fw75iyMpjYwJ56kpwe3uxiActXrX8yPE+NVxUBwt4RDZqlQ== X-Received: by 2002:adf:a556:: with SMTP id j22mr37971095wrb.431.1635326890018; Wed, 27 Oct 2021 02:28:10 -0700 (PDT) Received: from naush-laptop.pitowers.org ([2a00:1098:3142:14:6561:eb24:3f00:ce98]) by smtp.gmail.com with ESMTPSA id x2sm2861360wmj.3.2021.10.27.02.28.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Oct 2021 02:28:09 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Date: Wed, 27 Oct 2021 10:27:58 +0100 Message-Id: <20211027092803.3671096-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211027092803.3671096-1-naush@raspberrypi.com> References: <20211027092803.3671096-1-naush@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 4/9] libcamera: bayer_format: Add PixelFormat conversion helpers to 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" Add BayerFormat::toPixelFormat() and BayerFormat::fromPixelFormat() helper functions to convert between BayerFormat and PixelFormat types. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- include/libcamera/internal/bayer_format.h | 4 ++++ src/libcamera/bayer_format.cpp | 29 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h index 723382d4168d..ee96b9a86707 100644 --- a/include/libcamera/internal/bayer_format.h +++ b/include/libcamera/internal/bayer_format.h @@ -10,6 +10,8 @@ #include #include +#include + #include "libcamera/internal/v4l2_pixelformat.h" namespace libcamera { @@ -50,6 +52,8 @@ public: V4L2PixelFormat toV4L2PixelFormat() const; static BayerFormat fromV4L2PixelFormat(V4L2PixelFormat v4l2Format); + PixelFormat toPixelFormat() const; + static BayerFormat fromPixelFormat(PixelFormat format); BayerFormat transform(Transform t) const; Order order; diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp index 94e2294d7f6c..1edd238829ce 100644 --- a/src/libcamera/bayer_format.cpp +++ b/src/libcamera/bayer_format.cpp @@ -305,6 +305,35 @@ BayerFormat BayerFormat::fromV4L2PixelFormat(V4L2PixelFormat v4l2Format) return BayerFormat(); } +/** + * \brief Convert a BayerFormat into the corresponding PixelFormat + * \return The PixelFormat corresponding to this BayerFormat + */ +PixelFormat BayerFormat::toPixelFormat() const +{ + const auto it = bayerToFormat.find(*this); + if (it != bayerToFormat.end()) + return it->second.pixelFormat; + + return PixelFormat(); +} + +/** + * \brief Convert a PixelFormat into the corresponding BayerFormat + * \return The BayerFormat corresponding to this PixelFormat + */ +BayerFormat BayerFormat::fromPixelFormat(PixelFormat format) +{ + auto it = std::find_if(bayerToFormat.begin(), bayerToFormat.end(), + [format](const auto &i) { + return i.second.pixelFormat == format; + }); + if (it == bayerToFormat.end()) + return BayerFormat{}; + + return it->first; +} + /** * \brief Apply a transform to this BayerFormat * \param[in] t The transform to apply