From: Balakrishnan Sambath <balakrishnan.s@microchip.com>
To: <ehristev@kernel.org>
Cc: <linux-kernel@vger.kernel.org>,
Balakrishnan Sambath <balakrishnan.s@microchip.com>
Subject: [PATCH 11/15] media: microchip-isc: skip AWB on near-empty channels
Date: Wed, 2 Dec 2026 12:46:17 +0530 [thread overview]
Message-ID: <20261202-isc-series-v1-v1-11-4e2f17c0271c@microchip.com> (raw)
In-Reply-To: <20261202-isc-series-v1-v1-0-4e2f17c0271c@microchip.com>
A channel with only a few pixels left after the trim gives a noisy min,
max and mean, which swings the gains on dark or flat frames.
Track the kept pixel count in ctrls->total_pixels[]. Leave a channel at
offset 0 and gain 1.0 (1 << 9) when it has fewer than frame_pixels / 64
pixels, 64 at least. Leave all gains alone when either green channel is
under the limit, as the green average is the reference for R and B.
Signed-off-by: Balakrishnan Sambath <balakrishnan.s@microchip.com>
---
drivers/media/platform/microchip/microchip-isc-base.c | 19 +++++++++++++++++++
drivers/media/platform/microchip/microchip-isc.h | 1 +
2 files changed, 20 insertions(+)
diff --git a/drivers/media/platform/microchip/microchip-isc-base.c b/drivers/media/platform/microchip/microchip-isc-base.c
index 2787de606b4a..491f710fe08d 100644
--- a/drivers/media/platform/microchip/microchip-isc-base.c
+++ b/drivers/media/platform/microchip/microchip-isc-base.c
@@ -1295,6 +1295,7 @@ static void isc_hist_count(struct isc_device *isc, u32 *min, u32 *max)
/* No pixels, a zero average leaves the gains alone */
if (!total_pixels) {
ctrls->channel_avg[ctrls->hist_id] = 0;
+ ctrls->total_pixels[ctrls->hist_id] = 0;
*min = 0;
*max = HIST_ENTRIES - 2;
return;
@@ -1326,6 +1327,7 @@ static void isc_hist_count(struct isc_device *isc, u32 *min, u32 *max)
}
/* The minimum bin is occupied, so pixels is never zero */
+ ctrls->total_pixels[ctrls->hist_id] = pixels;
ctrls->channel_avg[ctrls->hist_id] = div_u64(weighted_sum, pixels);
dev_dbg(isc->dev,
@@ -1339,6 +1341,7 @@ static void isc_wb_update(struct isc_ctrls *ctrls)
struct isc_device *isc = container_of(ctrls, struct isc_device, ctrls);
u32 *channel_avg = &ctrls->channel_avg[0];
u32 c, offset[4];
+ u32 min_pixels;
u64 avg = 0;
/* We compute two gains, stretch gain and grey world gain */
u32 s_gain[4], gw_gain[4];
@@ -1359,7 +1362,23 @@ static void isc_wb_update(struct isc_ctrls *ctrls)
if (!avg)
return;
+ /* A channel under 1/64 of the frame, 64 pixels at least, is noise */
+ min_pixels = max(isc->fmt.fmt.pix.width * isc->fmt.fmt.pix.height >> 6,
+ 64u);
+
+ /* A noisy green skews the average the other gains aim for */
+ if (ctrls->total_pixels[ISC_HIS_CFG_MODE_GR] < min_pixels ||
+ ctrls->total_pixels[ISC_HIS_CFG_MODE_GB] < min_pixels)
+ return;
+
for (c = ISC_HIS_CFG_MODE_GR; c <= ISC_HIS_CFG_MODE_B; c++) {
+ /* Leave the channel neutral, no offset and a gain of 1.0 */
+ if (ctrls->total_pixels[c] < min_pixels) {
+ ctrls->offset[c] = 0;
+ ctrls->gain[c] = 1 << 9;
+ continue;
+ }
+
/*
* the color offset is the minimum value of the histogram.
* we stretch this color to the full range by substracting
diff --git a/drivers/media/platform/microchip/microchip-isc.h b/drivers/media/platform/microchip/microchip-isc.h
index 1784c0089296..2c3efd2fc56e 100644
--- a/drivers/media/platform/microchip/microchip-isc.h
+++ b/drivers/media/platform/microchip/microchip-isc.h
@@ -160,6 +160,7 @@ struct isc_ctrls {
#define HIST_MAX_INDEX 1
u32 hist_minmax[HIST_BAYER][2];
u32 channel_avg[HIST_BAYER];
+ u32 total_pixels[HIST_BAYER];
};
#define ISC_PIPE_LINE_NODE_NUM 15
--
2.34.1
next prev parent reply other threads:[~2026-12-02 7:16 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 7:16 [PATCH 00/15] media: microchip-isc: fix SAMA7G5 image pipeline and AWB Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 01/15] dt-bindings: media: microchip,xisc: add SAM9X7 compatible Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 02/15] media: microchip-isc: set SAM9X7 maximum resolution per SoC Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 03/15] media: microchip-isc: fix DPC black level scale Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 04/15] media: microchip-isc: enable black level correction on SAMA7G5 Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 05/15] media: microchip-isc: bypass SAMA7G5 pipeline for Bayer output Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 06/15] media: microchip-isc: add gamma 1.8 and 2.4 curves for SAMA7G5 Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 07/15] media: microchip-isc: fix CBHS register names Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 08/15] media: microchip-isc: add SAMA7G5 hue and saturation controls Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 09/15] media: microchip-isc: fix histogram bin index for AWB Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 10/15] media: microchip-isc: trim outliers in the AWB average Balakrishnan Sambath
2026-12-02 7:16 ` Balakrishnan Sambath [this message]
2026-12-02 7:16 ` [PATCH 12/15] media: microchip-isc: do the AWB gain product in 64 bits Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 13/15] media: microchip-isc: smooth AWB gains with an EMA filter Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 14/15] media: microchip-isc: use an unsigned contrast range Balakrishnan Sambath
2026-12-02 7:16 ` [PATCH 15/15] media: microchip-isc: add driver documentation Balakrishnan Sambath
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202-isc-series-v1-v1-11-4e2f17c0271c@microchip.com \
--to=balakrishnan.s@microchip.com \
--cc=ehristev@kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®