[libcamera-devel] [RFC PATCH v2 4/7] libcamera: ipa: Soft IPA: add a Soft IPA implementation

Pavel Machek pavel at ucw.cz
Wed Dec 13 08:39:46 CET 2023


Hi!

> ATM the statistics and debayer classes are mostly ready,
> but I need to merge this with Andrey's v2 RFC and
> then produce a clean new series from this
> (assuming people like the approach).

Ok, what about this one? I only converted half of the code, but the
other half of conversion should be very similar.

Compile-tested only as my sensor is bayer 8.

It makes it easier to see how we are skipping the low bits in 10P
bayer, and will make bayer 8 support easier, too, since the pixel_XXX
helpers are designed to be shared.

Best regards,
								Pavel

diff --git a/src/libcamera/software_isp/debayer_cpu.cpp b/src/libcamera/software_isp/debayer_cpu.cpp
index 97ab6c14..a340e500 100644
--- a/src/libcamera/software_isp/debayer_cpu.cpp
+++ b/src/libcamera/software_isp/debayer_cpu.cpp
@@ -29,13 +29,37 @@ DebayerCpu::DebayerCpu(std::unique_ptr<SwStatsLinaro> stats)
 		green_[i] = i;
 }
 
+struct ctxt {
+	/* Pointers to previous, current and next lines */
+	const uint8_t *prev;
+	const uint8_t *curr;
+	const uint8_t *next;
+
+	/* Pointers to gamma correction tables */
+	const uint8_t *red;
+	const uint8_t *green;
+	const uint8_t *blue;
+};
+  
+static inline void pixel_bggr(const struct ctxt &c, uint8_t *&dst, int x, int p, int n)
+{
+	*dst++ = c.blue[c.curr[x]];
+	*dst++ = c.green[(c.prev[x] + c.curr[x - p] + c.curr[x + p] + c.next[x]) / 4];
+	*dst++ = c.red[(c.prev[x - p] + c.prev[x + n] + c.next[x - p]  + c.next[x + n]) / 4];
+}
+
+static inline void pixel_gbrg(const struct ctxt &c, uint8_t *&dst, int x, int p, int n)
+{
+	*dst++ = c.blue[(c.curr[x - p] + c.curr[x + n]) / 2];
+	*dst++ = c.green[c.curr[x]];
+	*dst++ = c.red[(c.prev[x] + c.next[x]) / 2];
+}
+
 void DebayerCpu::debayerBGGR10PLine0(uint8_t *dst, const uint8_t *src)
 {
 	const int width_in_bytes = window_.width * 5 / 4;
-	/* Pointers to previous, current and next lines */
-	const uint8_t *prev = src - inputStride_;
-	const uint8_t *curr = src;
-	const uint8_t *next = src + inputStride_;
+	struct ctxt c = { src - inputStride_, src, src + inputStride_,
+			  red_, green_, blue_ };
 
 	/*
 	 * For the first pixel getting a pixel from the previous column uses
@@ -49,9 +73,7 @@ void DebayerCpu::debayerBGGR10PLine0(uint8_t *dst, const uint8_t *src)
 		 *                       RGR
 		 * Write BGR
 		 */
-		*dst++ = blue_[curr[x]];
-		*dst++ = green_[(prev[x] + curr[x - 2] + curr[x + 1] + next[x]) / 4];
-		*dst++ = red_[(prev[x - 2] + prev[x + 1] + next[x - 2]  + next[x + 1]) / 4];
+		pixel_bggr(c, dst, x, 2, 1);
 		x++;
 
 		/*
@@ -60,20 +82,14 @@ void DebayerCpu::debayerBGGR10PLine0(uint8_t *dst, const uint8_t *src)
 		 *                      GRG
 		 * Write BGR
 		 */
-		*dst++ = blue_[(curr[x - 1] + curr[x + 1]) / 2];
-		*dst++ = green_[curr[x]];
-		*dst++ = red_[(prev[x] + next[x]) / 2];
+		pixel_gbrg(c, dst, x, 1, 1);
 		x++;
 
 		/* Same thing for next 2 pixels */
-		*dst++ = blue_[curr[x]];
-		*dst++ = green_[(prev[x] + curr[x - 1] + curr[x + 1] + next[x]) / 4];
-		*dst++ = red_[(prev[x - 1] + prev[x + 1] + next[x - 1]  + next[x + 1]) / 4];
+		pixel_bggr(c, dst, x, 1, 1);
 		x++;
 
-		*dst++ = blue_[(curr[x - 1] + curr[x + 2]) / 2];
-		*dst++ = green_[curr[x]];
-		*dst++ = red_[(prev[x] + next[x]) / 2];
+		pixel_gbrg(c, dst, x, 1, 2);
 	}
 }
 
@@ -123,10 +139,8 @@ void DebayerCpu::debayerBGGR10PLine1(uint8_t *dst, const uint8_t *src)
 void DebayerCpu::debayerGBRG10PLine0(uint8_t *dst, const uint8_t *src)
 {
 	const int width_in_bytes = window_.width * 5 / 4;
-	/* Pointers to previous, current and next lines */
-	const uint8_t *prev = src - inputStride_;
-	const uint8_t *curr = src;
-	const uint8_t *next = src + inputStride_;
+	struct ctxt c = { src - inputStride_, src, src + inputStride_,
+			  red_, green_, blue_ };
 
 	for (int x = 0; x < width_in_bytes; x += 2) {
 		/*
@@ -135,9 +149,7 @@ void DebayerCpu::debayerGBRG10PLine0(uint8_t *dst, const uint8_t *src)
 		 *                       GRG
 		 * Write BGR
 		 */
-		*dst++ = blue_[(curr[x - 2] + curr[x + 1]) / 2];
-		*dst++ = green_[curr[x]];
-		*dst++ = red_[(prev[x] + next[x]) / 2];
+		pixel_gbrg(c, dst, x, 2, 1);
 		x++;
 
 		/*
@@ -146,20 +158,14 @@ void DebayerCpu::debayerGBRG10PLine0(uint8_t *dst, const uint8_t *src)
 		 *                      RGR
 		 * Write BGR
 		 */
-		*dst++ = blue_[curr[x]];
-		*dst++ = green_[(prev[x] + curr[x - 1] + curr[x + 1] + next[x]) / 4];
-		*dst++ = red_[(prev[x - 1] + prev[x + 1] + next[x - 1]  + next[x + 1]) / 4];
+		pixel_bggr(c, dst, x, 1, 1);
 		x++;
 
 		/* Same thing for next 2 pixels */
-		*dst++ = blue_[(curr[x - 1] + curr[x + 1]) / 2];
-		*dst++ = green_[curr[x]];
-		*dst++ = red_[(prev[x] + next[x]) / 2];
+		pixel_gbrg(c, dst, x, 1, 1);
 		x++;
 
-		*dst++ = blue_[curr[x]];
-		*dst++ = green_[(prev[x] + curr[x - 1] + curr[x + 2] + next[x]) / 4];
-		*dst++ = red_[(prev[x - 1] + prev[x + 2] + next[x - 1]  + next[x + 2]) / 4];
+		pixel_bggr(c, dst, x, 1, 2);
 	}
 }
 



-- 
People of Russia, stop Putin before his war on Ukraine escalates.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20231213/5336f0a8/attachment.sig>


More information about the libcamera-devel mailing list