libcamera: formats: Add planeSize() helpers to PixelFormatInfo

Add two helpers functions to the PixelFormatInfo class to compute the
byte size of a given plane, taking the frame size, the stride, the
alignment constraints and the vertical subsampling into account.

Use the new functions through the code base to replace manual
implementations.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
This commit is contained in:
Laurent Pinchart 2021-09-01 23:22:40 +03:00
parent e85978ef5f
commit 94cbaa381a
5 changed files with 74 additions and 34 deletions

View file

@ -107,16 +107,9 @@ CameraBuffer::Private::Private([[maybe_unused]] CameraBuffer *cameraBuffer,
unsigned int offset = 0;
for (unsigned int i = 0; i < numPlanes; ++i) {
/*
* \todo Remove if this plane size computation function is
* added to PixelFormatInfo.
*/
const unsigned int vertSubSample = info.planes[i].verticalSubSampling;
const unsigned int stride = info.stride(size.width, i, 1u);
const unsigned int planeSize =
stride * ((size.height + vertSubSample - 1) / vertSubSample);
const unsigned int planeSize = info.planeSize(size, i);
planeInfo_[i].stride = stride;
planeInfo_[i].stride = info.stride(size.width, i, 1u);
planeInfo_[i].offset = offset;
planeInfo_[i].size = planeSize;