|
7 | 7 | int main(int argc, char *argv[]) |
8 | 8 | { |
9 | 9 | // Define allowable filters |
10 | | - char *filters = "bgrsitB"; |
| 10 | + char *filters = "bgrsivB:"; |
11 | 11 |
|
12 | 12 |
|
13 | 13 | char filterArr[argc-3]; |
| 14 | + int filterCount = 0; |
14 | 15 |
|
15 | 16 | // gets all filter flags and checks validity |
16 | | - for(int i=0; i<argc; i++){ |
17 | | - char temp = getopt(argc,argv,filters); |
18 | | - if(temp == -1) break; |
19 | | - filterArr[i]= temp; |
20 | | - if(filterArr[i] == '?') { |
21 | | - printf("Invalid filter option"); |
| 17 | + int opt; |
| 18 | + while ((opt = getopt(argc, argv, filters)) != -1) { |
| 19 | + if (opt == '?') { |
| 20 | + printf("Invalid filter option\n"); |
22 | 21 | return 1; |
23 | 22 | } |
| 23 | + filterArr[filterCount++] = opt; |
24 | 24 | } |
25 | 25 |
|
26 | 26 |
|
@@ -98,7 +98,7 @@ int main(int argc, char *argv[]) |
98 | 98 | } |
99 | 99 |
|
100 | 100 | // Filter image |
101 | | - for(int i=0; i<argc-3; i++){ |
| 101 | + for(int i=0; i<filterCount; i++){ |
102 | 102 | switch (filterArr[i]) |
103 | 103 | { |
104 | 104 | // Blur |
@@ -126,27 +126,19 @@ int main(int argc, char *argv[]) |
126 | 126 | invert(height,width,image); |
127 | 127 | break; |
128 | 128 |
|
129 | | - // Threshold (black & white) |
130 | | - case 't': |
131 | | - threshold(height, width, image); |
| 129 | + // Vignette |
| 130 | + case 'v': |
| 131 | + vignette(height, width, image); |
132 | 132 | break; |
133 | 133 |
|
134 | 134 | // Brightness Adjust |
135 | 135 | case 'B': { |
136 | | - int brightness_value = 0; |
137 | | - // Get brightness value from argv, after -B flag (assume it appears as -B val) |
138 | | - if (optind < argc) { |
139 | | - brightness_value = atoi(argv[optind]); |
140 | | - optind++; |
141 | | - } else { |
142 | | - printf("Missing value for -B (brightness) flag.\n"); |
143 | | - return 8; |
144 | | - } |
| 136 | + int brightness_value = atoi(optarg); |
145 | 137 | brightness(height, width, image, brightness_value); |
146 | 138 | break; |
147 | 139 | } |
148 | 140 | default: |
149 | | - printf("%c", &filterArr[i]); |
| 141 | + printf("Unknown filter: %c\n", filterArr[i]); |
150 | 142 | break; |
151 | 143 |
|
152 | 144 | } |
|
0 commit comments