read numpy file: works

This commit is contained in:
Bechir
2024-03-08 18:26:02 +01:00
parent 146d2aed19
commit 765bbdc295
14 changed files with 154 additions and 67 deletions

View File

@ -22,6 +22,7 @@ template <class DataType> class Frame{
ssize_t cols;
DataType* data;
ssize_t bitdepth = sizeof(DataType)*8;
Frame(ssize_t rows, ssize_t cols);
Frame(std::byte* fp, ssize_t rows, ssize_t cols);
DataType get(int row, int col);

View File

@ -8,13 +8,18 @@ Frame<DataType>::Frame(std::byte* bytes, ssize_t rows, ssize_t cols):
std::memcpy(data, bytes, rows*cols*sizeof(DataType));
}
template <typename DataType>
Frame<DataType>::Frame(ssize_t rows, ssize_t cols):
rows(rows), cols(cols) {
data = new DataType[rows*cols];
}
template <typename DataType>
DataType Frame<DataType>::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;
throw std::runtime_error("Invalid row or column index");
}
return data[row*cols + col];
}