save work and start templating file with detector

This commit is contained in:
Bechir Braham 2024-02-26 18:29:22 +01:00
parent b0ce167471
commit 1bffa4a86d
No known key found for this signature in database
GPG Key ID: 7F511B55FD8E9671
6 changed files with 29 additions and 19 deletions

View File

@ -88,7 +88,8 @@
"locale": "cpp", "locale": "cpp",
"__tree": "cpp", "__tree": "cpp",
"queue": "cpp", "queue": "cpp",
"stack": "cpp" "stack": "cpp",
"shared_mutex": "cpp"
}, },
"C_Cpp.errorSquiggles": "enabled" "C_Cpp.errorSquiggles": "enabled"
} }

View File

@ -2,25 +2,21 @@
#include <iostream> #include <iostream>
template <class DataType> IFrame::IFrame(std::byte* bytes, ssize_t rows, ssize_t cols, ssize_t bitdepth)
Frame<DataType>::Frame(std::byte* bytes, ssize_t rows, ssize_t cols)
{ {
this->rows = rows; this->rows = rows;
this->cols = cols; this->cols = cols;
data = new DataType[rows * cols]; data = new std::byte[rows * cols*bitdepth/8];
std::memcpy(data, bytes, sizeof(DataType) * rows * cols); std::memcpy(data, bytes, bitdepth/8 * rows * cols);
} }
template <class DataType> std::byte* IFrame::get(int row, int col) {
DataType Frame<DataType>::get(int row, int col) {
if (row < 0 || row >= rows || col < 0 || col >= cols) { if (row < 0 || row >= rows || col < 0 || col >= cols) {
std::cerr << "Invalid row or column index" << std::endl; std::cerr << "Invalid row or column index" << std::endl;
return 0; return 0;
} }
return data[row * cols + col]; return data+(row * cols + col)*bitdepth/8;
} }
template class Frame<uint16_t>;
template class Frame<uint32_t>;

View File

@ -7,21 +7,30 @@
#include "defs.hpp" #include "defs.hpp"
/** /**
* @brief Frame class to represent a single frame of data * @brief Frame class to represent a single frame of data
* model class * model class
* should be able to work with streams coming from files or network * should be able to work with streams coming from files or network
*/ */
template <class DataType> class IFrame {
class Frame {
DataType* data{nullptr}; std::byte* data{nullptr};
ssize_t rows{}; ssize_t rows{};
ssize_t cols{}; ssize_t cols{};
ssize_t bitdepth{};
public: public:
Frame(std::byte* fp, ssize_t rows, ssize_t cols); IFrame(std::byte* fp, ssize_t rows, ssize_t cols, ssize_t bitdepth);
DataType get(int row, int col); std::byte* get(int row, int col);
~Frame(){ ~IFrame(){
delete[] data; delete[] data;
} }
};
template <class DataType> class Frame: public IFrame {
public:
Frame(std::byte* fp, ssize_t rows, ssize_t cols):IFrame(fp, rows, cols, sizeof(DataType)){}
DataType get(int row, int col){
return *((DataType*) IFrame::get(row, col));
}
}; };

View File

View File

@ -1,7 +1,8 @@
#include "JsonFile.hpp" #include "JsonFile.hpp"
#include <typeinfo> #include <typeinfo>
Frame<uint16_t> JsonFile::get_frame(int frame_number){ template <class T>
Frame<T> JsonFile::get_frame(int frame_number){
int subfile_id=frame_number/max_frames_per_file; int subfile_id=frame_number/max_frames_per_file;
std::byte* buffer; std::byte* buffer;
size_t frame_size = subfiles[subfile_id]->bytes_per_frame(); size_t frame_size = subfiles[subfile_id]->bytes_per_frame();
@ -11,7 +12,7 @@ Frame<uint16_t> JsonFile::get_frame(int frame_number){
auto f = Frame<uint16_t>(buffer, rows, cols); auto f = Frame<T>(buffer, rows, cols);
delete[] buffer; delete[] buffer;
return f; return f;

View File

@ -5,6 +5,9 @@
class JsonFile: public File class JsonFile: public File
{ {
Frame<uint16_t> get_frame(int frame_number); template <class T>
Frame<T> get_frame(int frame_number);
IFrame get_frame(int frame_number);
}; };