{"id":27155,"url":"https://patchwork.libcamera.org/api/patches/27155/?format=json","web_url":"https://patchwork.libcamera.org/patch/27155/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260702095903.79640-1-david.plowman@raspberrypi.com>","date":"2026-07-02T09:57:35","name":"pipeline: rpi: pisp: Fix colours for NV21 and NV61 pixel formats","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"882a9c33ab309c6c73d56d0d6eb99d581bfe61ca","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/?format=json","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/27155/mbox/","series":[{"id":6032,"url":"https://patchwork.libcamera.org/api/series/6032/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=6032","date":"2026-07-02T09:57:35","name":"pipeline: rpi: pisp: Fix colours for NV21 and NV61 pixel formats","version":1,"mbox":"https://patchwork.libcamera.org/series/6032/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/27155/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/27155/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 E7461C3302\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  2 Jul 2026 09:59:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0DF0D65FB6;\n\tThu,  2 Jul 2026 11:59:08 +0200 (CEST)","from mail-wr1-x429.google.com (mail-wr1-x429.google.com\n\t[IPv6:2a00:1450:4864:20::429])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E5323656DE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  2 Jul 2026 11:59:05 +0200 (CEST)","by mail-wr1-x429.google.com with SMTP id\n\tffacd0b85a97d-475881b9a4bso1644121f8f.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 02 Jul 2026 02:59:05 -0700 (PDT)","from davidp-pi5.pitowers.org\n\t([2a00:1098:3142:1f:4706:89ee:c47e:1087])\n\tby smtp.gmail.com with ESMTPSA id\n\tffacd0b85a97d-477ddf0f433sm8345917f8f.32.2026.07.02.02.59.04\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 02 Jul 2026 02:59:04 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"CJKq00ch\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1782986345; x=1783591145;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:from:to:cc:subject:date:message-id:reply-to:content-type;\n\tbh=LE+NzfGoGt9Hwzeu6FwUq+Tz6ZZOTWRrQoy37bAYpbA=;\n\tb=CJKq00chHDXn4qZsVYLU/Hrx8YOKIo9KLeKdezzDAonXiyDuP2T8UjGX9A5md4J5bj\n\tFVCZE5G1tnWzUk2vh5yR5PdyNajmwZQFNtb9vmDRc1OCy4IwNRFvXv6qi54wVD4nRIMp\n\t/2IcaqhmVa1heqFMsBThPrFbvdKpB0VjO8XFgG2WI8Lc/9A3ORHS4LHAic8BMP11lMqH\n\tsK0LH9zgbfNDsd4zq8b6O9DFDKV1ZmgWXpiEDkaP+A1EMfUs8lx/k8VzAFNnnXvquw14\n\ttUc/lLt8YKR2wOdy1fw6z8OK79wCiWYUFLHzeHumkG2PGtMFiz5nsadEs1w0jK2gYcVL\n\tcerA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20251104; t=1782986345; x=1783591145;\n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to:content-type;\n\tbh=LE+NzfGoGt9Hwzeu6FwUq+Tz6ZZOTWRrQoy37bAYpbA=;\n\tb=g20NWUFqcZCI4V97DOfAv02VQRlZ9lHfxE5OuoAYfaZiFKaal4nHLSFau1E5e1Irqc\n\t7/ogabgFFHmRBo/pSfxOGhZc7imY7jhpfBelfVAeCvxyaTdzFM/MJJ7Vqm1dzY+kEUE/\n\tMcdIBoMKiDMwgbnwglxz64AsNSBLuNK7kELCWUwGAybaYytdn/vAE4q4rF2Fr3fbrMea\n\t8rGrTKPgk8fMXCbLJabwaekGnDTSrRiEN8byDckWwzSkUs/HSn99vtHrUHhwpK4vST2v\n\tUZiuDk1rYDEfzve7u1ckZcB+ZUIdESNOxkrpRIRnhwxhTX/BUvLoFEp67xcnmCTh30Yk\n\thTbg==","X-Gm-Message-State":"AOJu0Yxt3BmYC8T1xtJVgs1Jgc7U2/9GlJabpJQuTh6ilvy+2mYRDkt1\n\tYjJqQuQ/i5LS8ZGh1vVwJRa+LBbWSZPBcTYdx+4Ebz1A5SepP80fnRU9nN9MmGQ/Qu2CDLlFbGA\n\tVsMOPpgk=","X-Gm-Gg":"AfdE7cmc10CNEucM34i9pWZFi+7R9x/VTxHH+f6KI6Y2VqJJYeneECaYL475QS5IlZw\n\tCRfXA3PcrzED2D9n3h7WsF5vMdDrnNg2EfvhVGS13ppzZExFEOPMPIxdRz5qU/5mJh7A2JwXPyT\n\tQWdloZxQb2BwFsXp0vNiOTvBtBMsBYst3ToLZ27myTEqbkLrblpjmvsAY/QFA1X9l0wzfTJhSeu\n\tjcB+/6TZuhX2R850q1PwpbAiIpNWyiXA/QuvYjGLGgEmNfSnENriwx6cjdzUDwqGJcHu2dAD4dZ\n\t1Bb8lJ21cova0YnVoT1QRevcEdRPzVKck6G7X3CRLu3DZ9jwnQLn51VgA8tiqhipP248R1J0vXn\n\tfaj+T0G0iojlNgtVTwu9UG+5PQkFOtmdpVVjwv4kz005EmMIoqTAN90RPinvzl82aJEnHZ8cFKt\n\tkn+bXjsYeHk6Zk+tFETSJjNmm3bJYj1gXZId1RyG6fJaJkEpzlcqbvPdSUqUklz8/oqOWuUI6wM\n\tQjv37A5UtXbEC8HvpNl4h23+DKZ6kwY","X-Received":"by 2002:a05:6000:41e4:b0:473:1706:7efe with SMTP id\n\tffacd0b85a97d-477b398440emr6423535f8f.24.1782986345166; \n\tThu, 02 Jul 2026 02:59:05 -0700 (PDT)","From":"David Plowman <david.plowman@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"David Plowman <david.plowman@raspberrypi.com>","Subject":"[PATCH] pipeline: rpi: pisp: Fix colours for NV21 and NV61 pixel\n\tformats","Date":"Thu,  2 Jul 2026 10:57:35 +0100","Message-ID":"<20260702095903.79640-1-david.plowman@raspberrypi.com>","X-Mailer":"git-send-email 2.47.3","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":"Code was previously passing the \"ORDER_SWAPPED\" flag to swap the U and\nV components, but our hardware doesn't actually support this for\nsemi-planar formats.\n\nInstead swap over the 2nd and 3rd rows of the output colour conversion\nmatrices to achieve the same effect.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n src/libcamera/pipeline/rpi/pisp/pisp.cpp | 27 ++++++++++++++++++++----\n 1 file changed, 23 insertions(+), 4 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/rpi/pisp/pisp.cpp b/src/libcamera/pipeline/rpi/pisp/pisp.cpp\nindex 23f4c14d..5ea57399 100644\n--- a/src/libcamera/pipeline/rpi/pisp/pisp.cpp\n+++ b/src/libcamera/pipeline/rpi/pisp/pisp.cpp\n@@ -172,11 +172,14 @@ pisp_image_format_config toPiSPImageFormat(V4L2DeviceFormat &format)\n \t\timage.stride2 = image.stride;\n \t\tbreak;\n \tcase formats::NV21:\n+\t\t/*\n+\t\t * ORDER_SWAPPED does not work with semi-planar formats, so\n+\t\t * we going to have swap rows in the output CSC matrix.\n+\t\t */\n \t\timage.format = PISP_IMAGE_FORMAT_THREE_CHANNEL +\n \t\t\t       PISP_IMAGE_FORMAT_BPS_8 +\n \t\t\t       PISP_IMAGE_FORMAT_SAMPLING_420 +\n-\t\t\t       PISP_IMAGE_FORMAT_PLANARITY_SEMI_PLANAR +\n-\t\t\t       PISP_IMAGE_FORMAT_ORDER_SWAPPED;\n+\t\t\t       PISP_IMAGE_FORMAT_PLANARITY_SEMI_PLANAR;\n \t\timage.stride2 = image.stride;\n \t\tbreak;\n \tcase formats::YUYV:\n@@ -200,11 +203,14 @@ pisp_image_format_config toPiSPImageFormat(V4L2DeviceFormat &format)\n \t\timage.stride2 = image.stride;\n \t\tbreak;\n \tcase formats::NV61:\n+\t\t/*\n+\t\t * ORDER_SWAPPED does not work with semi-planar formats, so\n+\t\t * we going to have swap rows in the output CSC matrix.\n+\t\t */\n \t\timage.format = PISP_IMAGE_FORMAT_THREE_CHANNEL +\n \t\t\t       PISP_IMAGE_FORMAT_BPS_8 +\n \t\t\t       PISP_IMAGE_FORMAT_SAMPLING_422 +\n-\t\t\t       PISP_IMAGE_FORMAT_PLANARITY_SEMI_PLANAR +\n-\t\t\t       PISP_IMAGE_FORMAT_ORDER_SWAPPED;\n+\t\t\t       PISP_IMAGE_FORMAT_PLANARITY_SEMI_PLANAR;\n \t\timage.stride2 = image.stride;\n \t\tbreak;\n \tcase formats::RGB888:\n@@ -1964,6 +1970,19 @@ bool PiSPCameraData::calculateCscConfiguration(const V4L2DeviceFormat &v4l2Forma\n \t\t\t\t<< \", defaulting to sYCC\";\n \t\t\tbe_->InitialiseYcbcr(csc, \"jpeg\");\n \t\t}\n+\n+\t\tif (pixFormat == formats::NV21 || pixFormat == formats::NV61) {\n+\t\t\t/*\n+\t\t\t * The ORDER_SWAPPED flag doesn't work with semi-planar formats,\n+\t\t\t * so instead we have to swap 2 matrix rows.\n+\t\t\t */\n+\t\t\tpisp_be_ccm_config copy = csc;\n+\t\t\tmemcpy(&csc.coeffs[3], &copy.coeffs[6], 3 * sizeof(csc.coeffs[0]));\n+\t\t\tmemcpy(&csc.coeffs[6], &copy.coeffs[3], 3 * sizeof(csc.coeffs[0]));\n+\t\t\tcsc.offsets[1] = copy.offsets[2];\n+\t\t\tcsc.offsets[2] = copy.offsets[1];\n+\t\t}\n+\n \t\treturn true;\n \t}\n \t/* There will be more formats to check for in due course. */\n","prefixes":[]}