From 80949709a1132b5198bb8006963f177fcde2e991 Mon Sep 17 00:00:00 2001 From: Nikita Kostovsky Date: Thu, 23 Jan 2025 13:41:27 +0100 Subject: fix CMakeLists.txt, add some debug info and prototypes --- src/camera/ov9281.cpp | 16 +++++++++++++++- src/image.cpp | 17 +++++++++++++++++ src/image.h | 2 ++ 3 files changed, 34 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/camera/ov9281.cpp b/src/camera/ov9281.cpp index 012eab6..b76ecdd 100644 --- a/src/camera/ov9281.cpp +++ b/src/camera/ov9281.cpp @@ -64,6 +64,18 @@ bool OV9281::init() libcamera::StreamConfiguration &streamConfig = m_config->at(0); + std::cout << "supported pixel formats:\n"; + + for (const auto &pixelFormat : streamConfig.formats().pixelformats()) + { + std::cout << "\t" << pixelFormat.toString() << std::endl; + + for (const auto &size : streamConfig.formats().sizes(pixelFormat)) + { + std::cout << "\t\t" << size.toString() << std::endl; + } + } + streamConfig.pixelFormat = OV9281::pixelFormat; streamConfig.bufferCount = OV9281::bufferCount; @@ -177,6 +189,7 @@ void OV9281::onRequestCompleted(libcamera::Request *completed_request) .planes()[i]; size_t size = std::min(metaplane.bytesused, plane.length); + std::cout << "size is: " << size << std::endl; void *data = m_mappedBuffers[plane.fd.get()].first; auto img = std::make_shared(); @@ -184,13 +197,14 @@ void OV9281::onRequestCompleted(libcamera::Request *completed_request) img->width = imageSize.width; img->height = imageSize.height; - memcpy(img->data, data, size); // img->dataSize = size; // img->stride = stride; img->pixelFormat = pixelFormat; img->counters.measurementCounter = metadata.sequence; img->counters.timestampUs = metadata.timestamp / 1000; img->counters.encoderPosition = RotaryEncoder::instance()->position(); + + memcpy(img->data, data, size); img->rotate(); auto pixels = img->pixels(); diff --git a/src/image.cpp b/src/image.cpp index ce814da..000ca2d 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -1,7 +1,11 @@ #include "image.h" +// #include + #include +#include + #include "macro.h" #include "pixels.h" @@ -125,3 +129,16 @@ std::shared_ptr Image::pixels() const return result; } + +void Image::copyFromData(const void *src, size_t size) +{ + if (size > sizeof(data)) + { + // throw std::logic_error(std::format) + } + + if (pixelFormat == libcamera::formats::R8) + { + memcpy(data, src, size); + } +} diff --git a/src/image.h b/src/image.h index 1ec1b93..934aa40 100644 --- a/src/image.h +++ b/src/image.h @@ -5,6 +5,7 @@ class Pixels; +// TODO: template struct Image { int width{0}; @@ -18,4 +19,5 @@ struct Image void rotate(); std::shared_ptr pixels() const; + void copyFromData(const void* src, size_t size); }; -- cgit v1.2.3-70-g09d2