[v7,6/7] libcamera: pipeline: Shift test pattern by 1 pixel left every frame
diff mbox series

Message ID 20240801073339.4061027-7-chenghaoyang@google.com
State Superseded
Headers show
Series
  • Add VirtualPipelineHandler
Related show

Commit Message

Harvey Yang Aug. 1, 2024, 7:31 a.m. UTC
From: Konami Shu <konamiz@google.com>

- This write the buffer every frame
- Shifting makes the frame rate dropped from about 160 to 40

Patchset1->2
- Use constant instead of using a magic number

Patchset2->3
- Make shiftLeft() private

Signed-off-by: Konami Shu <konamiz@google.com>
Co-developed-by: Harvey Yang <chenghaoyang@chromium.org>
Co-developed-by: Yunke Cao <yunkec@chromium.org>
Co-developed-by: Tomasz Figa <tfiga@chromium.org>
---
 .../pipeline/virtual/data/virtual.yaml        |  4 +--
 .../virtual/test_pattern_generator.cpp        | 36 +++++++++++++++++++
 2 files changed, 38 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/virtual/data/virtual.yaml b/src/libcamera/pipeline/virtual/data/virtual.yaml
index 4eb239e2..b8956f2d 100644
--- a/src/libcamera/pipeline/virtual/data/virtual.yaml
+++ b/src/libcamera/pipeline/virtual/data/virtual.yaml
@@ -28,8 +28,8 @@ 
   model: "Virtual Video Device1"
 "Virtual2":
   supported_formats:
-  - width: 100
-    height: 100
+  - width: 400
+    height: 300
   test_pattern: "lines"
   location: "front"
   model: "Virtual Video Device2"
diff --git a/src/libcamera/pipeline/virtual/test_pattern_generator.cpp b/src/libcamera/pipeline/virtual/test_pattern_generator.cpp
index 8dfe626e..6df9b31e 100644
--- a/src/libcamera/pipeline/virtual/test_pattern_generator.cpp
+++ b/src/libcamera/pipeline/virtual/test_pattern_generator.cpp
@@ -28,6 +28,9 @@  void TestPatternGenerator::generateFrame(
 
 	auto planes = mappedFrameBuffer.planes();
 
+	/* TODO: select whether to do shifting or not */
+	shiftLeft(size);
+
 	/* Convert the template_ to the frame buffer */
 	int ret = libyuv::ARGBToNV12(
 		template_.get(), /*src_stride_argb=*/size.width * kARGBSize,
@@ -39,6 +42,39 @@  void TestPatternGenerator::generateFrame(
 	}
 }
 
+void TestPatternGenerator::shiftLeft(const Size &size)
+{
+	/* Store the first column temporarily */
+	uint8_t firstColumn[size.height * kARGBSize];
+	for (size_t h = 0; h < size.height; h++) {
+		unsigned int index = h * size.width * kARGBSize;
+		unsigned int index1 = h * kARGBSize;
+		firstColumn[index1] = template_[index];
+		firstColumn[index1 + 1] = template_[index + 1];
+		firstColumn[index1 + 2] = template_[index + 2];
+		firstColumn[index1 + 3] = 0x00;
+	}
+
+	/* Overwrite template_ */
+	uint8_t *buf = template_.get();
+	for (size_t h = 0; h < size.height; h++) {
+		for (size_t w = 0; w < size.width - 1; w++) {
+			/* Overwrite with the pixel on the right */
+			unsigned int index = (h * size.width + w + 1) * kARGBSize;
+			*buf++ = template_[index]; // B
+			*buf++ = template_[index + 1]; // G
+			*buf++ = template_[index + 2]; // R
+			*buf++ = 0x00; // A
+		}
+		/* Overwrite the new last column with the original first column */
+		unsigned int index1 = h * kARGBSize;
+		*buf++ = firstColumn[index1]; // B
+		*buf++ = firstColumn[index1 + 1]; // G
+		*buf++ = firstColumn[index1 + 2]; // R
+		*buf++ = 0x00; // A
+	}
+}
+
 std::unique_ptr<ColorBarsGenerator> ColorBarsGenerator::create()
 {
 	return std::make_unique<ColorBarsGenerator>();