Fix colour in ScreenShot
[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         Document doc;
6         srand(time(NULL));
7
8         enum {OUTPUT_TO_BMP, LOOP} mode = LOOP;
9         
10         Rect bounds(0,0,1,1);
11         Colour c(0,0,0,1);
12         const char * input_bmp = NULL;
13         const char * output_bmp = NULL;
14         const char * input_filename = NULL;
15
16         int i = 0;
17         while (++i < argc)
18         {
19                 if (argv[i][0] != '-')
20                 {
21                         input_filename = argv[i];
22                         continue;               
23                 }
24                 switch (argv[i][1])
25                 {
26                         case 'o':
27                                 mode = OUTPUT_TO_BMP;
28                                 if (++i >= argc)
29                                         Fatal("No input argument following -o switch");
30                                 input_bmp = argv[i];
31                                 if (++i >= argc)
32                                         Fatal("No output argument following -o switch");
33                                 output_bmp = argv[i];
34
35                                 break;
36                         case 'c':
37                         {
38                                 Debug("Reading paint colour");
39                                 for (int j = 1; j <= 4; ++j)
40                                 {
41                                         if (i+j >= argc)
42                                                 Fatal("No %d colour component following -c switch", j);
43                                         char * e;
44                                         float * comp = (j == 1) ? (&c.r) : ((j == 2) ? (&c.g) : ((j == 3) ? (&c.b) : &(c.a)));
45                                         *comp = strtof(argv[i+j], &e);
46                                         if (*e != '\0')
47                                                 Fatal("Colour component %d not a valid float", j); 
48                                 }
49                                 i += 4;
50                                 break;
51                         }
52                 }       
53         }
54
55         if (input_filename != NULL)
56         {
57                 doc.Load(input_filename);
58         }
59         else 
60         {
61                 doc.Add(RECT_FILLED, Rect(0.2,0.2,0.6,0.6));
62         }
63
64         if (mode == LOOP)
65                 MainLoop(doc, bounds, c);
66         else if (mode == OUTPUT_TO_BMP)
67                 OverlayBMP(doc, input_bmp, output_bmp, bounds, c);
68         return 0;
69 }

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