ShishGL  1.0
A simple modular cross-platform graphics library
Image.hpp
Go to the documentation of this file.
1 /*============================================================================*/
2 #ifndef SHISHGL_IMAGE_HPP
3 #define SHISHGL_IMAGE_HPP
4 /*============================================================================*/
5 #include <cstddef>
6 #include <vector>
7 #include <memory>
8 #include <immintrin.h>
9 #include <cstring>
10 #include <cassert>
11 #include <cstdlib>
12 
13 #include "Color.hpp"
14 #include "Vector2.hpp"
15 #include "IPlatform.hpp"
16 #include "RenderSystem.hpp"
17 /*============================================================================*/
18 namespace Sh {
19 
20  class Image {
21  public:
22 
23  using Pixels = std::vector<Color>;
24 
25  explicit Image(const Vector2<size_t>& size,
26  const Color& color = Color::WHITE)
27  : img_size(size) {
28  pixels.resize(size.x * size.y, color);
29  //assert(reinterpret_cast<uint64_t>(pixels.data()) % 32 == 0);
30  }
31 
32  void fill(const Color& color) {
33  pixels.assign(size().x * size().y, color);
34  }
35 
36  void setPixel(const Vector2<size_t>& pos, const Color& color) {
37  pixels[pos.y * img_size.x + pos.x] = color;
38  }
39 
40  [[nodiscard]]
41  const Color* getPixels() const {
42  return pixels.data();
43  }
44 
45  [[nodiscard]]
46  const uint8_t* getData() const {
47  return reinterpret_cast<const uint8_t*>(pixels.data());
48  }
49 
50  [[nodiscard]]
51  Color getPixel(size_t x, size_t y) const {
52  return pixels[y * img_size.x + x];
53  }
54 
55  [[nodiscard]]
56  const Vector2<size_t>& size() const {
57  return img_size;
58  }
59 
60  void blend(const Image& other);
61 
62  void paste(IPlatform::IContext* context) {
63  context->update(pixels.data());
64  }
65 
66  private:
67 
68  Vector2<size_t> img_size;
69 
70  std::vector<Color> pixels;
71 
72  };
73 
74 }
75 /*============================================================================*/
76 #endif //SHISHGL_IMAGE_HPP
77 /*============================================================================*/
Sh::Image::Image
Image(const Vector2< size_t > &size, const Color &color=Color::WHITE)
Definition: Image.hpp:25
Sh::Image::Pixels
std::vector< Color > Pixels
Definition: Image.hpp:23
Vector2.hpp
Sh::Vector2::x
T x
Definition: Vector2.hpp:10
Sh::Image::size
const Vector2< size_t > & size() const
Definition: Image.hpp:56
Sh::Vector2< size_t >
Sh::Vector2::y
T y
Definition: Vector2.hpp:10
Sh::Image::paste
void paste(IPlatform::IContext *context)
Definition: Image.hpp:62
Sh::Color::WHITE
static const Color WHITE
Definition: Color.hpp:97
Sh::Image
Definition: Image.hpp:20
Sh
Definition: CoreApplication.hpp:10
Sh::Image::getPixel
Color getPixel(size_t x, size_t y) const
Definition: Image.hpp:51
RenderSystem.hpp
Sh::Image::getPixels
const Color * getPixels() const
Definition: Image.hpp:41
Sh::Image::getData
const uint8_t * getData() const
Definition: Image.hpp:46
Sh::Color
Definition: Color.hpp:9
Sh::Image::blend
void blend(const Image &other)
Definition: Image.cpp:9
Color.hpp
IPlatform.hpp
Sh::IPlatform::IContext
Definition: IPlatform.hpp:32
Sh::Image::setPixel
void setPixel(const Vector2< size_t > &pos, const Color &color)
Definition: Image.hpp:36
Sh::IPlatform::IContext::update
virtual void update(const Color *data)=0
Sh::Image::fill
void fill(const Color &color)
Definition: Image.hpp:32