-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestmain.c
More file actions
183 lines (154 loc) · 4.07 KB
/
testmain.c
File metadata and controls
183 lines (154 loc) · 4.07 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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include <stdio.h>
#include <stdbool.h>
// #include "testprocess.c"
#include "process.c"
// Main to test load_image
/*
int main()
{
const char *filename = "bars.hs16";
struct Image *img = load_image(filename);
if (img == NULL)
{
printf("Failed to load image from file %s\n", filename);
return 1;
}
printf("Image loaded successfully with dimensions: %d x %d\n", img->width, img->height);
free_image(img);
return 0;
}
*/
// Main to test save_image
/*
int main()
{
const char *input_filename = "coffee.hs16";
const char *output_filename = "coffee_output.hs16";
// Load the image
struct Image *image = load_image(input_filename);
if (image == NULL)
{
fprintf(stderr, "Failed to load the input image.\n");
return 1;
}
// Modify the image if needed (optional)
// Save the modified image
if (save_image(image, output_filename))
{
printf("Image saved successfully.\n");
}
else
{
fprintf(stderr, "Failed to save the image.\n");
return 1;
}
// Free memory allocated for the image
free_image(image);
return 0;
}
*/
// Main to test copy_image
/*
int main()
{
const char *filename = "coffee.hs16";
// Load the original image
struct Image *original = load_image(filename);
if (original == NULL)
{
fprintf(stderr, "Failed to load the original image from file %s\n", filename);
return 1;
}
// Create a copy of the original image
struct Image *copy = copy_image(original);
if (copy == NULL)
{
fprintf(stderr, "Failed to create a copy of the original image\n");
free_image(original);
return 1;
}
// Compare each pixel of the original image with the corresponding pixel in the copied image
bool identical = true;
for (int i = 0; i < original->width * original->height; i++)
{
if (original->pixels[i].red != copy->pixels[i].red ||
original->pixels[i].green != copy->pixels[i].green ||
original->pixels[i].blue != copy->pixels[i].blue)
{
identical = false;
break;
}
}
if (identical)
{
printf("The copy operation is successful. The original and copied images are identical.\n");
}
else
{
printf("The copy operation failed. The original and copied images are not identical.\n");
}
// Free memory allocated for the original and copied images
free_image(original);
free_image(copy);
return 0;
}
*/
// Main to test apply_NOISE
/*
int main(int argc, char **argv)
{
if (argc < 3)
{
fprintf(stderr, "Usage: %s input_image output_image [noise_strength]\n", argv[0]);
return 1;
}
const char *input_filename = argv[1];
const char *output_filename = argv[2];
// Parse the optional noise_strength argument
int noise_strength = 5;
if (argc >= 4)
{
noise_strength = atoi(argv[3]);
}
// Load the input image
struct Image *img = load_image(input_filename);
if (img == NULL)
{
fprintf(stderr, "Error loading image %s\n", input_filename);
return 1;
}
// Apply random noise to the image and create a new image
struct Image *noisy_img = apply_NOISE(img, noise_strength);
if (noisy_img == NULL)
{
fprintf(stderr, "Error applying noise to image %s\n", input_filename);
free_image(img);
return 1;
}
// Save the modified image to a file
if (!save_image(noisy_img, output_filename))
{
fprintf(stderr, "Error saving image %s\n", output_filename);
free_image(img);
free_image(noisy_img);
return 1;
}
// Free the image memory
free_image(img);
free_image(noisy_img);
return 0;
}
*/
// Main to check for apply_CODE
int main()
{
const char *filename = "coffee.hs16";
struct Image *img = load_image(filename);
bool success = apply_CODE(img);
if (!success)
{
printf("Error applying apply_CODE");
}
free_image(img);
return success ? 0 : 1;
}