summaryrefslogtreecommitdiff
path: root/src/pixels.cpp
diff options
context:
space:
mode:
authorNikita Kostovsky <nikita@kostovsky.me>2026-07-11 18:34:34 +0200
committerNikita Kostovsky <nikita@kostovsky.me>2026-07-11 18:35:26 +0200
commit169ddcb09cd26fa0a685f691f63b49e70e1be93b (patch)
tree201622d62d02db2719998f5510b70f4fda03e1d8 /src/pixels.cpp
parent7703c9efc6768d3a25eec4266594ab594cc91d4c (diff)
minor fixes and debugging
Diffstat (limited to 'src/pixels.cpp')
-rw-r--r--src/pixels.cpp64
1 files changed, 61 insertions, 3 deletions
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 <execution>
#include <filesystem>
#include <fstream>
@@ -38,13 +40,21 @@ std::optional<Pixels> 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<char*>(&result), sizeof(Pixels));
@@ -53,9 +63,11 @@ std::optional<Pixels> 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<std::mutex> 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<double> 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;
+}