-
Notifications
You must be signed in to change notification settings - Fork 0
/
libtest.c
134 lines (120 loc) · 2.79 KB
/
libtest.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include <stdio.h>
#include <stdlib.h>
#include "image.h"
#include "colorimage.h"
#include "show_image.h"
#include "libtest.h"
void debugImage(GrayImage *img)
{
int row,col,length,breadth,i,j;
printf("View image portion as matrix\n\n");
printf("Enter the image portion as matrix\n\n\n");
printf("Enter the x co-ordinate(%d-%d)\n",0,img->row-1);
scanf("%d",&row);
printf("Enter the y co-ordinate(%d-%d)\n",0,img->col-1);
scanf("%d",&col);
printf("Enter the length of the rectangle\n");
scanf("%d",&length);
printf("Enter the breadth of the rectangle\n");
scanf("%d",&breadth);
if(row+breadth>img->row || col+length>img->col || length>100 || breadth>100)
{
printf("Not possible... Please choose a shorter window...\n");
return;
}
for(i=0;i<breadth;i++)
{
for(j=0;j<length;j++)
{
printf("%d\t",img->f[row+i][col+j]);
}
printf("\n\n");
}
return;
}
void createImage(GrayImage *img)
{
char *filename=(char *)malloc(sizeof(char) * MAX_FILENAME_LENGTH);
int i,ch;
printf("This is a portal for creating test images..\n");
printf("Press enter to continue\n");
getchar();
while(1)
{
printf("Components\n1) Square(type 1)\n2) Rectangle(type 2)\n3) Show Image(type 3)\n4) Save(type 4)\n5) Exit(type 5)\nChoose an option from above..\n");
scanf("%d",&ch);
switch(ch)
{
case 1:insSquare(img);
break;
case 2:insRect(img);
break;
case 3:imshow(*img);
break;
case 4:
printf("Please enter a filename\n");
for(i=0;i<MAX_FILENAME_LENGTH && (filename[i]=getchar())!='\n';i++);
filename[i]='\0';
savePGM(*img,filename);
break;
case 5:
printf("Exiting..\n");
return;
break;
default:printf("Invalid option\n\n\n");
}
}
}
void insSquare(GrayImage *img)
{
int row,col,size,i,j;
printf("Enter the x co-ordinate(%d-%d)\n",0,img->row-1);
scanf("%d",&row);
printf("Enter the y co-ordinate(%d-%d)\n",0,img->col-1);
scanf("%d",&col);
printf("Enter the size of the square\n");
scanf("%d",&size);
if(row+size>img->row || col+size>img->col)
{
printf("Not possible\n");
return;
}
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
img->f[row+i][col+j]=img->maxval;
}
}
}
void insRect(GrayImage *img)
{
int row,col,length,breadth,i,j;
printf("Enter the x co-ordinate(%d-%d)\n",0,img->row-1);
scanf("%d",&row);
printf("Enter the y co-ordinate(%d-%d)\n",0,img->col-1);
scanf("%d",&col);
printf("Enter the length of the rectangle\n");
scanf("%d",&length);
printf("Enter the breadth of the rectangle\n");
scanf("%d",&breadth);
if(row+breadth>img->row || col+length>img->col)
{
printf("Not possible\n");
return;
}
for(i=0;i<breadth;i++)
{
for(j=0;j<length;j++)
{
img->f[row+i][col+j]=img->maxval;
}
}
}
/*main()
{
GrayImage img;
initGrayImage(&img,4,4,255);
createImage(&img);
debugImage(&img);
}*/