diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2018-06-27 01:58:45 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2018-06-27 01:58:45 +0000 |
commit | 8a9e82c734ac5da06c6d7347a33e505ce1aa26ec (patch) | |
tree | e0f33b03566bf6c2ba8a46a377a434094014973a /converter/other | |
parent | 67f4338ccd643cb39a3f50ec6910cab5fce14a3e (diff) | |
download | netpbm-mirror-8a9e82c734ac5da06c6d7347a33e505ce1aa26ec.tar.gz netpbm-mirror-8a9e82c734ac5da06c6d7347a33e505ce1aa26ec.tar.xz netpbm-mirror-8a9e82c734ac5da06c6d7347a33e505ce1aa26ec.zip |
Fix computation of pixel aspect ratio when PNG does not contain resolution information
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3266 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/other')
-rw-r--r-- | converter/other/pngtopam.c | 5 | ||||
-rw-r--r-- | converter/other/pngx.c | 28 | ||||
-rw-r--r-- | converter/other/pngx.h | 6 |
3 files changed, 34 insertions, 5 deletions
diff --git a/converter/other/pngtopam.c b/converter/other/pngtopam.c index 01690520..1023c6c6 100644 --- a/converter/other/pngtopam.c +++ b/converter/other/pngtopam.c @@ -1238,9 +1238,8 @@ static void warnNonsquarePixels(struct pngx * const pngxP, int * const errorLevelP) { - if (pngx_chunkIsPresent(pngxP, PNG_INFO_pHYs)) { - float const r = - (float)pngx_xPixelsPerMeter(pngxP) / pngx_yPixelsPerMeter(pngxP); + if (pngx_pixelAspectRatioIsKnown(pngxP)) { + float const r = pngx_pixelAspectRatio(pngxP); if (r != 1.0) { const char * const baseMsg = "warning - non-square pixels"; diff --git a/converter/other/pngx.c b/converter/other/pngx.c index 06b8a513..dfc74485 100644 --- a/converter/other/pngx.c +++ b/converter/other/pngx.c @@ -270,15 +270,39 @@ pngx_trns(struct pngx * const pngxP) { uint32_t pngx_xPixelsPerMeter(struct pngx * const pngxP) { - +/*---------------------------------------------------------------------------- + Horizontal pixel density in pixel per meter; 0 if unknown. +-----------------------------------------------------------------------------*/ return png_get_x_pixels_per_meter(pngxP->png_ptr, pngxP->info_ptr); } +float +pngx_pixelAspectRatio(struct pngx * const pngxP) { +/*---------------------------------------------------------------------------- + Aspect ratio - y/x. 0.0 if unknown +-----------------------------------------------------------------------------*/ + return png_get_pixel_aspect_ratio(pngxP->png_ptr, pngxP->info_ptr); +} + + + +bool +pngx_pixelAspectRatioIsKnown(struct pngx * const pngxP) { +/*---------------------------------------------------------------------------- + There is pixel aspect ratio information in the PNG image. +-----------------------------------------------------------------------------*/ + return png_get_pixel_aspect_ratio(pngxP->png_ptr, pngxP->info_ptr) != 0.0; +} + + + uint32_t pngx_yPixelsPerMeter(struct pngx * const pngxP) { - +/*---------------------------------------------------------------------------- + Vertical pixel density in pixel per meter; 0 if unknown. +-----------------------------------------------------------------------------*/ return png_get_y_pixels_per_meter(pngxP->png_ptr, pngxP->info_ptr); } diff --git a/converter/other/pngx.h b/converter/other/pngx.h index 008081eb..be9b9558 100644 --- a/converter/other/pngx.h +++ b/converter/other/pngx.h @@ -116,6 +116,12 @@ pngx_xPixelsPerMeter(struct pngx * const pngxP); uint32_t pngx_yPixelsPerMeter(struct pngx * const pngxP); +float +pngx_pixelAspectRatio(struct pngx * const pngxP); + +bool +pngx_pixelAspectRatioIsKnown(struct pngx * const pngxP); + void pngx_removeChunk(struct pngx * const pngxP, uint32_t const chunkType); |