AGL
A graphics library
image.h
1 // Copyright 2021, Savvy Sine, alinen
2 
3 #ifndef AGL_IMAGE_H_
4 #define AGL_IMAGE_H_
5 
6 #include <iostream>
7 #include <string>
8 #include "agl/aglm.h"
9 
10 namespace agl {
11 
17 struct Pixel {
18  unsigned char r;
19  unsigned char g;
20  unsigned char b;
21  unsigned char a;
22 };
23 
27 class Image {
28  public:
29  Image();
30  Image(int width, int height);
31  Image(const Image& orig);
32  Image& operator=(const Image& orig);
33 
34  virtual ~Image();
35 
42  bool load(const std::string& filename);
43 
49  bool save(const std::string& filename, bool flip = true) const;
50 
53  inline int width() const { return myWidth; }
54 
57  inline int height() const { return myHeight; }
58 
64  inline unsigned char* data() const { return myData; }
65 
74  void set(int width, int height, unsigned char* data);
75 
83  Pixel get(int row, int col) const;
84 
93  void set(int row, int col, const Pixel& color);
94 
102  void setVec4(int row, int col, const glm::vec4& color);
103 
111  glm::vec4 getVec4(int row, int col) const;
112 
113  private:
114  void clear();
115 
116  private:
117  unsigned char* myData;
118  unsigned int myWidth;
119  unsigned int myHeight;
120  bool myLoaded;
121 };
122 } // namespace agl
123 #endif // AGL_IMAGE_H_
agl::Image::set
void set(int width, int height, unsigned char *data)
Replace image RGBA data.
Definition: image.cpp:55
agl::Image::width
int width() const
Return the image width in pixels.
Definition: image.h:53
agl::Image::height
int height() const
Return the image height in pixels.
Definition: image.h:57
agl::Image::save
bool save(const std::string &filename, bool flip=true) const
Save the image to the given filename (.png)
Definition: image.cpp:87
agl::Pixel
Holder for a RGBA color.
Definition: image.h:17
agl::Image::getVec4
glm::vec4 getVec4(int row, int col) const
Get the pixel RGBA color at index (row, col)
Definition: image.cpp:117
agl::Image
Implements loading, modifying, and saving RGBA images.
Definition: image.h:27
aglm.h
Global utilities and common third party includes.
agl::Image::get
Pixel get(int row, int col) const
Get the pixel at index (row, col)
Definition: image.cpp:94
agl::Image::setVec4
void setVec4(int row, int col, const glm::vec4 &color)
Set the pixel RGBA color at index (row, col)
Definition: image.cpp:129
agl::Image::load
bool load(const std::string &filename)
Load the given filename (.png)
Definition: image.cpp:75
agl::Image::data
unsigned char * data() const
Return the RGBA data.
Definition: image.h:64