1#ifndef _IMAGE2DWRITER_HPP_
2#define _IMAGE2DWRITER_HPP_
11template <
typename TValue>
17 static bool write(
Image & img, std::ostream & output,
bool ascii );
20template <
typename TValue>
32 typedef unsigned char Value;
35 static bool write(
Image & img, std::ostream & output,
bool ascii );
45 static bool write(
Image & img, std::ostream & output,
bool ascii );
53 typedef unsigned char GrayLevel;
54 output << ( ascii ?
"P2" :
"P5" ) << std::endl;
55 output <<
"# Generated by You !" << std::endl;
56 output << img.w() <<
" " << img.h() << std::endl;
57 output <<
"255" << std::endl;
60 for ( Image::Iterator it = img.begin(), itE = img.end(); it != itE; ++it )
61 output << (
int) *it <<
" ";
65 for ( Image::Iterator it = img.begin(), itE = img.end(); it != itE; ++it )
66 output << (GrayLevel) *it;
73Image2DWriter<Color>::write( Image & img, std::ostream & output,
bool ascii )
75 output << ( ascii ?
"P3" :
"P6" ) << std::endl;
76 output <<
"# Generated by You !" << std::endl;
77 output << img.w() <<
" " << img.h() << std::endl;
78 output <<
"255" << std::endl;
81 for ( Image::Iterator it = img.begin(), itE = img.end(); it != itE; ++it )
84 output << (int) (c.r()*255.0f) <<
" " << (
int) (c.g()*255.0f) <<
" " << (
int) (c.b()*255.0f) <<
" ";
89 for ( Image::Iterator it = img.begin(), itE = img.end(); it != itE; ++it )
92 unsigned char red = (
unsigned char) (c.r()*255.0f);
93 unsigned char green = (
unsigned char) (c.g()*255.0f);
94 unsigned char blue = (
unsigned char) (c.b()*255.0f);
95 output << red << green << blue;
Classe générique pour représenter des images 2D.