Show a patch.

GET /api/1.1/patches/24756/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 24756,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/24756/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/24756/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20251023144841.403689-30-stefan.klug@ideasonboard.com>",
    "date": "2025-10-23T14:48:30",
    "name": "[v2,29/35] libcamera: rkisp1: Handle requested orientation using dewarper",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "d7ac6fa345f7271c42d1e4e29bf34155e554fd05",
    "submitter": {
        "id": 184,
        "url": "https://patchwork.libcamera.org/api/1.1/people/184/?format=api",
        "name": "Stefan Klug",
        "email": "stefan.klug@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/24756/mbox/",
    "series": [
        {
            "id": 5520,
            "url": "https://patchwork.libcamera.org/api/1.1/series/5520/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5520",
            "date": "2025-10-23T14:48:01",
            "name": "Full dewarper support on imx8mp",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/5520/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/24756/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/24756/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>",
        "X-Original-To": "parsemail@patchwork.libcamera.org",
        "Delivered-To": "parsemail@patchwork.libcamera.org",
        "Received": [
            "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 5772AC3336\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 23 Oct 2025 14:50:16 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id ED33260854;\n\tThu, 23 Oct 2025 16:50:15 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 59B6E607ED\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Oct 2025 16:50:14 +0200 (CEST)",
            "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:7328:357b:4ce1:72b6])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 62D8E1AA6; \n\tThu, 23 Oct 2025 16:48:29 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"bp+BjQYY\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1761230909;\n\tbh=fnekDP4Y6VsfeMeZXhHHLYR7osZb/stTo6p0peHGrrs=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=bp+BjQYYUp2//GnqxcbOuy2icDKtD0OlHM1sjAZM3XKoEONO8RZAlFYTb0St1O8Zd\n\tezlQ4TyVTEhjm34iVMYF64DXORI46w0K1ROu5zOI6gO6c4v5aLwkXfzg7geOhGOzni\n\ttrLJAMVnZdGsHIR+tIF1vuaI0OGibb82PKjsvhcs=",
        "From": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "Subject": "[PATCH v2 29/35] libcamera: rkisp1: Handle requested orientation\n\tusing dewarper",
        "Date": "Thu, 23 Oct 2025 16:48:30 +0200",
        "Message-ID": "<20251023144841.403689-30-stefan.klug@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.48.1",
        "In-Reply-To": "<20251023144841.403689-1-stefan.klug@ideasonboard.com>",
        "References": "<20251023144841.403689-1-stefan.klug@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "<libcamera-devel.lists.libcamera.org>",
        "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>",
        "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>",
        "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>",
        "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>",
        "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "When the dewarper is present it can handle arbitrary orientations\nspecified in the requested camera configuration. In that case handle all\ntransformations inside the dewarper (even if the sensor supports some of\nthem) because that makes it easier to handle coordinates for lens\ndewarping inside the dewarper.\n\nThis complicates the path selection a bit, as for transformations that\ninclude a transpose, the format before the dewarper has swapped\nwidth/height.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\n---\n\nChanges in v2:\n\n- Fix path validation for cases where a transpose is involved\n---\n src/libcamera/pipeline/rkisp1/rkisp1.cpp | 97 +++++++++++++++++-------\n 1 file changed, 71 insertions(+), 26 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex 943f26ece974..eaf82d0f1097 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -596,11 +596,6 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n \t\tstatus = Adjusted;\n \t}\n \n-\tOrientation requestedOrientation = orientation;\n-\tcombinedTransform_ = data_->sensor_->computeTransform(&orientation);\n-\tif (orientation != requestedOrientation)\n-\t\tstatus = Adjusted;\n-\n \t/*\n \t * Simultaneous capture of raw and processed streams isn't possible. If\n \t * there is any raw stream, cap the number of streams to one.\n@@ -618,9 +613,24 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n \t\t}\n \t}\n \n+\t/*\n+\t * If the dewarper supports orientation adjustments, apply that completely\n+\t * there. Even if the sensor supports flips, it is beneficial to do that\n+\t * in the dewarper so that lens dewarping happens on the unflipped image\n+\t */\n+\tbool transposeAfterIsp = false;\n \tbool useDewarper = false;\n-\tif (data_->canUseDewarper_ && !isRaw)\n+\tif (data_->canUseDewarper_ && !isRaw) {\n \t\tuseDewarper = true;\n+\t\tcombinedTransform_ = orientation / data_->sensor_->mountingOrientation();\n+\t\tif (!!(combinedTransform_ & Transform::Transpose))\n+\t\t\ttransposeAfterIsp = true;\n+\t} else {\n+\t\tOrientation requestedOrientation = orientation;\n+\t\tcombinedTransform_ = data_->sensor_->computeTransform(&orientation);\n+\t\tif (orientation != requestedOrientation)\n+\t\t\tstatus = Adjusted;\n+\t}\n \n \t/*\n \t * If there are more than one stream in the configuration figure out the\n@@ -636,12 +646,18 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n \n \t/*\n \t * Validate the configuration against the desired path and, if the\n-\t * platform supports it, the dewarper.\n+\t * platform supports it, the dewarper. While iterating over the\n+\t * configurations collect the smallest common sensor format.\n \t */\n+\tSize accumulatedSensorSize;\n \tauto validateConfig = [&](StreamConfiguration &cfg, RkISP1Path *path,\n \t\t\t\t  Stream *stream, Status expectedStatus) {\n \t\tStreamConfiguration tryCfg = cfg;\n \n+\t\t/* Need to validate the path before the transpose */\n+\t\tif (transposeAfterIsp)\n+\t\t\ttryCfg.size.transpose();\n+\n \t\tStatus ret = path->validate(sensor, sensorConfig, &tryCfg);\n \t\tif (ret == Invalid)\n \t\t\treturn false;\n@@ -650,6 +666,8 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n \t\t    (expectedStatus == Valid && ret == Adjusted))\n \t\t\treturn false;\n \n+\t\tSize sensorSize = tryCfg.size;\n+\n \t\tif (useDewarper) {\n \t\t\t/*\n \t\t\t * The dewarper output is independent of the ISP path.\n@@ -672,6 +690,8 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n \n \t\tcfg = tryCfg;\n \t\tcfg.setStream(stream);\n+\n+\t\taccumulatedSensorSize = std::max(accumulatedSensorSize, sensorSize);\n \t\treturn true;\n \t};\n \n@@ -722,13 +742,6 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n \t\treturn Invalid;\n \t}\n \n-\t/* Select the sensor format. */\n-\tSize maxSize;\n-\n-\tfor (const StreamConfiguration &cfg : config_) {\n-\t\tmaxSize = std::max(maxSize, cfg.size);\n-\t}\n-\n \tstd::vector<unsigned int> mbusCodes;\n \n \tif (isRaw) {\n@@ -739,7 +752,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n \t\t\t       [](const auto &value) { return value.second; });\n \t}\n \n-\tsensorFormat_ = sensor->getFormat(mbusCodes, maxSize,\n+\tsensorFormat_ = sensor->getFormat(mbusCodes, accumulatedSensorSize,\n \t\t\t\t\t  mainPath->maxResolution());\n \n \tif (sensorFormat_.size.isNull())\n@@ -774,6 +787,22 @@ PipelineHandlerRkISP1::generateConfiguration(Camera *camera,\n \tif (roles.empty())\n \t\treturn config;\n \n+\tTransform transform = Transform::Identity;\n+\tSize previewSize = kRkISP1PreviewSize;\n+\tbool transposeAfterIsp = false;\n+\tif (data->canUseDewarper_) {\n+\t\ttransform = Orientation::Rotate0 / data->sensor_->mountingOrientation();\n+\t\tif (!!(transform & Transform::Transpose))\n+\t\t\ttransposeAfterIsp = true;\n+\t}\n+\n+\t/*\n+\t * In case of a transpose transform we need to create a path for the\n+\t * transposed size.\n+\t */\n+\tif (transposeAfterIsp)\n+\t\tpreviewSize.transpose();\n+\n \t/*\n \t * As the ISP can't output different color spaces for the main and self\n \t * path, pick a sensible default color space based on the role of the\n@@ -802,7 +831,7 @@ PipelineHandlerRkISP1::generateConfiguration(Camera *camera,\n \t\t\tif (!colorSpace)\n \t\t\t\tcolorSpace = ColorSpace::Sycc;\n \n-\t\t\tsize = kRkISP1PreviewSize;\n+\t\t\tsize = previewSize;\n \t\t\tbreak;\n \n \t\tcase StreamRole::VideoRecording:\n@@ -810,7 +839,7 @@ PipelineHandlerRkISP1::generateConfiguration(Camera *camera,\n \t\t\tif (!colorSpace)\n \t\t\t\tcolorSpace = ColorSpace::Rec709;\n \n-\t\t\tsize = kRkISP1PreviewSize;\n+\t\t\tsize = previewSize;\n \t\t\tbreak;\n \n \t\tcase StreamRole::Raw:\n@@ -852,6 +881,9 @@ PipelineHandlerRkISP1::generateConfiguration(Camera *camera,\n \t\tif (!cfg.pixelFormat.isValid())\n \t\t\treturn nullptr;\n \n+\t\tif (transposeAfterIsp && role != StreamRole::Raw)\n+\t\t\tcfg.size.transpose();\n+\n \t\tcfg.colorSpace = colorSpace;\n \t\tcfg.bufferCount = kRkISP1MinBufferCount;\n \t\tconfig->addConfiguration(cfg);\n@@ -874,6 +906,19 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n \tif (ret)\n \t\treturn ret;\n \n+\tconst PixelFormat &streamFormat = config->at(0).pixelFormat;\n+\tconst PixelFormatInfo &info = PixelFormatInfo::info(streamFormat);\n+\tisRaw_ = info.colourEncoding == PixelFormatInfo::ColourEncodingRAW;\n+\tdata->usesDewarper_ = data->canUseDewarper_ && !isRaw_;\n+\n+\tTransform transform = config->combinedTransform();\n+\tbool transposeAfterIsp = false;\n+\tif (data->usesDewarper_) {\n+\t\tif (!!(transform & Transform::Transpose))\n+\t\t\ttransposeAfterIsp = true;\n+\t\ttransform = Transform::Identity;\n+\t}\n+\n \t/*\n \t * Configure the format on the sensor output and propagate it through\n \t * the pipeline.\n@@ -883,10 +928,10 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n \n \tif (config->sensorConfig)\n \t\tret = sensor->applyConfiguration(*config->sensorConfig,\n-\t\t\t\t\t\t config->combinedTransform(),\n+\t\t\t\t\t\t transform,\n \t\t\t\t\t\t &format);\n \telse\n-\t\tret = sensor->setFormat(&format, config->combinedTransform());\n+\t\tret = sensor->setFormat(&format, transform);\n \n \tif (ret < 0)\n \t\treturn ret;\n@@ -913,10 +958,6 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n \t\t<< \" crop \" << inputCrop;\n \n \tRectangle outputCrop = inputCrop;\n-\tconst PixelFormat &streamFormat = config->at(0).pixelFormat;\n-\tconst PixelFormatInfo &info = PixelFormatInfo::info(streamFormat);\n-\tisRaw_ = info.colourEncoding == PixelFormatInfo::ColourEncodingRAW;\n-\tdata->usesDewarper_ = dewarper_ && !isRaw_;\n \n \t/* YUYV8_2X8 is required on the ISP source path pad for YUV output. */\n \tif (!isRaw_)\n@@ -1008,15 +1049,19 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n \t\t\t\t\tinputCrop, sensorInfo.analogCrop);\n \t\t\t\tauto &vertexMap = dewarper_->vertexMap(cfg.stream());\n \t\t\t\tvertexMap.setSensorCrop(sensorCrop);\n+\t\t\t\tvertexMap.setTransform(config->combinedTransform());\n \t\t\t\tdata->properties_.set(properties::ScalerCropMaximum, sensorCrop);\n \n \t\t\t\t/*\n \t\t\t\t * Apply a default sensor crop that keeps the\n \t\t\t\t * aspect ratio.\n \t\t\t\t */\n-\t\t\t\tSize crop = format.size.boundedToAspectRatio(cfg.size);\n-\t\t\t\tvertexMap.setScalerCrop(crop.centeredTo(\n-\t\t\t\t\tRectangle(format.size).center()));\n+\t\t\t\tSize size = cfg.size;\n+\t\t\t\tif (transposeAfterIsp)\n+\t\t\t\t\tsize.transpose();\n+\t\t\t\tsize = sensorCrop.size().boundedToAspectRatio(size);\n+\t\t\t\tvertexMap.setScalerCrop(\n+\t\t\t\t\tsize.centeredTo(sensorCrop.center()));\n \t\t\t}\n \n \t\t\tret = mainPath_.configure(ispCfg, format);\n",
    "prefixes": [
        "v2",
        "29/35"
    ]
}