[{"id":36751,"web_url":"https://patchwork.libcamera.org/comment/36751/","msgid":"<f6e253b6-262a-4057-83ab-72109619186d@oss.qualcomm.com>","date":"2025-11-07T16:12:38","subject":"Re: [PATCH] libcamera: software_isp: Fix gamma table when CCM is\n\tused","submitter":{"id":242,"url":"https://patchwork.libcamera.org/api/people/242/","name":"Hans de Goede","email":"johannes.goede@oss.qualcomm.com"},"content":"Hi,\n\n\nOn 7-Nov-25 4:20 PM, Milan Zamazal wrote:\n> Software CPU ISP computes a gamma lookup table.  The table incorporates\n> black level and contrast.  All entries in the table below the black\n> level are set to 0.  This is not necessarily correct all the time.\n> \n> Let's consider this case: The CCM is\n> \n>   [1 0 0]\n>   [0 1 0]\n>   [0 0 0]\n> \n> and contrast is set to zero.  The gamma table has all the entries above\n> the black level set to 186 (due to zero contrast) and all the entries\n> below the black level set to 0.  CCM is applied before gamma, a\n> non-black level pixel has the blue component set to 0 with the CCM\n> above.  Now, when the gamma lookup is applied, the red and green\n> components are set to 186, while the blue component is set to 0.  The\n> resulting pixel is then yellow rather than grey (as it should be with\n> zero contrast).\n> \n> There are two ways to fix this: Either clamping pixel colour channels to\n> the black level in debayering or setting the below black level entries\n> in the gamma lookup table to the lowest value of the gamma table rather\n> than 0.  Both should have the same effect.  Let's opt for the latter for\n> its simplicity.\n> \n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n\nThanks, patch looks good to me:\n\nReviewed-by: Hans de Goede <johannes.goede@oss.qualcomm.com>\n\nRegards,\n\nHans\n\n\n> ---\n>  src/ipa/simple/algorithms/lut.cpp | 9 ++++++++-\n>  1 file changed, 8 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/ipa/simple/algorithms/lut.cpp b/src/ipa/simple/algorithms/lut.cpp\n> index d1d5f7271..d4a79e101 100644\n> --- a/src/ipa/simple/algorithms/lut.cpp\n> +++ b/src/ipa/simple/algorithms/lut.cpp\n> @@ -61,7 +61,6 @@ void Lut::updateGammaTable(IPAContext &context)\n>  \tconst unsigned int blackIndex = blackLevel * gammaTable.size() / 256;\n>  \tconst auto contrast = context.activeState.knobs.contrast.value_or(1.0);\n>  \n> -\tstd::fill(gammaTable.begin(), gammaTable.begin() + blackIndex, 0);\n>  \tconst float divisor = gammaTable.size() - blackIndex - 1.0;\n>  \tfor (unsigned int i = blackIndex; i < gammaTable.size(); i++) {\n>  \t\tdouble normalized = (i - blackIndex) / divisor;\n> @@ -75,6 +74,14 @@ void Lut::updateGammaTable(IPAContext &context)\n>  \t\tgammaTable[i] = UINT8_MAX *\n>  \t\t\t\tstd::pow(normalized, context.configuration.gamma);\n>  \t}\n> +\t/*\n> +\t * Due to CCM operations, the table lookup may reach indices below the black\n> +\t * level. Let's set the table values below black level to the minimum\n> +\t * non-black value to prevent problems when the minimum value is\n> +\t * significantly non-zero (for example, when the image should be all grey).\n> +\t */\n> +\tstd::fill(gammaTable.begin(), gammaTable.begin() + blackIndex,\n> +\t\t  gammaTable[blackIndex]);\n>  \n>  \tcontext.activeState.gamma.blackLevel = blackLevel;\n>  \tcontext.activeState.gamma.contrast = contrast;","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 E1C05BDE4C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  7 Nov 2025 16:12:44 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3103460A80;\n\tFri,  7 Nov 2025 17:12:44 +0100 (CET)","from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com\n\t[205.220.180.131])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9B676608CF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  7 Nov 2025 17:12:42 +0100 (CET)","from pps.filterd (m0279870.ppops.net [127.0.0.1])\n\tby mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id\n\t5A7B2TP73040981 for <libcamera-devel@lists.libcamera.org>;\n\tFri, 7 Nov 2025 16:12:41 GMT","from mail-qt1-f197.google.com (mail-qt1-f197.google.com\n\t[209.85.160.197])\n\tby mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4a9fj08t0c-1\n\t(version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT)\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 07 Nov 2025 16:12:41 +0000 (GMT)","by mail-qt1-f197.google.com with SMTP id\n\td75a77b69052e-4ed6ceab125so26181461cf.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 07 Nov 2025 08:12:41 -0800 (PST)","from ?IPV6:2001:1c00:c32:7800:5bfa:a036:83f0:f9ec?\n\t(2001-1c00-0c32-7800-5bfa-a036-83f0-f9ec.cable.dynamic.v6.ziggo.nl.\n\t[2001:1c00:c32:7800:5bfa:a036:83f0:f9ec])\n\tby smtp.gmail.com with ESMTPSA id\n\ta640c23a62f3a-b72bf407a01sm277776466b.22.2025.11.07.08.12.39\n\t(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n\tFri, 07 Nov 2025 08:12:39 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=qualcomm.com header.i=@qualcomm.com\n\theader.b=\"ogFUI/jo\"; dkim=pass (2048-bit key;\n\tunprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com\n\theader.b=\"I44Uap5V\"; dkim-atps=neutral","DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h=\n\tcontent-transfer-encoding:content-type:date:from:in-reply-to\n\t:message-id:mime-version:references:subject:to; s=qcppdkim1; bh=\n\tCC2RWyFdZKW/9K9XVe+OcVSpvjnIEKpGhT/ZmPy7T5U=; b=ogFUI/johkk7zQc3\n\thgXA99uhsmFgisRXnUVrnwgpoDm/VvElSqhQmUyoVmBQ3qWET7jDer92LFjrVPHS\n\taa7s5wYaG0bbu0m+TRDIDSop2hwz5pf4d+I/uYC5YIkaE5hNkkoTiiwuM5ChysWS\n\tYQBfSmN5PcxYJbcYJY1ZeAyRTh38BPh3+L03XRPP1igU/ggmUrW1SOhKK23bO2ek\n\tz5Uo7+8xAjnH1dqINFjVlzyyfHUFv4CVjK2PhB66d5nz0MNHPY9T7XQrgv4zBxAa\n\tkaNB3i/1+v3EZpwNGlw+Q4qsOXq4X5GtTIcAtfObE2BY/a1+NB2YqqcZMF3uGJw5\n\tbivLHg==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=oss.qualcomm.com; s=google; t=1762531960; x=1763136760;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:in-reply-to:content-language:from\n\t:references:to:subject:user-agent:mime-version:date:message-id:from\n\t:to:cc:subject:date:message-id:reply-to;\n\tbh=CC2RWyFdZKW/9K9XVe+OcVSpvjnIEKpGhT/ZmPy7T5U=;\n\tb=I44Uap5V9QRRpzk5OYgjTcqkXoHcnFQmxenH0btquPLszWsYtDdL5NSZxQhpnwSDdd\n\tZ/I1q/BsbnwOoVgNg4fnUgsmqndoKUwiZ3uQfDUa6eJ58wCsaUofK+zyF4YOxrKq7fQl\n\tEzsqbd1xxv5KDvtRJgbtSfLpyeA7AG0Is/1Pj3bQVpa69z9W3CAM3V7yzQYaD0/Wk29T\n\tfsRykksavmuUHpT1h88L3Ohd8AmULT2XCgFVFmmkI7iJHA3zky5DYTBdPnIPgOgM/uDw\n\t0la753fFxrLdCIzUNMV7SpI7RYuahpxPKAL+zY0cy24Xwh4l49sVxzrOljYSOFlCKp40\n\tps7A=="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1762531960; x=1763136760;\n\th=content-transfer-encoding:in-reply-to:content-language:from\n\t:references:to:subject:user-agent:mime-version:date:message-id\n\t:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=CC2RWyFdZKW/9K9XVe+OcVSpvjnIEKpGhT/ZmPy7T5U=;\n\tb=AEjPjNwq1GckUFoCiLF47Kb/j3jGwDWIf2pC4n0foWlO3UW1IDp1yHVueMZQzzbXj3\n\tod6vlzz+/wMrOXAolflQrflEKLB5BkL3lEX+UqdETPIMjaTJzEmMmrV34bhA5W4gVU0R\n\tKlYXdQHWbmqS08M+VMjHfhhlWvrxQUSuBTJLnxTFhWwBIPpu4krUTTX8+0KTsWkcIuZD\n\t3DC5WH0HOqDOzmB8bhtQ9TEFOLhU12DCf1bZZrdkj+qZadLoqKRUzKc80r3BcLFnqlzc\n\tTB78uNu9g4+ZUpxygsnKODIfYfve36ewReYfeFVls2FaNPxd/yOx36JuJPn6erCRiIwk\n\tZNNA==","X-Forwarded-Encrypted":"i=1;\n\tAJvYcCULqt5gpD3hrf63xTYnCxIZab8vZpvahwZ45o0fgUFdkXboI4ItDSSQN9A4DrLQXvvQgBA5/rDsWfvTkMzpf2U=@lists.libcamera.org","X-Gm-Message-State":"AOJu0YzKRVwKx+QiXNgKZVWLplp6EQfuwcVW59jRPyyFb0pVSeDlaG/z\n\tlOszcoHZSMW8aww7PeDFo73k3NoZW8AkQWLcKwtEJj7PNUQ8GoU29hqdGabu4sTExLi2pMY5bmt\n\t/RaX+0qsfl0N800K7Y3OyqsShtv6les05m548XV61/GDOU/HDQqSolH/tJg+EaSu6R05V8p5b63\n\tIS","X-Gm-Gg":"ASbGnctv600E8Uuy0m31yr3VL/8897Twy9BYQ+suBn9Mbyd7+i403SZy5zYDbdhN1kA\n\tgg+Oc+tZSb/AWPbcqvREWVXCfeDPPK0KMNKMEXI6Lh/A6/OI8koNKa/ZJNGaeQ1mpyTZrrJUZRg\n\tve7cMXkT6dwUkdEnIuUvm/VFl3UT2gq4zi6JwYDb/oImcI9iNlthlD4vLUv691ZUU1mwm9KLSiB\n\tmXvj+fmXJvjduZ60HuIPSQUoo7QVmiS7OgZijdUHuL3bpUzxxGiEEr/WZ1wAeSIeCitcDzdEYj/\n\tJtxJk8X0hjphA4vxIDcXf0zE51kHGQdTyUbLOwxAEqQr1iWans5x6Ej8ZO7nxxyNe4/i6/nhblA\n\th37rnYSz5LppudWNYdpT6RS8byF5HmwEbtTOSw7kykQh7Ph5uC5L8nORJkLhvFRwKe+5bKtZ9tp\n\ta9ve/RLMMIp+7fWKZ4fR2NrXejJoAJRXuCr1R33Wj4xqGkZxC9+Sg=","X-Received":["by 2002:ac8:5a09:0:b0:4ed:70f6:9675 with SMTP id\n\td75a77b69052e-4ed94978398mr46596341cf.27.1762531960352; \n\tFri, 07 Nov 2025 08:12:40 -0800 (PST)","by 2002:ac8:5a09:0:b0:4ed:70f6:9675 with SMTP id\n\td75a77b69052e-4ed94978398mr46595731cf.27.1762531959872; \n\tFri, 07 Nov 2025 08:12:39 -0800 (PST)"],"X-Google-Smtp-Source":"AGHT+IHvITOmhcD/VOR/AC12sARjTYbDCmFZDzCtArYJs4rJLVN+Zv7KFRX1mW2hdqeVXnQt2+5Fyg==","Message-ID":"<f6e253b6-262a-4057-83ab-72109619186d@oss.qualcomm.com>","Date":"Fri, 7 Nov 2025 17:12:38 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] libcamera: software_isp: Fix gamma table when CCM is\n\tused","To":"Milan Zamazal <mzamazal@redhat.com>, libcamera-devel@lists.libcamera.org","References":"<20251107152025.18434-1-mzamazal@redhat.com>","From":"Hans de Goede <johannes.goede@oss.qualcomm.com>","Content-Language":"en-US, nl","In-Reply-To":"<20251107152025.18434-1-mzamazal@redhat.com>","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"7bit","X-Authority-Analysis":"v=2.4 cv=XZyEDY55 c=1 sm=1 tr=0 ts=690e1a79 cx=c_pps\n\ta=EVbN6Ke/fEF3bsl7X48z0g==:117 a=xqWC_Br6kY4A:10 a=IkcTkHD0fZMA:10\n\ta=6UeiqGixMTsA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22\n\ta=20KFwNOVAAAA:8 a=EUspDBNiAAAA:8 a=jQRLU2Mw5QLz9IGVZvAA:9\n\ta=QEXdDO2ut3YA:10\n\ta=a_PwQJl-kcHnX1M80qC6:22 a=HhbK4dLum7pmb74im6QT:22","X-Proofpoint-ORIG-GUID":"sN6skzOBpNdYf6EBz5VfIUj8v5BT_X0K","X-Proofpoint-GUID":"sN6skzOBpNdYf6EBz5VfIUj8v5BT_X0K","X-Proofpoint-Spam-Details-Enc":"AW1haW4tMjUxMTA3MDEzMyBTYWx0ZWRfXzRJM1d5QLOhb\n\tm50KYLptev0Hyy9Z/6RdR4+d0A3mvEzRKzXKeoA5KnANGeHzZV0Bi91qJgQ+tDe2NoMIfK61YTI\n\tYVFSLEPp10qBmlfh/Bck6eLY1EAszCUC4EFrgqCxOs7s7MuCTubb0ZEUZ1bVjCDNh6zuf6Y+cHT\n\tqkwhE6Rk2BumLGEUEVP3bieAAMxrgc5iZYwjVUvqkedvO+MhL9MfgPj3W8oxITWnzwEXNblnQtu\n\tMm/FlxIp/oZsjecHf3gUJEFZ9MxzKOfNiozoBwMNi3jJLJn8T3ECxSW8ckF+I8RdmpgcWNuPwkN\n\t5SqLMZRZVBh76LvmsGjLoBD3zUFRpSx5Mm8rqkyc0mDOk8rhYqllfbjM1mSlLYhgw0h0SrxVnVm\n\t6w4Mu1jLwoHw4DqOvK+Rs5hjKuL3uQ==","X-Proofpoint-Virus-Version":"vendor=baseguard\n\tengine=ICAP:2.0.293, Aquarius:18.0.1121, Hydra:6.1.9,\n\tFMLib:17.12.100.49\n\tdefinitions=2025-11-07_04,2025-11-06_01,2025-10-01_01","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n\tadultscore=0 priorityscore=1501 spamscore=0 impostorscore=0\n\tlowpriorityscore=0 suspectscore=0 malwarescore=0 phishscore=0\n\tbulkscore=0\n\tclxscore=1011 classifier=typeunknown authscore=0 authtc= authcc=\n\troute=outbound adjust=0 reason=mlx scancount=1\n\tengine=8.22.0-2510240001\n\tdefinitions=main-2511070133","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>"}}]