Commit 0b4ad184 authored by Martin's avatar Martin Committed by Albert Astals Cid

Add -jpegopt optimize option support to utils

New option 'optimize=y' for utils that take a -jpegopt param,
pdftocairo and pdftoppm. This corresponds to the cjpeg -optimize
flag, and slightly reduces the size of the output jpeg but uses
additional cpu and memory.

New jpegOptimize boolean in splash/SplashBitmap WriteImgParams.

New setOptimize method on goo/JpegWriter taking a boolean.

Update manpages for new option.
parent 20d89699
......@@ -10,6 +10,7 @@
// Copyright (C) 2011 Thomas Freitag <Thomas.Freitag@alfa.de>
// Copyright (C) 2013 Peter Breitenlohner <peb@mppmu.mpg.de>
// Copyright (C) 2017 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2018 Martin Packman <gzlist@googlemail.com>
//
//========================================================================
......@@ -25,6 +26,7 @@ extern "C" {
struct JpegWriterPrivate {
bool progressive;
bool optimize;
int quality;
JpegWriter::Format format;
struct jpeg_compress_struct cinfo;
......@@ -46,6 +48,7 @@ JpegWriter::JpegWriter(int q, bool p, Format formatA)
{
priv = new JpegWriterPrivate;
priv->progressive = p;
priv->optimize = false;
priv->quality = q;
priv->format = formatA;
}
......@@ -54,6 +57,7 @@ JpegWriter::JpegWriter(Format formatA)
{
priv = new JpegWriterPrivate;
priv->progressive = false;
priv->optimize = false;
priv->quality = -1;
priv->format = formatA;
}
......@@ -75,6 +79,11 @@ void JpegWriter::setProgressive(bool progressive)
priv->progressive = progressive;
}
void JpegWriter::setOptimize(bool optimize)
{
priv->optimize = optimize;
}
bool JpegWriter::init(FILE *f, int width, int height, int hDPI, int vDPI)
{
// Setup error handler
......@@ -137,6 +146,9 @@ bool JpegWriter::init(FILE *f, int width, int height, int hDPI, int vDPI)
jpeg_simple_progression(&priv->cinfo);
}
// Set whether to compute optimal Huffman coding tables
priv->cinfo.optimize_coding = priv->optimize;
// Get ready for data
jpeg_start_compress(&priv->cinfo, TRUE);
......
......@@ -11,6 +11,7 @@
// Copyright (C) 2010 Brian Cameron <brian.cameron@oracle.com>
// Copyright (C) 2011 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2011 Thomas Freitag <Thomas.Freitag@alfa.de>
// Copyright (C) 2018 Martin Packman <gzlist@googlemail.com>
//
//========================================================================
......@@ -41,6 +42,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 writePointers(unsigned char **rowPointers, int rowCount) override;
......
......@@ -23,6 +23,7 @@
// Copyright (C) 2012 Anthony Wesley <awesley@smartnetworks.com.au>
// Copyright (C) 2015 Adam Reichold <adamreichold@myopera.com>
// Copyright (C) 2016 Kenji Uno <ku@digitaldolphins.jp>
// Copyright (C) 2018 Martin Packman <gzlist@googlemail.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
......@@ -356,6 +357,7 @@ void SplashBitmap::setJpegParams(ImgWriter *writer, WriteImgParams* params)
#ifdef ENABLE_LIBJPEG
if (params) {
static_cast<JpegWriter*>(writer)->setProgressive(params->jpegProgressive);
static_cast<JpegWriter*>(writer)->setOptimize(params->jpegOptimize);
if (params->jpegQuality >= 0)
static_cast<JpegWriter*>(writer)->setQuality(params->jpegQuality);
}
......
......@@ -22,6 +22,7 @@
// Copyright (C) 2012 Thomas Freitag <Thomas.Freitag@alfa.de>
// Copyright (C) 2015 Adam Reichold <adamreichold@myopera.com>
// Copyright (C) 2016 Kenji Uno <ku@digitaldolphins.jp>
// Copyright (C) 2018 Martin Packman <gzlist@googlemail.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
......@@ -81,6 +82,7 @@ public:
int jpegQuality = -1;
GBool jpegProgressive = gFalse;
GooString tiffCompression;
GBool jpegOptimize = gFalse;
};
SplashError writeImgFile(SplashImageFileFormat format, char *fileName, int hDPI, int vDPI, WriteImgParams* params = nullptr);
......
......@@ -310,6 +310,12 @@ Selects the JPEG quality value. The value must be an integer between 0 and 100.
.BI progressive
Select progressive JPEG output. The possible values are "y", "n",
indicating progressive (yes) or non-progressive (no), respectively.
.TP
.BI optimize
Sets whether to compute optimal Huffman coding tables for the JPEG output, which
will create smaller files but make an extra pass over the data. The value must
be "y" or "n", with "y" performing optimization, otherwise the default Huffman
tables are used.
.SH WINDOWS PRINTER OPTIONS
In Windows, you can use the \-print option to print directly to a system printer. Additionally, you can use the \-printopt
option to configure the printer. It takes a string of the form "<opt>=<val>[,<opt>=<val>]". Currently the available options are:
......
......@@ -30,6 +30,7 @@
// Copyright (C) 2013, 2017 Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp>
// Copyright (C) 2014 Rodrigo Rivas Costa <rodrigorivascosta@gmail.com>
// Copyright (C) 2016 Jason Crain <jason@aquaticape.us>
// Copyright (C) 2018 Martin Packman <gzlist@googlemail.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
......@@ -129,6 +130,7 @@ static GBool printHelp = gFalse;
static GooString jpegOpt;
static int jpegQuality = -1;
static bool jpegProgressive = false;
static bool jpegOptimize = false;
static GooString printer;
static GooString printOpt;
......@@ -369,6 +371,14 @@ static GBool parseJpegOptions()
fprintf(stderr, "jpeg progressive option must be \"y\" or \"n\"\n");
return gFalse;
}
} else if (opt.cmp("optimize") == 0 || opt.cmp("optimise") == 0) {
jpegOptimize = gFalse;
if (value.cmp("y") == 0) {
jpegOptimize = gTrue;
} else if (value.cmp("n") != 0) {
fprintf(stderr, "jpeg optimize option must be \"y\" or \"n\"\n");
return gFalse;
}
} else {
fprintf(stderr, "Unknown jpeg option \"%s\"\n", opt.getCString());
return gFalse;
......@@ -415,6 +425,7 @@ static void writePageImage(GooString *filename)
else
writer = new JpegWriter(JpegWriter::RGB);
static_cast<JpegWriter*>(writer)->setOptimize(jpegOptimize);
static_cast<JpegWriter*>(writer)->setProgressive(jpegProgressive);
if (jpegQuality >= 0)
static_cast<JpegWriter*>(writer)->setQuality(jpegQuality);
......
......@@ -171,6 +171,12 @@ Selects the JPEG quality value. The value must be an integer between 0 and 100.
.BI progressive
Select progressive JPEG output. The possible values are "y", "n",
indicating progressive (yes) or non-progressive (no), respectively.
.TP
.BI optimize
Sets whether to compute optimal Huffman coding tables for the JPEG output, which
will create smaller files but make an extra pass over the data. The value must
be "y" or "n", with "y" performing optimization, otherwise the default Huffman
tables are used.
.SH AUTHOR
The pdftoppm software and documentation are copyright 1996-2011 Glyph
& Cog, LLC.
......
......@@ -27,6 +27,7 @@
// Copyright (C) 2013, 2015 Adam Reichold <adamreichold@myopera.com>
// Copyright (C) 2013 Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp>
// Copyright (C) 2015 William Bader <williambader@hotmail.com>
// Copyright (C) 2018 Martin Packman <gzlist@googlemail.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
......@@ -92,6 +93,7 @@ static GBool tiff = gFalse;
static GooString jpegOpt;
static int jpegQuality = -1;
static bool jpegProgressive = false;
static bool jpegOptimize = false;
#ifdef SPLASH_CMYK
static GBool overprint = gFalse;
#endif
......@@ -257,6 +259,14 @@ static GBool parseJpegOptions()
fprintf(stderr, "jpeg progressive option must be \"y\" or \"n\"\n");
return gFalse;
}
} else if (opt.cmp("optimize") == 0 || opt.cmp("optimise") == 0) {
jpegOptimize = gFalse;
if (value.cmp("y") == 0) {
jpegOptimize = gTrue;
} else if (value.cmp("n") != 0) {
fprintf(stderr, "jpeg optimize option must be \"y\" or \"n\"\n");
return gFalse;
}
} else {
fprintf(stderr, "Unknown jpeg option \"%s\"\n", opt.getCString());
return gFalse;
......@@ -286,6 +296,7 @@ static void savePageSlice(PDFDoc *doc,
SplashBitmap::WriteImgParams params;
params.jpegQuality = jpegQuality;
params.jpegProgressive = jpegProgressive;
params.jpegOptimize = jpegOptimize;
params.tiffCompression.Set(TiffCompressionStr);
if (ppmFile != nullptr) {
......
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