Esempio n. 1
0
File: main.c Progetto: caomw/grass
int main(int argc, char **argv)
{
    struct GModule *module;
    struct Option *viewopts[MAXVIEWS], *out, *qual;
    struct Flag *conv;
    int i;
    int *sdimp, longdim, r_out;

    G_gisinit(argv[0]);

    module = G_define_module();
    G_add_keyword(_("raster"));
    G_add_keyword(_("export"));
    G_add_keyword(_("animation"));

    module->description =
	_("Converts raster map series to MPEG movie.");

    for (i = 0; i < MAXVIEWS; i++) {
	char *buf = NULL;
	viewopts[i] = G_define_standard_option(G_OPT_R_INPUTS);
	G_asprintf(&buf, "view%d", i + 1);
	viewopts[i]->key = G_store(buf);
	viewopts[i]->required = (i ? NO : YES);
	G_asprintf(&buf, _("Name of input raster map(s) for view no.%d"), i + 1);
	viewopts[i]->description = G_store(buf);
        viewopts[i]->guisection = _("Views");
	G_free(buf);
    }

    out = G_define_standard_option(G_OPT_R_OUTPUT);
    out->description = _("Name for output file");
    
    qual = G_define_option();
    qual->key = "qual";
    qual->type = TYPE_INTEGER;
    qual->required = NO;
    qual->multiple = NO;
    qual->answer = "3";
    qual->options = "1-5";
    qual->description =
	_("Quality factor (1 = highest quality, lowest compression)");
    qual->guisection = _("Settings");
    
    conv = G_define_flag();
    conv->key = 'c';
    conv->label = _("Convert on the fly, uses less disk space");
    conv->description =	_("Requires r.out.ppm with stdout option");
    
    if (G_parser(argc, argv))
	exit(EXIT_FAILURE);

    parse_command(viewopts, vfiles, &numviews, &frames);

    r_out = 0;
    if (conv->answer)
	r_out = 1;

    quality = 3;
    if (qual->answer != NULL)
	sscanf(qual->answer, "%d", &quality);
    if (quality > 5 || quality < 1)
	quality = 3;

    /* find a working encoder */
    if (check_encoder("ppmtompeg"))
	encoder = "ppmtompeg";
    else if (check_encoder("mpeg_encode"))
	encoder = "mpeg_encode";
    else
	G_fatal_error(_("Either mpeg_encode or ppmtompeg must be installed"));

    G_debug(1, "encoder = [%s]", encoder);

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

    /* short dimension */
    sdimp = nrows > ncols ? &ncols : &nrows;

    /* these proportions should work fine for 1 or 4 views, but for
       2 views, want to double the narrow dim & for 3 views triple it */
    if (numviews == 2)
	*sdimp *= 2;
    else if (numviews == 3)
	*sdimp *= 3;

    longdim = nrows > ncols ? nrows : ncols;

    scale = 1.0;

    {	/* find animation image size */
	int max, min;
	char *p;

	max = DEF_MAX;
	min = DEF_MIN;

	if ((p = getenv("GMPEG_SIZE")))
	    max = min = atoi(p);

	if (longdim > max)	/* scale down */
	    scale = (float)max / longdim;
	else if (longdim < min)	/* scale up */
	    scale = (float)min / longdim;
    }
    /* TODO: align image size to 16 pixel width & height */

    vscale = scale;
    if (numviews == 4)
	vscale = scale / 2.;

    nrows *= scale;
    ncols *= scale;
    /* now nrows & ncols are the size of the combined - views image */
    vrows *= vscale;
    vcols *= vscale;
    /* now vrows & vcols are the size for each sub-image */

    /* add to nrows & ncols for borders */
    /* irows, icols used for vert/horizontal determination in loop below */
    irows = nrows;
    icols = ncols;
    nrows += (1 + (nrows / vrows)) * BORDER_W;
    ncols += (1 + (ncols / vcols)) * BORDER_W;

    if (numviews == 1 && r_out)
	use_r_out();
    else
	load_files();

    return (EXIT_SUCCESS);
}
Esempio n. 2
0
void The_second_rtos_task() {
	rtos_wait(sem);
	pos = check_encoder();
	rtos_yield();
	rtos_signal(sem);
}