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
6 changed files with 29 additions and 19 deletions

View File

@ -2,25 +2,21 @@
#include <iostream>
template <class DataType>
Frame<DataType>::Frame(std::byte* bytes, ssize_t rows, ssize_t cols)
IFrame::IFrame(std::byte* bytes, ssize_t rows, ssize_t cols, ssize_t bitdepth)
{
this->rows = rows;
this->cols = cols;
data = new DataType[rows * cols];
std::memcpy(data, bytes, sizeof(DataType) * rows * cols);
data = new std::byte[rows * cols*bitdepth/8];
std::memcpy(data, bytes, bitdepth/8 * rows * cols);
}
template <class DataType>
DataType Frame<DataType>::get(int row, int col) {
std::byte* IFrame::get(int row, int col) {
if (row < 0 || row >= rows || col < 0 || col >= cols) {
std::cerr << "Invalid row or column index" << std::endl;
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"
/**
* @brief Frame class to represent a single frame of data
* model class
* should be able to work with streams coming from files or network
*/
template <class DataType>
class Frame {
class IFrame {
DataType* data{nullptr};
std::byte* data{nullptr};
ssize_t rows{};
ssize_t cols{};
ssize_t bitdepth{};
public:
Frame(std::byte* fp, ssize_t rows, ssize_t cols);
DataType get(int row, int col);
~Frame(){
IFrame(std::byte* fp, ssize_t rows, ssize_t cols, ssize_t bitdepth);
std::byte* get(int row, int col);
~IFrame(){
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));
}
};