X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=readpng.c;h=83936ae9ba3d087a9f71d959f82b67e201c69e6c;hb=ebf0e111a84cbd73511cc2b935c7bd688638cf5e;hp=cad121704998307c171a576a8aa5b45e9ace1f72;hpb=a86e9a3e58f55bf49d99dfd5e5d6413e17149593;p=libpicofe.git diff --git a/readpng.c b/readpng.c index cad1217..83936ae 100644 --- a/readpng.c +++ b/readpng.c @@ -5,6 +5,7 @@ * (at your option): * - GNU GPL, version 2 or later. * - GNU LGPL, version 2.1 or later. + * - MAME license. * See the COPYING file in the top-level directory. */ @@ -60,29 +61,35 @@ int readpng(void *dest, const char *fname, readpng_what what, int req_w, int req goto done; } - // lprintf("%s: %ix%i @ %ibpp\n", fname, (int)info_ptr->width, (int)info_ptr->height, info_ptr->pixel_depth); + // lprintf("%s: %ix%i @ %ibpp\n", fname, (int)png_get_image_width(png_ptr, info_ptr), + // (int)png_get_image_height(png_ptr, info_ptr), png_get_bit_depth(png_ptr, info_ptr)); switch (what) { case READPNG_BG: { - int height, width, h; + int height, width, h, x_ofs = 0, y_ofs = 0; unsigned short *dst = dest; - if (info_ptr->pixel_depth != 24) + + if (png_get_bit_depth(png_ptr, info_ptr) != 8) { - lprintf(__FILE__ ": bg image uses %ibpp, needed 24bpp\n", info_ptr->pixel_depth); + lprintf(__FILE__ ": bg image uses %ibpc, needed 8bpc\n", png_get_bit_depth(png_ptr, info_ptr)); break; } - height = info_ptr->height; - if (height > req_h) - height = req_h; - width = info_ptr->width; - if (width > req_w) + width = png_get_image_width(png_ptr, info_ptr); + if (width > req_w) { + x_ofs = (width - req_w) / 2; width = req_w; + } + height = png_get_image_height(png_ptr, info_ptr); + if (height > req_h) { + y_ofs = (height - req_h) / 2; + height = req_h; + } for (h = 0; h < height; h++) { - unsigned char *src = row_ptr[h]; + unsigned char *src = row_ptr[h + y_ofs] + x_ofs * 3; int len = width; while (len--) { @@ -102,15 +109,15 @@ int readpng(void *dest, const char *fname, readpng_what what, int req_w, int req { int x, y, x1, y1; unsigned char *dst = dest; - if (info_ptr->width != req_w || info_ptr->height != req_h) + if (png_get_image_width(png_ptr, info_ptr) != req_w || png_get_image_height(png_ptr, info_ptr) != req_h) { lprintf(__FILE__ ": unexpected font image size %dx%d, needed %dx%d\n", - (int)info_ptr->width, (int)info_ptr->height, req_w, req_h); + (int)png_get_image_width(png_ptr, info_ptr), (int)png_get_image_height(png_ptr, info_ptr), req_w, req_h); break; } - if (info_ptr->pixel_depth != 8) + if (png_get_bit_depth(png_ptr, info_ptr) != 8) { - lprintf(__FILE__ ": font image uses %ibpp, needed 8bpp\n", info_ptr->pixel_depth); + lprintf(__FILE__ ": font image uses %ibpp, needed 8bpp\n", png_get_bit_depth(png_ptr, info_ptr)); break; } for (y = 0; y < 16; y++) @@ -135,15 +142,15 @@ int readpng(void *dest, const char *fname, readpng_what what, int req_w, int req { int x1, y1; unsigned char *dst = dest; - if (info_ptr->width != req_w || info_ptr->height != req_h) + if (png_get_image_width(png_ptr, info_ptr) != req_w || png_get_image_height(png_ptr, info_ptr) != req_h) { lprintf(__FILE__ ": unexpected selector image size %ix%i, needed %dx%d\n", - (int)info_ptr->width, (int)info_ptr->height, req_w, req_h); + (int)png_get_image_width(png_ptr, info_ptr), (int)png_get_image_height(png_ptr, info_ptr), req_w, req_h); break; } - if (info_ptr->pixel_depth != 8) + if (png_get_bit_depth(png_ptr, info_ptr) != 8) { - lprintf(__FILE__ ": selector image uses %ibpp, needed 8bpp\n", info_ptr->pixel_depth); + lprintf(__FILE__ ": selector image uses %ibpp, needed 8bpp\n", png_get_bit_depth(png_ptr, info_ptr)); break; } for (y1 = 0; y1 < req_h; y1++) @@ -159,17 +166,17 @@ int readpng(void *dest, const char *fname, readpng_what what, int req_w, int req { int height, width, h; unsigned char *dst = dest; - if (info_ptr->pixel_depth != 24) + if (png_get_bit_depth(png_ptr, info_ptr) != 8) { - lprintf(__FILE__ ": image uses %ibpp, needed 24bpp\n", info_ptr->pixel_depth); + lprintf(__FILE__ ": image uses %ibpc, needed 8bpc\n", png_get_bit_depth(png_ptr, info_ptr)); break; } - height = info_ptr->height; - if (height > req_h) - height = req_h; - width = info_ptr->width; + width = png_get_image_width(png_ptr, info_ptr); if (width > req_w) width = req_w; + height = png_get_image_height(png_ptr, info_ptr); + if (height > req_h) + height = req_h; for (h = 0; h < height; h++) {