From b99b229fa733b794d19f0e9170fe09bfdfc0feb9 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Sat, 17 Aug 2013 15:17:11 +0930 Subject: [PATCH 1/8] pdfimages: print size, ratio, and ppi --- utils/ImageOutputDev.cc | 100 ++++++++++++++++++++++++++++++++++++++++++++---- utils/pdfimages.1 | 12 ++++++ utils/pdfimages.cc | 2 +- 3 files changed, 106 insertions(+), 8 deletions(-) diff --git a/utils/ImageOutputDev.cc b/utils/ImageOutputDev.cc index 8b18d2b..1d1064b 100644 --- a/utils/ImageOutputDev.cc +++ b/utils/ImageOutputDev.cc @@ -20,7 +20,7 @@ // Copyright (C) 2009 Carlos Garcia Campos // Copyright (C) 2009 William Bader // Copyright (C) 2010 Jakob Voss -// Copyright (C) 2012 Adrian Johnson +// Copyright (C) 2012, 2013 Adrian Johnson // Copyright (C) 2013 Thomas Fischer // // To see a description of the changes please see the Changelog file that @@ -39,6 +39,7 @@ #include #include #include +#include #include "goo/gmem.h" #include "Error.h" #include "GfxState.h" @@ -58,8 +59,8 @@ ImageOutputDev::ImageOutputDev(char *fileRootA, GBool pageNamesA, GBool dumpJPEG pageNum = 0; ok = gTrue; if (listImages) { - printf("page num type width height color comp bpc enc interp object ID\n"); - printf("---------------------------------------------------------------------\n"); + printf("page num type width height color comp bpc enc interp object ID x-ppi y-ppi size ratio\n"); + printf("--------------------------------------------------------------------------------------------\n"); } } @@ -79,6 +80,34 @@ void ImageOutputDev::setFilename(const char *fileExt) { } } + +// Print a floating point number between 0 - 9999 using 4 characters +// eg '1.23', '12.3', ' 123', '1234' +// +// We need to be careful to handle the cases where rounding adds an +// extra digit before the decimal. eg printf("%4.2f", 9.99999) +// outputs "10.00" instead of "9.99". +static void printNumber(double d) +{ + char buf[10]; + + if (d < 10.0) { + sprintf(buf, "%4.2f", d); + buf[4] = 0; + printf("%s", buf); + } else if (d < 100.0) { + sprintf(buf, "%4.1f", d); + if (!isdigit(buf[3])) { + buf[3] = 0; + printf(" %s", buf); + } else { + printf("%s", buf); + } + } else { + printf("%4.0f", d); + } +} + void ImageOutputDev::listImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, @@ -179,18 +208,75 @@ void ImageOutputDev::listImage(GfxState *state, Object *ref, Stream *str, printf("%-3s ", interpolate ? "yes" : "no"); if (inlineImg) { - printf("[inline]\n"); + printf("[inline] "); } else if (ref->isRef()) { const Ref imageRef = ref->getRef(); if (imageRef.gen >= 100000) { - printf("[none]\n"); + printf("[none] "); } else { - printf(" %6d %2d\n", imageRef.num, imageRef.gen); + printf(" %6d %2d ", imageRef.num, imageRef.gen); } } else { - printf("[none]\n"); + printf("[none] "); + } + + double *mat = state->getCTM(); + double width2 = mat[0] + mat[2]; + double height2 = mat[1] + mat[3]; + double xppi = fabs(width*72.0/width2) + 0.5; + double yppi = fabs(height*72.0/height2) + 0.5; + if (xppi < 1.0) + printf("%5.3f ", xppi); + else + printf("%5.0f ", xppi); + if (yppi < 1.0) + printf("%5.3f ", yppi); + else + printf("%5.0f ", yppi); + + Goffset embedSize = -1; + if (!inlineImg) + embedSize = str->getBaseStream()->getLength(); + + long long imageSize = 0; + if (colorMap && colorMap->isOk()) + imageSize = ((long long)width * height * colorMap->getNumPixelComps() * colorMap->getBits())/8; + else + imageSize = (long long)width*height/8; // mask + + double ratio = -1.0; + if (imageSize > 0) + ratio = 100.0*embedSize/imageSize; + + if (embedSize < 0) { + printf(" - "); + } else if (embedSize <= 9999) { + printf("%4lldB", embedSize); + } else { + double d = embedSize/1024.0; + if (d <= 9999.0) { + printNumber(d); + putchar('K'); + } else { + d /= 1024.0; + if (d <= 9999.0) { + printNumber(d); + putchar('M'); + } else { + d /= 1024.0; + printNumber(d); + putchar('G'); + } + } } + if (ratio > 9.9) + printf(" %3.0f%%\n", ratio); + else if (ratio >= 0.0) + printf(" %3.1f%%\n", ratio); + else + printf(" - \n"); + ++imgNum; } diff --git a/utils/pdfimages.1 b/utils/pdfimages.1 index 955d8b3..e98bf29 100644 --- a/utils/pdfimages.1 +++ b/utils/pdfimages.1 @@ -134,6 +134,18 @@ ccitt - CCITT Group 3 or Group 4 Fax .TP .B object ID the font dictionary object ID (number and generation) +.TP +.B x\-ppi +The horizontal resolution of the image (in pixels per inch) when rendered on the pdf page. +.TP +.B y\-ppi +The vertical resolution of the image (in pixels per inch) when rendered on the pdf page. +.TP +.B size +The size of the embedded image in the pdf file. The following suffixes are used: 'B' bytes, 'K' kilobytes, 'M' megabytes, and 'G' gigabytes. +.TP +.B ratio +The compression ratio of the embedded image. .RE .TP .BI \-opw " password" diff --git a/utils/pdfimages.cc b/utils/pdfimages.cc index 82c301c..7b6cad0 100644 --- a/utils/pdfimages.cc +++ b/utils/pdfimages.cc @@ -18,7 +18,7 @@ // Copyright (C) 2007-2008, 2010 Albert Astals Cid // Copyright (C) 2010 Hib Eris // Copyright (C) 2010 Jakob Voss -// Copyright (C) 2012 Adrian Johnson +// Copyright (C) 2012, 2013 Adrian Johnson // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git -- 1.8.1.2