about summary refs log tree commit diff
path: root/users/flokli/ipu6-softisp/libcamera/0021-libcamera-swstats_cpu-Add-support-for-10bpp-IGIG_GBG.patch
blob: 44985a94e16f7fa92fda33b3dd309b6c27a80dd8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
From f939e68a3ef556e572f0140df6d7ef17d72f457e Mon Sep 17 00:00:00 2001
From: Marttico <g.martti@gmail.com>
Date: Wed, 20 Dec 2023 20:26:15 +0100
Subject: [PATCH 21/25] libcamera: swstats_cpu: Add support for 10bpp
 IGIG_GBGR_IGIG_GRGB input

Add support to SwStatsCpu for 10bpp IGIG_GBGR_IGIG_GRGB input
generated by the Omnivision ov01a1s sensor.

Co-authored-by: Dennis Bonke <admin@dennisbonke.com>
Signed-off-by: Dennis Bonke <admin@dennisbonke.com>
Co-authored-by: Toon Langendam <t.langendam@gmail.com>
Signed-off-by: Toon Langendam <t.langendam@gmail.com>
Signed-off-by: Marttico <g.martti@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 .../internal/software_isp/swstats_cpu.h       |  3 +
 src/libcamera/software_isp/swstats_cpu.cpp    | 76 +++++++++++++++++++
 2 files changed, 79 insertions(+)

diff --git a/include/libcamera/internal/software_isp/swstats_cpu.h b/include/libcamera/internal/software_isp/swstats_cpu.h
index e7abc6bb..a47241e1 100644
--- a/include/libcamera/internal/software_isp/swstats_cpu.h
+++ b/include/libcamera/internal/software_isp/swstats_cpu.h
@@ -42,6 +42,9 @@ private:
 	/* Bayer 10 bpp packed */
 	void statsBGGR10PLine0(const uint8_t *src[]);
 	void statsGBRG10PLine0(const uint8_t *src[]);
+	/* IGIG_GBGR_IGIG_GRGB 10 bpp unpacked */
+	void statsRGBIR10Line0(const uint8_t *src[]);
+	void statsRGBIR10Line2(const uint8_t *src[]);
 	void resetStats(void);
 	void finishStats(void);
 
diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp
index 87550371..96e21be5 100644
--- a/src/libcamera/software_isp/swstats_cpu.cpp
+++ b/src/libcamera/software_isp/swstats_cpu.cpp
@@ -187,6 +187,68 @@ void SwStatsCpu::statsGBRG10PLine0(const uint8_t *src[])
 	statsBayer10P(window_.width, src0, src1, false, stats_);
 }
 
+void SwStatsCpu::statsRGBIR10Line0(const uint8_t *src[])
+{
+	const uint16_t *src0_16 = (const uint16_t *)src[2] + window_.x;
+	const uint16_t *src1_16 = (const uint16_t *)src[3] + window_.x;
+	uint16_t g3, g4;
+
+	SWISP_LINARO_START_LINE_STATS(uint16_t)
+
+	/* x += 8 sample every other 4x4 block */
+	for (int x = 0; x < (int)window_.width; x += 8) {
+		/* IGIG */
+		//i = src0_16[x];
+		g2 = src0_16[x + 1];
+		//i = src0_16[x + 2];
+		g4 = src0_16[x + 3];
+
+		/* GBGR */
+		g = src1_16[x];
+		b = src1_16[x + 1];
+		g3 = src1_16[x + 2];
+		r = src1_16[x + 3];
+
+		g = (g + g2 + g3 + g4) / 4;
+
+		/* divide Y by 4 for 10 -> 8 bpp value */
+		SWISP_LINARO_ACCUMULATE_LINE_STATS(4)
+	}
+
+	SWISP_LINARO_FINISH_LINE_STATS()
+}
+
+void SwStatsCpu::statsRGBIR10Line2(const uint8_t *src[])
+{
+	const uint16_t *src0_16 = (const uint16_t *)src[2] + window_.x;
+	const uint16_t *src1_16 = (const uint16_t *)src[3] + window_.x;
+	uint16_t g3, g4;
+
+	SWISP_LINARO_START_LINE_STATS(uint16_t)
+
+	/* x += 8 sample every other 4x4 block */
+	for (int x = 0; x < (int)window_.width; x += 8) {
+		/* IGIG */
+		//i = src0_16[x];
+		g2 = src0_16[x + 1];
+		//i = src0_16[x + 2];
+		g4 = src0_16[x + 3];
+
+		/* GRGB */
+		g = src1_16[x];
+		r = src1_16[x + 1];
+		g3 = src1_16[x + 2];
+		b = src1_16[x + 3];
+
+		g = (g + g2 + g3 + g4) / 4;
+
+		/* divide Y by 4 for 10 -> 8 bpp value */
+		SWISP_LINARO_ACCUMULATE_LINE_STATS(4)
+	}
+
+	SWISP_LINARO_FINISH_LINE_STATS()
+}
+
 void SwStatsCpu::resetStats(void)
 {
 	stats_.sumR_ = 0;
@@ -282,6 +344,20 @@ int SwStatsCpu::configure(const StreamConfiguration &inputCfg)
 		}
 	}
 
+	if (bayerFormat.bitDepth == 10 &&
+	    bayerFormat.packing == BayerFormat::Packing::None &&
+	    bayerFormat.order == BayerFormat::IGIG_GBGR_IGIG_GRGB) {
+		bpp_ = 16;
+		patternSize_.height = 4;
+		patternSize_.width = 4;
+		y_skip_mask_ = 0x04;
+		x_shift_ = 0;
+		swap_lines_ = false;
+		stats0_ = (SwStats::statsProcessFn)&SwStatsCpu::statsRGBIR10Line0;
+		stats2_ = (SwStats::statsProcessFn)&SwStatsCpu::statsRGBIR10Line2;
+		return 0;
+	}
+
 	LOG(SwStats, Info)
 		<< "Unsupported input format " << inputCfg.pixelFormat.toString();
 	return -EINVAL;
-- 
2.43.0