{"id":9062,"url":"https://patchwork.libcamera.org/api/1.1/patches/9062/?format=json","web_url":"https://patchwork.libcamera.org/patch/9062/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20200729093154.12296-5-david.plowman@raspberrypi.com>","date":"2020-07-29T09:31:53","name":"[libcamera-devel,4/5] libcamera: raspberrypi: ALSC: Handle transform in colour tables","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"30773c8896b0b36775db3fb8464c7719cce561b1","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/1.1/people/42/?format=json","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/9062/mbox/","series":[{"id":1160,"url":"https://patchwork.libcamera.org/api/1.1/series/1160/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1160","date":"2020-07-29T09:31:50","name":"Transform implementation","version":1,"mbox":"https://patchwork.libcamera.org/series/1160/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/9062/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/9062/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 C8CD8BD86F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 29 Jul 2020 09:32:07 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 94D996185C;\n\tWed, 29 Jul 2020 11:32:07 +0200 (CEST)","from mail-wr1-x443.google.com (mail-wr1-x443.google.com\n\t[IPv6:2a00:1450:4864:20::443])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DBCDE611A2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 29 Jul 2020 11:32:03 +0200 (CEST)","by mail-wr1-x443.google.com with SMTP id b6so20937787wrs.11\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 29 Jul 2020 02:32:03 -0700 (PDT)","from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72])\n\tby smtp.gmail.com with ESMTPSA id\n\tc15sm3709921wme.23.2020.07.29.02.32.02\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 29 Jul 2020 02:32:02 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"qHOsoKT6\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=5PMt33dqXzIUjSsz8EwXzOq9fkust7oXx3uBnBL8KqI=;\n\tb=qHOsoKT6HwVvQug4GrEMbiRqSxZhD35c5xxTq7oy6Iiz1Jf9S7q+KRgDD1Zk4Qb4p5\n\tsbWZN/eUmwutVcCTmBb8TRs3EMfKvdI+VcP/7XTjSrLdSLRO9AY1dxfCCG/tihsNpCgq\n\tJM0XH35tVGrHIb4b8zFyr6GiYBmIw6Ldk5//Fbjp6vy2A/n1qhpnMTc14RvXc2ZUKwBj\n\tX8dUJi9CMiigv+A26LVfxyrwK2gDmmGlRpilD4/txYoo1z62SdON3feNeFLPx5cp1lSB\n\tDG9O0eKKZWPigqqTP/lSbxYpzpLRAvvIw44GAU3Ft1LCr6jWYhup1QifGb7qjVVtYZNJ\n\tCyrQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=5PMt33dqXzIUjSsz8EwXzOq9fkust7oXx3uBnBL8KqI=;\n\tb=HLSv5IOS7a6yWPjFO0WqoSHtTQ/y/t/qgnefaOorv8akNDrEbScVjygbt5at7fTePX\n\t1HStnMRSH52anO7voJhsEKPouITsf8q81vM4Y5qb/jJLLW2pD7f6dZ78SOsiXu7kU1Y5\n\tVNMVVf3RB241HRJoPmGmqptor+AJ/0Q7Y2RoZre/QVdEuSkXVV0Ky7UIZRrCquAjJPMr\n\t/0GqOiaqMzn9zTsi81OLp/9tyDFhTwt+Y6jwYX8vehix1qxwK4+VJ0HiPoiY8ZHfu5Ft\n\tL0PqXdqWaNodJe0TkX4wkExpRi/2YXeT+KL7EjbjCy5JaHyY3jcOj/rZZsS7E36gq6L7\n\tsZiw==","X-Gm-Message-State":"AOAM532lOPoozKQFtwgyVzUFu18gXauA3GU06jVEkMufP8d6N+5Qfctm\n\tUQh7GKwXAxF1sL6rxhuQbIP+HFbdko4I4g==","X-Google-Smtp-Source":"ABdhPJwTzdpDWtWdKCBbPVchdcvQwYCBgoUkdFSs2m3tdbJycUvw39vdTsyltRRVqyR7bTkpDdNfOA==","X-Received":"by 2002:a5d:4984:: with SMTP id\n\tr4mr28624353wrq.401.1596015123277; \n\tWed, 29 Jul 2020 02:32:03 -0700 (PDT)","From":"David Plowman <david.plowman@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 29 Jul 2020 10:31:53 +0100","Message-Id":"<20200729093154.12296-5-david.plowman@raspberrypi.com>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20200729093154.12296-1-david.plowman@raspberrypi.com>","References":"<20200729093154.12296-1-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH 4/5] libcamera: raspberrypi: ALSC: Handle\n\ttransform in colour tables","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>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"This commit updates ALSC (Auto Lens Shading Correction) to handle the\ntransform now passed in the SwitchMode method.\n\nThe transform is applied by the sensor, so the statistics we get\nalready incorporates it, and the adpative algorithm is agnostic to\nit. That leaves only the calibrated tables (assumed measured without\nany user transform) that need to be flipped, and resample_cal_table -\nwhere we resample the calibrated table anyway - is an easy place to do\nit.\n---\n src/ipa/raspberrypi/controller/rpi/alsc.cpp | 22 ++++++++++++++-------\n src/ipa/raspberrypi/controller/rpi/alsc.hpp |  3 ++-\n 2 files changed, 17 insertions(+), 8 deletions(-)","diff":"diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.cpp b/src/ipa/raspberrypi/controller/rpi/alsc.cpp\nindex 5fac9dd..33c1a88 100644\n--- a/src/ipa/raspberrypi/controller/rpi/alsc.cpp\n+++ b/src/ipa/raspberrypi/controller/rpi/alsc.cpp\n@@ -151,8 +151,9 @@ static void get_cal_table(double ct,\n \t\t\t  std::vector<AlscCalibration> const &calibrations,\n \t\t\t  double cal_table[XY]);\n static void resample_cal_table(double const cal_table_in[XY],\n-\t\t\t       CameraMode const &camera_mode,\n-\t\t\t       double cal_table_out[XY]);\n+\t\t\t\t\t\t\t   CameraMode const &camera_mode,\n+\t\t\t\t\t\t\t   Transform transform,\n+\t\t\t\t\t\t\t   double cal_table_out[XY]);\n static void compensate_lambdas_for_cal(double const cal_table[XY],\n \t\t\t\t       double const old_lambdas[XY],\n \t\t\t\t       double new_lambdas[XY]);\n@@ -187,6 +188,7 @@ void Alsc::SwitchMode(CameraMode const &camera_mode, Transform transform, Metada\n \t// change, any effects should be transient, and if they're not transient\n \t// enough, we'll revisit the question then.\n \tcamera_mode_ = camera_mode;\n+\ttransform_ = transform;\n \tif (first_time_) {\n \t\t// On the first time, arrange for something sensible in the\n \t\t// initial tables. Construct the tables for some default colour\n@@ -194,9 +196,9 @@ void Alsc::SwitchMode(CameraMode const &camera_mode, Transform transform, Metada\n \t\t// adaptive algorithm.\n \t\tdouble cal_table_r[XY], cal_table_b[XY], cal_table_tmp[XY];\n \t\tget_cal_table(4000, config_.calibrations_Cr, cal_table_tmp);\n-\t\tresample_cal_table(cal_table_tmp, camera_mode_, cal_table_r);\n+\t\tresample_cal_table(cal_table_tmp, camera_mode_, transform_, cal_table_r);\n \t\tget_cal_table(4000, config_.calibrations_Cb, cal_table_tmp);\n-\t\tresample_cal_table(cal_table_tmp, camera_mode_, cal_table_b);\n+\t\tresample_cal_table(cal_table_tmp, camera_mode_, transform_, cal_table_b);\n \t\tcompensate_lambdas_for_cal(cal_table_r, lambda_r_,\n \t\t\t\t\t   async_lambda_r_);\n \t\tcompensate_lambdas_for_cal(cal_table_b, lambda_b_,\n@@ -379,7 +381,9 @@ void get_cal_table(double ct, std::vector<AlscCalibration> const &calibrations,\n }\n \n void resample_cal_table(double const cal_table_in[XY],\n-\t\t\tCameraMode const &camera_mode, double cal_table_out[XY])\n+\t\t\t\t\t\tCameraMode const &camera_mode,\n+\t\t\t\t\t\tTransform transform,\n+\t\t\t\t\t\tdouble cal_table_out[XY])\n {\n \t// Precalculate and cache the x sampling locations and phases to save\n \t// recomputing them on every row.\n@@ -395,6 +399,8 @@ void resample_cal_table(double const cal_table_in[XY],\n \t\txf[i] = x - x_lo[i];\n \t\tx_hi[i] = std::min(x_lo[i] + 1, X - 1);\n \t\tx_lo[i] = std::max(x_lo[i], 0);\n+\t\tif (transform.contains(Transform::hflip()))\n+\t\t\tx_lo[i] = X - 1 - x_lo[i], x_hi[i] = X - 1 - x_hi[i];\n \t}\n \t// Now march over the output table generating the new values.\n \tdouble scale_y = camera_mode.sensor_height /\n@@ -407,6 +413,8 @@ void resample_cal_table(double const cal_table_in[XY],\n \t\tdouble yf = y - y_lo;\n \t\tint y_hi = std::min(y_lo + 1, Y - 1);\n \t\ty_lo = std::max(y_lo, 0);\n+\t\tif (transform.contains(Transform::vflip()))\n+\t\t\ty_lo = Y - 1 - y_lo, y_hi = Y - 1 - y_hi;\n \t\tdouble const *row_above = cal_table_in + X * y_lo;\n \t\tdouble const *row_below = cal_table_in + X * y_hi;\n \t\tfor (int i = 0; i < X; i++) {\n@@ -671,9 +679,9 @@ void Alsc::doAlsc()\n \t// Fetch the new calibrations (if any) for this CT. Resample them in\n \t// case the camera mode is not full-frame.\n \tget_cal_table(ct_, config_.calibrations_Cr, cal_table_tmp);\n-\tresample_cal_table(cal_table_tmp, async_camera_mode_, cal_table_r);\n+\tresample_cal_table(cal_table_tmp, async_camera_mode_, transform_, cal_table_r);\n \tget_cal_table(ct_, config_.calibrations_Cb, cal_table_tmp);\n-\tresample_cal_table(cal_table_tmp, async_camera_mode_, cal_table_b);\n+\tresample_cal_table(cal_table_tmp, async_camera_mode_, transform_, cal_table_b);\n \t// You could print out the cal tables for this image here, if you're\n \t// tuning the algorithm...\n \t(void)print_cal_table;\ndiff --git a/src/ipa/raspberrypi/controller/rpi/alsc.hpp b/src/ipa/raspberrypi/controller/rpi/alsc.hpp\nindex 9b54578..9001e8a 100644\n--- a/src/ipa/raspberrypi/controller/rpi/alsc.hpp\n+++ b/src/ipa/raspberrypi/controller/rpi/alsc.hpp\n@@ -60,7 +60,8 @@ private:\n \t// configuration is read-only, and available to both threads\n \tAlscConfig config_;\n \tbool first_time_;\n-\tstd::atomic<CameraMode> camera_mode_;\n+\tCameraMode camera_mode_;\n+\tlibcamera::Transform transform_;\n \tstd::thread async_thread_;\n \tvoid asyncFunc(); // asynchronous thread function\n \tstd::mutex mutex_;\n","prefixes":["libcamera-devel","4/5"]}