-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpng2gray.c
74 lines (52 loc) · 997 Bytes
/
png2gray.c
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
//* width n height
#include<stdio.h>
int main()
{
FILE *p, *q;
int success,r,i=0,j=0, a[500][500], d[5], w, h;
char inputfile[30], outputfile[30], magicno[5];
printf("Enter the name of file to open\n");
scanf(" %s", inputfile);
printf("Enter the name of output file\n");
scanf(" %s", outputfile);
p=fopen(inputfile,"r");
if(p==0)
{
printf("Error occur in opening file\n");
return 1;
}
fscanf(p, "%s", magicno);
fscanf(p, "%d %d", &d[0], &d[1]);
fscanf(p, "%d", &d[2]);
for(i=0; i<d[0]; i++)
{
for(j=0; j<d[1]; j++)
{
fscanf(p,"%d", &a[i][j]);
}
}
fclose(p);
for(i=0; i<d[0]; i++)
{
for(j=0; j<d[1]; j++)
{
a[i][j] = d[2]-a[i][j];
}
}
q=fopen(outputfile, "w");
if (q==0)
{
fprintf(q,"File dint open correctly\n");
}
fprintf(q,"%s\n%d %d\n%d\n", magicno, d[0], d[1], d[2]);
for(i=0; i<d[0]; i++)
{
for(j=0; j<d[1]; j++)
{
fprintf(q,"%d ", a[i][j]);
}
fprintf(q,"\n");
}
fclose(q);
return 0;
}