ipa: rkisp1: agc: Simplify predivider calculation

The condition

	if (std::pow(std::floor(root), 2) < factor)
		predivider = static_cast<uint8_t>(std::ceil(root));
	else
		predivider = static_cast<uint8_t>(std::floor(root));

can only be false when the factor's root is an integer. In that case,
std::ceil(root) and std::floor(root) will be equal. The computation can
thus be simplified by always rounding up.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Laurent Pinchart 2024-06-16 00:34:16 +03:00
parent 05d0f952a3
commit ea43e056a8

View file

@ -115,12 +115,7 @@ uint8_t Agc::computeHistogramPredivider(const Size &size,
int count = mode == RKISP1_CIF_ISP_HISTOGRAM_MODE_RGB_COMBINED ? 3 : 1; int count = mode == RKISP1_CIF_ISP_HISTOGRAM_MODE_RGB_COMBINED ? 3 : 1;
double factor = size.width * size.height * count / 65536.0; double factor = size.width * size.height * count / 65536.0;
double root = std::sqrt(factor); double root = std::sqrt(factor);
uint8_t predivider; uint8_t predivider = static_cast<uint8_t>(std::ceil(root));
if (std::pow(std::floor(root), 2) < factor)
predivider = static_cast<uint8_t>(std::ceil(root));
else
predivider = static_cast<uint8_t>(std::floor(root));
return std::clamp<uint8_t>(predivider, 3, 127); return std::clamp<uint8_t>(predivider, 3, 127);
} }