summaryrefslogtreecommitdiff
path: root/include/linux/media-bus-format.h
diff options
context:
space:
mode:
authorUmang Jain <umang.jain@ideasonboard.com>2021-05-24 14:50:22 +0530
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-05-24 14:13:37 +0300
commitc76ca01323d8f7cb26b3a0c1137de92f7538a2c6 (patch)
treef636d016b2c304d4cc260cd3866bc323e5833fd0 /include/linux/media-bus-format.h
parent231d93557d8555d2bd713832203bb17b678d6ed0 (diff)
ipa: ipu3: Introduce IPAConfigInfo in IPC
IPAConfigInfo is a consolidated data structure passed from IPU3 pipeline-handler to IPU3 IPA. The structure can be extended with additional parameters to accommodate the requirements of multiple IPU3 IPA modules. Adapt the in-tree IPU3 IPA to use IPAConfigInfo as well. Signed-off-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'include/linux/media-bus-format.h')
0 files changed, 0 insertions, 0 deletions
'n126' href='#n126'>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
/* SPDX-License-Identifier: BSD-2-Clause */
/*
 * Copyright (C) 2019, Raspberry Pi (Trading) Limited
 *
 * histogram.cpp - histogram calculations
 */
#include "histogram.h"

#include <cmath>

#include "libcamera/internal/log.h"

/**
 * \file histogram.h
 * \brief Class to represent Histograms and manipulate them
 */

namespace libcamera {

namespace ipa {

/**
 * \class Histogram
 * \brief The base class for creating histograms
 *
 * This class stores a cumulative frequency histogram, which is a mapping that
 * counts the cumulative number of observations in all of the bins up to the
 * specified bin. It can be used to find quantiles and averages between quantiles.
 */

/**
 * \brief Create a cumulative histogram
 * \param[in] data A pre-sorted histogram to be passed
 */
Histogram::Histogram(Span<uint32_t> data)
{
	cumulative_.reserve(data.size());
	cumulative_.push_back(0);
	for (const uint32_t &value : data)
		cumulative_.push_back(cumulative_.back() + value);
}

/**
 * \fn Histogram::bins()
 * \brief Retrieve the number of bins currently used by the Histogram
 * \return Number of bins
 */

/**
 * \fn Histogram::total()
 * \brief Retrieve the total number of values in the data set
 * \return Number of values
 */

/**
 * \brief Cumulative frequency up to a (fractional) point in a bin.
 * \param[in] bin The bin up to which to cumulate
 *
 * With F(p) the cumulative frequency of the histogram, the value is 0 at
 * the bottom of the histogram, and the maximum is the number of bins.
 * The pixels are spread evenly throughout the “bin” in which they lie, so that
 * F(p) is a continuous (monotonically increasing) function.
 *
 * \return The cumulative frequency from 0 up to the specified bin
 */
uint64_t Histogram::cumulativeFrequency(double bin) const
{
	if (bin <= 0)
		return 0;
	else if (bin >= bins())
		return total();
	int b = static_cast<int32_t>(bin);
	return cumulative_[b] +
	       (bin - b) * (cumulative_[b + 1] - cumulative_[b]);
}

/**
 * \brief Return the (fractional) bin of the point through the histogram
 * \param[in] q the desired point (0 <= q <= 1)
 * \param[in] first low limit (default is 0)
 * \param[in] last high limit (default is UINT_MAX)
 *
 * A quantile gives us the point p = Q(q) in the range such that a proportion
 * q of the pixels lie below p. A familiar quantile is Q(0.5) which is the median
 * of a distribution.
 *
 * \return The fractional bin of the point
 */
double Histogram::quantile(double q, uint32_t first, uint32_t last) const
{
	if (last == UINT_MAX)
		last = cumulative_.size() - 2;
	ASSERT(first <= last);

	uint64_t item = q * total();
	/* Binary search to find the right bin */
	while (first < last) {
		int middle = (first + last) / 2;
		/* Is it between first and middle ? */
		if (cumulative_[middle + 1] > item)
			last = middle;
		else
			first = middle + 1;
	}
	ASSERT(item >= cumulative_[first] && item <= cumulative_[last + 1]);

	double frac;