1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
/* Image conversion example */
#include <stdio.h>
#include "allegro5/allegro.h"
#include "allegro5/allegro_image.h"
#include "common.c"
int main(int argc, char **argv)
{
ALLEGRO_BITMAP *bitmap;
double t0;
double t1;
if (!al_init()) {
abort_example("Could not init Allegro.\n");
}
open_log();
if (argc < 3) {
log_printf("This example needs to be run from the command line.\n");
log_printf("Usage: %s <infile> <outfile>\n", argv[0]);
log_printf("\tPossible file types: BMP PCX PNG TGA\n");
goto done;
}
al_init_image_addon();
al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ARGB_8888);
al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
bitmap = al_load_bitmap_flags(argv[1], ALLEGRO_NO_PREMULTIPLIED_ALPHA);
if (!bitmap) {
log_printf("Error loading input file\n");
goto done;
}
t0 = al_get_time();
if (!al_save_bitmap(argv[2], bitmap)) {
log_printf("Error saving bitmap\n");
goto done;
}
t1 = al_get_time();
log_printf("Saving took %.4f seconds\n", t1 - t0);
al_destroy_bitmap(bitmap);
done:
close_log(true);
return 0;
}
|