SPH
Bitmap.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include "gui/objects/Color.h"
9 #include "gui/objects/Point.h"
11 
13 
14 class Path;
15 
16 template <typename Type>
17 class Bitmap : public Noncopyable {
18 private:
19  Array<Type> values;
20  Pixel res;
21 
22 public:
24  : res(0, 0) {}
25 
26  explicit Bitmap(const Pixel resolution)
27  : res(resolution) {
28  values.resize(res.x * res.y);
29  }
30 
31  Bitmap clone() const {
32  Bitmap cloned;
33  cloned.values = values.clone();
34  cloned.res = res;
35  return cloned;
36  }
37 
38  void resize(const Pixel newResolution, const Type& value) {
39  res = newResolution;
40  values.resize(res.x * res.y);
41  this->fill(value);
42  }
43 
44  void fill(const Type& value) {
45  values.fill(value);
46  }
47 
48  Type& operator[](const Pixel p) {
49  return values[map(p)];
50  }
51 
52  const Type& operator[](const Pixel p) const {
53  return values[map(p)];
54  }
55 
56  Type& operator()(const int x, const int y) {
57  return values[map(Pixel(x, y))];
58  }
59 
60  const Type& operator()(const int x, const int y) const {
61  return values[map(Pixel(x, y))];
62  }
63 
64  Type* data() {
65  return &values[0];
66  }
67 
68  const Type* data() const {
69  return &values[0];
70  }
71 
72  Pixel size() const {
73  return res;
74  }
75 
76  bool empty() const {
77  return values.empty();
78  }
79 
80 private:
81  INLINE Size map(const Pixel p) const {
82  return p.y * res.x + p.x;
83  }
84 };
85 
86 void toWxBitmap(const Bitmap<Rgba>& bitmap, wxBitmap& wx);
87 
88 Bitmap<Rgba> toBitmap(wxBitmap& wx);
89 
90 void saveToFile(const wxBitmap& wx, const Path& path);
91 
92 void saveToFile(const Bitmap<Rgba>& bitmap, const Path& path);
93 
95 
Generic dynamically allocated resizable storage.
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Bitmap< Rgba > loadBitmapFromFile(const Path &path)
Definition: Bitmap.cpp:70
Bitmap< Rgba > toBitmap(wxBitmap &wx)
Definition: Bitmap.cpp:39
void saveToFile(const wxBitmap &wx, const Path &path)
Definition: Bitmap.cpp:59
void toWxBitmap(const Bitmap< Rgba > &bitmap, wxBitmap &wx)
Definition: Bitmap.cpp:12
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
#define INLINE
Macros for conditional compilation based on selected compiler.
Definition: Object.h:31
#define NAMESPACE_SPH_END
Definition: Object.h:12
void resize(const TCounter newSize)
Resizes the array to new size.
Definition: Array.h:215
void fill(const T &t)
Sets all elements of the array to given value.
Definition: Array.h:187
INLINE bool empty() const noexcept
Definition: Array.h:201
Array clone() const
Performs a deep copy of all elements of the array.
Definition: Array.h:147
Definition: Bitmap.h:17
void resize(const Pixel newResolution, const Type &value)
Definition: Bitmap.h:38
bool empty() const
Definition: Bitmap.h:76
Type & operator()(const int x, const int y)
Definition: Bitmap.h:56
const Type & operator()(const int x, const int y) const
Definition: Bitmap.h:60
Bitmap clone() const
Definition: Bitmap.h:31
Bitmap(const Pixel resolution)
Definition: Bitmap.h:26
Type & operator[](const Pixel p)
Definition: Bitmap.h:48
Type * data()
Definition: Bitmap.h:64
Bitmap()
Definition: Bitmap.h:23
const Type * data() const
Definition: Bitmap.h:68
Pixel size() const
Definition: Bitmap.h:72
void fill(const Type &value)
Definition: Bitmap.h:44
const Type & operator[](const Pixel p) const
Definition: Bitmap.h:52
Object representing a path on a filesystem.
Definition: Path.h:17
Simple 2D vector with integer coordinates. Provides conversion from and to wxPoint.
Object with deleted copy constructor and copy operator.
Definition: Object.h:54
Definition: Point.h:101