mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-06 21:00:41 +02:00
moved set to Frame.hpp to avoid explicitly having to declare specializations
This commit is contained in:
parent
166a78a2a5
commit
3f83e37e6b
@ -21,6 +21,7 @@ if(AARE_TESTS)
|
|||||||
set(TestSources
|
set(TestSources
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/test/defs.test.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/test/defs.test.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/test/DType.test.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/test/DType.test.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/test/Frame.test.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/test/ProducerConsumerQueue.test.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/test/ProducerConsumerQueue.test.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/test/NDArray.test.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/test/NDArray.test.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/test/NDView.test.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/test/NDView.test.cpp
|
||||||
|
@ -26,13 +26,23 @@ class Frame {
|
|||||||
Frame(ssize_t rows, ssize_t cols, ssize_t m_bitdepth);
|
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);
|
Frame(std::byte *fp, ssize_t rows, ssize_t cols, ssize_t m_bitdepth);
|
||||||
std::byte *get(int row, int col);
|
std::byte *get(int row, int col);
|
||||||
template <typename T> void set(int row, int col, T data);
|
// 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) {
|
||||||
|
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 rows() const { return m_rows; }
|
||||||
ssize_t cols() const { return m_cols; }
|
ssize_t cols() const { return m_cols; }
|
||||||
ssize_t bitdepth() const { return m_bitdepth; }
|
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; }
|
std::byte *_get_data() { return m_data; }
|
||||||
|
|
||||||
Frame &operator=(Frame &other) {
|
Frame &operator=(Frame &other) {
|
||||||
m_rows = other.rows();
|
m_rows = other.rows();
|
||||||
m_cols = other.cols();
|
m_cols = other.cols();
|
||||||
|
@ -14,6 +14,7 @@ Frame::Frame(std::byte* bytes, ssize_t rows, ssize_t cols, ssize_t bitdepth):
|
|||||||
Frame::Frame(ssize_t rows, ssize_t cols, ssize_t bitdepth):
|
Frame::Frame(ssize_t rows, ssize_t cols, ssize_t bitdepth):
|
||||||
m_rows(rows), m_cols(cols), m_bitdepth(bitdepth) {
|
m_rows(rows), m_cols(cols), m_bitdepth(bitdepth) {
|
||||||
m_data = new std::byte[rows*cols*bitdepth/8];
|
m_data = new std::byte[rows*cols*bitdepth/8];
|
||||||
|
std::memset(m_data, 0, rows*cols*bitdepth/8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -26,29 +27,5 @@ std::byte* Frame::get(int row, int col) {
|
|||||||
return m_data+(row*m_cols + col)*(m_bitdepth/8);
|
return m_data+(row*m_cols + col)*(m_bitdepth/8);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void Frame::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);
|
|
||||||
}
|
|
||||||
|
|
||||||
template void Frame::set(int row, int col, uint16_t data);
|
|
||||||
template void Frame::set(int row, int col, uint32_t data);
|
|
||||||
|
|
||||||
|
|
||||||
// std::vector<std::vector<DataType>> Frame<DataType>::get_array() {
|
|
||||||
// std::vector<std::vector<DataType>> array;
|
|
||||||
// for (int i = 0; i < m_rows; i++) {
|
|
||||||
// std::vector<DataType> row;
|
|
||||||
// row.assign(m_data + i*m_cols, m_data + (i+1)*m_cols);
|
|
||||||
// array.push_back(row);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return array;
|
|
||||||
// }
|
|
||||||
|
|
||||||
} // namespace aare
|
} // namespace aare
|
||||||
|
Loading…
x
Reference in New Issue
Block a user