Commit c4cbb4fd authored by Adrian Johnson's avatar Adrian Johnson Committed by Albert Astals Cid

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
parent f8723829
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
// Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org> // Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright (C) 2009 William Bader <williambader@hotmail.com> // Copyright (C) 2009 William Bader <williambader@hotmail.com>
// Copyright (C) 2010 Jakob Voss <jakob.voss@gbv.de> // Copyright (C) 2010 Jakob Voss <jakob.voss@gbv.de>
// Copyright (C) 2012, 2013, 2017 Adrian Johnson <ajohnson@redneon.com> // Copyright (C) 2012, 2013, 2017, 2018 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2013 Thomas Fischer <fischer@unix-ag.uni-kl.de> // Copyright (C) 2013 Thomas Fischer <fischer@unix-ag.uni-kl.de>
// Copyright (C) 2013 Hib Eris <hib@hiberis.nl> // Copyright (C) 2013 Hib Eris <hib@hiberis.nl>
// Copyright (C) 2017 Caolán McNamara <caolanm@redhat.com> // Copyright (C) 2017 Caolán McNamara <caolanm@redhat.com>
...@@ -292,25 +292,6 @@ void ImageOutputDev::listImage(GfxState *state, Object *ref, Stream *str, ...@@ -292,25 +292,6 @@ void ImageOutputDev::listImage(GfxState *state, Object *ref, Stream *str,
++imgNum; ++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, long ImageOutputDev::getInlineImageLength(Stream *str, int width, int height,
...@@ -337,16 +318,12 @@ 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()); EmbedStream *embedStr = (EmbedStream *) (str->getBaseStream());
embedStr->rewind(); embedStr->rewind();
if (str->getKind() == strDCT || str->getKind() == strCCITTFax)
str = str->getNextStream();
len = 0; len = 0;
str->reset(); while (embedStr->getChar() != EOF)
while (str->getChar() != EOF)
len++; len++;
embedStr->restore(); embedStr->restore();
return len; return len;
} }
...@@ -539,19 +516,18 @@ void ImageOutputDev::writeImage(GfxState *state, Object *ref, Stream *str, ...@@ -539,19 +516,18 @@ void ImageOutputDev::writeImage(GfxState *state, Object *ref, Stream *str,
ImageFormat format; ImageFormat format;
EmbedStream *embedStr; EmbedStream *embedStr;
if (dumpJPEG && str->getKind() == strDCT) { if (inlineImg) {
if (inlineImg) {
embedStr = (EmbedStream *) (str->getBaseStream()); 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(); embedStr->rewind();
} }
if (dumpJPEG && str->getKind() == strDCT) {
// dump JPEG file // dump JPEG file
writeRawImage(str, "jpg"); writeRawImage(str, "jpg");
if (inlineImg)
embedStr->restore();
} else if (dumpJP2 && str->getKind() == strJPX && !inlineImg) { } else if (dumpJP2 && str->getKind() == strJPX && !inlineImg) {
// dump JPEG2000 file // dump JPEG2000 file
writeRawImage(str, "jp2"); writeRawImage(str, "jp2");
...@@ -612,18 +588,9 @@ void ImageOutputDev::writeImage(GfxState *state, Object *ref, Stream *str, ...@@ -612,18 +588,9 @@ void ImageOutputDev::writeImage(GfxState *state, Object *ref, Stream *str,
fclose(f); fclose(f);
if (inlineImg) {
embedStr = (EmbedStream *) (str->getBaseStream());
getInlineImageLength(str, width, height, colorMap); // record the strean
embedStr->rewind();
}
// dump CCITT file // dump CCITT file
writeRawImage(str, "ccitt"); writeRawImage(str, "ccitt");
if (inlineImg)
embedStr->restore();
} else if (outputPNG && !(outputTiff && colorMap && } else if (outputPNG && !(outputTiff && colorMap &&
(colorMap->getColorSpace()->getMode() == csDeviceCMYK || (colorMap->getColorSpace()->getMode() == csDeviceCMYK ||
(colorMap->getColorSpace()->getMode() == csICCBased && (colorMap->getColorSpace()->getMode() == csICCBased &&
...@@ -653,6 +620,7 @@ void ImageOutputDev::writeImage(GfxState *state, Object *ref, Stream *str, ...@@ -653,6 +620,7 @@ void ImageOutputDev::writeImage(GfxState *state, Object *ref, Stream *str,
writeImageFile(writer, format, "png", str, width, height, colorMap); writeImageFile(writer, format, "png", str, width, height, colorMap);
#endif #endif
delete writer;
} else if (outputTiff) { } else if (outputTiff) {
// output in TIFF format // output in TIFF format
...@@ -684,6 +652,7 @@ void ImageOutputDev::writeImage(GfxState *state, Object *ref, Stream *str, ...@@ -684,6 +652,7 @@ void ImageOutputDev::writeImage(GfxState *state, Object *ref, Stream *str,
writeImageFile(writer, format, "tif", str, width, height, colorMap); writeImageFile(writer, format, "tif", str, width, height, colorMap);
#endif #endif
delete writer;
} else { } else {
// output in PPM/PBM format // output in PPM/PBM format
...@@ -703,6 +672,9 @@ void ImageOutputDev::writeImage(GfxState *state, Object *ref, Stream *str, ...@@ -703,6 +672,9 @@ void ImageOutputDev::writeImage(GfxState *state, Object *ref, Stream *str,
delete writer; delete writer;
} }
if (inlineImg)
embedStr->restore();
} }
GBool ImageOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Catalog *cat, Object *str, GBool ImageOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Catalog *cat, Object *str,
......
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