moved set to Frame.hpp to avoid explicitly having to declare specializations

This commit is contained in:
Erik Frojdh
2024-04-03 12:05:21 +02:00
parent 166a78a2a5
commit 3f83e37e6b
3 changed files with 15 additions and 27 deletions

View File

@@ -26,13 +26,23 @@ class Frame {
Frame(ssize_t rows, ssize_t cols, ssize_t m_bitdepth);
Frame(std::byte *fp, ssize_t rows, ssize_t cols, ssize_t m_bitdepth);
std::byte *get(int row, int col);
template <typename T> void set(int row, int col, T data);
// std::vector<std::vector<DataType>> get_array();
// template <typename T> void set(int row, int col, T data);
template <typename T>
void set(int row, int col, T data) {
assert(sizeof(T) == m_bitdepth/8);
if (row < 0 || row >= m_rows || col < 0 || col >= m_cols) {
std::cerr << "Invalid row or column index" << std::endl;
return;
}
std::memcpy(m_data+(row*m_cols + col)*(m_bitdepth/8), &data, m_bitdepth/8);
}
ssize_t rows() const { return m_rows; }
ssize_t cols() const { return m_cols; }
ssize_t bitdepth() const { return m_bitdepth; }
inline ssize_t size() const { return m_rows * m_cols * m_bitdepth / 8; }
ssize_t size() const { return m_rows * m_cols * m_bitdepth / 8; }
std::byte *_get_data() { return m_data; }
Frame &operator=(Frame &other) {
m_rows = other.rows();
m_cols = other.cols();