Arty
image.h
1 #ifndef IMAGE_H
2 #define IMAGE_H
3 
4 #include <string>
5 #include <vector>
6 
7 #include "color.h"
8 
9 struct Image {
10  Image() {}
11  Image(size_t w, size_t h)
12  : pixels(w * h), width(w), height(h)
13  {}
14 
15  const rgba& operator () (size_t x, size_t y) const { return pixels[y * width + x]; }
16  rgba& operator () (size_t x, size_t y) { return pixels[y * width + x]; }
17 
18  const rgba* row(size_t y) const { return &pixels[y * width]; }
19  rgba* row(size_t y) { return &pixels[y * width]; }
20 
21  void resize(size_t w, size_t h) {
22  width = w;
23  height = h;
24  pixels.resize(w * h);
25  }
26 
27  void clear() {
28  std::fill(pixels.begin(), pixels.end(), rgba(0.0f, 0.0f, 0.0f, 1.0f));
29  }
30 
31  std::vector<rgba> pixels;
32  size_t width, height;
33 };
34 
36 bool load_png(const std::string& png_file, Image& image);
38 bool save_png(const Image& image, const std::string& png_file);
39 
41 bool load_tga(const std::string& tga_file, Image& image);
42 
43 #endif // IMAGE_H
Definition: color.h:32
Definition: image.h:9