X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=libpicofe.git;a=blobdiff_plain;f=readpng.c;h=83936ae9ba3d087a9f71d959f82b67e201c69e6c;hp=af6bd5652c6c22a6eb1520625845c8eb08b451f5;hb=HEAD;hpb=a085ae5ef139fca7910f70994c65f7a48769dfe1 diff --git a/readpng.c b/readpng.c index af6bd56..ac24dd4 100644 --- a/readpng.c +++ b/readpng.c @@ -68,23 +68,30 @@ int readpng(void *dest, const char *fname, readpng_what what, int req_w, int req { case READPNG_BG: { - int height, width, h; + int height, width, h, x_ofs = 0, y_ofs = 0; unsigned short *dst = dest; + if (png_get_bit_depth(png_ptr, info_ptr) != 8) { lprintf(__FILE__ ": bg image uses %ibpc, needed 8bpc\n", png_get_bit_depth(png_ptr, info_ptr)); break; } width = png_get_image_width(png_ptr, info_ptr); - if (width > req_w) + if (width > req_w) { + x_ofs = (width - req_w) / 2; width = req_w; + } else + dst += (req_w - width) / 2; height = png_get_image_height(png_ptr, info_ptr); - if (height > req_h) + if (height > req_h) { + y_ofs = (height - req_h) / 2; height = req_h; + } else + dst += (req_h - height) / 2 * req_w; 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--) {