Maybe don't use all of the lines. Or maybe do.
[ipdf/code.git] / src / main.cpp
1 #include "main.h"
2 #include <unistd.h> // Because we can.
3 int main(int argc, char ** argv)
4 {       
5         #ifndef __STDC_IEC_559__
6         Warn("__STDC_IEC_559__ not defined. IEEE 754 floating point not fully supported.\n");
7         #endif
8
9
10         Debug("Compiled with REAL = %d => \"%s\" sizeof(Real) == %d bytes", REAL, g_real_name[REAL], sizeof(Real));
11
12         Document doc;
13         srand(time(NULL));
14
15         enum {OUTPUT_TO_BMP, LOOP} mode = LOOP;
16         
17         
18         Colour c(0,0,0,1);
19         const char * input_bmp = NULL;
20         const char * output_bmp = NULL;
21         const char * input_filename = NULL;
22         float b[4] = {0,0,1,1};
23
24         int i = 0;
25         while (++i < argc)
26         {
27                 if (argv[i][0] != '-')
28                 {
29                         input_filename = argv[i];
30                         continue;               
31                 }
32                 switch (argv[i][1])
33                 {
34                         case 'o':
35                                 mode = OUTPUT_TO_BMP;
36                                 if (++i >= argc)
37                                         Fatal("No input argument following -o switch");
38                                 input_bmp = argv[i];
39                                 if (++i >= argc)
40                                         Fatal("No output argument following -o switch");
41                                 output_bmp = argv[i];
42
43                                 break;
44                         case 'c':
45                         {
46                                 Debug("Reading paint colour");
47                                 for (int j = 1; j <= 4; ++j)
48                                 {
49                                         if (i+j >= argc)
50                                                 Fatal("No %d colour component following -c switch", j);
51                                         char * e;
52                                         float * comp = (j == 1) ? (&c.r) : ((j == 2) ? (&c.g) : ((j == 3) ? (&c.b) : &(c.a)));
53                                         *comp = strtof(argv[i+j], &e);
54                                         if (*e != '\0')
55                                                 Fatal("Colour component %d not a valid float", j); 
56                                 }
57                                 i += 4;
58                                 break;
59                         }
60                         case 'b':
61                         {
62                                 Debug("Reading view bounds");
63                                 for (int j = 1; j <= 4; ++j)
64                                 {
65                                         if (i+j >= argc)
66                                                 Fatal("No %d bounds component following -b switch", j);
67                                         char * e;
68                                         b[j-1] = strtof(argv[i+j], &e);
69                                         if (*e != '\0')
70                                                 Fatal("Bounds component %d not a valid float", j); 
71                                 }
72                                 i += 4;
73                                 break;
74                         }
75                 }       
76         }
77
78         if (input_filename != NULL)
79         {
80                 doc.Load(input_filename);
81         }
82         else 
83         {
84                 doc.AddBezierData(Bezier(0,0,0,1,1,0));
85                 doc.AddBezierData(Bezier(0,0,1,0,0,1));
86                 doc.AddBezierData(Bezier(0,0,1,1,1,0));
87                 doc.AddBezierData(Bezier(0,1,1,0,0,1));
88                 
89                 
90                 
91                 for(int x = 0; x < 8; ++x)
92                 {
93                         
94                         for (int y = 0; y < 8; ++y)
95                         {
96                                 //doc.Add(static_cast<IPDF::ObjectType>((x^y)%3), Rect(0.2+x-4.0,0.2+y-4.0,0.6,0.6));
97                                 //doc.Add(BEZIER, Rect(0.2+x-4.0, 0.2+y-4.0, 0.6,0.6), (x^y)%3);
98                         }
99                         
100                         //doc.Add(RECT_OUTLINE, Rect(0.1,0.1,0.8,0.8), 0);
101                         doc.Add(BEZIER, Rect(0,0,1,1), 0);
102                 }
103                 
104         }
105         Rect bounds(b[0],b[1],b[2],b[3]);
106
107         if (mode == LOOP)
108                 MainLoop(doc, bounds, c);
109         else if (mode == OUTPUT_TO_BMP)
110                 OverlayBMP(doc, input_bmp, output_bmp, bounds, c);
111         return 0;
112 }

UCC git Repository :: git.ucc.asn.au