AARE
Data analysis library for PSI hybrid detectors
Loading...
Searching...
No Matches
Frame.hpp
Go to the documentation of this file.
1#pragma once
3#include "aare/core/defs.hpp"
4#include <cstddef>
5#include <cstdint>
6#include <memory>
7#include <sys/types.h>
8#include <vector>
9
16namespace aare {
17
18class Frame {
19 ssize_t m_rows;
20 ssize_t m_cols;
21 ssize_t m_bitdepth;
22 std::byte *m_data;
23
24 public:
25 Frame(ssize_t rows, ssize_t cols, ssize_t m_bitdepth);
26 Frame(std::byte *fp, ssize_t rows, ssize_t cols, ssize_t m_bitdepth);
27 std::byte *get(int row, int col);
28
29 // TODO! can we, or even want to remove the template?
30 template <typename T> void set(int row, int col, T data) {
31 assert(sizeof(T) == m_bitdepth / 8);
32 if (row < 0 || row >= m_rows || col < 0 || col >= m_cols) {
33 throw std::out_of_range("Invalid row or column index");
34 }
35 std::memcpy(m_data + (row * m_cols + col) * (m_bitdepth / 8), &data, m_bitdepth / 8);
36 }
37
38 ssize_t rows() const { return m_rows; }
39 ssize_t cols() const { return m_cols; }
40 ssize_t bitdepth() const { return m_bitdepth; }
41 ssize_t size() const { return m_rows * m_cols * m_bitdepth / 8; }
42 std::byte *data() const { return m_data; }
43
45 m_rows = other.rows();
46 m_cols = other.cols();
47 m_bitdepth = other.bitdepth();
48 m_data = new std::byte[m_rows * m_cols * m_bitdepth / 8];
49 std::memcpy(m_data, other.m_data, m_rows * m_cols * m_bitdepth / 8);
50 return *this;
51 }
52 // add move constructor
53 Frame(Frame &&other) {
54 m_rows = other.rows();
55 m_cols = other.cols();
56 m_bitdepth = other.bitdepth();
57 m_data = other.m_data;
58 other.m_data = nullptr;
59 other.m_rows = other.m_cols = other.m_bitdepth = 0;
60 }
61 // copy constructor
62 Frame(const Frame &other) {
63 m_rows = other.rows();
64 m_cols = other.cols();
65 m_bitdepth = other.bitdepth();
66 m_data = new std::byte[m_rows * m_cols * m_bitdepth / 8];
67 std::memcpy(m_data, other.m_data, m_rows * m_cols * m_bitdepth / 8);
68 }
69
70 template <typename T> NDView<T> view() {
71 std::vector<ssize_t> shape = {m_rows, m_cols};
72 T *data = reinterpret_cast<T *>(m_data);
73 return NDView<T>(data, shape);
74 }
75
76 template <typename T> NDArray<T> image() { return NDArray<T>(this->view<T>()); }
77
78 ~Frame() { delete[] m_data; }
79};
80
81} // namespace aare
Definition Frame.hpp:18
ssize_t size() const
Definition Frame.hpp:41
ssize_t m_bitdepth
Definition Frame.hpp:21
ssize_t m_rows
Definition Frame.hpp:19
Frame(Frame &&other)
Definition Frame.hpp:53
ssize_t m_cols
Definition Frame.hpp:20
ssize_t rows() const
Definition Frame.hpp:38
std::byte * data() const
Definition Frame.hpp:42
ssize_t cols() const
Definition Frame.hpp:39
std::byte * get(int row, int col)
Definition Frame.cpp:19
~Frame()
Definition Frame.hpp:78
Frame(const Frame &other)
Definition Frame.hpp:62
NDArray< T > image()
Definition Frame.hpp:76
Frame & operator=(Frame &other)
Definition Frame.hpp:44
void set(int row, int col, T data)
Definition Frame.hpp:30
ssize_t bitdepth() const
Definition Frame.hpp:40
NDView< T > view()
Definition Frame.hpp:70
std::byte * m_data
Definition Frame.hpp:22
Definition NDArray.hpp:23
Definition NDView.hpp:46
Frame class to represent a single frame of data model class should be able to work with streams comin...
Definition CircularFifo.hpp:11