Commit 898e939d authored by Adrian Johnson's avatar Adrian Johnson Committed by Albert Astals Cid
Browse files

Make pdftoppm embed correct resolution in PNG and JPEG files

parent df569dc2
......@@ -6,6 +6,7 @@
//
// Copyright (C) 2009 Stefan Thomas <thomas@eload24.com>
// Copyright (C) 2009 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2010 Adrian Johnson <ajohnson@redneon.com>
//
//========================================================================
......@@ -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;
......
......@@ -5,6 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright (C) 2009 Stefan Thomas <thomas@eload24.com>
// Copyright (C) 2010 Adrian Johnson <ajohnson@redneon.com>
//
//========================================================================
......@@ -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);
......
......@@ -5,6 +5,7 @@
// This file is licensed under the GPLv2 or later
//
// Copyright (C) 2009 Stefan Thomas <thomas@eload24.com>
// Copyright (C) 2010 Adrian Johnson <ajohnson@redneon.com>
//
//========================================================================
......@@ -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);
......
......@@ -8,6 +8,7 @@
// Copyright (C) 2009 Shen Liang <shenzhuxi@gmail.com>
// Copyright (C) 2009 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2009 Stefan Thomas <thomas@eload24.com>
// Copyright (C) 2010 Adrian Johnson <ajohnson@redneon.com>
//
//========================================================================
......@@ -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");
......
......@@ -8,6 +8,7 @@
// Copyright (C) 2009 Shen Liang <shenzhuxi@gmail.com>
// Copyright (C) 2009 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2009 Stefan Thomas <thomas@eload24.com>
// Copyright (C) 2010 Adrian Johnson <ajohnson@redneon.com>
//
//========================================================================
......@@ -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);
......
......@@ -15,6 +15,7 @@
// Copyright (C) 2007 Ilmari Heikkinen <ilmari.heikkinen@gmail.com>
// Copyright (C) 2009 Shen Liang <shenzhuxi@gmail.com>
// Copyright (C) 2009 Stefan Thomas <thomas@eload24.com>
// Copyright (C) 2010 Adrian Johnson <ajohnson@redneon.com>
//
// 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;
}
......
......@@ -15,6 +15,7 @@
// Copyright (C) 2009 Shen Liang <shenzhuxi@gmail.com>
// Copyright (C) 2009 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2009 Stefan Thomas <thomas@eload24.com>
// Copyright (C) 2010 Adrian Johnson <ajohnson@redneon.com>
//
// 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);
......
......@@ -25,6 +25,7 @@
// Copyright (C) 2009 Warren Toomey <wkt@tuhs.org>
// Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright (C) 2009 Reece Dunn <msclrhd@gmail.com>
// Copyright (C) 2010 Adrian Johnson <ajohnson@redneon.com>
//
// 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;
......
......@@ -19,6 +19,7 @@
// Copyright (C) 2009 Shen Liang <shenzhuxi@gmail.com>
// Copyright (C) 2009 Stefan Thomas <thomas@eload24.com>
// Copyright (C) 2009 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2010 Adrian Johnson <ajohnson@redneon.com>
//
// 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);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment