INFO702 - TPs
Loading...
Searching...
No Matches
testGrayLevelImage2D.cpp
1#include <iostream>
2#include <fstream>
3#include "GrayLevelImage2D.hpp"
4
5using namespace std;
6
7int main( int argc, char** argv )
8{
9 {
10 //! [tgli2d-sec3]
11 GrayLevelImage2D img( 8, 8, 5 ); // imagette 8x8 remplie de 5
12 for ( int y = 0; y < img.h(); ++y )
13 for ( int x = 0; x < img.w(); ++x )
14 std::cout << " " << (int) img.at( x, y ); // la conversion permet de voir les caractères sous forme d'entiers.
15 std::cout << std::endl;
16 //! [tgli2d-sec3]
17 }
18 {
19 GrayLevelImage2D img( 8, 8, 5 ); // imagette 8x8 remplie de 5
20 //! [tgli2d-sec4]
21 for ( GrayLevelImage2D::Iterator it = img.begin(), itE = img.end(); it != itE; ++it )
22 std::cout << " " << (int) *it; // la conversion permet de voir les caractères sous forme d'entiers.
23 //! [tgli2d-sec4]
24 }
25
26 typedef GrayLevelImage2D::GrayLevel GrayLevel;
27 typedef GrayLevelImage2D::Iterator Iterator;
29 ifstream input( argv[1] );
30 try {
31 img.importPGM( input );
32 }
33 catch ( char const * msg ) {
34 std::cerr << "Exception: " << msg << std::endl;
35 }
36 catch (...) {
37 std::cerr << "Exception." << std::endl;
38 }
39 input.close();
40 for ( Iterator it = img.begin(), itE = img.end(); it != itE; ++it )
41 {
42 const GrayLevel g = (13*((int)(*it))) % 256;
43 *it = g;
44 }
45 ofstream output( argv[2] );
46 img.exportPGM( output, false );
47 output.close();
48 std::cout << std::endl;
49 return 0;
50}
Iterator begin()
[gli2d-sec3]