doodle  0.1.0
Intended to support teaching C++, doodle is a simple librarythat helps make a window and makes it easy to do some drawing.
image.hpp
Go to the documentation of this file.
1 /*--------------------------------------------------------------*
2  Copyright (C) 2019 Rudy Castan
3 
4  This file is distributed WITHOUT ANY WARRANTY. See the file
5  `License.md' for details.
6 *--------------------------------------------------------------*/
7 #pragma once
8 
9 #include <filesystem>
10 
11 namespace doodle
12 {
13  struct Color;
14 
28  class [[nodiscard]] Image
29  {
30  public:
42  static int MaxImageSize() noexcept;
43 
44  public:
95  Image(int width, int height, bool smooth_it = false);
142  explicit Image(const std::filesystem::path& file_path, bool smooth_it = false);
149  Image();
158  ~Image();
169  Image(const Image&) = delete;
181  Image& operator=(const Image&) = delete;
192  Image(Image && other) noexcept;
205  Image& operator=(Image&& other) noexcept;
206 
210  enum class FileType
211  {
215  PNG,
219  BMP,
223  TGA
224  };
232  void SaveToFile(const std::filesystem::path& file_path, FileType file_type = FileType::PNG) const;
237  int GetWidth() const noexcept;
242  int GetHeight() const noexcept;
247  int GetNumberOfColors() const noexcept;
252  bool IsSmooth() const noexcept;
253 
257  struct color
258  {
259  using byte = unsigned char;
260  byte red = 0, green = 0, blue = 0, alpha = 255;
261 
265  color() = default;
270  color(const doodle::Color& c) noexcept;
274  operator doodle::Color() const noexcept;
275  };
276 
337  color operator[](int index) const;
400  color& operator[](int index);
401 
470  color operator()(int column, int row) const;
540  color& operator()(int column, int row);
541 
613  color* begin();
682  color* end();
683 
738  const color* begin() const;
792  const color* end() const;
793 
794  private:
795  class ImageImpl;
796  std::unique_ptr<ImageImpl> impl;
797 
798  private:
799  friend void draw_image(const Image& image, double x, double y) noexcept;
800  friend void draw_image(const Image& image, double x, double y, double width, double height) noexcept;
801  friend void draw_image(const Image& image, double x, double y, double width, double height) noexcept;
802  friend void draw_image(const Image& image, double x, double y, double width, double height, int texel_x,
803  int texel_y) noexcept;
804  friend void draw_image(const Image& image, double x, double y, double width, double height, int texel_x,
805  int texel_y, int texel_width, int texel_height) noexcept;
806  };
808 }
Image class to store a 2D array of RGBA colors. Also manages an image on the Graphics Card.
Definition: image.hpp:29
void SaveToFile(const std::filesystem::path &file_path, FileType file_type=FileType::PNG) const
Save the Image as an image file on disk.
FileType
Lists all of the supported image file formats.
Definition: image.hpp:211
int GetWidth() const noexcept
Return the width of the image.
static int MaxImageSize() noexcept
Get the maximum image size allowed.
void draw_image(const Image &image, double x, double y) noexcept
Draw an entire image to the screen.
Definition: angle.hpp:11
Color is a color represented with four unsigned bytes.
Definition: color.hpp:53
struct to represent the colors of the Image.
Definition: image.hpp:258
color()=default
Defaults to black.
color(const doodle::Color &c) noexcept
Can be constructed from a Color object.