# HG changeset patch # User Matti Hamalainen # Date 1526474544 -10800 # Node ID a549d33d543ae440e23a7c504da7c9719303a180 # Parent d0e626e039bfd595d75c4aaebaccdcbb05495279 Add image aspect ratio information. diff -r d0e626e039bf -r a549d33d543a tools/libgfx.c --- a/tools/libgfx.c Wed May 16 15:15:39 2018 +0300 +++ b/tools/libgfx.c Wed May 16 15:42:24 2018 +0300 @@ -118,8 +118,9 @@ img->format = format; img->bpp = (bpp <= 0) ? dmImageGetBytesPerPixel(format) * 8 : bpp; img->pitch = width * img->bpp; - img->size = img->pitch * img->height; + img->size = img->pitch * img->height; img->ctransp = -1; + img->aspect = -1; if ((img->data = dmMalloc(img->size)) == NULL) { @@ -599,8 +600,8 @@ png_colorp palette = NULL; png_bytep *row_pointers = NULL; png_bytep trans = NULL; - png_uint_32 width, height; - int i, bit_depth, color_type, ncolors, ntrans; + png_uint_32 width, height, res_x, res_y; + int i, bit_depth, color_type, ncolors, ntrans, unit_type; int res = DMERR_OK; DMImage *img; @@ -687,6 +688,13 @@ goto error; } + // Set image aspect ratio + png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y, &unit_type); + + if (res_x > 0 && res_y > 0 && + res_y / res_x != (unsigned) (img->height / img->width)) + img->aspect = (float) res_y / (float) res_x; + // ... row_pointers = png_malloc(png_ptr, height * sizeof(png_bytep)); for (i = 0; i < img->height; i++) @@ -1254,6 +1262,11 @@ goto error; } + // Set image aspect ratio + if (hdr.hScreenSize > 0 && hdr.vScreenSize > 0 && + hdr.vScreenSize / hdr.hScreenSize != img->height / img->width) + img->aspect = (float) hdr.vScreenSize / (float) hdr.hScreenSize; + // Sanity check bytes per line value if (hdr.bpl < (img->width * hdr.bitsPerPlane) / 8) { @@ -1860,6 +1873,9 @@ )) == NULL) return DMERR_MALLOC; + // Set image aspect ratio + if (iff.bmhd.xasp > 0 && iff.bmhd.yasp > 0) + (*pimg)->aspect = (float) iff.bmhd.yasp / (float) iff.bmhd.xasp; // Decode the body if (iff.planar) diff -r d0e626e039bf -r a549d33d543a tools/libgfx.h --- a/tools/libgfx.h Wed May 16 15:15:39 2018 +0300 +++ b/tools/libgfx.h Wed May 16 15:42:24 2018 +0300 @@ -73,6 +73,8 @@ int pitch; // bytes per scanline int bpp; // bits per pixel + float aspect; // aspect ratio (vert / horiz), <= 0 if not set + int ncolors; // number of colors in palette, if any int ctransp; // transparency color index BOOL constpal; // is the palette a const?