#include "main.h"
#include <unistd.h> // Because we can.
+
+#include "controlpanel.h"
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include <fenv.h>
+#include <signal.h>
+
+bool ignore_sigfpe = false;
+const char *script_filename;
+
+void sigfpe_handler(int sig)
+{
+ if (!ignore_sigfpe)
+ Fatal("Floating point exception!");
+ exit(EXIT_SUCCESS);
+}
+
int main(int argc, char ** argv)
{
- Debug("Compiled with REAL = %d => \"%s\"", REAL, g_real_name[REAL]);
+ signal(SIGFPE, sigfpe_handler);
+ #if REALTYPE == REAL_IRRAM
+ iRRAM_initialize(argc,argv);
+ #endif
+
+ #ifndef __STDC_IEC_559__
+ Warn("__STDC_IEC_559__ not defined. IEEE 754 floating point not fully supported.\n");
+ #endif
+
+ // We want to crash if we ever get a NaN.
+ feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
+
+ DebugRealInfo();
- Document doc;
+ Document doc("","fonts/ComicSans.ttf");
srand(time(NULL));
enum {OUTPUT_TO_BMP, LOOP} mode = LOOP;
Colour c(0,0,0,1);
- const char * input_bmp = NULL;
+
const char * output_bmp = NULL;
const char * input_filename = NULL;
- float b[4] = {0,0,1,1};
+ const char * input_text = NULL;
+ Real b[4] = {0,0,1,1};
+ int max_frames = -1;
+ bool hide_control_panel = false;
+ bool lazy_rendering = true;
+ bool window_visible = true;
+ bool gpu_transform = true;
+ bool gpu_rendering = true;
+
+
int i = 0;
while (++i < argc)
{
{
case 'o':
mode = OUTPUT_TO_BMP;
- if (++i >= argc)
- Fatal("No input argument following -o switch");
- input_bmp = argv[i];
if (++i >= argc)
Fatal("No output argument following -o switch");
output_bmp = argv[i];
-
+ hide_control_panel = true;
break;
- case 'c':
+ case 'b':
{
- Debug("Reading paint colour");
+ Debug("Reading view bounds");
for (int j = 1; j <= 4; ++j)
{
if (i+j >= argc)
- Fatal("No %d colour component following -c switch", j);
- char * e;
- float * comp = (j == 1) ? (&c.r) : ((j == 2) ? (&c.g) : ((j == 3) ? (&c.b) : &(c.a)));
- *comp = strtof(argv[i+j], &e);
- if (*e != '\0')
- Fatal("Colour component %d not a valid float", j);
+ Fatal("No %d bounds component following -b switch", j);
+ b[j-1] = RealFromStr(argv[i+j]);
}
i += 4;
break;
}
- case 'b':
+ case 't':
{
- Debug("Reading view bounds");
- for (int j = 1; j <= 4; ++j)
+ if (++i >= argc)
+ Fatal("No text input following -t switch");
+ input_text = argv[i];
+ Debug("Insert text: %s", input_text);
+ break;
+ }
+
+ case 'r':
+ {
+ if (++i >= argc)
+ Fatal("Expected \"gpu\" or \"cpu\" after -r switch");
+ if (strcmp(argv[i], "gpu") == 0)
{
- if (i+j >= argc)
- Fatal("No %d bounds component following -b switch", j);
- char * e;
- b[j-1] = strtof(argv[i+j], &e);
- if (*e != '\0')
- Fatal("Bounds component %d not a valid float", j);
+ gpu_rendering = true;
+ }
+ else if (strcmp(argv[i], "cpu") == 0)
+ {
+ gpu_rendering = false;
+ }
+ else
+ {
+ Fatal("Expected \"gpu\" or \"cpu\" after -r switch, not \"%s\"", argv[i]);
}
- i += 4;
break;
}
+
+ case 'T':
+ {
+ if (++i >= argc)
+ Fatal("Expected \"gpu\" or \"cpu\" after -T switch");
+ if (strcmp(argv[i], "gpu") == 0)
+ {
+ gpu_transform = true;
+ }
+ else if (strcmp(argv[i], "cpu") == 0)
+ {
+ gpu_transform = false;
+ }
+ else
+ {
+ Fatal("Expected \"gpu\" or \"cpu\" after -T switch, not \"%s\"", argv[i]);
+ }
+ break;
+ }
+
+
+ case 'l':
+ lazy_rendering = !lazy_rendering;
+ break;
+
+ case 'f':
+ if (++i >= argc)
+ Fatal("No frame number following -f switch");
+ max_frames = strtol(argv[i], NULL, 10);
+ hide_control_panel = true;
+ break;
+
+ case 'q':
+ hide_control_panel = true;
+ break;
+
+ case 'Q':
+ hide_control_panel = true;
+ window_visible = !window_visible;
+ break;
+ case 's':
+ hide_control_panel = true;
+ if (++i >= argc)
+ Fatal("Expected filename after -s switch");
+ script_filename = argv[i];
+ break;
}
}
+ Rect bounds(b[0],b[1],b[2],b[3]);
+ Screen scr(window_visible);
+ View view(doc,scr, bounds);
+
+ view.SetLazyRendering(lazy_rendering);
+ view.SetGPURendering(gpu_rendering);
+ view.SetGPUTransform(gpu_transform);
+
if (input_filename != NULL)
{
- doc.Load(input_filename);
+ #ifdef TRANSFORM_OBJECTS_NOT_VIEW
+ doc.LoadSVG(input_filename, Rect(Real(1)/Real(2),Real(1)/Real(2),Real(1)/Real(800),Real(1)/Real(600)));
+ #else
+ doc.LoadSVG(input_filename, Rect(bounds.x+bounds.w/Real(2),bounds.y+bounds.h/Real(2),bounds.w/Real(800),bounds.h/Real(600)));
+ #endif
+ }
+ else if (input_text != NULL)
+ {
+ doc.AddText(input_text, bounds.h/Real(2), bounds.x, bounds.y+bounds.h/Real(2));
}
- else
+
+
+
+ #ifndef CONTROLPANEL_DISABLED
+ if (!scr.Valid()) hide_control_panel = true;
+ SDL_Thread * cp_thread = NULL;
+ if (!hide_control_panel)
{
- for(int i = 0; i < 1024; ++i)
+ ControlPanel::RunArgs args = {argc, argv, view, doc, scr};
+ cp_thread = SDL_CreateThread(ControlPanel::Run, "ControlPanel", &args);
+ if (cp_thread == NULL)
{
- for (int j = 0; j < 1024; ++j)
- {
- doc.Add(((i^j)&1)?RECT_OUTLINE:RECT_FILLED, Rect(0.2+i-512.0,0.2+j-512.0,0.6,0.6));
- }
+ Error("Couldn't create ControlPanel thread: %s", SDL_GetError());
}
-
}
- Rect bounds(b[0],b[1],b[2],b[3]);
+ #else //CONTROLPANEL_DISABLED
+ Debug("No control panel, hide_control_panel is %d", hide_control_panel);
+ #endif
if (mode == LOOP)
- MainLoop(doc, bounds, c);
+ MainLoop(doc, scr, view, max_frames);
else if (mode == OUTPUT_TO_BMP)
- OverlayBMP(doc, input_bmp, output_bmp, bounds, c);
+ {
+ view.SaveBMP(output_bmp);
+ }
+
+ #ifndef CONTROLPANEL_DISABLED
+ if (cp_thread != NULL)
+ {
+ int cp_return;
+ qApp->quit(); // will close the control panel
+ // (seems to not explode if the qApp has already been quit)
+ SDL_WaitThread(cp_thread, &cp_return);
+ Debug("ControlPanel thread returned %d", cp_return);
+ }
+ #endif //CONTROLPANEL_DISABLED
+
+ ignore_sigfpe = true;
return 0;
}