gKit2 light
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gKit
image.h
Go to the documentation of this file.
1
2
#ifndef _IMAGE_H
3
#define _IMAGE_H
4
5
#include <cmath>
6
#include <cassert>
7
#include <vector>
8
#include <algorithm>
9
10
#include "
color.h
"
11
12
15
18
20
class
Image
21
{
22
protected
:
23
std::vector<Color> m_pixels;
24
unsigned
m_width;
25
unsigned
m_height;
26
27
public
:
28
Image( ) : m_pixels(), m_width(0), m_height(0) {}
29
Image(
const
unsigned
w,
const
unsigned
h,
const
Color
& color=
Black
() ) : m_pixels(w*h, color), m_width(w), m_height(h) {}
30
40
Color
&
operator()
(
const
int
x,
const
int
y )
41
{
42
return
m_pixels[
offset
(x, y)];
43
}
44
46
Color
operator()
(
const
int
x,
const
int
y )
const
47
{
48
return
m_pixels[
offset
(x, y)];
49
}
50
52
Color
&
operator()
(
const
unsigned
offset
)
53
{
54
assert(
offset
< m_pixels.size());
55
return
m_pixels[
offset
];
56
}
57
59
Color
operator()
(
const
unsigned
offset
)
const
60
{
61
assert(
offset
< m_pixels.size());
62
return
m_pixels[
offset
];
63
}
64
66
Color
sample
(
const
float
x,
const
float
y )
const
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
}
78
80
Color
texture
(
const
float
x,
const
float
y )
const
81
{
82
return
sample
(x * m_width, y * m_height);
83
}
84
86
const
float
*
data
( )
const
87
{
88
assert(!m_pixels.empty());
89
return
(
const
float
*) m_pixels.data();
90
}
91
93
float
*
data
( )
94
{
95
assert(!m_pixels.empty());
96
return
(
float
*) m_pixels.data();
97
}
98
100
unsigned
width
( )
const
{
return
m_width; }
102
unsigned
height
( )
const
{
return
m_height; }
104
unsigned
size
( )
const
{
return
m_width * m_height; }
105
108
unsigned
offset
(
const
int
x,
const
int
y )
const
109
{
110
unsigned
px= (x < 0) ? 0 : unsigned(x);
111
if
(px >= m_width) px= m_width -1;
112
113
unsigned
py= (y < 0) ? 0 : unsigned(y);
114
if
(py >= m_height) py= m_height -1;
115
116
unsigned
p= py * m_width + px;
117
assert(p < m_pixels.size());
118
return
p;
119
}
120
};
121
123
#endif
Image::width
unsigned width() const
renvoie la largeur de l'image.
Definition
image.h:100
Image::size
unsigned size() const
renvoie le nombre de pixels de l'image.
Definition
image.h:104
Image::height
unsigned height() const
renvoie la hauteur de l'image.
Definition
image.h:102
Image::data
const float * data() const
renvoie un const pointeur sur le stockage des couleurs des pixels.
Definition
image.h:86
Image::data
float * data()
renvoie un pointeur sur le stockage des couleurs des pixels.
Definition
image.h:93
Image::texture
Color texture(const float x, const float y) const
renvoie la couleur interpolee aux coordonnees normalisees (x, y) [0 .. 1]x[0 .. 1].
Definition
image.h:80
Image::operator()
Color & operator()(const int x, const int y)
Definition
image.h:40
Image::offset
unsigned offset(const int x, const int y) const
Definition
image.h:108
Image::sample
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
color.h
Black
Color Black()
utilitaire. renvoie une couleur noire.
Definition
color.cpp:18
Color
representation d'une couleur (rgba) transparente ou opaque.
Definition
color.h:14
Generated on
for gKit2 light by
1.17.0