summaryrefslogtreecommitdiff
path: root/src/ipa/rkisp1/params.h
blob: 28a781bc447cafa5ba5f68789eacb12d6a42a152 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2024, Ideas On Board
 *
 * RkISP1 ISP Parameters
 */

#pragma once

#include <map>
#include <stdint.h>

#include <linux/rkisp1-config.h>

#include <libcamera/base/class.h>
#include <libcamera/base/span.h>

namespace libcamera {

namespace ipa::rkisp1 {

enum class BlockType {
	Bls,
	Dpcc,
	Sdg,
	AwbGain,
	Flt,
	Bdm,
	Ctk,
	Goc,
	Dpf,
	DpfStrength,
	Cproc,
	Ie,
	Lsc,
	Awb,
	Hst,
	Aec,
	Afc,
};

namespace details {

template<BlockType B>
struct block_type {
};

#define RKISP1_DEFINE_BLOCK_TYPE(blockType, blockStruct)		\
template<>								\
struct block_type<BlockType::blockType> {				\
	using type = struct rkisp1_cif_isp_##blockStruct##_config;	\
};

RKISP1_DEFINE_BLOCK_TYPE(Bls, bls)
RKISP1_DEFINE_BLOCK_TYPE(Dpcc, dpcc)
RKISP1_DEFINE_BLOCK_TYPE(Sdg, sdg)
RKISP1_DEFINE_BLOCK_TYPE(AwbGain, awb_gain)
RKISP1_DEFINE_BLOCK_TYPE(Flt, flt)
RKISP1_DEFINE_BLOCK_TYPE(Bdm, bdm)
RKISP1_DEFINE_BLOCK_TYPE(Ctk, ctk)
RKISP1_DEFINE_BLOCK_TYPE(Goc, goc)
RKISP1_DEFINE_BLOCK_TYPE(Dpf, dpf)
RKISP1_DEFINE_BLOCK_TYPE(DpfStrength, dpf_strength)
RKISP1_DEFINE_BLOCK_TYPE(Cproc, cproc)
RKISP1_DEFINE_BLOCK_TYPE(Ie, ie)
RKISP1_DEFINE_BLOCK_TYPE(Lsc, lsc)
RKISP1_DEFINE_BLOCK_TYPE(Awb, awb_meas)
RKISP1_DEFINE_BLOCK_TYPE(Hst, hst)
RKISP1_DEFINE_BLOCK_TYPE(Aec, aec)
RKISP1_DEFINE_BLOCK_TYPE(Afc, afc)

} /* namespace details */

class RkISP1Params;

class RkISP1ParamsBlockBase
{
public:
	RkISP1ParamsBlockBase(RkISP1Params *params, BlockType type,
			      const Span<uint8_t> &data);

	Span<uint8_t> data() const { return data_; }

	void setEnabled(bool enabled);

private:
	LIBCAMERA_DISABLE_COPY(RkISP1ParamsBlockBase)

	RkISP1Params *params_;
	BlockType type_;
	Span<uint8_t> header_;
	Span<uint8_t> data_;
};

template<BlockType B>
class RkISP1ParamsBlock : public RkISP1ParamsBlockBase
{
public:
	using Type = typename details::block_type<B>::type;

	RkISP1ParamsBlock(RkISP1Params *params, const Span<uint8_t> &data)
		: RkISP1ParamsBlockBase(params, B, data)
	{
	}

	const Type *operator->() const
	{
		return reinterpret_cast<const Type *>(data().data());
	}

	Type *operator->()
	{
		return reinterpret_cast<Type *>(data().data());
	}

	const Type &operator*() const &
	{
		return *reinterpret_cast<const Type *>(data().data());
	}

	Type &operator*() &
	{
		return *reinterpret_cast<Type *>(data().data());
	}
};

class RkISP1Params
{
public:
	RkISP1Params(uint32_t format, Span<uint8_t> data);

	template<BlockType B>
	RkISP1ParamsBlock<B> block()
	{
		return RkISP1ParamsBlock<B>(this, block(B));
	}

	uint32_t format() const { return format_; }
	size_t size() const { return used_; }

private:
	friend class RkISP1ParamsBlockBase;

	Span<uint8_t> block(BlockType type);
	void setBlockEnabled(BlockType type, bool enabled);

	uint32_t format_;

	Span<uint8_t> data_;
	size_t used_;

	std::map<BlockType, Span<uint8_t>> blocks_;
};

} /* namespace ipa::rkisp1 */

} /* namespace libcamera*/