-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheffects_main.c
executable file
·64 lines (55 loc) · 2.25 KB
/
effects_main.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "pgm.h"
#include "effects.h"
#define THRESHOLD 130
int main(int argc, char *argv[]) {
char effect_name[20];
const char fileloc[] = "effect_images/", extension[] = "pgm";
char file[50], newfile[50];
if(argc < 2) {
printf("\nUsage: ./pgm_effect <PGM image 1> ... <PGM image N>\n");
exit(1);
}
for(int i = 1; i < argc; ++i) {
while(strstr(argv[i], extension)){
printf("\nPlease enter the file names without the extension.\n");
exit(1);
}
}
PGMInfo pgm_info;
srand(time(NULL));
printf("\nSelect an effect you want to apply.\nEffects available: binarize, noise, smooth, invert, solarize\n>> ");
scanf(" %s", effect_name);
while(strcmp(effect_name, "binarize") && strcmp(effect_name, "noise") && strcmp(effect_name, "smooth") && strcmp(effect_name, "invert") && strcmp(effect_name, "solarize")) {
printf("\nPlease select a valid one.\n>> ");
scanf(" %s", effect_name);
}
printf("\n===== PROCESSED IMAGES\n");
for(int i = 1; i < argc; ++i) {
sprintf(file, "%s%s.%s", fileloc, argv[i], extension);
sprintf(newfile, "%s%s_%s.%s", fileloc, argv[i], effect_name, extension);
pgm_info = pgm_read(file);
if(pgm_info.error != 0) {
pgm_print_error(pgm_info);
exit(1);
}
pgm_print_header(pgm_info);
if(!strcmp(effect_name, "invert"))
effect_invert(pgm_info.pixels, pgm_info.width, pgm_info.height);
else if(!strcmp(effect_name, "binarize"))
effect_binarize(pgm_info.pixels, pgm_info.width, pgm_info.height, THRESHOLD);
else if(!strcmp(effect_name, "noise"))
effect_random_noise(pgm_info.pixels, pgm_info.width, pgm_info.height);
else if(!strcmp(effect_name, "smooth"))
effect_smooth(pgm_info.pixels, pgm_info.width, pgm_info.height);
else if(!strcmp(effect_name, "solarize"))
effect_solarize(pgm_info.pixels, pgm_info.width, pgm_info.height, THRESHOLD);
if(!pgm_write(newfile, pgm_info)) {
printf("Error while writing PMG file.\n");
}
free(pgm_info.pixels);
} return 0;
}