-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile_pgm.cpp
More file actions
76 lines (58 loc) · 1.65 KB
/
Copy pathprofile_pgm.cpp
File metadata and controls
76 lines (58 loc) · 1.65 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string>
#include "image_ppm.h"
// ./profile_pgm ../src/01.pgm ../dst/profile.dat l 200
int main(int argc, char* argv[])
{
char cNomImgLue[250];
char profileOut[256];
int nH, nW, nTaille;
int *profil;
char indication;
int indice;
if (argc != 5)
{
printf("Usage: ImageIn.pgm, profileOut.dat (l pour ligne c pour colonne), une inice \n");
exit (1) ;
}
sscanf (argv[1],"%s",cNomImgLue);
sscanf (argv[2],"%s",profileOut);
sscanf (argv[3],"%s", &indication);
sscanf (argv[4],"%d", &indice);
if (indication != 'c' && indication != 'l') {
printf("écrire <<c>> ou <<l>>\n");
exit(1);
}
OCTET *ImgIn;
lire_nb_lignes_colonnes_image_pgm(cNomImgLue, &nH, &nW);
nTaille = nH * nW;
allocation_tableau(ImgIn, OCTET, nTaille);
lire_image_pgm(cNomImgLue, ImgIn, nH * nW);
if ((indication == 'l' && indice > nW) || (indication == 'c' && indice > nH))
std::cerr<<" Erreur indice hors de la taille !!!\n";
int size = 0;
if (indication == 'l')
{
size = nW;
profil = new int[nW];
for (int i = 0; i < nW; ++i)
profil[i] = ImgIn[indice*nW+i];
}
else if (indication == 'c')
{
size = nH;
profil = new int[nH];
for (int i = 0; i < nH; ++i)
profil[i] = ImgIn[i*nW+indice];
}
else {
std::cerr<<" Indication pas reconnu hors de 'l' ou 'c' !!! \n";
}
std::ofstream outfile(profileOut); //std::ofstream outfile("profile.dat");
for (int i = 0; i < size; i++)
outfile<<i<<" "<<profil[i]<<" "<<std::endl;
free(ImgIn);
return 1;
}