Sirius  0.0.0
image.h
Go to the documentation of this file.
1 
22 #ifndef SIRIUS_IMAGE_H_
23 #define SIRIUS_IMAGE_H_
24 
25 #include <cassert>
26 
27 #include "sirius/types.h"
28 
29 namespace sirius {
30 
31 enum class PaddingType {
32  kZeroPadding = 0,
33  kMirrorPadding = 1,
34 };
35 
39 struct Padding {
40  Padding() = default;
41  Padding(int top, int bottom, int left, int right,
43 
44  ~Padding() = default;
45  Padding(const Padding&) = default;
46  Padding& operator=(const Padding&) = default;
47  Padding(Padding&&) = default;
48  Padding& operator=(Padding&&) = default;
49 
50  int top{0};
51  int bottom{0};
52  int left{0};
53  int right{0};
54 
55  bool IsEmpty() const {
56  return (top == 0 && bottom == 0 && left == 0 && right == 0);
57  }
58 
60 };
61 
65 class Image {
66  public:
67  Image() = default;
68 
74  explicit Image(const Size& size);
75 
81  Image(const Size& size, Buffer&& buffer);
82 
83  ~Image() = default;
84 
85  Image(const Image&) = default;
86  Image& operator=(const Image&) = default;
87  Image(Image&&);
88  Image& operator=(Image&&);
89 
94  int CellCount() const { return size.CellCount(); }
95 
101  Buffer::value_type Get(int row, int col) const {
102  assert(row < size.row && col < size.col);
103 
104  return data[row * size.col + col];
105  }
106 
111  void Set(int row, int col, Buffer::value_type val) {
112  assert(row < size.row && col < size.col);
113 
114  data[row * size.col + col] = val;
115  }
116 
122  bool IsLoaded() const {
123  return size.row != 0 && size.col != 0 &&
124  data.size() >= static_cast<std::size_t>(CellCount());
125  }
126 
135  Image CreatePaddedImage(const Padding& padding) const;
136 
142  Image CreateZeroPaddedImage(const Padding& zero_padding) const;
143 
149  Image CreateMirrorPaddedImage(const Padding& mirror_padding) const;
150 
154  void CreateEvenImage();
155 
156  public:
157  Size size{0, 0};
159 };
160 
161 } // namespace sirius
162 
163 #endif // SIRIUS_IMAGE_H_
int left
Definition: image.h:52
PaddingType
Definition: image.h:31
Definition: exception.h:27
Buffer data
Definition: image.h:158
void Set(int row, int col, Buffer::value_type val)
Set the value at cell (row, col) Row and col starts at 0.
Definition: image.h:111
void CreateEvenImage()
add row and col according to odd dim of calling image
~Padding()=default
Image CreateZeroPaddedImage(const Padding &zero_padding) const
Create a zero padded image from the current image.
Image & operator=(const Image &)=default
std::vector< double > Buffer
Definition: types.h:33
int top
Definition: image.h:50
int bottom
Definition: image.h:51
~Image()=default
Image CreateMirrorPaddedImage(const Padding &mirror_padding) const
Create a padded image using mirroring on borders.
Padding()=default
int CellCount() const
Definition: types.h:77
int CellCount() const
Get the cell count of the image (row x col)
Definition: image.h:94
Data class that represents the padding of an image.
Definition: image.h:39
Data class that represents the size of an image.
Definition: types.h:38
Image CreatePaddedImage(const Padding &padding) const
Create padded image from the current image.
int row
Definition: types.h:79
bool IsEmpty() const
Definition: image.h:55
int right
Definition: image.h:53
Image()=default
int col
Definition: types.h:80
Buffer::value_type Get(int row, int col) const
Get the value at cell (row, col) Row and col starts at 0.
Definition: image.h:101
Data class that represents an image (Size + Buffer)
Definition: image.h:65
PaddingType type
Definition: image.h:59
Padding & operator=(const Padding &)=default
bool IsLoaded() const
Check that the image is loaded Row, col and data are set.
Definition: image.h:122
Size size
Definition: image.h:157