-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodifY.cpp
More file actions
53 lines (40 loc) · 1.03 KB
/
modifY.cpp
File metadata and controls
53 lines (40 loc) · 1.03 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
#include <stdio.h>
#include "image_ppm.h"
/*
On modifie la composante(Y) avec une valeur (+/-)k
*/
int main(int argc, char* argv[])
{
char cNomImgLue[250], cNomImgOut[250];
int k;
int nH, nW, nTaille;
if (argc != 4)
{
printf("Usage: Y.pgm k(-128<k<+128) Ymodif.pgm \n");
exit (1) ;
}
sscanf (argv[1],"%s",cNomImgLue) ;
k = atoi(argv[2]);
if (k > 128 || k < -128)
{
perror("k n'est pas dans les bonne bornes \n");
exit(1);
}
sscanf (argv[3],"%s",cNomImgOut) ;
OCTET *ImgIn, *ImgOut;
lire_nb_lignes_colonnes_image_pgm(cNomImgLue, &nH, &nW);
nTaille = nH * nW;
allocation_tableau(ImgIn, OCTET, nTaille);
lire_image_pgm(cNomImgLue, ImgIn, nH * nW);
allocation_tableau(ImgOut, OCTET, nTaille);
for (int i = 0; i < nTaille; ++i){
int y = ImgIn[i] + k;
y = y > 255 ? 255 : y;
y = y < 0 ? 0 : y;
ImgOut[i] = y;
}
ecrire_image_pgm(cNomImgOut, ImgOut, nH, nW);
free(ImgIn);
free(ImgOut);
return 1;
}