gKit2 light
image.h
Go to the documentation of this file.
1 
2 #ifndef _IMAGE_H
3 #define _IMAGE_H
4 
5 #include <vector>
6 #include <cassert>
7 
8 #include "color.h"
9 
10 
13 
16 
18 class Image
19 {
20 protected:
21  std::vector<Color> m_data;
22  int m_width;
23  int m_height;
24 
25 public:
26  Image( ) : m_data(), m_width(0), m_height(0) {}
27  Image( const int w, const int h, const Color& color= Black() ) : m_data(w*h, color), m_width(w), m_height(h) {}
28 
38  Color& operator() ( const int x, const int y )
39  {
40  std::size_t offset= y * m_width + x;
41  assert(offset < m_data.size());
42  return m_data[offset];
43  }
44 
46  Color operator() ( const int x, const int y ) const
47  {
48  std::size_t offset= y * m_width + x;
49  assert(offset < m_data.size());
50  return m_data[offset];
51  }
52 
54  const void * buffer( ) const
55  {
56  assert(!m_data.empty());
57  return &m_data.front();
58  }
59 
61  int width( ) const { return m_width; }
63  int height( ) const { return m_height; }
65  std::size_t size( ) const { return m_width * m_height; }
66 
75  static Image& error( )
76  {
77  static Image image;
78  return image;
79  }
80 
82  bool operator== ( const Image& im ) const
83  {
84  // renvoie vrai si im ou l'objet est la sentinelle
85  return (this == &im);
86  }
87 };
88 
90 #endif
const void * buffer() const
renvoie un pointeur sur le stockage des couleurs des pixels.
Definition: image.h:54
static Image & error()
Definition: image.h:75
bool operator==(const Image &im) const
comparaison avec la sentinelle.
Definition: image.h:82
Color Black()
utilitaire. renvoie une couleur noire.
Definition: color.cpp:5
representation d'une couleur (rgba) transparente ou opaque.
Definition: color.h:13
Color & operator()(const int x, const int y)
Definition: image.h:38
std::size_t size() const
renvoie le nombre de pixels de l'image.
Definition: image.h:65
int height() const
renvoie la hauteur de l'image.
Definition: image.h:63
representation d'une image.
Definition: image.h:18
int width() const
renvoie la largeur de l'image.
Definition: image.h:61