Message ID | 20240820172202.526547-7-chenghaoyang@google.com |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Hi On Tue, Aug 20, 2024 at 04:23:37PM GMT, Harvey Yang wrote: > 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 +-- This can be squashed in 5/8 > .../virtual/test_pattern_generator.cpp | 36 +++++++++++++++++++ And this in 4/8 Or is there a reason I'm missing why these changes have to be introduced later ? > 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 4eb239e24..b8956f2d4 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 8dfe626e5..6df9b31e9 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 */ Who selects this ? and how ? I'm a bit confused :) > + 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.184.g6999bdac58-goog >
diff --git a/src/libcamera/pipeline/virtual/data/virtual.yaml b/src/libcamera/pipeline/virtual/data/virtual.yaml index 4eb239e24..b8956f2d4 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 8dfe626e5..6df9b31e9 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>();