doodle  0.2
Intended to support teaching C++, doodle is a simple library that 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) 2021 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 #include <memory>
11 
12 namespace doodle
13 {
14  struct Color;
15 
29  class [[nodiscard]] Image
30  {
31  public:
43  static int MaxImageSize() noexcept;
44 
45  public:
93  Image(int width, int height, bool smooth_it = false);
94 
138  explicit Image(const std::filesystem::path& file_path, bool smooth_it = false);
139 
144  Image();
145 
149  enum class FileType
150  {
154  PNG,
158  BMP,
162  TGA
163  };
171  void SaveToFile(const std::filesystem::path& file_path, FileType file_type = FileType::PNG) const;
176  int GetWidth() const noexcept;
181  int GetHeight() const noexcept;
186  int GetNumberOfColors() const noexcept;
191  bool IsSmooth() const noexcept;
192 
253  Color operator[](int index) const;
316  Color& operator[](int index);
317 
386  Color operator()(int column, int row) const;
456  Color& operator()(int column, int row);
457 
529  Color* begin();
604  Color* end();
605 
620  const Color* begin() const;
674  const Color* end() const;
675 
676  private:
677  class ImageImpl;
678  std::shared_ptr<ImageImpl> impl{};
679 
680  private:
681  explicit Image(const std::shared_ptr<ImageImpl>& impl);
682 
683  private:
684  friend void draw_image(const Image& image, double x, double y) noexcept;
685  friend void draw_image(const Image& image, double x, double y, double width, double height) noexcept;
686  friend void draw_image(const Image& image, double x, double y, double width, double height) noexcept;
687  friend void draw_image(const Image& image, double x, double y, double width, double height, int texel_x,
688  int texel_y) noexcept;
689  friend void draw_image(const Image& image, double x, double y, double width, double height, int texel_x,
690  int texel_y, int texel_width, int texel_height) noexcept;
691  friend Image end_drawing_to_image(bool smooth_texture);
692  };
694 }
Image class to store a 2D array of RGBA colors. Also manages an image on the Graphics Card.
Definition: image.hpp:30
friend void draw_image(const Image &image, double x, double y, double width, double height, int texel_x, int texel_y) noexcept
Draw a subsection of the image to the screen.
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:150
int GetWidth() const noexcept
Return the width of the image.
friend void draw_image(const Image &image, double x, double y, double width, double height, int texel_x, int texel_y, int texel_width, int texel_height) noexcept
Draw a subsection of the image to the screen.
friend void draw_image(const Image &image, double x, double y, double width, double height) noexcept
Draw an entire image to the screen and resize it to a custom size.
friend void draw_image(const Image &image, double x, double y) noexcept
Draw an entire image to the screen.
static int MaxImageSize() noexcept
Get the maximum image size allowed.
friend Image end_drawing_to_image(bool smooth_texture)
End a session of drawing to an image.
Definition: angle.hpp:11
Color is a color represented with four unsigned bytes.
Definition: color.hpp:53