summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo.mondi@ideasonboard.com>2023-03-21 18:20:02 +0100
committerJacopo Mondi <jacopo.mondi@ideasonboard.com>2023-06-06 18:59:26 +0200
commit311e5bc1a8fa06a858e3d930ea57bff796732c8d (patch)
tree515c5ac19a9fd3184e62fdb62018183155564f28
parentc6124d757cac2661108a806edc9b0a9b72b1abd3 (diff)
libcamera: rkisp1: Crop on ISP before downscaling
Crop on the resizer sink pad before downscaling to the aspect ratio of the desired output size. Cropping the input frame to the output aspect ratio allows to maintain the correct picture proportions, as otherwise downscaling would change the image geometry. Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
-rw-r--r--src/libcamera/pipeline/rkisp1/rkisp1_path.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
index 5079b268..0f728cea 100644
--- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
+++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
@@ -314,7 +314,18 @@ int RkISP1Path::configure(const StreamConfiguration &config,
if (ret < 0)
return ret;
- Rectangle rect(0, 0, ispFormat.size);
+ /*
+ * Crop on the resizer input to maintain FOV before downscaling.
+ *
+ * \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
+ * also take into account the need to crop away the edge pixels affected
+ * by the ISP processing blocks.
+ */
+ Size ispCrop = inputFormat.size.boundedToAspectRatio(config.size)
+ .alignedUpTo(2, 2);
+ Rectangle rect = ispCrop.centeredTo(Rectangle(inputFormat.size).center());
ret = resizer_->setSelection(0, V4L2_SEL_TGT_CROP, &rect);
if (ret < 0)
return ret;