Message ID | 20241120085753.1993436-3-stefan.klug@ideasonboard.com |
---|---|
State | New |
Headers | show |
Series |
|
Related | show |
On Wed, Nov 20, 2024 at 09:57:41AM +0100, Stefan Klug wrote: > In the current code, the input stage of the image resizer is used to > apply a crop to keep the aspect ratio in cases where the requested > output aspect ratio differs from the one of the selected sensor mode. On > the imx8mp the resizer hardware is not capable of cropping (for > reference see also rkisp1-resizer.c:rkisp1_rsz_set_sink_crop() in the > linux kernel v6.10). > > Therefore apply the necessary cropping on the output of the ISP (on the > image stabilization block). The cropping code on the image resizer > doesn't need modifications as the requested crop gets ignored by the > kernel. > > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> > --- > src/libcamera/pipeline/rkisp1/rkisp1.cpp | 15 +++++++++++++++ > src/libcamera/pipeline/rkisp1/rkisp1_path.cpp | 6 ++++++ > 2 files changed, 21 insertions(+) > > diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp > index 5ffcfbce56be..9d36554cec6e 100644 > --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp > +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp > @@ -811,6 +811,21 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c) > if (!isRaw_) > format.code = MEDIA_BUS_FMT_YUYV8_2X8; > > + /* > + * On devices without DUAL_CROP (like the imx8mp) cropping needs to be > + * done on the ISP/IS output. > + */ > + if (media_->hwRevision() == RKISP1_V_IMX8MP) { > + const auto &cfg = config->at(0); > + Size ispCrop = format.size.boundedToAspectRatio(cfg.size) > + .alignedUpTo(2, 2); > + rect = ispCrop.centeredTo(Rectangle(format.size).center()); > + if (ispCrop != format.size) > + LOG(RkISP1, Info) << "ISP output needs to be cropped to " > + << rect; > + format.size = ispCrop; > + } > + > LOG(RkISP1, Debug) > << "Configuring ISP output pad with " << format > << " crop " << rect; > diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp > index 236d05af7a2f..0651de464907 100644 > --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp > +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp > @@ -417,6 +417,12 @@ int RkISP1Path::configure(const StreamConfiguration &config, > /* > * Crop on the resizer input to maintain FOV before downscaling. > * > + * Note that this does not apply on the imx8mp, where the cropping needs > + * to be done on the ImageStabilizer output and therefore is configured > + * before this stage. For simplicity we still set the crop. This gets > + * ignored by the kernel driver because the hardware is missing the > + * capability. > + * > * \todo The alignment to a multiple of 2 pixels is required but may > * change the aspect ratio very slightly. A more advanced algorithm to > * compute the resizer input crop rectangle is needed, and it should > -- > 2.43.0 >
diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 5ffcfbce56be..9d36554cec6e 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -811,6 +811,21 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c) if (!isRaw_) format.code = MEDIA_BUS_FMT_YUYV8_2X8; + /* + * On devices without DUAL_CROP (like the imx8mp) cropping needs to be + * done on the ISP/IS output. + */ + if (media_->hwRevision() == RKISP1_V_IMX8MP) { + const auto &cfg = config->at(0); + Size ispCrop = format.size.boundedToAspectRatio(cfg.size) + .alignedUpTo(2, 2); + rect = ispCrop.centeredTo(Rectangle(format.size).center()); + if (ispCrop != format.size) + LOG(RkISP1, Info) << "ISP output needs to be cropped to " + << rect; + format.size = ispCrop; + } + LOG(RkISP1, Debug) << "Configuring ISP output pad with " << format << " crop " << rect; diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp index 236d05af7a2f..0651de464907 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp @@ -417,6 +417,12 @@ int RkISP1Path::configure(const StreamConfiguration &config, /* * Crop on the resizer input to maintain FOV before downscaling. * + * Note that this does not apply on the imx8mp, where the cropping needs + * to be done on the ImageStabilizer output and therefore is configured + * before this stage. For simplicity we still set the crop. This gets + * ignored by the kernel driver because the hardware is missing the + * capability. + * * \todo The alignment to a multiple of 2 pixels is required but may * change the aspect ratio very slightly. A more advanced algorithm to * compute the resizer input crop rectangle is needed, and it should
In the current code, the input stage of the image resizer is used to apply a crop to keep the aspect ratio in cases where the requested output aspect ratio differs from the one of the selected sensor mode. On the imx8mp the resizer hardware is not capable of cropping (for reference see also rkisp1-resizer.c:rkisp1_rsz_set_sink_crop() in the linux kernel v6.10). Therefore apply the necessary cropping on the output of the ISP (on the image stabilization block). The cropping code on the image resizer doesn't need modifications as the requested crop gets ignored by the kernel. Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> --- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 15 +++++++++++++++ src/libcamera/pipeline/rkisp1/rkisp1_path.cpp | 6 ++++++ 2 files changed, 21 insertions(+)