-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
107 lines (97 loc) · 2.44 KB
/
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
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
#include <stdio.h>
#include <stdlib.h>
#include "rtree.h"
#include "qdbmp.h"
#include "hmap.h"
#include "sphere.h"
#include "cylinder.h"
#include "rectarray.h"
#define TESTFILE "testing/checker.bmp"
#define OUTFILE "out.bmp"
#define MANFILE "manual.txt"
/* Add an element for each flag here */
enum FLAGS {
NONE,
MAXSDEV,
OUTFILENAME
} FLAGS;
int main(int argc, char *argv[]) {
int i;
int pcount; /* Number of pixels/points in bitmap */
rtree *rrt, *grt, *brt; /* R, G, B channels */
point* p;
char* arg, *filename, *outfilename; /* Strings for use in flags.
These should only be set if the corresponding
flags have been called */
enum FLAGS curflag; /* Current flag */
FILE* manual;
int complevel = 5;
rrt = creatert();
grt = creatert();
brt = creatert();
/* rcctobmp("out.rcc", "out.bmp"); */
filename = NULL;
outfilename = OUTFILE;
curflag = NONE;
/* FLAG CODE */
for (i = 1; i < argc; i++){
arg = argv[i];
/* How to respond to each -* command */
/* Usually just setting the enum curflag to the appropriate value */
if (arg[0] == '-'){
switch (arg[1]){
case 'm':
curflag = MAXSDEV;
break;
case 'o':
curflag = OUTFILENAME;
break;
case 'h':
manual = fopen(MANFILE, "r");
while(!feof(manual)) {
printf("%c", (char) fgetc(manual));
}
fclose(manual);
exit(EXIT_SUCCESS);
}
continue;
} else {
switch(curflag){ /* How to behave if a flag has been set */
case MAXSDEV:
complevel = atoi(arg);
printf("Set compression level to %d\n", atoi(argv[i]));
break;
case OUTFILENAME:
outfilename = arg;
/* printf("Output file set to %s\n", outfilename);*/
break;
default:
filename = arg;
/* printf("Looking for something? Run with '-h' for documentation.\n");*/
break;
}
curflag = NONE; /* The flag has taken input, and is disabled */
}
}
setmaxsdev(atoi(arg));
if (filename){
printf("Loading rtrees from \'%s\'\n", filename);
if (!loadbmp(filename, rrt, grt, brt)){
printf("Failed to load BMP. Exiting.\n");
exit(0);
}
printf("Saving rtrees to \'%s\' with compression level of %d\n",
outfilename, complevel);
savebmp(outfilename, rrt, grt, brt);
} else {
printf("Using default BMP %s\n", TESTFILE);
if (!loadbmp(TESTFILE, rrt, grt, brt)){
printf("Failed to load BMP. Exiting.\n");
exit(0);
}
}
if (!(rrt && grt && brt)){
printf("R/G/B trees do not all exist. Exiting.\n");
exit(0);
}
}