goo/ImgWriter.h | 4 ++-- goo/JpegWriter.cc | 15 +++++++++++---- goo/JpegWriter.h | 4 ++-- goo/NetPBMWriter.cc | 4 ++-- goo/NetPBMWriter.h | 4 ++-- goo/PNGWriter.cc | 18 +++++++++++++++--- goo/PNGWriter.h | 4 ++-- goo/TiffWriter.cc | 8 ++++---- goo/TiffWriter.h | 4 ++-- splash/SplashBitmap.cc | 8 ++++---- splash/SplashBitmap.h | 8 ++++---- utils/InMemoryFile.cc | 2 +- utils/InMemoryFile.h | 7 +++++-- 13 files changed, 56 insertions(+), 34 deletions(-)
New commits: commit 487e62541df7ebc2278e84b7b1e3b021e86facc5 Author: Albert Astals Cid <[email protected]> Date: Wed Apr 6 14:58:26 2022 +0200 ImgWriter::init: take double for dpi instead of int In pdftoppm/pdftocairo the dpi are doubles, so pass them down as doubles as much as we can until we need to convert them to ints (in some formats like Tiff, we don't even need to do it since dpi is also a double) diff --git a/goo/ImgWriter.h b/goo/ImgWriter.h index 64f60efb..860b310f 100644 --- a/goo/ImgWriter.h +++ b/goo/ImgWriter.h @@ -5,7 +5,7 @@ // This file is licensed under the GPLv2 or later // // Copyright (C) 2009 Stefan Thomas <[email protected]> -// Copyright (C) 2009, 2011, 2018 Albert Astals Cid <[email protected]> +// Copyright (C) 2009, 2011, 2018, 2022 Albert Astals Cid <[email protected]> // Copyright (C) 2010 Adrian Johnson <[email protected]> // Copyright (C) 2010 Brian Cameron <[email protected]> // Copyright (C) 2011 Thomas Freitag <[email protected]> @@ -27,7 +27,7 @@ public: ImgWriter &operator=(const ImgWriter &other) = delete; virtual ~ImgWriter(); - virtual bool init(FILE *f, int width, int height, int hDPI, int vDPI) = 0; + virtual bool init(FILE *f, int width, int height, double hDPI, double 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 c6be3a9f..ca69fd05 100644 --- a/goo/JpegWriter.cc +++ b/goo/JpegWriter.cc @@ -9,7 +9,7 @@ // Copyright (C) 2010 Harry Roberts <[email protected]> // Copyright (C) 2011 Thomas Freitag <[email protected]> // Copyright (C) 2013 Peter Breitenlohner <[email protected]> -// Copyright (C) 2017, 2018 Albert Astals Cid <[email protected]> +// Copyright (C) 2017, 2018, 2022 Albert Astals Cid <[email protected]> // Copyright (C) 2018 Martin Packman <[email protected]> // Copyright (C) 2018 Ed Porras <[email protected]> // Copyright (C) 2021 Peter Williams <[email protected]> @@ -18,6 +18,8 @@ #include "JpegWriter.h" +#include <limits> + #ifdef ENABLE_LIBJPEG # include "poppler/Error.h" @@ -80,8 +82,13 @@ void JpegWriter::setOptimize(bool optimize) priv->optimize = optimize; } -bool JpegWriter::init(FILE *f, int width, int height, int hDPI, int vDPI) +bool JpegWriter::init(FILE *f, int width, int height, double hDPI, double vDPI) { + if (hDPI < 0 || vDPI < 0 || hDPI > std::numeric_limits<UINT16>::max() || vDPI > std::numeric_limits<UINT16>::max()) { + error(errInternal, -1, "JpegWriter::init: hDPI or vDPI values are invalid {0:f} {1:f}", hDPI, vDPI); + return false; + } + // Setup error handler priv->cinfo.err = jpeg_std_error(&priv->jerr); priv->jerr.output_message = &outputMessage; @@ -114,8 +121,8 @@ bool JpegWriter::init(FILE *f, int width, int height, int hDPI, int vDPI) priv->cinfo.image_width = width; priv->cinfo.image_height = height; priv->cinfo.density_unit = 1; // dots per inch - priv->cinfo.X_density = hDPI; - priv->cinfo.Y_density = vDPI; + priv->cinfo.X_density = static_cast<UINT16>(hDPI); + priv->cinfo.Y_density = static_cast<UINT16>(vDPI); switch (priv->format) { case GRAY: priv->cinfo.input_components = 1; diff --git a/goo/JpegWriter.h b/goo/JpegWriter.h index a495859d..4b94c51e 100644 --- a/goo/JpegWriter.h +++ b/goo/JpegWriter.h @@ -9,7 +9,7 @@ // Copyright (C) 2010 Jürg Billeter <[email protected]> // Copyright (C) 2010 Harry Roberts <[email protected]> // Copyright (C) 2010 Brian Cameron <[email protected]> -// Copyright (C) 2011, 2021 Albert Astals Cid <[email protected]> +// Copyright (C) 2011, 2021, 2022 Albert Astals Cid <[email protected]> // Copyright (C) 2011 Thomas Freitag <[email protected]> // Copyright (C) 2018 Martin Packman <[email protected]> // @@ -52,7 +52,7 @@ public: void setQuality(int quality); void setProgressive(bool progressive); void setOptimize(bool optimize); - bool init(FILE *f, int width, int height, int hDPI, int vDPI) override; + bool init(FILE *f, int width, int height, double hDPI, double vDPI) override; bool writePointers(unsigned char **rowPointers, int rowCount) override; bool writeRow(unsigned char **row) override; diff --git a/goo/NetPBMWriter.cc b/goo/NetPBMWriter.cc index a79ea2a9..44302fd8 100644 --- a/goo/NetPBMWriter.cc +++ b/goo/NetPBMWriter.cc @@ -13,7 +13,7 @@ // All changes made under the Poppler project to this file are licensed // under GPL version 2 or later // -// Copyright (C) 2005, 2007, 2011 Albert Astals Cid <[email protected]> +// Copyright (C) 2005, 2007, 2011, 2022 Albert Astals Cid <[email protected]> // Copyright (C) 2006 Rainer Keller <[email protected]> // Copyright (C) 2008 Timothy Lee <[email protected]> // Copyright (C) 2008 Vasile Gaburici <[email protected]> @@ -39,7 +39,7 @@ NetPBMWriter::NetPBMWriter(Format formatA) : format(formatA) { } -bool NetPBMWriter::init(FILE *f, int widthA, int heightA, int hDPI, int vDPI) +bool NetPBMWriter::init(FILE *f, int widthA, int heightA, double /*hDPI*/, double /*vDPI*/) { file = f; width = widthA; diff --git a/goo/NetPBMWriter.h b/goo/NetPBMWriter.h index 8a0fe318..3075d730 100644 --- a/goo/NetPBMWriter.h +++ b/goo/NetPBMWriter.h @@ -5,7 +5,7 @@ // This file is licensed under the GPLv2 or later // // Copyright (C) 2009 Stefan Thomas <[email protected]> -// Copyright (C) 2009, 2011, 2021 Albert Astals Cid <[email protected]> +// Copyright (C) 2009, 2011, 2021, 2022 Albert Astals Cid <[email protected]> // Copyright (C) 2010, 2013 Adrian Johnson <[email protected]> // Copyright (C) 2010 Brian Cameron <[email protected]> // Copyright (C) 2011 Thomas Freitag <[email protected]> @@ -40,7 +40,7 @@ public: explicit NetPBMWriter(Format formatA = RGB); ~NetPBMWriter() override {}; - bool init(FILE *f, int width, int height, int hDPI, int vDPI) override; + bool init(FILE *f, int width, int height, double /*hDPI*/, double /*vDPI*/) override; bool writePointers(unsigned char **rowPointers, int rowCount) override; bool writeRow(unsigned char **row) override; diff --git a/goo/PNGWriter.cc b/goo/PNGWriter.cc index 6545c569..c3449ae6 100644 --- a/goo/PNGWriter.cc +++ b/goo/PNGWriter.cc @@ -6,7 +6,7 @@ // // Copyright (C) 2009 Warren Toomey <[email protected]> // Copyright (C) 2009 Shen Liang <[email protected]> -// Copyright (C) 2009, 2011 Albert Astals Cid <[email protected]> +// Copyright (C) 2009, 2011, 2022 Albert Astals Cid <[email protected]> // Copyright (C) 2009 Stefan Thomas <[email protected]> // Copyright (C) 2010, 2011, 2013, 2017 Adrian Johnson <[email protected]> // Copyright (C) 2011 Thomas Klausner <[email protected]> @@ -73,7 +73,7 @@ void PNGWriter::setSRGBProfile() priv->sRGB_profile = true; } -bool PNGWriter::init(FILE *f, int width, int height, int hDPI, int vDPI) +bool PNGWriter::init(FILE *f, int width, int height, double hDPI, double vDPI) { /* libpng changed the png_set_iCCP() prototype in 1.5.0 */ # if PNG_LIBPNG_VER < 10500 @@ -82,6 +82,18 @@ bool PNGWriter::init(FILE *f, int width, int height, int hDPI, int vDPI) png_const_bytep icc_data_ptr = (png_const_bytep)priv->icc_data; # endif + if (hDPI < 0 || vDPI < 0) { + error(errInternal, -1, "PNGWriter::init: hDPI or vDPI values are invalid {0:f} {1:f}", hDPI, vDPI); + return false; + } + + const double png_res_x = hDPI / 0.0254; + const double png_res_y = vDPI / 0.0254; + if (png_res_x > std::numeric_limits<png_uint_32>::max() || png_res_y > std::numeric_limits<png_uint_32>::max()) { + error(errInternal, -1, "PNGWriter::init: hDPI or vDPI values are invalid {0:f} {1:f}", hDPI, vDPI); + return false; + } + /* initialize stuff */ priv->png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); if (!priv->png_ptr) { @@ -139,7 +151,7 @@ bool PNGWriter::init(FILE *f, int width, int height, int hDPI, int vDPI) png_set_IHDR(priv->png_ptr, priv->info_ptr, width, height, bit_depth, color_type, interlace_type, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); - png_set_pHYs(priv->png_ptr, priv->info_ptr, hDPI / 0.0254, vDPI / 0.0254, PNG_RESOLUTION_METER); + png_set_pHYs(priv->png_ptr, priv->info_ptr, static_cast<png_uint_32>(png_res_x), static_cast<png_uint_32>(png_res_y), PNG_RESOLUTION_METER); if (priv->icc_data) { png_set_iCCP(priv->png_ptr, priv->info_ptr, priv->icc_name, PNG_COMPRESSION_TYPE_BASE, icc_data_ptr, priv->icc_data_size); diff --git a/goo/PNGWriter.h b/goo/PNGWriter.h index a241d2e2..cd0ce4b8 100644 --- a/goo/PNGWriter.h +++ b/goo/PNGWriter.h @@ -6,7 +6,7 @@ // // Copyright (C) 2009 Warren Toomey <[email protected]> // Copyright (C) 2009 Shen Liang <[email protected]> -// Copyright (C) 2009, 2011-2013, 2021 Albert Astals Cid <[email protected]> +// Copyright (C) 2009, 2011-2013, 2021, 2022 Albert Astals Cid <[email protected]> // Copyright (C) 2009 Stefan Thomas <[email protected]> // Copyright (C) 2010, 2011, 2013, 2017 Adrian Johnson <[email protected]> // Copyright (C) 2012 Pino Toscano <[email protected]> @@ -52,7 +52,7 @@ public: void setICCProfile(const char *name, unsigned char *data, int size); void setSRGBProfile(); - bool init(FILE *f, int width, int height, int hDPI, int vDPI) override; + bool init(FILE *f, int width, int height, double hDPI, double vDPI) override; bool writePointers(unsigned char **rowPointers, int rowCount) override; bool writeRow(unsigned char **row) override; diff --git a/goo/TiffWriter.cc b/goo/TiffWriter.cc index 98cbea52..967a92de 100644 --- a/goo/TiffWriter.cc +++ b/goo/TiffWriter.cc @@ -5,7 +5,7 @@ // This file is licensed under the GPLv2 or later // // Copyright (C) 2010, 2012 William Bader <[email protected]> -// Copyright (C) 2012, 2021 Albert Astals Cid <[email protected]> +// Copyright (C) 2012, 2021, 2022 Albert Astals Cid <[email protected]> // Copyright (C) 2012, 2017 Adrian Johnson <[email protected]> // Copyright (C) 2012 Pino Toscano <[email protected]> // Copyright (C) 2014 Steven Lee <[email protected]> @@ -61,7 +61,7 @@ void TiffWriter::setCompressionString(const char *compressionStringArg) // Write a TIFF file. -bool TiffWriter::init(FILE *openedFile, int width, int height, int hDPI, int vDPI) +bool TiffWriter::init(FILE *openedFile, int width, int height, double hDPI, double vDPI) { unsigned int compression; uint16_t photometric = 0; @@ -186,8 +186,8 @@ bool TiffWriter::init(FILE *openedFile, int width, int height, int hDPI, int vDP TIFFSetField(priv->f, TIFFTAG_PHOTOMETRIC, photometric); TIFFSetField(priv->f, TIFFTAG_COMPRESSION, (uint16_t)compression); TIFFSetField(priv->f, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(priv->f, rowsperstrip)); - TIFFSetField(priv->f, TIFFTAG_XRESOLUTION, (double)hDPI); - TIFFSetField(priv->f, TIFFTAG_YRESOLUTION, (double)vDPI); + TIFFSetField(priv->f, TIFFTAG_XRESOLUTION, hDPI); + TIFFSetField(priv->f, TIFFTAG_YRESOLUTION, vDPI); TIFFSetField(priv->f, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH); if (priv->format == RGBA_PREMULTIPLIED) { diff --git a/goo/TiffWriter.h b/goo/TiffWriter.h index b91220bf..3691a6e2 100644 --- a/goo/TiffWriter.h +++ b/goo/TiffWriter.h @@ -5,7 +5,7 @@ // This file is licensed under the GPLv2 or later // // Copyright (C) 2010, 2012 William Bader <[email protected]> -// Copyright (C) 2011, 2012, 2021 Albert Astals Cid <[email protected]> +// Copyright (C) 2011, 2012, 2021, 2022 Albert Astals Cid <[email protected]> // Copyright (C) 2012, 2017 Adrian Johnson <[email protected]> // Copyright (C) 2012 Pino Toscano <[email protected]> // @@ -52,7 +52,7 @@ public: void setCompressionString(const char *compressionStringArg); - bool init(FILE *openedFile, int width, int height, int hDPI, int vDPI) override; + bool init(FILE *openedFile, int width, int height, double hDPI, double vDPI) override; bool writePointers(unsigned char **rowPointers, int rowCount) override; bool writeRow(unsigned char **rowData) override; diff --git a/splash/SplashBitmap.cc b/splash/SplashBitmap.cc index 31a52858..ff0996e9 100644 --- a/splash/SplashBitmap.cc +++ b/splash/SplashBitmap.cc @@ -11,7 +11,7 @@ // All changes made under the Poppler project to this file are licensed // under GPL version 2 or later // -// Copyright (C) 2006, 2009, 2010, 2012, 2015, 2018, 2019, 2021 Albert Astals Cid <[email protected]> +// Copyright (C) 2006, 2009, 2010, 2012, 2015, 2018, 2019, 2021, 2022 Albert Astals Cid <[email protected]> // Copyright (C) 2007 Ilmari Heikkinen <[email protected]> // Copyright (C) 2009 Shen Liang <[email protected]> // Copyright (C) 2009 Stefan Thomas <[email protected]> @@ -339,7 +339,7 @@ SplashColorPtr SplashBitmap::takeData() return data2; } -SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, const char *fileName, int hDPI, int vDPI, WriteImgParams *params) +SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, const char *fileName, double hDPI, double vDPI, WriteImgParams *params) { FILE *f; SplashError e; @@ -367,7 +367,7 @@ void SplashBitmap::setJpegParams(ImgWriter *writer, WriteImgParams *params) #endif } -SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, FILE *f, int hDPI, int vDPI, WriteImgParams *params) +SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, FILE *f, double hDPI, double vDPI, WriteImgParams *params) { ImgWriter *writer; SplashError e; @@ -652,7 +652,7 @@ void SplashBitmap::getCMYKLine(int yl, SplashColorPtr line) } } -SplashError SplashBitmap::writeImgFile(ImgWriter *writer, FILE *f, int hDPI, int vDPI, SplashColorMode imageWriterFormat) +SplashError SplashBitmap::writeImgFile(ImgWriter *writer, FILE *f, double hDPI, double vDPI, SplashColorMode imageWriterFormat) { if (mode != splashModeRGB8 && mode != splashModeMono8 && mode != splashModeMono1 && mode != splashModeXBGR8 && mode != splashModeBGR8 && mode != splashModeCMYK8 && mode != splashModeDeviceN8) { error(errInternal, -1, "unsupported SplashBitmap mode"); diff --git a/splash/SplashBitmap.h b/splash/SplashBitmap.h index 9e2d9912..c80a66d7 100644 --- a/splash/SplashBitmap.h +++ b/splash/SplashBitmap.h @@ -13,7 +13,7 @@ // // Copyright (C) 2007 Ilmari Heikkinen <[email protected]> // Copyright (C) 2009 Shen Liang <[email protected]> -// Copyright (C) 2009, 2012, 2018, 2021 Albert Astals Cid <[email protected]> +// Copyright (C) 2009, 2012, 2018, 2021, 2022 Albert Astals Cid <[email protected]> // Copyright (C) 2009 Stefan Thomas <[email protected]> // Copyright (C) 2010, 2017 Adrian Johnson <[email protected]> // Copyright (C) 2010 Harry Roberts <[email protected]> @@ -84,9 +84,9 @@ public: bool jpegOptimize = false; }; - SplashError writeImgFile(SplashImageFileFormat format, const char *fileName, int hDPI, int vDPI, WriteImgParams *params = nullptr); - SplashError writeImgFile(SplashImageFileFormat format, FILE *f, int hDPI, int vDPI, WriteImgParams *params = nullptr); - SplashError writeImgFile(ImgWriter *writer, FILE *f, int hDPI, int vDPI, SplashColorMode imageWriterFormat); + SplashError writeImgFile(SplashImageFileFormat format, const char *fileName, double hDPI, double vDPI, WriteImgParams *params = nullptr); + SplashError writeImgFile(SplashImageFileFormat format, FILE *f, double hDPI, double vDPI, WriteImgParams *params = nullptr); + SplashError writeImgFile(ImgWriter *writer, FILE *f, double hDPI, double vDPI, SplashColorMode imageWriterFormat); enum ConversionMode { commit bcec8308c5c7ce7a781097dbd5669603b66b3e6a Author: Albert Astals Cid <[email protected]> Date: Wed Apr 6 14:36:45 2022 +0200 Fix warning when compiling on FreeBSD diff --git a/utils/InMemoryFile.cc b/utils/InMemoryFile.cc index 5aead712..d9afc970 100644 --- a/utils/InMemoryFile.cc +++ b/utils/InMemoryFile.cc @@ -20,7 +20,7 @@ #include <cstring> #include <sstream> -InMemoryFile::InMemoryFile() : iohead(0), fptr(nullptr) { } +InMemoryFile::InMemoryFile() = default; #ifdef HAVE_IN_MEMORY_FILE_FOPENCOOKIE ssize_t InMemoryFile::_read(char *buf, size_t sz) diff --git a/utils/InMemoryFile.h b/utils/InMemoryFile.h index 5e16ad09..a578f524 100644 --- a/utils/InMemoryFile.h +++ b/utils/InMemoryFile.h @@ -11,6 +11,7 @@ // This file is licensed under the GPLv2 or later // // Copyright (C) 2018, 2019 Greg Knight <[email protected]> +// Copyright (C) 2022 Albert Astals Cid <[email protected]> // //======================================================================== @@ -29,9 +30,11 @@ class InMemoryFile { private: - size_t iohead; +#ifdef HAVE_IN_MEMORY_FILE_FOPENCOOKIE + size_t iohead = 0; + FILE *fptr = nullptr; +#endif std::vector<char> data; - FILE *fptr; #ifdef HAVE_IN_MEMORY_FILE_FOPENCOOKIE ssize_t _read(char *buf, size_t sz);
