From 69c5e9c07941212ac77368effd1c60db3140d4a3 Mon Sep 17 00:00:00 2001 From: Nikita Kostovsky Date: Sat, 8 Nov 2025 18:24:01 +0100 Subject: use vld1q_u32/vst1q_u32 for memcpy --- src/camera/veyeimx287m.cpp | 18 ++++++++++++++---- src/main.cpp | 4 +++- src/mem_utils.cpp | 1 + src/mem_utils.h | 25 +++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 src/mem_utils.cpp create mode 100644 src/mem_utils.h (limited to 'src') diff --git a/src/camera/veyeimx287m.cpp b/src/camera/veyeimx287m.cpp index c7e519a..d4c19fe 100644 --- a/src/camera/veyeimx287m.cpp +++ b/src/camera/veyeimx287m.cpp @@ -16,6 +16,7 @@ #include "constants.h" #include "imagealgos.h" +#include "mem_utils.h" #include "pixels.h" // #include "rotaryencoder.h" @@ -80,7 +81,8 @@ std::vector > VeyeIMX287m::search() if (!cam->init()) return {}; - if (!cam->setExposureTimeUs(30)) + // if (!cam->setExposureTimeUs(30)) + if (!cam->setExposureTimeUs(250)) return {}; if (!cam->setLaserLevel(1)) @@ -143,7 +145,8 @@ bool VeyeIMX287m::init() bool VeyeIMX287m::setExposureTimeUs(int valueUs) { //return true; - std::cout << __func__ << ": " << valueUs << std::endl << std::flush; + std::cout << __func__ << ": " << V4L2_CID_EXPOSURE << " - " << valueUs << std::endl + << std::flush; /* * Shutter Time. Value is from 8721ns to 8721*885ns, must be integral @@ -162,6 +165,7 @@ bool VeyeIMX287m::setExposureTimeUs(int valueUs) // setLaserLevel(rand() % 100); // int exp = rand() % 10; // return setCamParam(V4L2_CID_EXPOSURE, exp * exp * exp * exp * exp * exp); + // return setCamParam(V4L2_CID_EXPOSURE, valueUs); return setCamParam(V4L2_CID_EXPOSURE, valueUs); } @@ -218,7 +222,7 @@ bool VeyeIMX287m::setCamParam(unsigned int v4l2controlId, int value) return false; } - // std::cout << __func__ << ": new value is " << ctl.value << std::endl; + std::cout << __func__ << ": new value is " << ctl.value << std::endl; return true; } @@ -374,7 +378,13 @@ void VeyeIMX287m::calcFrameLoop(std::stop_token stopToken) { t.start(); // std::lock_guard buffer_lock{m_bufferMutexes[bufferIdx]}; - memcpy(&image.data, m_videoBuffers[bufferIdx], img_size); + // get: 4100-4500 + // memcpy(&image.data, m_videoBuffers[bufferIdx], img_size); + // get: 5000-5100 + // memcpy_1by1((std::byte *) &image.data, + // (std::byte *) m_videoBuffers[bufferIdx]); + memcpy_neon((ARRAY_TYPE *) &image.data, + (ARRAY_TYPE *) m_videoBuffers[bufferIdx]); get_elapsed_ns += t.nsecsElapsed(); } diff --git a/src/main.cpp b/src/main.cpp index ca2da6f..46f8d6d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -656,9 +656,11 @@ int main(int argc, char* argv[]) // qDebug() << "set new exposure time:" << value; // requested_params.exposureTime = value; - if (!camera->setExposureTimeUs(value)) + if (!camera->setExposureTimeUs(value)) { + qDebug() << "cannot set exp"; return QHttpServerResponse::StatusCode:: RequestRangeNotSatisfiable; + } } if (json.contains(gainKey)) diff --git a/src/mem_utils.cpp b/src/mem_utils.cpp new file mode 100644 index 0000000..f5fae0f --- /dev/null +++ b/src/mem_utils.cpp @@ -0,0 +1 @@ +#include "mem_utils.h" diff --git a/src/mem_utils.h b/src/mem_utils.h new file mode 100644 index 0000000..8601f78 --- /dev/null +++ b/src/mem_utils.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include + +template +void memcpy_1by1(std::byte *dst, const std::byte *src) +{ + for (std::size_t i{0}; i < S; ++i) { + dst[i] = src[i]; + } +} + +using ARRAY_TYPE = uint32_t; +template +void memcpy_neon(ARRAY_TYPE *dst, const ARRAY_TYPE *src) +{ + uint32x4_t tmp; + + for (std::size_t i{0}; i < (S / 4); i += 4) { + tmp = vld1q_u32(src + i); + vst1q_u32(&dst[i], tmp); + } +} -- cgit v1.2.3-70-g09d2