Skip to content

Commit 8f729c8

Browse files
committed
libcamera: pipeline: raspberrypi: Fix scaler crop when sensor is configured
We must calculate the initial scaler crop when the camera is configured, otherwise the metadata will report this rectangle as being all zeroes. Because the calculation is identical to that performed later in handling the scaler crop control, we factor it into a small helper function, RPiCameraData::scaleIspCrop. Signed-off-by: David Plowman <[email protected]>
1 parent e68e0f1 commit 8f729c8

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/libcamera/pipeline/raspberrypi/raspberrypi.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ class RPiCameraData : public Camera::Private
212212
void handleStreamBuffer(FrameBuffer *buffer, RPi::Stream *stream);
213213
void handleExternalBuffer(FrameBuffer *buffer, RPi::Stream *stream);
214214
void handleState();
215+
Rectangle scaleIspCrop(const Rectangle &ispCrop) const;
215216
void applyScalerCrop(const ControlList &controls);
216217

217218
std::unique_ptr<ipa::RPi::IPAProxyRPi> ipa_;
@@ -887,6 +888,9 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)
887888
if (ret)
888889
LOG(RPI, Error) << "Failed to configure the IPA: " << ret;
889890

891+
/* Set the scaler crop to the value we are using (scaled to native sensor coordinates). */
892+
data->scalerCrop_ = data->scaleIspCrop(data->ispCrop_);
893+
890894
/*
891895
* Configure the Unicam embedded data output format only if the sensor
892896
* supports it.
@@ -1974,6 +1978,18 @@ void RPiCameraData::checkRequestCompleted()
19741978
}
19751979
}
19761980

1981+
Rectangle RPiCameraData::scaleIspCrop(const Rectangle &ispCrop) const
1982+
{
1983+
/*
1984+
* Scale a crop rectangle defined in the ISP's coordinates into native sensor
1985+
* coordinates.
1986+
*/
1987+
Rectangle nativeCrop = ispCrop.scaledBy(sensorInfo_.analogCrop.size(),
1988+
sensorInfo_.outputSize);
1989+
nativeCrop.translateBy(sensorInfo_.analogCrop.topLeft());
1990+
return nativeCrop;
1991+
}
1992+
19771993
void RPiCameraData::applyScalerCrop(const ControlList &controls)
19781994
{
19791995
if (controls.contains(controls::ScalerCrop)) {
@@ -2006,9 +2022,7 @@ void RPiCameraData::applyScalerCrop(const ControlList &controls)
20062022
* used. But we must first rescale that from ISP (camera mode) pixels
20072023
* back into sensor native pixels.
20082024
*/
2009-
scalerCrop_ = ispCrop_.scaledBy(sensorInfo_.analogCrop.size(),
2010-
sensorInfo_.outputSize);
2011-
scalerCrop_.translateBy(sensorInfo_.analogCrop.topLeft());
2025+
scalerCrop_ = scaleIspCrop(ispCrop_);
20122026
}
20132027
}
20142028
}

0 commit comments

Comments
 (0)