2009-11-19 00:34:07 +00:00
|
|
|
/* loadpng, Allegro wrapper routines for libpng
|
|
|
|
* by Peter Wang (tjaden@users.sf.net).
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <allegro.h>
|
|
|
|
#include "loadpng.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* register_png_file_type:
|
|
|
|
*/
|
|
|
|
void register_png_file_type(void)
|
|
|
|
{
|
|
|
|
register_bitmap_file_type("png", load_png, save_png);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* register_png_datafile_object:
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void *load_datafile_png(PACKFILE *f, long size)
|
|
|
|
{
|
|
|
|
BITMAP *bmp;
|
|
|
|
void *buffer;
|
|
|
|
|
|
|
|
buffer = malloc(size);
|
|
|
|
if (!buffer)
|
2012-01-05 22:45:03 +00:00
|
|
|
return NULL;
|
2009-11-19 00:34:07 +00:00
|
|
|
|
|
|
|
if (pack_fread(buffer, size, f) != size) {
|
2012-01-05 22:45:03 +00:00
|
|
|
free(buffer);
|
|
|
|
return NULL;
|
2009-11-19 00:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bmp = load_memory_png(buffer, size, NULL);
|
|
|
|
|
|
|
|
free(buffer);
|
|
|
|
|
|
|
|
return bmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void destroy_datafile_png(void *data)
|
|
|
|
{
|
|
|
|
if (data) {
|
2012-01-05 22:45:03 +00:00
|
|
|
destroy_bitmap((BITMAP *)data);
|
2009-11-19 00:34:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void register_png_datafile_object(int id)
|
|
|
|
{
|
|
|
|
register_datafile_object(id, load_datafile_png, destroy_datafile_png);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* loadpng_init:
|
|
|
|
* This is supposed to resemble jpgalleg_init in JPGalleg 2.0.
|
|
|
|
*/
|
|
|
|
int loadpng_init(void)
|
|
|
|
{
|
|
|
|
register_png_datafile_object(DAT_ID('P','N','G',' '));
|
|
|
|
register_png_file_type();
|
|
|
|
return 0;
|
|
|
|
}
|