Beispiel #1
0
int main(int argc, char *argv[])
{
	const unsigned int width = 640;
	const unsigned int height = 480;
	struct display *display;
	struct window *window;

	display = display_open();
	if (!display) {
		fprintf(stderr, "failed to open display\n");
		return 1;
	}

	window = window_create(display, argv[0], 0, 0, width, height);
	if (!window) {
		fprintf(stderr, "failed to create window\n");
		return 1;
	}

	window_show(window);

	event_loop(window);

	window_close(window);
	display_close(display);
	return 0;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
	display_init();
	intro_display();
	/*User function calls
	 */
    getch();
    display_close();
    return 0;
}
Beispiel #3
0
static gboolean
gst_sh_video_sink_stop (GstBaseSink *bsink)
{
	GstSHVideoSink *sink = GST_SH_VIDEO_SINK (bsink);

	GST_DEBUG_OBJECT(sink,"STOP, closing devices.");
	display_close(sink->display);

	return TRUE;
}
Beispiel #4
0
/**
 * @brief Initialize the console
 *
 * Initialize the console system.  This will initialize the video properly, so
 * a call to the display_init() fuction is not necessary.
 */
void console_init()
{
    /* In case they initialized the display already */
    display_close();
    display_init( RESOLUTION_320x240, DEPTH_16_BPP, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE );

    render_buffer = malloc(CONSOLE_SIZE);

    console_clear();
    console_set_render_mode(RENDER_AUTOMATIC);

    /* Register ourselves with newlib */
    hook_stdio_calls( &console_calls );
}
void file_is_unloaded()
{
    // stop decode window
    display_close(engine);
    engine = NULL;
    set_GOP_selected(0);

    // toggle our file options
    gtk_widget_set_sensitive(menu_load_mpeg2, TRUE);
    gtk_widget_set_sensitive(menu_load_clip_list, TRUE);
    gtk_widget_set_sensitive(menu_save_clip_list, FALSE);
    gtk_widget_set_sensitive(menu_export_mpeg2, FALSE);
    gtk_widget_set_sensitive(menu_close, FALSE);

    gtk_widget_set_sensitive(menu_delete, FALSE);
    gtk_widget_set_sensitive(menu_clear, FALSE);

    gtk_widget_set_sensitive(menu_video_window, FALSE);

    gtk_widget_set_sensitive(button_run, FALSE);
    gtk_widget_set_sensitive(button_prev, FALSE);
    gtk_widget_set_sensitive(button_next, FALSE);
    gtk_widget_set_sensitive(button_refresh, FALSE);
    gtk_widget_set_sensitive(button_start_mark, FALSE);
    gtk_widget_set_sensitive(button_end_mark, FALSE);

    // adjust the slider scales
    gtk_range_set_range(GTK_RANGE(GOP_selector), 0.0, 0.1);
    gtk_spin_button_set_range(GTK_SPIN_BUTTON(GOP_selector_spinbutton), 0.0, 0.1);

    // wipe out GOP info window
    clear_GOP_info();

    // wipe out clip window
    clear_GOP_slices();

    // reset parser
    mpeg2parser->reset();

    if (error_dialog)
    {
        // hide the errors (no errors now!)
        gtk_widget_hide(error_dialog);
    }
}
Beispiel #6
0
void sig_die (char *str, ...)
{
	char   *out;

	va_list argp;

	display_close ();

	va_start (argp, str);
	vasprintf (&out, str, argp);
	va_end (argp);

	printf ("%s", out);

	free (out);

	exit (1);
}
void file_is_loaded()
{
    List *GOPs;
    List *pictures;
    gchar buf[128];
    char *pathname;
    int picture_count = 0;

    // toggle our file options
    gtk_widget_set_sensitive(menu_load_mpeg2, FALSE);
    gtk_widget_set_sensitive(menu_load_clip_list, FALSE);
    gtk_widget_set_sensitive(menu_save_clip_list, TRUE);
    gtk_widget_set_sensitive(menu_export_mpeg2, TRUE);
    gtk_widget_set_sensitive(menu_close, TRUE);

    gtk_widget_set_sensitive(menu_delete, TRUE);
    gtk_widget_set_sensitive(menu_clear, TRUE);

    gtk_widget_set_sensitive(menu_video_window, TRUE);

    gtk_widget_set_sensitive(button_run, TRUE);
    gtk_widget_set_sensitive(button_prev, TRUE);
    gtk_widget_set_sensitive(button_next, TRUE);
    gtk_widget_set_sensitive(button_refresh, TRUE);
    gtk_widget_set_sensitive(button_start_mark, TRUE);
    gtk_widget_set_sensitive(button_end_mark, FALSE);

    // adjust the slider scales
    gtk_range_set_range(GTK_RANGE(GOP_selector), 0.0, (gdouble) (mpeg2parser->numGOPs()));
    gtk_spin_button_set_range(GTK_SPIN_BUTTON(GOP_selector_spinbutton), 0.0, (gdouble) (mpeg2parser->numGOPs()-1));

    // start decode window
    display_close(engine);
    engine = display_open(desired_output,opt_pipe,opt_videoout,opt_show_states);
    set_GOP_selected(0);
    flush();
    slider_updated_actions(0);

    pathname = mpeg2parser->getFilename();
    if (!pathname)
        pathname = "unknown";
    gtk_label_set_text(GTK_LABEL(GOP_label_filename), pathname);
}
Beispiel #8
0
void sig_cleanexit (char *str, ...)
{
	char   *out;

	va_list argp;

	display_close ();

	editor_fini ();

	va_start (argp, str);
	vasprintf (&out, str, argp);
	va_end (argp);

	printf ("%s", out);

	free (out);

	exit (0);
}
Beispiel #9
0
/* main code entry point */
int main(void)
{
    display_context_t _dc;
    char temp[128];
	int res = 0;
	unsigned short buttons, previous = 0;

    init_n64();

    while (1)
    {
		int j;
		int width[4] = { 320, 640, 256, 512 };
		int height[4] = { 240, 480, 240, 480 };
		unsigned int color;

        _dc = lockVideo(1);
		color = graphics_make_color(0xCC, 0xCC, 0xCC, 0xFF);
		graphics_fill_screen(_dc, color);

		color = graphics_make_color(0xFF, 0xFF, 0xFF, 0xFF);
		graphics_draw_line(_dc, 0, 0, width[res]-1, 0, color);
		graphics_draw_line(_dc, width[res]-1, 0, width[res]-1, height[res]-1, color);
		graphics_draw_line(_dc, width[res]-1, height[res]-1, 0, height[res]-1, color);
		graphics_draw_line(_dc, 0, height[res]-1, 0, 0, color);

		graphics_draw_line(_dc, 0, 0, width[res]-1, height[res]-1, color);
		graphics_draw_line(_dc, 0, height[res]-1, width[res]-1, 0, color);

		color = graphics_make_color(0x00, 0x00, 0x00, 0xFF);
		graphics_set_color(color, 0);

        printText(_dc, "Video Resolution Test", width[res]/16 - 10, 3);
		switch (res)
		{
			case 0:
				printText(_dc, "320x240", width[res]/16 - 3, 5);
				break;
			case 1:
				printText(_dc, "640x480", width[res]/16 - 3, 5);
				break;
			case 2:
				printText(_dc, "256x240", width[res]/16 - 3, 5);
				break;
			case 3:
				printText(_dc, "512x480", width[res]/16 - 3, 5);
				break;
		}

		for (j=0; j<8; j++)
		{
			sprintf(temp, "Line %d", j);
			printText(_dc, temp, 3, j);
			sprintf(temp, "Line %d", height[res]/8 - j - 1);
			printText(_dc, temp, 3, height[res]/8 - j - 1);
		}
		printText(_dc, "0123456789", 0, 16);
		printText(_dc, "9876543210", width[res]/8 - 10, 16);

        unlockVideo(_dc);

        while (1)
        {
            // wait for change in buttons
            buttons = getButtons(0);
            if (buttons ^ previous)
                break;
            delay(1);
        }

        if (A_BUTTON(buttons ^ previous))
        {
            // A changed
            if (!A_BUTTON(buttons))
			{
				resolution_t mode[4] = { RESOLUTION_320x240, RESOLUTION_640x480, RESOLUTION_256x240, RESOLUTION_512x480 };
				res = (res+1) & 3;
				display_close();
				display_init(mode[res], DEPTH_16_BPP, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE);
			}
		}

        previous = buttons;
    }

    return 0;
}
Beispiel #10
0
int main (int argc, char **argv)
{
	SADisplay *display;
	VisVideo *video;

	VisInput *input;
	VisActor *actor;
	VisEventQueue *localqueue;
	VisVideoAttributeOptions *vidoptions;

	int running = TRUE;
	int fullscreen = FALSE;
	int visible = TRUE;

	int depth;

	//visual_mem_alloc_install_vtable (visual_mem_alloc_vtable_profile ());

	visual_init (&argc, &argv);

	display = display_new (sdl_driver_new ());

	/* Libvisual stuff */
	if (argc > 1)
		actor = visual_actor_new (argv[1]);
	else
		actor = visual_actor_new ("projectM");


	if (argc > 3) {
		depth = visual_video_depth_enum_from_value (atoi (argv[3]));
	} else
		depth = visual_video_depth_get_highest (visual_actor_get_supported_depth (actor));

	vidoptions = visual_actor_get_video_attribute_options (actor);

	display_create (display, depth, vidoptions, 480, 360, TRUE);

	visual_actor_realize (actor);

	video = display_get_video (display);

        visual_actor_set_video (actor, video);
	visual_actor_video_negotiate (actor, 0, FALSE, FALSE);

	if (argc > 2)
		input = visual_input_new (argv[2]);
	else
		input = visual_input_new ("alsa");

	visual_input_realize (input);

	localqueue = visual_event_queue_new ();

	while (running) {
		VisEventQueue *pluginqueue;
		VisEvent *ev;

		/* Handle all events */
		display_drain_events (display, localqueue);

		pluginqueue = visual_plugin_get_eventqueue (visual_actor_get_plugin (actor));
		while (visual_event_queue_poll_by_reference (localqueue, &ev)) {

			if (ev->type != VISUAL_EVENT_RESIZE)
				visual_event_queue_add (pluginqueue, ev);

			switch (ev->type) {
				case VISUAL_EVENT_RESIZE:
					video = display_get_video (display);
					visual_actor_set_video (actor, video);

					visual_actor_video_negotiate (actor, depth, FALSE, FALSE);
					break;

				case VISUAL_EVENT_MOUSEMOTION:
					break;

				case VISUAL_EVENT_MOUSEBUTTONDOWN:

					break;

				case VISUAL_EVENT_MOUSEBUTTONUP:
					break;

				case VISUAL_EVENT_KEYDOWN:
					switch (ev->event.keyboard.keysym.sym) {
						case VKEY_ESCAPE:
							running = FALSE;
							break;

						case VKEY_TAB:
							fullscreen = !fullscreen;

							display_set_fullscreen (display, fullscreen, TRUE);

							/* Resync video */
							video = display_get_video (display);
							visual_actor_set_video (actor, video);

							visual_actor_video_negotiate (actor, depth, FALSE, FALSE);

							break;

						default:
							printf ("key: %c\n", ev->event.keyboard.keysym.sym);
							break;
					}

					break;

				case VISUAL_EVENT_KEYUP:
					break;

				case VISUAL_EVENT_QUIT:
					running = FALSE;
					break;

				case VISUAL_EVENT_VISIBILITY:
					visible = ev->event.visibility.is_visible;
					break;

				default:
					break;
			}
		}

		if (visible == FALSE) {
			visual_input_run (input);

			visual_time_usleep (10000);

			continue;
		}

		/* Do a run cycle */
		visual_input_run (input);

		display_lock (display);
		visual_actor_run (actor, input->audio);
		display_unlock (display);

		display_update_all (display);

		display_fps_limit (display, 30);
	}

	/* Termination procedure */
	display_set_fullscreen (display, FALSE, TRUE);
	display_close (display);

	visual_quit ();

	//visual_mem_alloc_profile ();

	printf ("Total frames: %d, average fps: %f\n", display_fps_total (display), display_fps_average (display));

	return 0;
}
Beispiel #11
0
void display_cycle(void)
{
    unsigned long counter;
    int ch;

    counter = loopDelay;
    while (--counter);

    if (!(cycle & keyDelay)) {

#if defined(DJGPP) || defined(WATCOM)
#if defined(DOSALLGRAPHX)
	if (displayMode == TEXT)
#ifdef CONIOGRAPHX
	    CacheScreenUpdate(Screen[CORE_PAGE]);
#else
	    ScreenUpdate((void *) Screen[CORE_PAGE]);
#endif
#else
#if defined(DOSTXTGRAPHX)
#ifdef CONIOGRAPHX
	CacheScreenUpdate(Screen[CORE_PAGE]);
#else
	ScreenUpdate((void *) Screen[CORE_PAGE]);
#endif
#endif				/* DOSTXTGRAPHX */
#endif				/* DOSALLGRAPHX */
#endif				/* DJGPP */

#if defined(DOSALLGRAPHX)
	if (displayMode != TEXT)
	    bgi_update_cycle_meter();
#else
#if defined(DOSGRXGRAPHX)
	bgi_update_cycle_meter();
#endif
#endif
	if (KEYPRESSED && !inputRedirection) {
	    switch (ch = getch()) {
	    case '0':
		displayLevel = 0;
		break;
	    case '1':
		displayLevel = 1;
		break;
	    case '2':
		displayLevel = 2;
		break;
	    case '3':
		displayLevel = 3;
		break;
	    case '4':
		displayLevel = 4;
		break;
	    case 'd':
		debugState = STEP;
		/* stepping = FALSE; */ break;
	    case '>':
		if (displaySpeed > 0) {
		    --displaySpeed;
		    loopDelay = loopDelayAr[displaySpeed];
		    keyDelay = keyDelayAr[displaySpeed];
		}
		break;
	    case '<':
		if (displaySpeed < SPEEDLEVELS - 1) {
		    ++displaySpeed;
		    loopDelay = loopDelayAr[displaySpeed];
		    keyDelay = keyDelayAr[displaySpeed];
		}
		break;
	    case ' ':
	    case 'r':
#if defined(DOSALLGRAPHX)
		if (displayMode == TEXT)
		    text_display_clear();
		else
		    bgi_clear_arena();
#else
#if defined(DOSTXTGRAPHX)
		text_display_clear();
#else
		bgi_clear_arena();
#endif
#endif
		break;
	    case 27:		/* escape */
	    case 'q':
		display_close();
		Exit(USERABORT);
#if defined(DOSALLGRAPHX)
	    case 'v':
		if (displayMode == TEXT)
		    displayMode = GRX;
		else
		    bgi_display_close(NOWAIT);
		display_init();
		break;
#endif
#if 0
#if defined(DOSALLGRAPHX)
	    case '?':
	    case 'h':
		if (displayMode == TEXT)
		    disp_help();
		break;
#else
#if defined(DOSTXTGRAPHX)
	    case '?':
	    case 'h':
		disp_help();
		break;
#endif
#endif
#endif				/* 0 */
	    default:
		if (ch > 32 && ch < 128)
		    ch += 128;
		ungetch(ch);
		debugState = STEP;
		break;
	    }
#if defined(DOSALLGRAPHX)
	    if (displayMode != TEXT)
		write_menu();
#else
#if defined(DOSGRXGRAPHX)
	    write_menu();
#endif
#endif
	}
    }
}
Beispiel #12
0
Datei: mtr.c Projekt: RichiH/mtr
int main(int argc, char **argv)
{
  struct hostent *  host                = NULL;
  int               net_preopen_result;
#ifdef ENABLE_IPV6
  struct addrinfo       hints, *res;
  int                   error;
  struct hostent        trhost;
  char *                alptr[2];
  struct sockaddr_in *  sa4;
  struct sockaddr_in6 * sa6;
#endif

  /*  Get the raw sockets first thing, so we can drop to user euid immediately  */

  if ( ( net_preopen_result = net_preopen () ) ) {
    fprintf( stderr, "mtr: unable to get raw sockets.\n" );
    exit( EXIT_FAILURE );
  }

  /*  Now drop to user permissions  */
  if (setgid(getgid()) || setuid(getuid())) {
    fprintf (stderr, "mtr: Unable to drop permissions.\n");
    exit(1);
  }

  /*  Double check, just in case  */
  if ((geteuid() != getuid()) || (getegid() != getgid())) {
    fprintf (stderr, "mtr: Unable to drop permissions.\n");
    exit(1);
  }

  /* reset the random seed */
  srand (getpid());

  display_detect(&argc, &argv);

  /* The field options are now in a static array all together,
     but that requires a run-time initialization. */
  init_fld_options ();

  parse_mtr_options (getenv ("MTR_OPTIONS"));

  parse_arg (argc, argv);

  while (optind < argc) {
    char* name = argv[optind++];
    append_to_names(argv[0], name);
  }

  /* Now that we know mtrtype we can select which socket to use */
  if (net_selectsocket() != 0) {
    fprintf( stderr, "mtr: Couldn't determine raw socket type.\n" );
    exit( EXIT_FAILURE );
  }

  if (PrintVersion) {
    printf ("mtr " MTR_VERSION "\n");
    exit(0);
  }

  if (PrintHelp) {
    printf("usage: %s [-hvrwctglspniuT46] [--help] [--version] [--report]\n"
	   "\t\t[--report-wide] [--report-cycles=COUNT] [--curses] [--gtk]\n"
           "\t\t[--csv|-C] [--raw] [--split] [--mpls] [--no-dns] [--show-ips]\n"
           "\t\t[--address interface] [--filename=FILE|-F]\n" /* BL */
#ifdef IPINFO
           "\t\t[--ipinfo=item_no|-y item_no]\n"
           "\t\t[--aslookup|-z]\n"
#endif
           "\t\t[--psize=bytes/-s bytes]\n"            /* ok */
           "\t\t[--report-wide|-w] [-u|-T] [--port=PORT] [--timeout=SECONDS]\n"            /* rew */
	   "\t\t[--interval=SECONDS] HOSTNAME\n", argv[0]);
    exit(0);
  }

  time_t now = time(NULL);

  if (!names) append_to_names (argv[0], "localhost"); // default: localhost. 

  names_t* head = names;
  while (names != NULL) {

    Hostname = names->name;
    //  if (Hostname == NULL) Hostname = "localhost"; // no longer necessary.
    if (gethostname(LocalHostname, sizeof(LocalHostname))) {
      strcpy(LocalHostname, "UNKNOWNHOST");
    }

    if (net_preopen_result != 0) {
      fprintf(stderr, "mtr: Unable to get raw socket.  (Executable not suid?)\n");
      if ( DisplayMode != DisplayCSV ) exit(EXIT_FAILURE);
      else {
        names = names->next;
        continue;
      }
    }

#ifdef ENABLE_IPV6
    /* gethostbyname2() is deprecated so we'll use getaddrinfo() instead. */
    bzero( &hints, sizeof hints );
    hints.ai_family = af;
    hints.ai_socktype = SOCK_DGRAM;
    error = getaddrinfo( Hostname, NULL, &hints, &res );
    if ( error ) {
      if (error == EAI_SYSTEM)
         perror ("Failed to resolve host");
      else
         fprintf (stderr, "Failed to resolve host: %s\n", gai_strerror(error));

      if ( DisplayMode != DisplayCSV ) exit(EXIT_FAILURE);
      else {
        names = names->next;
        continue;
      }
    }
    /* Convert the first addrinfo into a hostent. */
    host = &trhost;
    bzero( host, sizeof trhost );
    host->h_name = res->ai_canonname;
    host->h_aliases = NULL;
    host->h_addrtype = res->ai_family;
    af = res->ai_family;
    host->h_length = res->ai_addrlen;
    host->h_addr_list = alptr;
    switch ( af ) {
    case AF_INET:
      sa4 = (struct sockaddr_in *) res->ai_addr;
      alptr[0] = (void *) &(sa4->sin_addr);
      break;
    case AF_INET6:
      sa6 = (struct sockaddr_in6 *) res->ai_addr;
      alptr[0] = (void *) &(sa6->sin6_addr);
      break;
    default:
      fprintf( stderr, "mtr unknown address type\n" );
      if ( DisplayMode != DisplayCSV ) exit(EXIT_FAILURE);
      else {
        names = names->next;
        continue;
      }
    }
    alptr[1] = NULL;
#else
      host = gethostbyname(Hostname);
    if (host == NULL) {
      herror("mtr gethostbyname");
      if ( DisplayMode != DisplayCSV ) exit(EXIT_FAILURE);
      else {
        names = names->next;
        continue;
      }
    }
    af = host->h_addrtype;
#endif

    if (net_open(host) != 0) {
      fprintf(stderr, "mtr: Unable to start net module.\n");
      if ( DisplayMode != DisplayCSV ) exit(EXIT_FAILURE);
      else {
        names = names->next;
        continue;
      }
    }

    if (net_set_interfaceaddress (InterfaceAddress) != 0) {
      fprintf( stderr, "mtr: Couldn't set interface address.\n" );
      if ( DisplayMode != DisplayCSV ) exit(EXIT_FAILURE);
      else {
        names = names->next;
        continue;
      }
    }

    lock(argv[0], stdout);
      display_open();
      dns_open();

      display_mode = 0;
      display_loop();

      net_end_transit();
      display_close(now);
    unlock(argv[0], stdout);

    if ( DisplayMode != DisplayCSV ) break;
    else names = names->next;

  }

  net_close();

  while (head != NULL) {
    names_t* item = head;
    free(item->name); item->name = NULL;
    head = head->next;
    free(item); item = NULL;
  }
  head=NULL;

  return 0;
}
Beispiel #13
0
extern "C" int main(int argc , char** argv)
{
	int preview_width = 640;
	int preview_height = 480;

	V4l2 * camera = new V4l2(NULL, preview_width, preview_height);
	camera->v4l2_config(preview_width, preview_height, V4l2_YUV422P);

	display_cfg * disconf = NULL;

	int ret = display_open(&disconf);
	if(ret != 0)
	{
		printf("display_open is error %d\n", ret);
	}
	
	disconf->bpp = 16;
	disconf->format = FORMAT_PLANAR_422;
	disconf->screen_width = 320;
	disconf->screen_height = 480;
	disconf->screen_pos_x = 0;
	disconf->screen_pos_y = 0;
	disconf->step = 640;
	disconf->height = 480;

    ret = display_config(disconf);
	if( ret != 0 )
	{
		display_close(&disconf);
		printf("overlay2 config error... close");
	}

	unsigned char * src[3] = {0};
	while(1)
	{
		if(!camera->getNextFrameAsYuv422(src))
		{
			printf("getNextFrameAsYuv422 is error\n");

			goto  camera_stop;
			break;
		}

		ret = copy_to_overlay(disconf, src);
		if(ret != 0)
		{
			printf("copy_to_overlay is error %d\n", ret);
			
			goto camera_stop;
			break;
		}
	
	};

camera_stop:
	
		delete camera;
		display_close(&disconf);

		return 0;
};
void *
evas_software_wince_gapi_init(HWND window,
                              int  width,
                              int  height)
{
   WCHAR                        oemstr[100];
   _GAPI_Display_Properties     prop;
   HMODULE                      gapi_lib;
   Evas_Engine_WinCE_GAPI_Priv *priv;

   gapi_display_open            display_open = NULL;
   gapi_display_close           display_close = NULL;
   gapi_display_properties_get  display_properties_get = NULL;
   gapi_draw_begin              draw_begin = NULL;
   gapi_draw_end                draw_end = NULL;

   priv = (Evas_Engine_WinCE_GAPI_Priv *)malloc(sizeof(Evas_Engine_WinCE_GAPI_Priv));
   if (!priv)
     return NULL;

   gapi_lib = LoadLibrary(L"\\Windows\\gx.dll");
   if (!gapi_lib)
     {
        gapi_lib = LoadLibrary(L"gx.dll");
        if (!gapi_lib)
          {
             ERR("[Engine] [WinCE GAPI] Can not load gx.dll");
             goto free_priv;
          }
     }

   LINK(display_open, display_open, L"?GXOpenDisplay@@YAHPAUHWND__@@K@Z");
   LINK(display_close, display_close, L"?GXCloseDisplay@@YAHXZ");
   LINK(display_properties_get, display_properties_get, L"?GXGetDisplayProperties@@YA?AUGXDisplayProperties@@XZ");
   LINK(draw_begin, draw_begin, L"?GXBeginDraw@@YAPAXXZ");
   LINK(draw_end, draw_end, L"?GXEndDraw@@YAHXZ");
   LINK(suspend, suspend, L"?GXSuspend@@YAHXZ" );
   LINK(resume, resume, L"?GXResume@@YAHXZ" );

   if (!display_open ||
       !display_close ||
       !display_properties_get ||
       !draw_begin ||
       !draw_end ||
       !suspend ||
       !resume)
     {
	ERR("[Engine] [WinCE GAPI] Can not find valid symbols");
        goto free_lib;
     }

   if (!display_open(window, GX_FULLSCREEN))
     {
	ERR("[Engine] [WinCE GAPI] Can not open display");
        goto free_lib;
     }

   prop = display_properties_get();

   // verify pixel format
   if(!(prop.ffFormat & kfDirect565) || (prop.cBPP != 16))
     {
        ERR("[Engine] [WinCE GAPI] display format mismatch\n");
        goto close_display;
     }

   // verify we have a vga device
   if ((GetSystemMetrics(SM_CXSCREEN) != (int)prop.cxWidth) ||
       (GetSystemMetrics(SM_CYSCREEN) != (int)prop.cyHeight))
     {
        ERR("[Engine] [WinCE GAPI] display size mismatch\n");
        goto close_display;
     }

   priv->lib = gapi_lib;
   priv->close_display = display_close;
   priv->draw_begin = draw_begin;
   priv->draw_end = draw_end;

   /* GAPI on Ipaq H38** and H39** is completely buggy */
   /* They are detected as portrait device (width = 240 and height = 320) */
   /* but the framebuffer is managed like a landscape device : */
   /*
     240
 +---------+
 |         |
 |         |
 |         |
 |         |
 |         | 320
 | ^^^     |
 | |||     |
 | |||     |
 | |||     |
 +---------+
  ---->

   */
   /* So these devices are considered as landscape devices */
   /* and width and height are switched. */
   /* Other devices are managed normally : */
   /*
     240
  +---------+
| |--->     |
| |--->     |
| |--->     |
v |         |
  |         | 320
  |         |
  |         |
  |         |
  |         |
  +---------+

    */

   SystemParametersInfo (SPI_GETOEMINFO, sizeof (oemstr), oemstr, 0);

   if (((oemstr[12] == 'H') &&
        (oemstr[13] == '3') &&
        (oemstr[14] == '8')) ||
       ((oemstr[12] == 'H') &&
        (oemstr[13] == '3') &&
        (oemstr[14] == '9')))
     {
        _GXDeviceInfo gxInfo = { 0 };
        HDC           dc;
        int           result;

        priv->width = prop.cyHeight;
        priv->height = prop.cxWidth;
        priv->stride = prop.cbxPitch;

        dc = GetDC (window);
        if (!dc)
          {
             ERR("[Engine] [WinCE GAPI] Can not get device\n");
             goto close_display;
          }

        gxInfo.Version = 100;
        result = ExtEscape(dc, GETGXINFO, 0, NULL, sizeof(gxInfo),
                           (char *) &gxInfo);
        if (result <= 0)
          {
             ERR("[Engine] [WinCE GAPI] ExtEscape failed\n");
             ReleaseDC(window, dc);
             goto close_display;
          }

        priv->buffer = gxInfo.pvFrameBuffer;
        ReleaseDC(window, dc);
     }
   else
     {
        priv->width = prop.cxWidth;
        priv->height = prop.cyHeight;
        priv->stride = prop.cbyPitch;
        priv->buffer = NULL;
     }

   if ((priv->width != width) ||
       (priv->height != height))
     {
        ERR("[Engine] [WinCE GAPI] Size mismatch\n");
        ERR("[Engine] [WinCE GAPI] asked: %dx%d\n", width, height);
        ERR("[Engine] [WinCE GAPI] got  : %dx%d\n", priv->width, priv->height);
        goto close_display;
     }

   return priv;

 close_display:
   display_close();
 free_lib:
   FreeLibrary(gapi_lib);
 free_priv:
   free(priv);
   return NULL;
}
Beispiel #15
0
int main ( int argc, char* argv[] )
{
  // We have to be told where MPD is running.
  char* host = "guanaco"; // Well, that's mine. Maybe this should be localhost.
  int   port = 6600;      // The standard MPD port.
  // Default database.
  char* database = "album_art.sqlite3";

  bool bad_argument = false;
  int c;

  // Start the logger.
  main_data.logger = log_init();

  while ( 1 ) {
    int option_index = 0;
    static struct option long_options[] = {
      { "host", required_argument, 0, 'h' },
      { "port", required_argument, 0, 'p' },
      { "database", required_argument, 0, 'd' },
      { 0,      0,                 0, 0 }
    };

    c = getopt_long( argc, argv, "h:p:d:", long_options, &option_index );

    if ( c == -1 ) {
      break;
    }

    switch ( c ) {
    case 'h':
      if ( *optarg == '\0' ) {
	bad_argument = true;
	printf( "--host argument must be non-empty\n" );
      }
      host = optarg;
      break;
    case 'p':
#if 0
      port = optarg;
      {
	int port_n = convert_int( optarg );
	if ( errno != 0 ) {
	  bad_argument = true;
	  printf( "--port argument was not a valid integer: '%s' (%s)\n",
		  optarg, strerror( errno ) );
	}
	if ( port_n <= 0 ) {
	  bad_argument = true;
	  printf( "--port argument must be positive (%s)\n", port );
	}
      }
#else
      {
	port = convert_int( optarg );
	if ( errno != 0 ) {
	  bad_argument = true;
	  printf( "--port argument was not a valid integer: '%s' (%s)\n",
		  optarg, strerror( errno ) );
	}
	if ( port <= 0 ) {
	  bad_argument = true;
	  printf( "--port argument must be positive (%d)\n", port );
	}
      }
#endif
      break;
    case 'd':
      if ( *optarg == '\0' ) {
	bad_argument = true;
	printf( "--database argument must be non-empty\n" );
      }
      database = optarg;
      break;
    default:
      bad_argument = true;
      printf( "?? getopt returned character code 0%o ??\n", c );
    }
  }
  if ( bad_argument ) {
    printf( USAGE, argv[0] );
    return 1;
  }

  log_message_info( main_data.logger, "MPD host: '%s'", host );
  log_message_info( main_data.logger, "MPD port: '%d'", port );
  log_message_info( main_data.logger, "Database: '%s'", database );

  main_data.mpd = mpd_create( host, port, main_data.logger );

  if ( mpd_status( main_data.mpd ) < 0 ) {
    printf( USAGE, argv[0] );
    return 1;
  }

  // Try to open the image database connection.

  main_data.image_db = image_db_create( database, main_data.logger );

  // If we get this far, we can try to initialize the graphics.

  main_data.display = display_init( main_data.image_db, main_data.mpd );

  if ( display_status( main_data.display ) < 0 ) {
    return 1;
  }

  // Well, after all that, we can now start polling MPD to see what's up.

  main_data.loop = g_main_loop_new( NULL, FALSE );

  // Poll MPD periodically.
  (void)g_timeout_add_seconds( 1, poll_mpd, &main_data );

  // Also try to poll the buttons on the Pibrella (if it is configured
  // properly).
  add_pibrella_button10( &main_data );
  add_pibrella_button11( &main_data );

  // Mouse or touch screen events.
  add_event( &main_data );

  g_main_loop_run( main_data.loop );

  log_message_info( main_data.logger, "Done with main loop. Cleaning up." );

  g_main_loop_unref( main_data.loop );

  display_close( main_data.display );

  mpd_free( main_data.mpd );

  log_close( main_data.logger );

  return 0;
}
Beispiel #16
0
int main(int argc, char *argv[])
{
    int col, row;

    /* to menage start (source) raster map */
    struct Range start_range;
    CELL start_range_min, start_range_max;
    int start_is_time;  /* 0 or 1 */

    struct
    {
	struct Option *max, *dir, *base, *start,
	    *spotdist, *velocity, *mois,
	    *least, *comp_dens, *init_time,
	    *time_lag, *backdrop, *out, *x_out, *y_out;
    } parm;
    struct
    {
	/* please, remove display before GRASS 7 released */
	struct Flag *display, *spotting, *start_is_time;
    } flag;
    struct GModule *module;

    /* initialize access to database and create temporary files */

    G_gisinit(argv[0]);

    /* Set description */
    module = G_define_module();
    G_add_keyword(_("raster"));
    G_add_keyword(_("fire"));
    G_add_keyword(_("spread"));
    G_add_keyword(_("hazard"));
    module->label =
	_("Simulates elliptically anisotropic spread.");
    module->description =
	_("Generates a raster map of the cumulative time of spread, "
	  "given raster maps containing the rates of spread (ROS), "
	  "the ROS directions and the spread origins. "
	  "It optionally produces raster maps to contain backlink UTM "
	  "coordinates for tracing spread paths. "
	  "Usable for fire spread simulations.");

    parm.max = G_define_option();
    parm.max->key = "max";
    parm.max->type = TYPE_STRING;
    parm.max->required = YES;
    parm.max->gisprompt = "old,cell,raster";
    parm.max->guisection = _("Input maps");
    parm.max->label =
	_("Raster map containing maximal ROS (cm/min)");
	parm.max->description =
	_("Name of an existing raster map layer in the user's current "
	  "mapset search path containing the maximum ROS values (cm/minute).");

    parm.dir = G_define_option();
    parm.dir->key = "dir";
    parm.dir->type = TYPE_STRING;
    parm.dir->required = YES;
    parm.dir->gisprompt = "old,cell,raster";
    parm.dir->guisection = _("Input maps");
    parm.dir->label =
	_("Raster map containing directions of maximal ROS (degree)");
    parm.dir->description =
	_("Name of an existing raster map layer in the user's "
	  "current mapset search path containing directions of the maximum ROSes, "
	  "clockwise from north (degree)."); /* TODO: clockwise from north? see r.ros */

    parm.base = G_define_option();
    parm.base->key = "base";
    parm.base->type = TYPE_STRING;
    parm.base->required = YES;
    parm.base->gisprompt = "old,cell,raster";
    parm.base->guisection = _("Input maps");
    parm.base->label =
	_("Raster map containing base ROS (cm/min)");
    parm.base->description =
	_("Name of an existing raster map layer in the user's "
	  "current mapset search path containing the ROS values in the directions "
	  "perpendicular to maximum ROSes' (cm/minute). These ROSes are also the ones "
	  "without the effect of directional factors.");

    parm.start = G_define_option();
    parm.start->key = "start";
    parm.start->type = TYPE_STRING;
    parm.start->required = YES;
    parm.start->gisprompt = "old,cell,raster";
    parm.start->guisection = _("Input maps");
    parm.start->description =
	_("Raster map containing starting sources");
    parm.start->description =
	_("Name of an existing raster map layer in the "
	  "user's current mapset search path containing starting locations of the "
	  "spread phenomenon. Any positive integers in this map are recognized as "
	  "starting sources (seeds).");

    parm.spotdist = G_define_option();
    parm.spotdist->key = "spot_dist";
    parm.spotdist->type = TYPE_STRING;
    parm.spotdist->gisprompt = "old,cell,raster";
    parm.spotdist->guisection = _("Input maps");
    parm.spotdist->label =
	_("Raster map containing maximal spotting distance (m, required with -s)");
    parm.spotdist->description =
	_("Name of an existing raster map layer in "
	  "the user's current mapset search path containing the maximum potential "
	  "spotting distances (meters).");

    parm.velocity = G_define_option();
    parm.velocity->key = "w_speed";
    parm.velocity->type = TYPE_STRING;
    parm.velocity->gisprompt = "old,cell,raster";
    parm.velocity->guisection = _("Input maps");
    parm.velocity->label =
	_("Raster map containing midflame wind speed (ft/min, required with -s)");
    parm.velocity->description =
	_("Name of an existing raster map layer in the "
	  "user's current mapset search path containing wind velocities at half of "
	  "the average flame height (feet/minute).");

    parm.mois = G_define_option();
    parm.mois->key = "f_mois";
    parm.mois->type = TYPE_STRING;
    parm.mois->gisprompt = "old,cell,raster";
    parm.mois->guisection = _("Input maps");
    parm.mois->label =
	_("Raster map containing fine fuel moisture of the cell receiving a spotting firebrand (%, required with -s)");
    parm.mois->description =
	_("Name of an existing raster map layer in the "
	  "user's current mapset search path containing the 1-hour (<.25\") fuel "
	  "moisture (percentage content multiplied by 100).");

    parm.least = G_define_option();
    parm.least->key = "least_size";
    parm.least->type = TYPE_STRING;
    parm.least->key_desc = "odd int";
    parm.least->options = "3,5,7,9,11,13,15";
    parm.least->description =
	_("Basic sampling window size needed to meet certain accuracy (3)"); /* TODO: what is 3 here? default? */
    parm.least->description =
	_("An odd integer ranging 3 - 15 indicating "
	  "the basic sampling window size within which all cells will be considered "
	  "to see whether they will be reached by the current spread cell. The default "
	  "number is 3 which means a 3x3 window.");

    parm.comp_dens = G_define_option();
    parm.comp_dens->key = "comp_dens";
    parm.comp_dens->type = TYPE_STRING;
    parm.comp_dens->key_desc = "decimal";
    parm.comp_dens->label =
	_("Sampling density for additional computing (range: 0.0 - 1.0 (0.5))"); /* TODO: again, what is 0.5?, TODO: range not set */
    parm.comp_dens->description =
	_("A decimal number ranging 0.0 - 1.0 indicating "
	  "additional sampling cells will be considered to see whether they will be "
	  "reached by the current spread cell. The closer to 1.0 the decimal number "
	  "is, the longer the program will run and the higher the simulation accuracy "
	  "will be. The default number is 0.5.");

    parm.init_time = G_define_option();
    parm.init_time->key = "init_time";
    parm.init_time->type = TYPE_STRING;
    parm.init_time->key_desc = "int (>= 0)"; /* TODO: move to ->options */
    parm.init_time->answer = "0";
    parm.init_time->label =
	_("Initial time for current simulation (0) (min)");
    parm.init_time->description =
	_("A non-negative number specifying the initial "
	  "time for the current spread simulation (minutes). This is useful when multiple "
	  "phase simulation is conducted. The default time is 0.");

    parm.time_lag = G_define_option();
    parm.time_lag->key = "lag";
    parm.time_lag->type = TYPE_STRING;
    parm.time_lag->key_desc = "int (>= 0)"; /* TODO: move to ->options */
    parm.time_lag->description =
	_("Simulating time duration LAG (fill the region) (min)"); /* TODO: what does this mean? */
    parm.time_lag->description =
	_("A non-negative integer specifying the simulating "
	  "duration time lag (minutes). The default is infinite, but the program will "
	  "terminate when the current geographic region/mask has been filled. It also "
	  "controls the computational time, the shorter the time lag, the faster the "
	  "program will run.");

    /* TODO: what's this? probably display, so remove */
    parm.backdrop = G_define_option();
    parm.backdrop->key = "backdrop";
    parm.backdrop->type = TYPE_STRING;
    parm.backdrop->gisprompt = "old,cell,raster";
    parm.backdrop->label =
	_("Name of raster map as a display backdrop");
    parm.backdrop->description =
	_("Name of an existing raster map layer in the "
	  "user's current mapset search path to be used as the background on which "
	  "the \"live\" movement will be shown.");

    parm.out = G_define_option();
    parm.out->key = "output";
    parm.out->type = TYPE_STRING;
    parm.out->required = YES;
    parm.out->gisprompt = "new,cell,raster";
    parm.out->guisection = _("Output maps");
    parm.out->label =
	_("Raster map to contain output spread time (min)");
    parm.out->description =
	_("Name of the new raster map layer to contain "
	  "the results of the cumulative spread time needed for a phenomenon to reach "
	  "each cell from the starting sources (minutes).");

    parm.x_out = G_define_option();
    parm.x_out->key = "x_output";
    parm.x_out->type = TYPE_STRING;
    parm.x_out->gisprompt = "new,cell,raster";
    parm.x_out->guisection = _("Output maps");
    parm.x_out->label =
	_("Name of raster map to contain X back coordinates");
    parm.x_out->description =
	_("Name of the new raster map layer to contain "
	  "the results of backlink information in UTM easting coordinates for each "
	  "cell.");

    parm.y_out = G_define_option();
    parm.y_out->key = "y_output";
    parm.y_out->type = TYPE_STRING;
    parm.y_out->gisprompt = "new,cell,raster";
    parm.y_out->guisection = _("Output maps");
    parm.y_out->label =
	_("Name of raster map to contain Y back coordinates");
    parm.y_out->description =
	_("Name of the new raster map layer to contain "
	  "the results of backlink information in UTM northing coordinates for each "
	  "cell.");

    flag.display = G_define_flag();
    flag.display->key = 'd';
#if 0
    flag.display->label = _("DISPLAY 'live' spread process on screen");
    flag.display->description =
	_("Display the 'live' simulation on screen. A graphics window "
	  "must be opened and selected before using this option.");
#else
    flag.display->description = _("Live display - disabled and depreciated");
#endif

    flag.spotting = G_define_flag();
    flag.spotting->key = 's';
    flag.spotting->description = _("Consider spotting effect (for wildfires)");

    flag.start_is_time = G_define_flag();
    flag.start_is_time->key = 'i';
    flag.start_is_time->label = _("Use start raster map values in"
	" output spread time raster map");
    flag.start_is_time->description = _("Designed to be used with output"
	" of previous run of r.spread when computing spread iteratively."
	" The values in start raster map are considered as time."
	" Allowed values in raster map are from zero"
	" to the value of init_time option."
	" If not enabled, init_time is used in the area of start raster map");

    /*   Parse command line */
    if (G_parser(argc, argv))
	exit(EXIT_FAILURE);


    /* FIXME - allow seed to be specified for repeatability */
    G_srand48_auto();

    display = flag.display->answer;
#if 1
    if (display)
	G_fatal_error(_("The display feature is disabled"));
#endif
    spotting = flag.spotting->answer;

    max_layer = parm.max->answer;
    dir_layer = parm.dir->answer;
    base_layer = parm.base->answer;
    start_layer = parm.start->answer;
    backdrop_layer = parm.backdrop->answer;
    out_layer = parm.out->answer;
    if (parm.x_out->answer) {
	x_out = 1;
	x_out_layer = parm.x_out->answer;
    }
    if (parm.y_out->answer) {
	y_out = 1;
	y_out_layer = parm.y_out->answer;
    }
    if (spotting) {
	if (!
	    (parm.spotdist->answer && parm.velocity->answer &&
	     parm.mois->answer)) {
	    G_warning
		("SPOTTING DISTANCE, fuel MOISTURE, or wind VELOCITY map not given w/ -s");
	    G_usage();
	    exit(EXIT_FAILURE);
	}
	else {
	    spotdist_layer = parm.spotdist->answer;
	    velocity_layer = parm.velocity->answer;
	    mois_layer = parm.mois->answer;
	}
    }
    /*Check the given the least sampling size, assign the default if needed */
    if (parm.least->answer)
	least = atoi(parm.least->answer);
    else
	least = 3;
    /*Check the given computing density, assign the default if needed */
    if (parm.comp_dens->answer) {
	comp_dens = atof(parm.comp_dens->answer);
	if (comp_dens < 0.0 || comp_dens > 1.0) {
	    G_warning("Illegal computing density <%s>",
		      parm.comp_dens->answer);
	    G_usage();
	    exit(EXIT_FAILURE);
	}
    }
    else {
	comp_dens = 0.5;
    }
    /*Check the given initial time and simulation time lag, assign the default if needed */
    init_time = atoi(parm.init_time->answer);
    if (init_time < 0) {
	G_warning("Illegal initial time <%s>", parm.init_time->answer);
	G_usage();
	exit(EXIT_FAILURE);
    }

    if (parm.time_lag->answer) {
	time_lag = atoi(parm.time_lag->answer);
	if (time_lag < 0) {
	    G_warning("Illegal simulating time lag <%s>",
		      parm.time_lag->answer);
	    G_usage();
	    exit(EXIT_FAILURE);
	}
    }
    else {
	time_lag = 99999;
    }

    /*  Get database window parameters  */

    G_get_window(&window);

    /*  find number of rows and columns in window    */

    nrows = Rast_window_rows();
    ncols = Rast_window_cols();

    /*transfor measurement unit from meters to centimeters due to ROS unit
     *if the input ROSs are in m/min units, cancell the following*/
    window.ns_res = 100 * window.ns_res;
    window.ew_res = 100 * window.ew_res;

    /* Initialize display screens */
#if 0
    if (display)
	display_init();
#endif

    /*  Check if input layers exists in data base  */

    if (G_find_raster2(max_layer, "") == NULL)
	G_fatal_error("Raster map <%s> not found", max_layer);

    if (G_find_raster2(dir_layer, "") == NULL)
	G_fatal_error(_("Raster map <%s> not found"), dir_layer);

    if (G_find_raster2(base_layer, "") == NULL)
	G_fatal_error(_("Raster map <%s> not found"), base_layer);

    if (G_find_raster2(start_layer, "") == NULL)
	G_fatal_error(_("Raster map <%s> not found"), start_layer);

    if (spotting) {
	if (G_find_raster2(spotdist_layer, "") == NULL)
	    G_fatal_error(_("Raster map <%s> not found"), spotdist_layer);

	if (G_find_raster2(velocity_layer, "") == NULL)
	    G_fatal_error(_("Raster map <%s> not found"), velocity_layer);

	if (G_find_raster2(mois_layer, "") == NULL)
	    G_fatal_error(_("Raster map <%s> not found"), mois_layer);
    }

    /*  Open input cell layers for reading  */

    max_fd = Rast_open_old(max_layer, G_find_raster2(max_layer, ""));

    dir_fd = Rast_open_old(dir_layer, G_find_raster2(dir_layer, ""));

    base_fd = Rast_open_old(base_layer, G_find_raster2(base_layer, ""));

    if (spotting) {
	spotdist_fd =
	    Rast_open_old(spotdist_layer, G_find_raster2(spotdist_layer, ""));

	velocity_fd =
	    Rast_open_old(velocity_layer, G_find_raster2(velocity_layer, ""));

	mois_fd = Rast_open_old(mois_layer, G_find_raster2(mois_layer, ""));
    }

    /*  Allocate memories for a row  */
    cell = Rast_allocate_c_buf();
    if (x_out)
	x_cell = Rast_allocate_c_buf();
    if (y_out)
	y_cell = Rast_allocate_c_buf();

    /*  Allocate memories for a map  */
    map_max = (CELL *) G_calloc(nrows * ncols + 1, sizeof(CELL));
    map_dir = (CELL *) G_calloc(nrows * ncols + 1, sizeof(CELL));
    map_base = (CELL *) G_calloc(nrows * ncols + 1, sizeof(CELL));
    map_visit = (CELL *) G_calloc(nrows * ncols + 1, sizeof(CELL));
    map_out = (float *)G_calloc(nrows * ncols + 1, sizeof(float));
    if (spotting) {
	map_spotdist = (CELL *) G_calloc(nrows * ncols + 1, sizeof(CELL));
	map_velocity = (CELL *) G_calloc(nrows * ncols + 1, sizeof(CELL));
	map_mois = (CELL *) G_calloc(nrows * ncols + 1, sizeof(CELL));
    }
    if (x_out)
	map_x_out = (CELL *) G_calloc(nrows * ncols + 1, sizeof(CELL));
    if (y_out)
	map_y_out = (CELL *) G_calloc(nrows * ncols + 1, sizeof(CELL));


    /*   Write the input layers in the map "arrays"  */

    G_message(_("Reading inputs..."));

    for (row = 0; row < nrows; row++) {
	G_percent(row, nrows, 2);
	Rast_get_c_row(max_fd, cell, row);
	for (col = 0; col < ncols; col++)
	    DATA(map_max, row, col) = cell[col];
	Rast_get_c_row(dir_fd, cell, row);
	for (col = 0; col < ncols; col++)
	    DATA(map_dir, row, col) = cell[col];
	Rast_get_c_row(base_fd, cell, row);
	for (col = 0; col < ncols; col++)
	    DATA(map_base, row, col) = cell[col];
	if (spotting) {
	    Rast_get_c_row(spotdist_fd, cell, row);
	    for (col = 0; col < ncols; col++)
		DATA(map_spotdist, row, col) = cell[col];
	    Rast_get_c_row(velocity_fd, cell, row);
	    for (col = 0; col < ncols; col++)
		DATA(map_velocity, row, col) = cell[col];
	    Rast_get_c_row(mois_fd, cell, row);
	    for (col = 0; col < ncols; col++)
		DATA(map_mois, row, col) = cell[col];
	}
    }
    G_percent(row, nrows, 2);


    /*   Scan the START layer searching for starting points.
     *   Create an array of starting points (min_heap) ordered by costs.
     */

    start_fd = Rast_open_old(start_layer, G_find_raster2(start_layer, ""));

    Rast_read_range(start_layer, G_find_file("cell", start_layer, ""),
		    &start_range);
    Rast_get_range_min_max(&start_range, &start_range_min, &start_range_max);

    start_is_time = flag.start_is_time->answer;
    /* values higher than init_time are unexpected and may cause segfaults */
    if (start_is_time && start_range_max > init_time)
	G_fatal_error(_("Maximum of start raster map is grater than init_time"
			" (%d > %d)"), start_range_max, init_time);
    /* values lower then zero does not make sense for time */
    if (start_is_time && start_range_min < 0)
	G_fatal_error(_("Minimum of start raster map is less than zero"
			" (%d < 0)"), start_range_min, init_time);

    /*  Initialize the heap  */
    heap =
	(struct costHa *)G_calloc(nrows * ncols + 1, sizeof(struct costHa));
    heap_len = 0;

    G_message(_("Reading %s..."), start_layer);
    G_debug(1, "Collecting origins...");
    collect_ori(start_fd, start_is_time);
    G_debug(1, "Done");


    /* Major computation of spread time */
    G_debug(1, "Spreading...");
    spread();
    G_debug(1, "Done");


    /*  Open cumulative cost layer (and x, y direction layers) for writing */

    cum_fd = Rast_open_c_new(out_layer);
    if (x_out)
	x_fd = Rast_open_c_new(x_out_layer);
    if (y_out)
	y_fd = Rast_open_c_new(y_out_layer);

    /* prepare output -- adjust from cm to m */
    window.ew_res = window.ew_res / 100;
    window.ns_res = window.ns_res / 100;

    /* copy maps in ram to output maps */
    ram2out();

    G_free(map_max);
    G_free(map_dir);
    G_free(map_base);
    G_free(map_out);
    G_free(map_visit);
    if (x_out)
	G_free(map_x_out);
    if (y_out)
	G_free(map_y_out);
    if (spotting) {
	G_free(map_spotdist);
	G_free(map_mois);
	G_free(map_velocity);
    }

    Rast_close(max_fd);
    Rast_close(dir_fd);
    Rast_close(base_fd);
    Rast_close(start_fd);
    Rast_close(cum_fd);
    if (x_out)
	Rast_close(x_fd);
    if (y_out)
	Rast_close(y_fd);
    if (spotting) {
	Rast_close(spotdist_fd);
	Rast_close(velocity_fd);
	Rast_close(mois_fd);
    }

    /* close graphics */
#if 0
    if (display)
	display_close();
#endif

    exit(EXIT_SUCCESS);
}