From f3316d36985ad16f1d82aea44eddc311cb739d6d Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sat, 22 Nov 2014 18:41:45 +0000 Subject: Fix %g for platform without vasprintf (but scores of %f still exist) git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@2320 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- converter/pgm/fstopgm.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'converter/pgm') diff --git a/converter/pgm/fstopgm.c b/converter/pgm/fstopgm.c index 8a9ed721..1f574604 100644 --- a/converter/pgm/fstopgm.c +++ b/converter/pgm/fstopgm.c @@ -42,6 +42,29 @@ gethexit(FILE * const ifP) { +static void +warnNonsquarePixels(unsigned int const cols, + unsigned int const xcols, + unsigned int const rows, + unsigned int const xrows) { + + const char * const baseMsg = "warning, non-square pixels"; + + if (pm_have_float_format()) { + float const rowratio = (float) xrows / (float) rows; + float const colratio = (float) xcols / (float) cols; + + pm_message("%s; to fix do a 'pamscale -%cscale %g'", + baseMsg, + rowratio > colratio ? 'y' : 'x', + rowratio > colratio ? + rowratio / colratio : colratio / rowratio); + } else + pm_message("%s", baseMsg); +} + + + int main(int argc, const char ** argv) { @@ -110,15 +133,8 @@ main(int argc, const char ** argv) { if (maxval > PGM_OVERALLMAXVAL) pm_error("depth %d is too large. Our maximum is %d", maxval, PGM_OVERALLMAXVAL); - if (xcols != 0 && xrows != 0 && (xcols != cols || xrows != rows)) { - float const rowratio = (float) xrows / (float) rows; - float const colratio = (float) xcols / (float) cols; - - pm_message( - "warning, non-square pixels; to fix do a 'pamscale -%cscale %g'", - rowratio > colratio ? 'y' : 'x', - rowratio > colratio ? rowratio / colratio : colratio / rowratio ); - } + if (xcols != 0 && xrows != 0 && (xcols != cols || xrows != rows)) + warnNonsquarePixels(cols, xcols, rows, xrows); /* Read the hex bits. */ grays = pgm_allocarray(cols, rows); -- cgit 1.4.1