[poppler] 2 commits - poppler/Stream.cc utils/ImageOutputDev.cc
Albert Astals Cid
aacid at kemper.freedesktop.org
Wed Jan 3 22:16:54 UTC 2018
poppler/Stream.cc | 4 +--
utils/ImageOutputDev.cc | 54 +++++++++++-------------------------------------
2 files changed, 15 insertions(+), 43 deletions(-)
New commits:
commit c4cbb4fd5e062544bf34109140266d0b027a512b
Author: Adrian Johnson <ajohnson at redneon.com>
Date: Mon Oct 30 19:21:41 2017 +1030
Fix pdfimages with flate encoded inline images
- Remove advance strem pos to end of image code from listImage().
getInlineImageLength() already does this.
- Always EmbedStream in getInlineImageLength() to get size of stored image.
The type of encoding does not matter.
- Use same record EmbeddeStream code for all image types in writeImage()
- Fix some memory leaks
Bug #103446
diff --git a/utils/ImageOutputDev.cc b/utils/ImageOutputDev.cc
index 41bbcdb4..64505421 100644
--- a/utils/ImageOutputDev.cc
+++ b/utils/ImageOutputDev.cc
@@ -20,7 +20,7 @@
// Copyright (C) 2009 Carlos Garcia Campos <carlosgc at gnome.org>
// Copyright (C) 2009 William Bader <williambader at hotmail.com>
// Copyright (C) 2010 Jakob Voss <jakob.voss at gbv.de>
-// Copyright (C) 2012, 2013, 2017 Adrian Johnson <ajohnson at redneon.com>
+// Copyright (C) 2012, 2013, 2017, 2018 Adrian Johnson <ajohnson at redneon.com>
// Copyright (C) 2013 Thomas Fischer <fischer at unix-ag.uni-kl.de>
// Copyright (C) 2013 Hib Eris <hib at hiberis.nl>
// Copyright (C) 2017 Caolán McNamara <caolanm at redhat.com>
@@ -292,25 +292,6 @@ void ImageOutputDev::listImage(GfxState *state, Object *ref, Stream *str,
++imgNum;
- if (inlineImg) {
- // For inline images we need to advance the stream position to the end of the image
- // as Gfx needs to continue reading content after the image data.
- ImageFormat format;
- if (!colorMap || (colorMap->getNumPixelComps() == 1 && colorMap->getBits() == 1)) {
- format = imgMonochrome;
- } else if (colorMap->getColorSpace()->getMode() == csDeviceGray ||
- colorMap->getColorSpace()->getMode() == csCalGray) {
- format = imgGray;
- } else if ((colorMap->getColorSpace()->getMode() == csDeviceRGB ||
- colorMap->getColorSpace()->getMode() == csCalRGB ||
- (colorMap->getColorSpace()->getMode() == csICCBased && colorMap->getNumPixelComps() == 3)) &&
- colorMap->getBits() > 8) {
- format = imgRGB48;
- } else {
- format = imgRGB;
- }
- writeImageFile(NULL, format, "", str, width, height, colorMap);
- }
}
long ImageOutputDev::getInlineImageLength(Stream *str, int width, int height,
@@ -337,16 +318,12 @@ long ImageOutputDev::getInlineImageLength(Stream *str, int width, int height,
EmbedStream *embedStr = (EmbedStream *) (str->getBaseStream());
embedStr->rewind();
- if (str->getKind() == strDCT || str->getKind() == strCCITTFax)
- str = str->getNextStream();
len = 0;
- str->reset();
- while (str->getChar() != EOF)
+ while (embedStr->getChar() != EOF)
len++;
embedStr->restore();
-
return len;
}
@@ -539,19 +516,18 @@ void ImageOutputDev::writeImage(GfxState *state, Object *ref, Stream *str,
ImageFormat format;
EmbedStream *embedStr;
- if (dumpJPEG && str->getKind() == strDCT) {
- if (inlineImg) {
+ if (inlineImg) {
embedStr = (EmbedStream *) (str->getBaseStream());
- getInlineImageLength(str, width, height, colorMap); // record the strean
+ // Record the stream. This determines the size.
+ getInlineImageLength(str, width, height, colorMap);
+ // Reading the stream again will return EOF at end of recording.
embedStr->rewind();
- }
+ }
+ if (dumpJPEG && str->getKind() == strDCT) {
// dump JPEG file
writeRawImage(str, "jpg");
- if (inlineImg)
- embedStr->restore();
-
} else if (dumpJP2 && str->getKind() == strJPX && !inlineImg) {
// dump JPEG2000 file
writeRawImage(str, "jp2");
@@ -612,18 +588,9 @@ void ImageOutputDev::writeImage(GfxState *state, Object *ref, Stream *str,
fclose(f);
- if (inlineImg) {
- embedStr = (EmbedStream *) (str->getBaseStream());
- getInlineImageLength(str, width, height, colorMap); // record the strean
- embedStr->rewind();
- }
-
// dump CCITT file
writeRawImage(str, "ccitt");
- if (inlineImg)
- embedStr->restore();
-
} else if (outputPNG && !(outputTiff && colorMap &&
(colorMap->getColorSpace()->getMode() == csDeviceCMYK ||
(colorMap->getColorSpace()->getMode() == csICCBased &&
@@ -653,6 +620,7 @@ void ImageOutputDev::writeImage(GfxState *state, Object *ref, Stream *str,
writeImageFile(writer, format, "png", str, width, height, colorMap);
#endif
+ delete writer;
} else if (outputTiff) {
// output in TIFF format
@@ -684,6 +652,7 @@ void ImageOutputDev::writeImage(GfxState *state, Object *ref, Stream *str,
writeImageFile(writer, format, "tif", str, width, height, colorMap);
#endif
+ delete writer;
} else {
// output in PPM/PBM format
@@ -703,6 +672,9 @@ void ImageOutputDev::writeImage(GfxState *state, Object *ref, Stream *str,
delete writer;
}
+
+ if (inlineImg)
+ embedStr->restore();
}
GBool ImageOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Catalog *cat, Object *str,
commit f87238296f7a81f131f2525c4ea3a26d14e8a7ff
Author: Adrian Johnson <ajohnson at redneon.com>
Date: Wed Jan 3 08:36:58 2018 +1030
Fix EmbedStream replay
Bug #103446
diff --git a/poppler/Stream.cc b/poppler/Stream.cc
index 2dbd6c82..32288221 100644
--- a/poppler/Stream.cc
+++ b/poppler/Stream.cc
@@ -27,7 +27,7 @@
// Copyright (C) 2012 Oliver Sander <sander at mi.fu-berlin.de>
// Copyright (C) 2012 Fabio D'Urso <fabiodurso at hotmail.it>
// Copyright (C) 2012 Even Rouault <even.rouault at mines-paris.org>
-// Copyright (C) 2013, 2017 Adrian Johnson <ajohnson at redneon.com>
+// Copyright (C) 2013, 2017, 2018 Adrian Johnson <ajohnson at redneon.com>
// Copyright (C) 2013 Adam Reichold <adamreichold at myopera.com>
// Copyright (C) 2013 Pino Toscano <pino at kde.org>
// Copyright (C) 2015 Suzuki Toshiya <mpsuzuki at hiroshima-u.ac.jp>
@@ -1137,7 +1137,7 @@ int EmbedStream::getChars(int nChars, Guchar *buffer) {
len = bufLen - bufPos;
if (nChars > len)
nChars = len;
- memcpy(buffer, bufData, len);
+ memcpy(buffer, bufData, nChars);
return len;
} else {
if (limited && length < nChars) {
More information about the poppler
mailing list