gKit2 light
Loading...
Searching...
No Matches
utilitaires pour manipuler des images

Files

file  src/gKit/color.h
file  src/gKit/image.h
file  src/gKit/image_io.h

Classes

struct  Color
 representation d'une couleur (rgba) transparente ou opaque. More...
class  Image
 representation d'une image. More...
struct  ImageData
 stockage temporaire des donnees d'une image. More...

Functions

Color Black ()
 utilitaire. renvoie une couleur noire.
Color White ()
 utilitaire. renvoie une couleur blanche.
Color Red ()
 utilitaire. renvoie une couleur rouge.
Color Green ()
 utilitaire. renvoie une couleur verte.
Color Blue ()
 utilitaire. renvoie une couleur bleue.
Color Yellow ()
 utilitaire. renvoie une couleur jaune.
Color operator+ (const Color &a, const Color &b)
Color operator- (const Color &a, const Color &b)
Color operator- (const Color &c)
Color operator* (const Color &a, const Color &b)
Color operator* (const Color &c, const float k)
Color operator* (const float k, const Color &c)
Color operator/ (const Color &a, const Color &b)
Color operator/ (const float k, const Color &c)
Color operator/ (const Color &c, const float k)
Color srgb (const Color &color)
 transformation couleur : rgb lineaire vers srgb
Color linear (const Color &color)
 transformation couleur : srgb vers rgb lineaire
Color abs (const Color &color)
 renvoie la valeur absolue de chaque canal.
float clamp (const float x, const float a, const float b)
 renvoie une valeur comprise entre a et b.
Color clamp (const Color &color, const float a, const float b)
 renvoie une couleur dont chaque canal est compris entre a et b.
Image read_image (const char *filename, const bool flipY=true)
Image read_image_hdr (const char *filename, const bool flipY=true)
unsigned read_image_size (const char *filename)
 renvoie la taille en octets de l'image chargee. ou 0 si erreur.
bool write_image (const Image &image, const char *filename, const bool flipY=true)
 enregistre une image au format .png
bool write_image_png (const Image &image, const char *filename, const bool flipY=true)
 enregistre une image au format .png
bool write_image_bmp (const Image &image, const char *filename, const bool flipY=true)
 enregistre une image au format .bmp
bool write_image_hdr (const Image &image, const char *filename, const bool flipY=true)
 enregistre une image au format .hdr
bool write_image_preview (const Image &image, const char *filename, const bool flipY=true)
 raccourci pour write_image_png(tone(image, range(image)), "image.png")
Image mipmap (const Image &image)
 reduit une image.
Image srgb (const Image &image)
 transformation couleur : rgb lineaire vers srgb
Image linear (const Image &image)
 transformation couleur : srgb vers rgb lineaire
Image flipY (const Image &image)
 retourne l'image
Image flipX (const Image &image)
 retourne l'image
Image copy (const Image &image, const unsigned xmin, const unsigned ymin, const unsigned width, const unsigned height)
 renvoie un bloc de l'image
Imageblit (Image &image, const unsigned xmin, const unsigned ymin, const Image &pixels)
 remplace un bout d'image par une autre. copie l'image pixels dans image [xmin, xmin+pixels.width] x [ymin, ymin+pixels.height].
ImageData read_image_data (const char *filename, const bool flipY=true)
 charge les donnees d'un fichier png. renvoie une image initialisee par defaut en cas d'echec.
int write_image_data (const ImageData &image, const char *filename, const bool flipY=true)
 enregistre des donnees dans un fichier png.
ImageData read_image_data (const void *buffer, const unsigned size, const bool flipY=true)
 charge les donnees d'un fichier png stocke en memoire. renvoie une image initialisee par defaut en cas d'echec.
ImageData srgb (const ImageData &image)
 transformation couleur : rgb lineaire vers srgb
ImageData linear (const ImageData &image)
 transformation couleur : srgb vers rgb lineaire
ImageData flipY (const ImageData &image)
 retourne l'image
ImageData flipX (const ImageData &image)
 retourne l'image
ImageData copy (const ImageData &image, const unsigned xmin, const unsigned ymin, const unsigned width, const unsigned height)
 renvoie un bloc de l'image
ImageDatablit (ImageData &image, const unsigned xmin, const unsigned ymin, const ImageData &pixels)
 remplace un bout d'image par une autre. copie l'image pixels dans image [xmin, xmin+pixels.width] x [ymin, ymin+pixels.height].
ImageData mipmap (const ImageData &image)
 renvoie une image filtree plus petite.
int miplevels (const int width, const int height)
 renvoie le nombre de mipmap d'une image width x height.

Detailed Description

Function Documentation

◆ Black()

Color Black ( )

utilitaire. renvoie une couleur noire.

Definition at line 18 of file color.cpp.

19{
20 return Color(0, 0, 0);
21}
representation d'une couleur (rgba) transparente ou opaque.
Definition color.h:14

◆ White()

Color White ( )

utilitaire. renvoie une couleur blanche.

Definition at line 23 of file color.cpp.

24{
25 return Color(1, 1, 1);
26}

◆ Red()

Color Red ( )

utilitaire. renvoie une couleur rouge.

Definition at line 28 of file color.cpp.

29{
30 return Color(1, 0, 0);
31}

◆ Green()

Color Green ( )

utilitaire. renvoie une couleur verte.

Definition at line 33 of file color.cpp.

34{
35 return Color(0, 1, 0);
36}

◆ Blue()

Color Blue ( )

utilitaire. renvoie une couleur bleue.

Definition at line 38 of file color.cpp.

39{
40 return Color(0, 0, 1);
41}

◆ Yellow()

Color Yellow ( )

utilitaire. renvoie une couleur jaune.

Definition at line 43 of file color.cpp.

44{
45 return Color(1, 1, 0);
46}

◆ operator+()

Color operator+ ( const Color & a,
const Color & b )

Definition at line 89 of file color.cpp.

90{
91 return Color(a.r + b.r, a.g + b.g, a.b + b.b, a.a + b.a);
92}

◆ operator-() [1/2]

Color operator- ( const Color & a,
const Color & b )

Definition at line 99 of file color.cpp.

100{
101 return a + (-b);
102}

◆ operator-() [2/2]

Color operator- ( const Color & c)

Definition at line 94 of file color.cpp.

95{
96 return Color(-c.r, -c.g, -c.b, -c.a);
97}

◆ operator*() [1/3]

Color operator* ( const Color & a,
const Color & b )

Definition at line 104 of file color.cpp.

105{
106 return Color(a.r * b.r, a.g * b.g, a.b * b.b, a.a * b.a);
107}

◆ operator*() [2/3]

Color operator* ( const Color & c,
const float k )

Definition at line 114 of file color.cpp.

115{
116 return k * c;
117}

◆ operator*() [3/3]

Color operator* ( const float k,
const Color & c )

Definition at line 109 of file color.cpp.

110{
111 return Color(c.r * k, c.g * k, c.b * k, c.a * k);
112}

◆ operator/() [1/3]

Color operator/ ( const Color & a,
const Color & b )

Definition at line 119 of file color.cpp.

120{
121 return Color(a.r / b.r, a.g / b.g, a.b / b.b, a.a / b.a);
122}

◆ operator/() [2/3]

Color operator/ ( const float k,
const Color & c )

Definition at line 124 of file color.cpp.

125{
126 return Color(k / c.r, k / c.g, k / c.b, k / c.a);
127}

◆ operator/() [3/3]

Color operator/ ( const Color & c,
const float k )

Definition at line 129 of file color.cpp.

130{
131 float kk= 1 / k;
132 return kk * c;
133}

◆ srgb() [1/3]

Color srgb ( const Color & color)

transformation couleur : rgb lineaire vers srgb

Definition at line 61 of file color.cpp.

62{
63 return Color( srgb(color.r), srgb(color.g), srgb(color.b), color.a );
64}

◆ linear() [1/3]

Color linear ( const Color & color)

transformation couleur : srgb vers rgb lineaire

Definition at line 66 of file color.cpp.

67{
68 return Color( linear(color.r), linear(color.g), linear(color.b), color.a );
69}

◆ abs()

Color abs ( const Color & color)

renvoie la valeur absolue de chaque canal.

Definition at line 71 of file color.cpp.

72{
73 return Color( std::abs(color.r), std::abs(color.g), std::abs(color.b), std::abs(color.a) );
74}

◆ clamp() [1/2]

float clamp ( const float x,
const float a,
const float b )
inline

renvoie une valeur comprise entre a et b.

Definition at line 76 of file color.cpp.

77{
78 if(x < a) return a;
79 else if(x > b) return b;
80 else return x;
81}

◆ clamp() [2/2]

Color clamp ( const Color & color,
const float a,
const float b )

renvoie une couleur dont chaque canal est compris entre a et b.

Definition at line 83 of file color.cpp.

84{
85 return Color( clamp(color.r, a, b), clamp(color.g, a, b), clamp(color.b, a, b), clamp(color.a, a, b) );
86}
float clamp(const float x, const float a, const float b)
renvoie une valeur comprise entre a et b.
Definition color.cpp:76

◆ read_image()

Image read_image ( const char * filename,
const bool flipY = true )

charge une image a partir d'un fichier. renvoie Image::error() en cas d'echec. a detruire avec image::release( ).

Parameters
filemanenom de l'image a charger

Definition at line 191 of file image_io.cpp.

192{
193 stbi_ldr_to_hdr_scale(1);
194 stbi_ldr_to_hdr_gamma(1);
195 stbi_set_flip_vertically_on_load(flipY);
196
197 int width, height, channels;
198 float *data= stbi_loadf(filename, &width, &height, &channels, 4);
199 if(!data)
200 {
201 printf("[error] loading '%s'...\n", filename);
202 return {};
203 }
204
205 Image image(width, height);
206 for(unsigned i= 0, offset= 0; i < image.size(); i++, offset+= 4)
207 image(i)= Color( data[offset], data[offset + 1], data[offset + 2], data[offset + 3]);
208
209 stbi_image_free(data);
210 return image;
211}
representation d'une image.
Definition image.h:21
void printf(Text &text, const int px, const int py, const char *format,...)
affiche un texte a la position x, y. meme utilisation que printf().
Definition text.cpp:140
Image flipY(const Image &image)
retourne l'image
Definition image_io.cpp:113

◆ read_image_hdr()

Image read_image_hdr ( const char * filename,
const bool flipY = true )

Definition at line 213 of file image_io.cpp.

214{
215 return read_image(filename, flipY );
216}
Image read_image(const char *filename, const bool flipY)
Definition image_io.cpp:191

◆ read_image_size()

unsigned read_image_size ( const char * filename)

renvoie la taille en octets de l'image chargee. ou 0 si erreur.

Definition at line 182 of file image_io.cpp.

183{
184 int w, h, c;
185 if(!stbi_info(filename, &w, &h, &c))
186 return 0;
187
188 return sizeof(Color)*w*h;
189}

◆ write_image()

bool write_image ( const Image & image,
const char * filename,
const bool flipY = true )

enregistre une image au format .png

Definition at line 245 of file image_io.cpp.

246{
247 return write_image_png(image, filename, flipY );
248}
bool write_image_png(const Image &image, const char *filename, const bool flipY)
enregistre une image au format .png
Definition image_io.cpp:226

◆ write_image_png()

bool write_image_png ( const Image & image,
const char * filename,
const bool flipY = true )

enregistre une image au format .png

Definition at line 226 of file image_io.cpp.

227{
228 if(image.size() == 0)
229 return false;
230
231 std::vector<unsigned char> tmp(image.width()*image.height()*4);
232 for(unsigned i= 0, offset= 0; i < image.size(); i++, offset+= 4)
233 {
234 Color pixel= image(i) * 255;
235 tmp[offset ]= clamp(pixel.r, 0, 255);
236 tmp[offset +1]= clamp(pixel.g, 0, 255);
237 tmp[offset +2]= clamp(pixel.b, 0, 255);
238 tmp[offset +3]= clamp(pixel.a, 0, 255);
239 }
240
241 stbi_flip_vertically_on_write(flipY);
242 return stbi_write_png(filename, image.width(), image.height(), 4, tmp.data(), image.width() * 4) != 0;
243}

◆ write_image_bmp()

bool write_image_bmp ( const Image & image,
const char * filename,
const bool flipY = true )

enregistre une image au format .bmp

Definition at line 250 of file image_io.cpp.

251{
252 if(image.size() == 0)
253 return false;
254
255 std::vector<unsigned char> tmp(image.width()*image.height()*4);
256 for(unsigned i= 0, offset= 0; i < image.size(); i++, offset+= 4)
257 {
258 Color pixel= image(i) * 255;
259 tmp[offset ]= clamp(pixel.r, 0, 255);
260 tmp[offset +1]= clamp(pixel.g, 0, 255);
261 tmp[offset +2]= clamp(pixel.b, 0, 255);
262 tmp[offset +3]= clamp(pixel.a, 0, 255);
263 }
264
265 stbi_flip_vertically_on_write(flipY);
266 return stbi_write_bmp(filename, image.width(), image.height(), 4, tmp.data()) != 0;
267}

◆ write_image_hdr()

bool write_image_hdr ( const Image & image,
const char * filename,
const bool flipY = true )

enregistre une image au format .hdr

Definition at line 269 of file image_io.cpp.

270{
271 if(image.size() == 0)
272 return false;
273
274 stbi_flip_vertically_on_write(flipY);
275 return stbi_write_hdr(filename, image.width(), image.height(), 4, image.data()) != 0;
276}

◆ write_image_preview()

bool write_image_preview ( const Image & image,
const char * filename,
const bool flipY = true )

raccourci pour write_image_png(tone(image, range(image)), "image.png")

Definition at line 278 of file image_io.cpp.

279{
280 if(image.size() == 0)
281 return false;
282
283 Image tmp= tone(image, range(image));
284 return write_image_png(tmp, filename, flipY);
285}

◆ mipmap() [1/2]

Image mipmap ( const Image & image)

reduit une image.

Definition at line 95 of file image_io.cpp.

96{
97 unsigned w= std::max(unsigned(1), image.width() / 2);
98 unsigned h= std::max(unsigned(1), image.height() / 2);
99
100 Image tmp(w, h);
101
102 for(unsigned py= 0; py < h; py++)
103 for(unsigned px= 0; px < w; px++)
104 {
105 unsigned x= 2*px;
106 unsigned y= 2*py;
107 tmp(px, py)= (image(x, y) + image(x +1, y) + image(x +1, y +1) + image(x, y +1)) / 4;
108 }
109
110 return tmp;
111}

◆ srgb() [2/3]

Image srgb ( const Image & image)

transformation couleur : rgb lineaire vers srgb

Definition at line 15 of file image_io.cpp.

16{
17 Image tmp(image.width(), image.height());
18
19 for(unsigned i= 0; i < image.size(); i++)
20 tmp(i)= srgb(image(i));
21
22 return tmp;
23}
Image srgb(const Image &image)
transformation couleur : rgb lineaire vers srgb
Definition image_io.cpp:15

◆ linear() [2/3]

Image linear ( const Image & image)

transformation couleur : srgb vers rgb lineaire

Definition at line 25 of file image_io.cpp.

26{
27 Image tmp(image.width(), image.height());
28
29 for(unsigned i= 0; i < image.size(); i++)
30 tmp(i)= linear(image(i));
31
32 return tmp;
33}
Image linear(const Image &image)
transformation couleur : srgb vers rgb lineaire
Definition image_io.cpp:25

◆ flipY() [1/2]

Image flipY ( const Image & image)

retourne l'image

Definition at line 113 of file image_io.cpp.

114{
115 // flip de l'image : origine en haut a gauche
116 Image flip(image.width(), image.height());
117
118 for(unsigned y= 0; y < image.height(); y++)
119 for(unsigned x= 0; x < image.width(); x++)
120 {
121 unsigned s= image.offset(x, y);
122 unsigned d= flip.offset(x, flip.height() - y -1);
123
124 flip(d)= image(s);
125 }
126
127 return flip;
128}

◆ flipX() [1/2]

Image flipX ( const Image & image)

retourne l'image

Definition at line 130 of file image_io.cpp.

131{
132 Image flip(image.width(), image.height());
133
134 for(unsigned y= 0; y < image.height(); y++)
135 for(unsigned x= 0; x < image.width(); x++)
136 {
137 unsigned s= image.offset(x, y);
138 unsigned d= flip.offset(flip.width() -x -1, y);
139
140 flip(d)= image(s);
141 }
142
143 return flip;
144}

◆ copy() [1/2]

Image copy ( const Image & image,
const unsigned xmin,
const unsigned ymin,
const unsigned width,
const unsigned height )

renvoie un bloc de l'image

Definition at line 146 of file image_io.cpp.

147{
148 Image copy(width, height);
149
150 for(unsigned y= 0; y < height; y++)
151 for(unsigned x= 0; x < width; x++)
152 {
153 unsigned s= image.offset(xmin+x, ymin+y);
154 unsigned d= copy.offset(x, y);
155
156 copy(d)= image(s);
157 }
158
159 return copy;
160}
Image copy(const Image &image, const unsigned xmin, const unsigned ymin, const unsigned width, const unsigned height)
renvoie un bloc de l'image
Definition image_io.cpp:146

◆ blit() [1/2]

Image & blit ( Image & image,
const unsigned xmin,
const unsigned ymin,
const Image & pixels )

remplace un bout d'image par une autre. copie l'image pixels dans image [xmin, xmin+pixels.width] x [ymin, ymin+pixels.height].

Definition at line 162 of file image_io.cpp.

163{
164 if(image.size() == 0)
165 return image;
166 if(pixels.size() == 0)
167 return image;
168
169 unsigned xmax= std::min( image.width(), xmin + pixels.width() );
170 unsigned ymax= std::min( image.height(), ymin + pixels.height() );
171 unsigned w= xmax - xmin;
172 unsigned h= ymax - ymin;
173
174 for(unsigned y= 0; y < h; y++)
175 for(unsigned x= 0; x < w; x++)
176 image(x + xmin, y + ymin)= pixels(x, y);
177
178 return image;
179}

◆ read_image_data() [1/2]

ImageData read_image_data ( const char * filename,
const bool flipY = true )

charge les donnees d'un fichier png. renvoie une image initialisee par defaut en cas d'echec.

Definition at line 350 of file image_io.cpp.

351{
352 stbi_set_flip_vertically_on_load(flipY);
353
354 int width, height, channels;
355 unsigned char *data= stbi_load(filename, &width, &height, &channels, 0);
356 if(!data)
357 {
358 printf("[error] loading '%s'...\n", filename);
359 return {};
360 }
361
362 return image_data(data, width, height, channels);
363}

◆ write_image_data()

int write_image_data ( const ImageData & image,
const char * filename,
const bool flipY = true )

enregistre des donnees dans un fichier png.

Definition at line 366 of file image_io.cpp.

367{
368 if(image.size != 1)
369 {
370 printf("[error] writing color image '%s'... not an 8 bits image.\n", filename);
371 return -1;
372 }
373
374 stbi_flip_vertically_on_write(flipY);
375
376 int code= 0;
377 if(std::string(filename).rfind(".png") != std::string::npos)
378 code= stbi_write_png(filename, image.width, image.height, image.channels, image.pixels.data(), image.width * image.channels) != 0;
379 else if(std::string(filename).rfind(".bmp") != std::string::npos)
380 code= stbi_write_bmp(filename, image.width, image.height, image.channels, image.pixels.data()) != 0;
381
382 else
383 {
384 printf("[error] writing color image '%s'... not a .png / .bmp image.\n", filename);
385 return -1;
386 }
387
388 if(code > 0)
389 return 0;
390
391 printf("[error] writing color image '%s'...\n", filename);
392 return -1;
393}

◆ read_image_data() [2/2]

ImageData read_image_data ( const void * buffer,
const unsigned size,
const bool flipY = true )

charge les donnees d'un fichier png stocke en memoire. renvoie une image initialisee par defaut en cas d'echec.

Definition at line 335 of file image_io.cpp.

336{
337 stbi_set_flip_vertically_on_load(flipY);
338
339 int width, height, channels;
340 unsigned char *data= stbi_load_from_memory((const unsigned char *) buffer, size, &width, &height, &channels, 0);
341 if(!data)
342 {
343 printf("[error] reading buffer image...\n");
344 return {};
345 }
346
347 return image_data(data, width, height, channels);
348}

◆ srgb() [3/3]

ImageData srgb ( const ImageData & image)

transformation couleur : rgb lineaire vers srgb

Definition at line 397 of file image_io.cpp.

398{
399 ImageData tmp(image.width, image.height, image.channels);
400
401 for(unsigned i= 0; i < image.pixels.size(); i+= image.channels)
402 {
403 Color pixel= srgb( Color( image.pixels[i], image.pixels[i+1], image.pixels[i+2], (image.channels > 3) ? image.pixels[i+3] : 255 ) / 255 );
404
405 tmp.pixels[i]= clamp(pixel.r * 255, 0, 255);
406 tmp.pixels[i +1]= clamp(pixel.g * 255, 0, 255);
407 tmp.pixels[i +2]= clamp(pixel.b * 255, 0, 255);
408 if(image.channels > 3)
409 tmp.pixels[i +3]= clamp(pixel.a * 255, 0, 255);
410 }
411
412 return tmp;
413}
stockage temporaire des donnees d'une image.
Definition image_io.h:55

◆ linear() [3/3]

ImageData linear ( const ImageData & image)

transformation couleur : srgb vers rgb lineaire

Definition at line 415 of file image_io.cpp.

416{
417 ImageData tmp(image.width, image.height, image.channels);
418
419 for(unsigned i= 0; i < image.pixels.size(); i+= image.channels)
420 {
421 Color pixel= linear( Color( image.pixels[i], image.pixels[i+1], image.pixels[i+2], (image.channels > 3) ? image.pixels[i+3] : 255 ) / 255 );
422
423 tmp.pixels[i]= clamp(pixel.r * 255, 0, 255);
424 tmp.pixels[i +1]= clamp(pixel.g * 255, 0, 255);
425 tmp.pixels[i +2]= clamp(pixel.b * 255, 0, 255);
426 if(image.channels > 3)
427 tmp.pixels[i +3]= clamp(pixel.a * 255, 0, 255);
428 }
429
430 return tmp;
431}

◆ flipY() [2/2]

ImageData flipY ( const ImageData & image)

retourne l'image

Definition at line 433 of file image_io.cpp.

434{
435 // flip de l'image : origine en haut a gauche
436 ImageData flip(image.width, image.height, image.channels);
437
438 for(unsigned y= 0; y < image.height; y++)
439 for(unsigned x= 0; x < image.width; x++)
440 {
441 unsigned s= image.offset(x, y);
442 unsigned d= flip.offset(x, flip.height - y -1);
443
444 for(unsigned i= 0; i < image.channels; i++)
445 flip.pixels[d +i]= image.pixels[s +i];
446 }
447
448 return flip;
449}

◆ flipX() [2/2]

ImageData flipX ( const ImageData & image)

retourne l'image

Definition at line 451 of file image_io.cpp.

452{
453 ImageData flip(image.width, image.height, image.channels);
454
455 for(unsigned y= 0; y < image.height; y++)
456 for(unsigned x= 0; x < image.width; x++)
457 {
458 unsigned s= image.offset(x, y);
459 unsigned d= flip.offset(flip.width -x -1, y);
460
461 for(unsigned i= 0; i < image.channels; i++)
462 flip.pixels[d +i]= image.pixels[s +i];
463 }
464
465 return flip;
466}

◆ copy() [2/2]

ImageData copy ( const ImageData & image,
const unsigned xmin,
const unsigned ymin,
const unsigned width,
const unsigned height )

renvoie un bloc de l'image

Definition at line 468 of file image_io.cpp.

469{
470 ImageData copy(width, height, image.channels);
471
472 for(unsigned y= 0; y < height; y++)
473 for(unsigned x= 0; x < width; x++)
474 {
475 unsigned s= image.offset(xmin +x, ymin +y);
476 unsigned d= copy.offset(x, y);
477
478 for(unsigned i= 0; i < image.channels; i++)
479 copy.pixels[d +i]= image.pixels[s +i];
480 }
481
482 return copy;
483}

◆ blit() [2/2]

ImageData & blit ( ImageData & image,
const unsigned xmin,
const unsigned ymin,
const ImageData & pixels )

remplace un bout d'image par une autre. copie l'image pixels dans image [xmin, xmin+pixels.width] x [ymin, ymin+pixels.height].

Definition at line 486 of file image_io.cpp.

487{
488 if(image.pixels.size() == 0)
489 return image;
490 if(pixels.pixels.size() == 0)
491 return image;
492 if(image.channels != pixels.channels)
493 return image;
494
495 unsigned xmax= std::min( image.width, xmin + pixels.width );
496 unsigned ymax= std::min( image.height, ymin + pixels.height );
497 unsigned w= xmax - xmin;
498 unsigned h= ymax - ymin;
499
500 for(unsigned y= 0; y < h; y++)
501 for(unsigned x= 0; x < w; x++)
502 {
503 unsigned char *dst= image.pixels.data() + image.offset(x + xmin, y + ymin);
504 const unsigned char *src= pixels.pixels.data() + pixels.offset(x, y);
505 for(unsigned i= 0; i < pixels.channels; i++)
506 dst[i]= src[i];
507 }
508
509 return image;
510}

◆ mipmap() [2/2]

ImageData mipmap ( const ImageData & image)

renvoie une image filtree plus petite.

Definition at line 512 of file image_io.cpp.

513{
514 unsigned w= std::max(unsigned(1), image.width / 2);
515 unsigned h= std::max(unsigned(1), image.height / 2);
516
517 ImageData tmp(w, h, image.channels);
518
519 for(unsigned py= 0; py < h; py++)
520 for(unsigned px= 0; px < w; px++)
521 {
522 unsigned x= 2*px;
523 unsigned y= 2*py;
524 unsigned d= tmp.offset(px, py);
525
526 for(unsigned i= 0; i < image.channels; i++)
527 tmp.pixels[d +i]= (
528 image.pixels[image.offset(x, y) +i]
529 + image.pixels[image.offset(x+1, y) +i]
530 + image.pixels[image.offset(x, y+1) +i]
531 + image.pixels[image.offset(x+1, y+1) +i] ) / 4;
532 }
533
534 return tmp;
535}

◆ miplevels()

int miplevels ( const int width,
const int height )

renvoie le nombre de mipmap d'une image width x height.

Definition at line 537 of file image_io.cpp.

538{
539 int w= width;
540 int h= height;
541 int levels= 1;
542 while(w > 1 || h > 1)
543 {
544 w= std::max(1, w / 2);
545 h= std::max(1, h / 2);
546 levels= levels + 1;
547 }
548
549 return levels;
550}