int main(int argc, char *argv[])
{
    int ret = 0;
    int i;

    allegro_init();
    install_keyboard();
    install_mouse();
    install_timer();

    srand(time(NULL));

    for (i=1; i<argc; i++) {

        if (stricmp(argv[i], "-bpp") == 0) {
            if ((i >= argc-1) || (bpp > 0)) {
                usage();
                return 1;
            }

            bpp = atoi(argv[++i]);
        }
        else if (stricmp(argv[i], "-frames") == 0) {
            if ((i >= argc-1) || (frames > 0)) {
                usage();
                return 1;
            }

            frames = atoi(argv[++i]);
        }
        else if (stricmp(argv[i], "-size") == 0) {
            if ((i >= argc-2) || (size_x > 0) || (size_y > 0)) {
                usage();
                return 1;
            }

            size_x = atoi(argv[++i]);
            size_y = atoi(argv[++i]);
        }
        else if (stricmp(argv[i], "-mode") == 0) {
            if ((i >= argc-2) || (mode_x > 0) || (mode_y > 0)) {
                usage();
                return 1;
            }

            mode_x = atoi(argv[++i]);
            mode_y = atoi(argv[++i]);
        }
        else if (stricmp(argv[i], "-step") == 0) {
            step = TRUE;
        }
        else if (stricmp(argv[i], "-modesel") == 0) {
            modesel = TRUE;
        }
        else if (stricmp(argv[i], "-pregen") == 0) {
            pregen = TRUE;
        }
        else if (stricmp(argv[i], "-o") == 0) {
            if ((i >= argc-1) || (out_file)) {
                usage();
                return 1;
            }

            out_file = argv[++i];
        }
        else if (stricmp(argv[i], "-pal") == 0) {
            if ((i >= argc-1) || (pal_file)) {
                usage();
                return 1;
            }

            pal_file = argv[++i];
        }
        else {
            if ((*argv[i] == '-') || (in_file)) {
                usage();
                return 1;
            }

            in_file = argv[i];
        }
    }

    if (!in_file) {
        usage();
        return 1;
    }

    if ((pregen) && ((frames <= 0) || (step))) {
        allegro_message("The '-pregen' option requires '-frames num' to be specified,\nand cannot be used at the same time as '-step'\n");
        return 1;
    }

    if (!set_video_mode()) {
        ret = 1;
        goto getout;
    }

    the_egg = load_egg(in_file, error);

    if (!the_egg) {
        set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
        allegro_message("%s", error);
        return 1;
    }

    if (size_x <= 0)
        size_x = 128;

    if (size_y <= 0)
        size_y = 128;

    if (pal_file) {
        BITMAP *tmp = load_bitmap(pal_file, pal);

        if (!tmp) {
            set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
            allegro_message("Error reading palette from '%s'\n", pal_file);
            ret = 1;
            goto getout;
        }

        destroy_bitmap(tmp);
    }
    else
        generate_332_palette(pal);

    clear(screen);

    set_palette(pal);

    text_mode(0);

    do {
        if (pregen) {
            textprintf_centre(screen, font, SCREEN_W/2, SCREEN_H/2-24, makecol(128, 128, 128), "Rendering frame %d/%d", the_egg->frame+1, frames);
            textprintf_centre(screen, font, SCREEN_W/2, SCREEN_H/2+24, makecol(128, 128, 128), "Please Wait");
        }

        if (update_egg(the_egg, error) != 0) {
            allegro_exit();
            printf("Error running EGG script:\n%s\n\n", error);
            ret = 1;
            goto getout;
        }

        bmp[frame] = create_bitmap(size_x, size_y);

        lay_egg(the_egg, bmp[frame]);

        if (!pregen) {
            vsync();
            blit(bmp[frame], screen, 0, 0, (SCREEN_W-size_x)/2, (SCREEN_H-size_y)/2, size_x, size_y);
            textprintf(screen, font, 0, 0, makecol(128, 128, 128), "Frame %d, %d particles        ", the_egg->frame, the_egg->part_count);
        }

        if ((!pregen) && (!out_file)) {
            destroy_bitmap(bmp[frame]);
            bmp[frame] = NULL;
        }

        frame++;

        if ((step) || (keypressed())) {
            if ((readkey()&0xFF) == 27)
                break;

            clear_keybuf();
        }

    } while (((frames <= 0) || (frame < frames)) && (frame < 4096));

    if (pregen)
        view_animation();

    if (out_file)
        save_animation();

getout:

    if (the_egg)
        destroy_egg(the_egg);

    for (i=0; i<frame; i++)
        if (bmp[frame])
            destroy_bitmap(bmp[frame]);

    return ret;
}
Beispiel #2
0
/* Save a WebP image to disk */
gboolean save_image(const gchar    *filename,
#ifdef WEBP_0_5
                    gint32          nLayers,
                    gint32         *allLayers,
#endif
                    gint32          drawable_ID,
                    WebPSaveParams *params,
                    GError        **error)
{
    gboolean status  = FALSE;
    FILE    *outfile = NULL;

#ifdef GIMP_2_9
    /* Initialize GEGL */
    gegl_init(NULL, NULL);
#endif

    /* Begin displaying export progress */
    gimp_progress_init_printf("Saving '%s'",
                              gimp_filename_to_utf8(filename));

    /* Attempt to open the output file */
    if((outfile = g_fopen(filename, "wb+")) == NULL) {
        g_set_error(error,
                    G_FILE_ERROR,
                    g_file_error_from_errno(errno),
                    "Unable to open '%s' for writing",
                    gimp_filename_to_utf8(filename));
        return FALSE;
    }

#ifdef WEBP_0_5
    if (params->animation == TRUE) {
        status = save_animation(nLayers,
                                allLayers,
                                outfile,
                                params,
                                error);
    } else {
#endif
        status = save_layer(drawable_ID,
                            webp_file_writer,
                            outfile,
#ifdef WEBP_0_5
                            FALSE,
                            NULL,
                            0,
#endif
                            params,
                            error);
#ifdef WEBP_0_5
    }
#endif

    /* Close the file */
    if(outfile) {
        fclose(outfile);
    }

    return status;
}