Bonjour,
J'ai écris un programme qui fait cela avec cet algorithme, que je vous demande d'analyser svp.
le fichier ppm en input est constitue de char triplets.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 if(fp){ fp >> ppm.magicnumber >> ppm.nrows >> ppm.ncols >> ppm.maxvalue; dim = ppm.nrows * ppm.ncols; if (ppm.maxvalue > 255){ cerr << "Invalid RGB value." << endl; exit(0); } } else { cerr << "File specified does not exist."<<endl; exit(0); } uchar r[dim], g[dim], b[dim]; //lecture des donnes for (int i=0; i<dim;i++) { fp >> r[i] >> g[i] >> b[i]; } cout << "Rows : " << ppm.nrows << endl; cout << "Cols : " << ppm.ncols << endl; cout << "RGB : " << ppm.maxvalue << endl; cout << "dim : " << dim << endl; ofstream out("op.ppm"); out << "P6"<<endl; out << ppm.nrows << " " << ppm.ncols << " " << ppm.maxvalue << endl; for (int j=0; j<dim;j++) { r[j]=255-r[j]; //Inversion des couleurs RGB g[j]=255-g[j]; b[j]=255-b[j]; out << r[j] << g[j] << b[j]; //ecriture sur le fichier }
Le probleme c'est que mon code fait tres bien l'inversion pour ces deux photos, celle-la et celle-ci. Mais ces deux : 1 2 non, mon programme cree une image pleines de parasites (c'est comme dans une "chaine de tv qui capte pas").
Merci
Partager