summaryrefslogtreecommitdiff
path: root/test/camera/configuration_default.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/camera/configuration_default.cpp')
0 files changed, 0 insertions, 0 deletions
'n60' href='#n60'>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 Ltd
 *
 * contrast.cpp - contrast (gamma) control algorithm
 */
#include <stdint.h>

#include <libcamera/base/log.h>

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

#include "contrast.h"

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;
}

int Contrast::read(const libcamera::YamlObject &params)
{
	// enable adaptive enhancement by default
	config_.ceEnable = params["ce_enable"].get<int>(1);
	// the point near the bottom of the histogram to move
	config_.loHistogram = params["lo_histogram"].get<double>(0.01);
	// where in the range to try and move it to
	config_.loLevel = params["lo_level"].get<double>(0.015);
	// but don't move by more than this
	config_.loMax = params["lo_max"].get<double>(500);
	// equivalent values for the top of the histogram...
	config_.hiHistogram = params["hi_histogram"].get<double>(0.95);
	config_.hiLevel = params["hi_level"].get<double>(0.95);
	config_.hiMax = params["hi_max"].get<double>(2000);
	return config_.gammaCurve.read(params["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 (unsigned int i = 0; i < ContrastNumPoints - 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[ContrastNumPoints - 1].x = 65535;
	status.points[ContrastNumPoints - 1].y = 65535;
}