/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2021, Google Inc. * * camera_buffer.h - Frame buffer handling interface definition */ #pragma once #include #include #include #include #include class CameraBuffer final : public libcamera::Extensible { LIBCAMERA_DECLARE_PRIVATE() public: CameraBuffer(buffer_handle_t camera3Buffer, libcamera::PixelFormat pixelFormat, const libcamera::Size &size, int flags); ~CameraBuffer(); bool isValid() const; unsigned int numPlanes() const; libcamera::Span plane(unsigned int plane) const; libcamera::Span plane(unsigned int plane); unsigned int stride(unsigned int plane) const; unsigned int offset(unsigned int plane) const; unsigned int size(unsigned int plane) const; size_t jpegBufferSize(size_t maxJpegBufferSize) const; }; #define PUBLIC_CAMERA_BUFFER_IMPLEMENTATION \ CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, \ libcamera::PixelFormat pixelFormat, \ const libcamera::Size &size, int flags) \ : Extensible(std::make_unique(this, camera3Buffer, \ pixelFormat, size, \ flags)) \ { \ } \ CameraBuffer::~CameraBuffer() \ { \ } \ bool CameraBuffer::isValid() const \ { \ return _d()->isValid(); \ } \ unsigned int CameraBuffer::numPlanes() const \ { \ return _d()->numPlanes(); \ } \ Span CameraBuffer::plane(unsigned int plane) const \ { \ return const_cast(_d())->plane(plane); \ } \ Span CameraBuffer::plane(unsigned int plane) \ { \ return _d()->plane(plane); \ } \ unsigned int CameraBuffer::stride(unsigned int plane) const \ { \ return _d()->stride(plane); \ } \ unsigned int CameraBuffer::offset(unsigned int plane) const \ { \ return _d()->offset(plane); \ } \ unsigned int CameraBuffer::size(unsigned int plane) const \ { \ return _d()->size(plane); \ } \ size_t CameraBuffer::jpegBufferSize(size_t maxJpegBufferSize) const \ { \ return _d()->jpegBufferSize(maxJpegBufferSize); \ } e='committer'>committer
blob: f11c834a0192ce2c767997eddbab2c1667e7314b (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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/* SPDX-License-Identifier: BSD-2-Clause */
/*
 * Copyright (C) 2019, Raspberry Pi (Trading) Limited
 *
 * contrast.cpp - contrast (gamma) control algorithm
 */
#include <stdint.h>

#include <libcamera/base/log.h>

#include "../contrast_status.h"
#include "../histogram.hpp"

#include "contrast.hpp"

using namespace RPiController;
using namespace libcamera;

LOG_DEFINE_CATEGORY(RPiContrast)

/*
 * This is a very simple control algorithm which simply retrieves the results of
 * AGC and AWB via their "status" metadata, and applies digital gain to the
 * colour channels in accordance with those instructions. We take care never to
 * apply less than unity gains, as that would cause fully saturated pixels to go
 * off-white.
 */

#define NAME "rpi.contrast"

Contrast::Contrast(Controller *controller)
	: ContrastAlgorithm(controller), brightness_(0.0), contrast_(1.0)
{
}

char const *Contrast::name() const
{
	return NAME;
}

void Contrast::read(boost::property_tree::ptree const &params)
{
	/* enable adaptive enhancement by default */
	config_.ceEnable = params.get<int>("ce_enable", 1);
	/* the point near the bottom of the histogram to move */
	config_.loHistogram = params.get<double>("lo_histogram", 0.01);
	/* where in the range to try and move it to */
	config_.loLevel = params.get<double>("lo_level", 0.015);
	/* but don't move by more than this */
	config_.loMax = params.get<double>("lo_max", 500);
	/* equivalent values for the top of the histogram... */
	config_.hiHistogram = params.get<double>("hi_histogram", 0.95);
	config_.hiLevel = params.get<double>("hi_level", 0.95);
	config_.hiMax = params.get<double>("hi_max", 2000);
	config_.gammaCurve.read(params.get_child("gamma_curve"));
}

void Contrast::setBrightness(double brightness)
{
	brightness_ = brightness;
}

void Contrast::setContrast(double contrast)
{
	contrast_ = contrast;
}

static void fillInStatus(ContrastStatus &status, double brightness,
			 double contrast, Pwl &gammaCurve)
{
	status.brightness = brightness;
	status.contrast = contrast;
	for (int i = 0; i < CONTRAST_NUM_POINTS - 1; i++) {
		int x = i < 16 ? i * 1024
			       : (i < 24 ? (i - 16) * 2048 + 16384
					 : (i - 24) * 4096 + 32768);
		status.points[i].x = x;
		status.points[i].y = std::min(65535.0, gammaCurve.eval(x));
	}
	status.points[CONTRAST_NUM_POINTS - 1].x = 65535;
	status.points[CONTRAST_NUM_POINTS - 1].y = 65535;
}

void Contrast::initialise()
{
	/*
	 * Fill in some default values as Prepare will run before Process gets
	 * called.
	 */
	fillInStatus(status_, brightness_, contrast_, config_.gammaCurve);
}

void Contrast::prepare(Metadata *imageMetadata)
{
	std::unique_lock<std::mutex> lock(mutex_);