[PATCH v7 6/7] libcamera: pipeline: Shift test pattern by 1 pixel left every frame
Harvey Yang
chenghaoyang at chromium.org
Thu Aug 1 09:31:02 CEST 2024
From: Konami Shu <konamiz at 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 at google.com>
Co-developed-by: Harvey Yang <chenghaoyang at chromium.org>
Co-developed-by: Yunke Cao <yunkec at chromium.org>
Co-developed-by: Tomasz Figa <tfiga at chromium.org>
---
.../pipeline/virtual/data/virtual.yaml | 4 +--
.../virtual/test_pattern_generator.cpp | 36 +++++++++++++++++++
2 files changed, 38 insertions(+), 2 deletions(-)
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>();
--
2.46.0.rc1.232.g9752f9e123-goog
More information about the libcamera-devel
mailing list