From patchwork Tue Jun 8 14:44:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 12519 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 13323BD22E for ; Tue, 8 Jun 2021 14:44:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B4122602A7; Tue, 8 Jun 2021 16:44:19 +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="oklJMHz9"; dkim-atps=neutral Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D27E5602A7 for ; Tue, 8 Jun 2021 16:44:17 +0200 (CEST) Received: by mail-wr1-x42d.google.com with SMTP id a20so21936961wrc.0 for ; Tue, 08 Jun 2021 07:44:17 -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=tU0Kgc4GIfvHcEcZhIZFYCoGFnSm56EXIbRc7F5nySU=; b=oklJMHz9WudEoA/SEDjRqhilKCdt2ARNfDY40tgi6+24jgMElRlxDtcfYrlQEeIgaO nXYh6nzkQJlLqONLI3+g2j03jYbfXXyotNa0f2+UV1FsbjoIS+dpOIDaq5XStF53Frlm 4LafXOe6xujysS6xBMYIuGvKDTs8QgtI6iTPKRD25/8Ci1wWo3fu9Fa1yWK7GPpTXdRF 9ZYJZoiyVK1b/bvWzA9oyUNjsjCTTAVnHQ0C6gqio/ivDwRRiIIzzHOfFYEUGg/tciN3 Lr0BsFGkyzPyNrK5Oi/R1UEvulPGjHAyrJXIJgzfl0NBmM/P+GT9/LmET48tBV6Rk4lK 0ULQ== 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=tU0Kgc4GIfvHcEcZhIZFYCoGFnSm56EXIbRc7F5nySU=; b=rh8CSxAlZrvZrzgRQacQBpYzi6XaL2B22/SOh6YqAKf/xYgOvW+W1YUChoOMX4vdC6 vhKYK6/3XR0hYFytlh3NpoLFtWuZVyOhmj6W0RxLX5xGrrbN66UzyjY/h/8JUuY9zy1H XgTg5FAan4xQP5tDWQKjrv4qtxl3dIhxKRE+ScdBsuT/KdPs5qOGmgEtPn+q6yz3Hvt9 mZ/rZmQPpJwjpprideKdtF+eoYN2QjgUQRmofG19v0g+WhKb0C+VNVxFOXrnwVRy2Ck8 fjT8Hn3EuHM20JTMcCOZFeMue63tOF0qz/lm5HsROaT9nTF2dszYX4gitUqQNswo0jsU sqow== X-Gm-Message-State: AOAM532MTIiz8GhbqQyrjJPiLzMLhkJfVKjBmKTLHKGIG5/a9qjbQURT K34epNjQ3uR93AamA6AbSoOlK0FA/vJ/xmK2 X-Google-Smtp-Source: ABdhPJzW44Lcju/Xck5Bm/h69OihMCNS0vxZ5WDW/l8vyIILhTJsjFvnHYYuwpSnDsxFJz887iwsYA== X-Received: by 2002:a5d:638b:: with SMTP id p11mr4363402wru.380.1623163457180; Tue, 08 Jun 2021 07:44:17 -0700 (PDT) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:1ce1:9965:4328:89c4]) by smtp.gmail.com with ESMTPSA id i21sm3053173wmq.12.2021.06.08.07.44.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 07:44:16 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Jun 2021 15:44:11 +0100 Message-Id: <20210608144413.1529-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210608144413.1529-1-david.plowman@raspberrypi.com> References: <20210608144413.1529-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 1/3] libcamera: Add ColorSpace 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" This class represents a colour space by defining its YCbCr encoding, the transfer (gamma) function is uses, and whether the output is full or limited range. --- include/libcamera/color_space.h | 94 +++++++++++++++++++++++++++++++++ include/libcamera/meson.build | 1 + src/libcamera/color_space.cpp | 43 +++++++++++++++ src/libcamera/meson.build | 1 + 4 files changed, 139 insertions(+) create mode 100644 include/libcamera/color_space.h create mode 100644 src/libcamera/color_space.cpp diff --git a/include/libcamera/color_space.h b/include/libcamera/color_space.h new file mode 100644 index 00000000..3d990f99 --- /dev/null +++ b/include/libcamera/color_space.h @@ -0,0 +1,94 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Raspberry Pi (Trading) Limited + * + * color_space.h - color space definitions + */ + +#ifndef __LIBCAMERA_COLOR_SPACE_H__ +#define __LIBCAMERA_COLOR_SPACE_H__ + +#include + +namespace libcamera { + +class ColorSpace +{ +public: + enum class Encoding : int { + UNDEFINED, + RAW, + REC601, + REC709, + REC2020, + VIDEO, + }; + + enum class TransferFunction : int { + UNDEFINED, + IDENTITY, + SRGB, + REC709, + }; + + enum class Range : int { + UNDEFINED, + FULL, + LIMITED, + }; + + constexpr ColorSpace(Encoding e, TransferFunction t, Range r) + : encoding(e), transferFunction(t), range(r) + { + } + + constexpr ColorSpace() + : ColorSpace(Encoding::UNDEFINED, TransferFunction::UNDEFINED, Range::UNDEFINED) + { + } + + static const ColorSpace UNDEFINED; + static const ColorSpace RAW; + static const ColorSpace JFIF; + static const ColorSpace SMPTE170M; + static const ColorSpace REC709; + static const ColorSpace REC2020; + static const ColorSpace VIDEO; + + Encoding encoding; + TransferFunction transferFunction; + Range range; + + bool isFullyDefined() const + { + return encoding != Encoding::UNDEFINED && + transferFunction != TransferFunction::UNDEFINED && + range != Range::UNDEFINED; + } + + const std::string toString() const; +}; + +constexpr ColorSpace ColorSpace::UNDEFINED = { Encoding::UNDEFINED, TransferFunction::UNDEFINED, Range::UNDEFINED }; +constexpr ColorSpace ColorSpace::RAW = { Encoding::RAW, TransferFunction::IDENTITY, Range::FULL }; +constexpr ColorSpace ColorSpace::JFIF = { Encoding::REC601, TransferFunction::SRGB, Range::FULL }; +constexpr ColorSpace ColorSpace::SMPTE170M = { Encoding::REC601, TransferFunction::REC709, Range::LIMITED }; +constexpr ColorSpace ColorSpace::REC709 = { Encoding::REC709, TransferFunction::REC709, Range::LIMITED }; +constexpr ColorSpace ColorSpace::REC2020 = { Encoding::REC2020, TransferFunction::REC709, Range::LIMITED }; +constexpr ColorSpace ColorSpace::VIDEO = { Encoding::VIDEO, TransferFunction::REC709, Range::LIMITED }; + +static inline bool operator==(const ColorSpace &lhs, const ColorSpace &rhs) +{ + return lhs.encoding == rhs.encoding && + lhs.transferFunction == rhs.transferFunction && + lhs.range == rhs.range; +} + +static inline bool operator!=(const ColorSpace &lhs, const ColorSpace &rhs) +{ + return !(lhs == rhs); +} + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_COLOR_SPACE_H__ */ diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build index 086c958b..7d61d285 100644 --- a/include/libcamera/meson.build +++ b/include/libcamera/meson.build @@ -6,6 +6,7 @@ libcamera_public_headers = files([ 'camera.h', 'camera_manager.h', 'class.h', + 'color_space.h', 'compiler.h', 'controls.h', 'file_descriptor.h', diff --git a/src/libcamera/color_space.cpp b/src/libcamera/color_space.cpp new file mode 100644 index 00000000..888762ae --- /dev/null +++ b/src/libcamera/color_space.cpp @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Raspberry Pi (Trading) Limited + * + * color_space.cpp - color spaces. + */ + +#include + +/** + * \file color_space.h + * \brief Class and enums to represent colour spaces. + */ + +namespace libcamera { + +const std::string ColorSpace::toString() const +{ + static const char *encodings[] = { + "UNDEFINED", + "RAW", + "REC601", + "REC709", + "REC2020", + }; + static const char *transferFunctions[] = { + "UNDEFINED", + "IDENTITY", + "SRGB", + "REC709", + }; + static const char *ranges[] = { + "UNDEFINED", + "FULL", + "LIMITED", + }; + + return std::string(encodings[static_cast(encoding)]) + "+" + + std::string(transferFunctions[static_cast(transferFunction)]) + "+" + + std::string(ranges[static_cast(range)]); +} + +} /* namespace libcamera */ diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 7e19a177..f7b48a32 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -11,6 +11,7 @@ libcamera_sources = files([ 'camera_sensor.cpp', 'camera_sensor_properties.cpp', 'class.cpp', + 'color_space.cpp', 'controls.cpp', 'control_serializer.cpp', 'control_validator.cpp',