gKit3
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members

representation d'une image. More...

#include <image.h>

Public Member Functions

 Image (const int w, const int h, const Color &color=Black())
 
Coloroperator() (const int x, const int y)
 
Color operator() (const int x, const int y) const
 renvoie la couleur d'un pixel de l'image (image non modifiable).
 
Coloroperator() (const size_t offset)
 renvoie une reference sur le ieme pixel de l'image.
 
Color operator() (const size_t offset) const
 renvoie lacouleur du ieme pixel de l'image.
 
Color sample (const float x, const float y) const
 renvoie la couleur interpolee a la position (x, y) [0 .. width]x[0 .. height].
 
Color texture (const float x, const float y) const
 renvoie la couleur interpolee aux coordonnees normalisees (x, y) [0 .. 1]x[0 .. 1].
 
const float * data () const
 renvoie un const pointeur sur le stockage des couleurs des pixels.
 
float * data ()
 renvoie un pointeur sur le stockage des couleurs des pixels.
 
int width () const
 renvoie la largeur de l'image.
 
int height () const
 renvoie la hauteur de l'image.
 
unsigned size () const
 renvoie le nombre de pixels de l'image.
 
unsigned offset (const int x, const int y) const
 

Protected Attributes

std::vector< Colorm_pixels
 
int m_width
 
int m_height
 

Detailed Description

representation d'une image.

Definition at line 20 of file image.h.

Constructor & Destructor Documentation

◆ Image() [1/2]

Image::Image ( )
inline

Definition at line 28 of file image.h.

28: m_pixels(), m_width(0), m_height(0) {}

◆ Image() [2/2]

Image::Image ( const int  w,
const int  h,
const Color color = Black() 
)
inline

Definition at line 29 of file image.h.

29: m_pixels(w*h, color), m_width(w), m_height(h) {}

Member Function Documentation

◆ operator()() [1/4]

Color & Image::operator() ( const int  x,
const int  y 
)
inline

renvoie une reference sur la couleur d'un pixel de l'image. permet de modifier et/ou de connaitre la couleur d'un pixel :

Image image(512, 512);
image(10, 10)= Red(); // le pixel (10, 10) devient rouge
image(0, 0)= image(10, 10); // le pixel (0, 0) recupere la couleur du pixel (10, 10)
representation d'une image.
Definition image.h:21
Color Red()
utilitaire. renvoie une couleur rouge.
Definition color.cpp:28

Definition at line 40 of file image.h.

41 {
42 return m_pixels[offset(x, y)];
43 }
unsigned offset(const int x, const int y) const
Definition image.h:108

◆ operator()() [2/4]

Color Image::operator() ( const int  x,
const int  y 
) const
inline

renvoie la couleur d'un pixel de l'image (image non modifiable).

Definition at line 46 of file image.h.

47 {
48 return m_pixels[offset(x, y)];
49 }

◆ operator()() [3/4]

Color & Image::operator() ( const size_t  offset)
inline

renvoie une reference sur le ieme pixel de l'image.

Definition at line 52 of file image.h.

53 {
54 assert(offset < m_pixels.size());
55 return m_pixels[offset];
56 }

◆ operator()() [4/4]

Color Image::operator() ( const size_t  offset) const
inline

renvoie lacouleur du ieme pixel de l'image.

Definition at line 59 of file image.h.

60 {
61 assert(offset < m_pixels.size());
62 return m_pixels[offset];
63 }

◆ sample()

Color Image::sample ( const float  x,
const float  y 
) const
inline

renvoie la couleur interpolee a la position (x, y) [0 .. width]x[0 .. height].

Definition at line 66 of file image.h.

67 {
68 // interpolation bilineaire
69 float u= x - std::floor(x);
70 float v= y - std::floor(y);
71 int ix= x;
72 int iy= y;
73 return (*this)(ix, iy) * ((1 - u) * (1 - v))
74 + (*this)(ix+1, iy) * (u * (1 - v))
75 + (*this)(ix, iy+1) * ((1 - u) * v)
76 + (*this)(ix+1, iy+1) * (u * v);
77 }

◆ texture()

Color Image::texture ( const float  x,
const float  y 
) const
inline

renvoie la couleur interpolee aux coordonnees normalisees (x, y) [0 .. 1]x[0 .. 1].

Definition at line 80 of file image.h.

81 {
82 return sample(x * m_width, y * m_height);
83 }
Color sample(const float x, const float y) const
renvoie la couleur interpolee a la position (x, y) [0 .. width]x[0 .. height].
Definition image.h:66

◆ data() [1/2]

const float * Image::data ( ) const
inline

renvoie un const pointeur sur le stockage des couleurs des pixels.

Definition at line 86 of file image.h.

87 {
88 assert(!m_pixels.empty());
89 return (const float *) m_pixels.data();
90 }

◆ data() [2/2]

float * Image::data ( )
inline

renvoie un pointeur sur le stockage des couleurs des pixels.

Definition at line 93 of file image.h.

94 {
95 assert(!m_pixels.empty());
96 return (float *) m_pixels.data();
97 }

◆ width()

int Image::width ( ) const
inline

renvoie la largeur de l'image.

Definition at line 100 of file image.h.

100{ return m_width; }

◆ height()

int Image::height ( ) const
inline

renvoie la hauteur de l'image.

Definition at line 102 of file image.h.

102{ return m_height; }

◆ size()

unsigned Image::size ( ) const
inline

renvoie le nombre de pixels de l'image.

Definition at line 104 of file image.h.

104{ return m_width * m_height; }

◆ offset()

unsigned Image::offset ( const int  x,
const int  y 
) const
inline

renvoie l'indice du pixel (x, y) [0 .. width]x[0 .. height]. renvoie le pixel le plus proche si (x, y) est en dehors de l'image...

Definition at line 108 of file image.h.

109 {
110 int px= x;
111 if(px < 0) px= 0;
112 if(px > m_width-1) px= m_width-1;
113 int py= y;
114 if(py < 0) py= 0;
115 if(py > m_height-1) py= m_height-1;
116
117 unsigned p= py * m_width + px;
118 assert(p < m_pixels.size());
119 return p;
120 }

Member Data Documentation

◆ m_pixels

std::vector<Color> Image::m_pixels
protected

Definition at line 23 of file image.h.

◆ m_width

int Image::m_width
protected

Definition at line 24 of file image.h.

◆ m_height

int Image::m_height
protected

Definition at line 25 of file image.h.


The documentation for this class was generated from the following file: