From 169ddcb09cd26fa0a685f691f63b49e70e1be93b Mon Sep 17 00:00:00 2001 From: Nikita Kostovsky Date: Sat, 11 Jul 2026 18:34:34 +0200 Subject: minor fixes and debugging --- src/pixels.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 3 deletions(-) (limited to 'src/pixels.cpp') diff --git a/src/pixels.cpp b/src/pixels.cpp index e6d359c..5b7b226 100644 --- a/src/pixels.cpp +++ b/src/pixels.cpp @@ -1,5 +1,7 @@ #include "pixels.h" +#include "fuck_intel.h" + #include #include #include @@ -38,13 +40,21 @@ std::optional Pixels::load( if (!std::filesystem::exists(filepath)) { std::cerr << "no such file: " << filepath << std::endl; - return {}; + return std::nullopt; + } + + const auto fileSize = std::filesystem::file_size(filepath); + + if (fileSize != sizeof(Pixels)) { + std::cerr << "wrong file size: " << filepath << std::endl; + std::cerr << "sizeof(Pixels): " << sizeof(Pixels) << std::endl; + return std::nullopt; } std::ifstream ifs(filepath, std::ios::in | std::ios::binary); if (!ifs) - return {}; + return std::nullopt; Pixels result; ifs.read(reinterpret_cast(&result), sizeof(Pixels)); @@ -53,9 +63,11 @@ std::optional Pixels::load( if (!ifs) { std::cerr << "cannot read " << filepath << std::endl; - return {}; + return std::nullopt; } + result.debugPrintIfInvalid(); + return result; } @@ -87,6 +99,8 @@ bool Pixels::save( return false; } + debugPrintIfInvalid(); + std::cout << "saved pixels at enc pos " << counters.encoderPosition << std::endl; return true; @@ -104,7 +118,51 @@ Pixels::operator bool() const return result; } +bool Pixels::debugPrintIfInvalid() const +{ + const bool valid{std::find_if(std::execution::par_unseq, + pixels.cbegin(), + pixels.cend(), + [](const auto &p) { return p > 280; }) + == pixels.cend()}; + + if (!valid) { + qCritical() << Q_FUNC_INFO << "got invalid profile:" << *this; + } + + return valid; +} + // std::lock_guard Pixels::lock() // { // return std::move(std::lock_guard{m_mtx}); // } + +QDebug &operator<<(QDebug &debug, const Pixels &pixels) +{ + QDebugStateSaver saver{debug}; + const auto &c = pixels.counters; + const auto &px = pixels.pixels; + + QList numbers; + + for (size_t i{0}; i < 4 && i < px.size(); ++i) { + numbers << px.at(i); + } + + for (size_t i{(px.size() - 4) / 2}; i < px.size() / 2 + 2 && i < px.size(); ++i) { + numbers << px.at(i); + } + + for (size_t i{px.size() - 4 - 1}; i < px.size(); ++i) { + numbers << px.at(i); + } + + debug.nospace().noquote() << QStringLiteral("Pixels { ts: %1 mc: %2 ep: %3 [ %4 ] }") + .arg(QString::number(c.timestampUs), + QString::number(c.measurementCounter), + QString::number(c.encoderPosition)) + << qSetRealNumberPrecision(4) << numbers; + + return debug; +} -- cgit v1.3.1