goo/ImgWriter.h | 3 ++- goo/JpegWriter.cc | 6 +++++- goo/JpegWriter.h | 3 ++- goo/PNGWriter.cc | 6 +++++- goo/PNGWriter.h | 3 ++- splash/SplashBitmap.cc | 9 +++++---- splash/SplashBitmap.h | 5 +++-- utils/HtmlOutputDev.cc | 4 +++- utils/pdftoppm.cc | 9 +++++---- 9 files changed, 32 insertions(+), 16 deletions(-)
New commits: commit 898e939d8c0ac74cc7ee3f5d42d83083ed31036e Author: Adrian Johnson <[email protected]> Date: Sat Jan 2 02:33:58 2010 +0100 Make pdftoppm embed correct resolution in PNG and JPEG files diff --git a/goo/ImgWriter.h b/goo/ImgWriter.h index 181620b..e11a30b 100644 --- a/goo/ImgWriter.h +++ b/goo/ImgWriter.h @@ -6,6 +6,7 @@ // // Copyright (C) 2009 Stefan Thomas <[email protected]> // Copyright (C) 2009 Albert Astals Cid <[email protected]> +// Copyright (C) 2010 Adrian Johnson <[email protected]> // //======================================================================== @@ -19,7 +20,7 @@ class ImgWriter { public: virtual ~ImgWriter(); - virtual bool init(FILE *f, int width, int height) = 0; + virtual bool init(FILE *f, int width, int height, int hDPI, int vDPI) = 0; virtual bool writePointers(unsigned char **rowPointers, int rowCount) = 0; virtual bool writeRow(unsigned char **row) = 0; diff --git a/goo/JpegWriter.cc b/goo/JpegWriter.cc index 434febb..64df68a 100644 --- a/goo/JpegWriter.cc +++ b/goo/JpegWriter.cc @@ -5,6 +5,7 @@ // This file is licensed under the GPLv2 or later // // Copyright (C) 2009 Stefan Thomas <[email protected]> +// Copyright (C) 2010 Adrian Johnson <[email protected]> // //======================================================================== @@ -35,7 +36,7 @@ JpegWriter::~JpegWriter() jpeg_destroy_compress(&cinfo); } -bool JpegWriter::init(FILE *f, int width, int height) +bool JpegWriter::init(FILE *f, int width, int height, int hDPI, int vDPI) { // Setup error handler cinfo.err = jpeg_std_error(&jerr); @@ -50,6 +51,9 @@ bool JpegWriter::init(FILE *f, int width, int height) // Set libjpeg configuration cinfo.image_width = width; cinfo.image_height = height; + cinfo.density_unit = 1; // dots per inch + cinfo.X_density = hDPI; + cinfo.Y_density = vDPI; cinfo.input_components = 3; /* # of color components per pixel */ cinfo.in_color_space = JCS_RGB; /* colorspace of input image */ jpeg_set_defaults(&cinfo); diff --git a/goo/JpegWriter.h b/goo/JpegWriter.h index 9e4bf0c..0972ce8 100644 --- a/goo/JpegWriter.h +++ b/goo/JpegWriter.h @@ -5,6 +5,7 @@ // This file is licensed under the GPLv2 or later // // Copyright (C) 2009 Stefan Thomas <[email protected]> +// Copyright (C) 2010 Adrian Johnson <[email protected]> // //======================================================================== @@ -25,7 +26,7 @@ class JpegWriter : public ImgWriter JpegWriter(); ~JpegWriter(); - bool init(FILE *f, int width, int height); + bool init(FILE *f, int width, int height, int hDPI, int vDPI); bool writePointers(unsigned char **rowPointers, int rowCount); bool writeRow(unsigned char **row); diff --git a/goo/PNGWriter.cc b/goo/PNGWriter.cc index 564d2fa..aebab9e 100644 --- a/goo/PNGWriter.cc +++ b/goo/PNGWriter.cc @@ -8,6 +8,7 @@ // Copyright (C) 2009 Shen Liang <[email protected]> // Copyright (C) 2009 Albert Astals Cid <[email protected]> // Copyright (C) 2009 Stefan Thomas <[email protected]> +// Copyright (C) 2010 Adrian Johnson <[email protected]> // //======================================================================== @@ -27,7 +28,7 @@ PNGWriter::~PNGWriter() png_destroy_write_struct(&png_ptr, &info_ptr); } -bool PNGWriter::init(FILE *f, int width, int height) +bool PNGWriter::init(FILE *f, int width, int height, int hDPI, int vDPI) { /* initialize stuff */ png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); @@ -63,6 +64,9 @@ bool PNGWriter::init(FILE *f, int width, int height) png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, color_type, interlace_type, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); + // PNG_RESOLUTION_UNKNOWN means dots per inch + png_set_pHYs(png_ptr, info_ptr, hDPI, vDPI, PNG_RESOLUTION_UNKNOWN); + png_write_info(png_ptr, info_ptr); if (setjmp(png_jmpbuf(png_ptr))) { error(-1, "error during writing png info bytes"); diff --git a/goo/PNGWriter.h b/goo/PNGWriter.h index 97de86c..64ffc67 100644 --- a/goo/PNGWriter.h +++ b/goo/PNGWriter.h @@ -8,6 +8,7 @@ // Copyright (C) 2009 Shen Liang <[email protected]> // Copyright (C) 2009 Albert Astals Cid <[email protected]> // Copyright (C) 2009 Stefan Thomas <[email protected]> +// Copyright (C) 2010 Adrian Johnson <[email protected]> // //======================================================================== @@ -28,7 +29,7 @@ class PNGWriter : public ImgWriter PNGWriter(); ~PNGWriter(); - bool init(FILE *f, int width, int height); + bool init(FILE *f, int width, int height, int hDPI, int vDPI); bool writePointers(unsigned char **rowPointers, int rowCount); bool writeRow(unsigned char **row); diff --git a/splash/SplashBitmap.cc b/splash/SplashBitmap.cc index 999efd1..4844d0b 100644 --- a/splash/SplashBitmap.cc +++ b/splash/SplashBitmap.cc @@ -15,6 +15,7 @@ // Copyright (C) 2007 Ilmari Heikkinen <[email protected]> // Copyright (C) 2009 Shen Liang <[email protected]> // Copyright (C) 2009 Stefan Thomas <[email protected]> +// Copyright (C) 2010 Adrian Johnson <[email protected]> // // 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 @@ -269,7 +270,7 @@ Guchar SplashBitmap::getAlpha(int x, int y) { return alpha[y * width + x]; } -SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, char *fileName) { +SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, char *fileName, int hDPI, int vDPI) { FILE *f; SplashError e; @@ -277,13 +278,13 @@ SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, char *fileN return splashErrOpenFile; } - e = writeImgFile(format, f); + e = writeImgFile(format, f, hDPI, vDPI); fclose(f); return e; } -SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, FILE *f) { +SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, FILE *f, int hDPI, int vDPI) { ImgWriter *writer; switch (format) { @@ -311,7 +312,7 @@ SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, FILE *f) { return splashErrGeneric; } - if (!writer->init(f, width, height)) { + if (!writer->init(f, width, height, hDPI, vDPI)) { delete writer; return splashErrGeneric; } diff --git a/splash/SplashBitmap.h b/splash/SplashBitmap.h index de38445..c25e325 100644 --- a/splash/SplashBitmap.h +++ b/splash/SplashBitmap.h @@ -15,6 +15,7 @@ // Copyright (C) 2009 Shen Liang <[email protected]> // Copyright (C) 2009 Albert Astals Cid <[email protected]> // Copyright (C) 2009 Stefan Thomas <[email protected]> +// Copyright (C) 2010 Adrian Johnson <[email protected]> // // 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 @@ -59,8 +60,8 @@ public: SplashError writePNMFile(char *fileName); SplashError writePNMFile(FILE *f); - SplashError writeImgFile(SplashImageFileFormat format, char *fileName); - SplashError writeImgFile(SplashImageFileFormat format, FILE *f); + SplashError writeImgFile(SplashImageFileFormat format, char *fileName, int hDPI, int vDPI); + SplashError writeImgFile(SplashImageFileFormat format, FILE *f, int hDPI, int vDPI); void getPixel(int x, int y, SplashColorPtr pixel); Guchar getAlpha(int x, int y); diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc index 89650dd..6df1b7c 100644 --- a/utils/HtmlOutputDev.cc +++ b/utils/HtmlOutputDev.cc @@ -25,6 +25,7 @@ // Copyright (C) 2009 Warren Toomey <[email protected]> // Copyright (C) 2009 Carlos Garcia Campos <[email protected]> // Copyright (C) 2009 Reece Dunn <[email protected]> +// Copyright (C) 2010 Adrian Johnson <[email protected]> // // 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 @@ -1329,7 +1330,8 @@ void HtmlOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, } PNGWriter *writer = new PNGWriter(); - if (!writer->init(f1, width, height)) { + // TODO can we calculate the resolution of the image? + if (!writer->init(f1, width, height, 72, 72)) { delete writer; fclose(f1); return; diff --git a/utils/pdftoppm.cc b/utils/pdftoppm.cc index 2c4e869..e5d3ba0 100644 --- a/utils/pdftoppm.cc +++ b/utils/pdftoppm.cc @@ -19,6 +19,7 @@ // Copyright (C) 2009 Shen Liang <[email protected]> // Copyright (C) 2009 Stefan Thomas <[email protected]> // Copyright (C) 2009 Albert Astals Cid <[email protected]> +// Copyright (C) 2010 Adrian Johnson <[email protected]> // // 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 @@ -162,17 +163,17 @@ static void savePageSlice(PDFDoc *doc, if (ppmFile != NULL) { if (png) { - bitmap->writeImgFile(splashFormatPng, ppmFile); + bitmap->writeImgFile(splashFormatPng, ppmFile, x_resolution, y_resolution); } else if (jpeg) { - bitmap->writeImgFile(splashFormatJpeg, ppmFile); + bitmap->writeImgFile(splashFormatJpeg, ppmFile, x_resolution, y_resolution); } else { bitmap->writePNMFile(ppmFile); } } else { if (png) { - bitmap->writeImgFile(splashFormatPng, stdout); + bitmap->writeImgFile(splashFormatPng, stdout, x_resolution, y_resolution); } else if (jpeg) { - bitmap->writeImgFile(splashFormatJpeg, stdout); + bitmap->writeImgFile(splashFormatJpeg, stdout, x_resolution, y_resolution); } else { bitmap->writePNMFile(stdout); } _______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
