Symphony Of Empires
binary_image.hpp
Go to the documentation of this file.
1 // Eng3D - General purpouse game engine
2 // Copyright (C) 2021, Eng3D contributors
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <https://www.gnu.org/licenses/>.
16 //
17 // ----------------------------------------------------------------------------
18 // Name:
19 // binary_image.hpp
20 //
21 // Abstract:
22 // Does some important stuff.
23 // ----------------------------------------------------------------------------
24 
25 #pragma once
26 
27 #include <cstdint>
28 #include <cstddef>
29 #include <exception>
30 #include <memory>
31 #include <string>
32 #include <variant>
33 
34 #include "eng3d/io.hpp"
35 #include "eng3d/color.hpp"
36 
37 namespace Eng3D {
38  class BinaryImageException: public std::exception {
39  std::string buffer;
40  public:
41  BinaryImageException(const std::string& filename, const std::string& message) {
42  buffer = "" + filename + ": " + message;
43  }
44 
45  virtual const char* what() const noexcept {
46  return buffer.c_str();
47  }
48  };
49 
53  struct BinaryImage {
54  BinaryImage() = default;
55  BinaryImage(const Eng3D::IO::Path& path);
56  BinaryImage(size_t _width, size_t _height, size_t bpp = 32);
57  BinaryImage(const BinaryImage& tex);
58  BinaryImage& operator=(const BinaryImage&) = delete;
59  virtual ~BinaryImage() = default;
60  virtual void from_file(const Eng3D::IO::Path& path);
61  virtual void to_file(const std::string& filename);
62 
67  inline Eng3D::Color get_pixel(size_t x, size_t y) const {
68  if(x >= width || y >= height)
69  return Eng3D::Color::argb32(0xffffffff);
70  return Eng3D::Color::argb32(buffer[x + y * width]);
71  }
72 
73  /*std::variant<
74  std::unique_ptr<uint8_t[]>,
75  std::unique_ptr<uint16_t[]>,
76  std::unique_ptr<uint32_t[]>> buffer;*/
77  std::unique_ptr<uint32_t[]> buffer;
78  size_t width, height;
79  size_t bpp;
80  };
81 }
virtual const char * what() const noexcept
BinaryImageException(const std::string &filename, const std::string &message)
This binary image class helps load images and visual resources from the disk; the binary image IS NOT...
virtual ~BinaryImage()=default
virtual void from_file(const Eng3D::IO::Path &path)
BinaryImage()=default
virtual void to_file(const std::string &filename)
Eng3D::Color get_pixel(size_t x, size_t y) const
Obtains a pixel from the binary image.
std::unique_ptr< uint32_t[]> buffer
BinaryImage & operator=(const BinaryImage &)=delete
Primitive color type used through the engine.
Definition: color.hpp:32
constexpr static Color argb32(uint32_t argb)
Create a color from RGBA32 components.
Definition: color.hpp:78
The path class abstracts away most of the burden from handling system-dependant filesystem paths.
Definition: io.hpp:44