diff options
Diffstat (limited to 'xpdf/ImageOutputDev.cc')
-rw-r--r-- | xpdf/ImageOutputDev.cc | 84 |
1 files changed, 64 insertions, 20 deletions
diff --git a/xpdf/ImageOutputDev.cc b/xpdf/ImageOutputDev.cc index a5c9314..3f6b1a1 100644 --- a/xpdf/ImageOutputDev.cc +++ b/xpdf/ImageOutputDev.cc @@ -37,7 +37,8 @@ ImageOutputDev::~ImageOutputDev() { gfree(fileRoot); } -void ImageOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Object *str, +void ImageOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, + Object *strRef, int paintType, Dict *resDict, double *mat, double *bbox, int x0, int y0, int x1, int y1, @@ -47,16 +48,16 @@ void ImageOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Object *str, void ImageOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, GBool invert, - GBool inlineImg) { + GBool inlineImg, GBool interpolate) { FILE *f; - int c; - int size, i; + char buf[4096]; + int size, n, i; // dump JPEG file if (dumpJPEG && str->getKind() == strDCT && !inlineImg) { // open the image file - sprintf(fileName, "%s-%03d.jpg", fileRoot, imgNum); + sprintf(fileName, "%s-%04d.jpg", fileRoot, imgNum); ++imgNum; if (!(f = fopen(fileName, "wb"))) { error(errIO, -1, "Couldn't open image file '{0:s}'", fileName); @@ -68,8 +69,9 @@ void ImageOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str, str->reset(); // copy the stream - while ((c = str->getChar()) != EOF) - fputc(c, f); + while ((n = str->getBlock(buf, sizeof(buf))) > 0) { + fwrite(buf, 1, n, f); + } str->close(); fclose(f); @@ -78,7 +80,7 @@ void ImageOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str, } else { // open the image file and write the PBM header - sprintf(fileName, "%s-%03d.pbm", fileRoot, imgNum); + sprintf(fileName, "%s-%04d.pbm", fileRoot, imgNum); ++imgNum; if (!(f = fopen(fileName, "wb"))) { error(errIO, -1, "Couldn't open image file '{0:s}'", fileName); @@ -92,8 +94,14 @@ void ImageOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str, // copy the stream size = height * ((width + 7) / 8); - for (i = 0; i < size; ++i) { - fputc(str->getChar(), f); + while (size > 0) { + i = size < (int)sizeof(buf) ? size : (int)sizeof(buf); + n = str->getBlock(buf, i); + fwrite(buf, 1, n, f); + if (n < i) { + break; + } + size -= n; } str->close(); @@ -104,14 +112,15 @@ void ImageOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str, void ImageOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, - int *maskColors, GBool inlineImg) { + int *maskColors, GBool inlineImg, + GBool interpolate) { FILE *f; ImageStream *imgStr; Guchar *p; GfxRGB rgb; int x, y; - int c; - int size, i; + char buf[4096]; + int size, n, i; // dump JPEG file if (dumpJPEG && str->getKind() == strDCT && @@ -120,7 +129,7 @@ void ImageOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, !inlineImg) { // open the image file - sprintf(fileName, "%s-%03d.jpg", fileRoot, imgNum); + sprintf(fileName, "%s-%04d.jpg", fileRoot, imgNum); ++imgNum; if (!(f = fopen(fileName, "wb"))) { error(errIO, -1, "Couldn't open image file '{0:s}'", fileName); @@ -132,8 +141,9 @@ void ImageOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, str->reset(); // copy the stream - while ((c = str->getChar()) != EOF) - fputc(c, f); + while ((n = str->getBlock(buf, sizeof(buf))) > 0) { + fwrite(buf, 1, n, f); + } str->close(); fclose(f); @@ -143,7 +153,7 @@ void ImageOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, colorMap->getBits() == 1) { // open the image file and write the PBM header - sprintf(fileName, "%s-%03d.pbm", fileRoot, imgNum); + sprintf(fileName, "%s-%04d.pbm", fileRoot, imgNum); ++imgNum; if (!(f = fopen(fileName, "wb"))) { error(errIO, -1, "Couldn't open image file '{0:s}'", fileName); @@ -157,8 +167,14 @@ void ImageOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, // copy the stream size = height * ((width + 7) / 8); - for (i = 0; i < size; ++i) { - fputc(str->getChar() ^ 0xff, f); + while (size > 0) { + i = size < (int)sizeof(buf) ? size : (int)sizeof(buf); + n = str->getBlock(buf, i); + fwrite(buf, 1, n, f); + if (n < i) { + break; + } + size -= n; } str->close(); @@ -168,7 +184,7 @@ void ImageOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, } else { // open the image file and write the PPM header - sprintf(fileName, "%s-%03d.ppm", fileRoot, imgNum); + sprintf(fileName, "%s-%04d.ppm", fileRoot, imgNum); ++imgNum; if (!(f = fopen(fileName, "wb"))) { error(errIO, -1, "Couldn't open image file '{0:s}'", fileName); @@ -203,8 +219,36 @@ void ImageOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, } } } + + imgStr->close(); delete imgStr; fclose(f); } } + +void ImageOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str, + int width, int height, + GfxImageColorMap *colorMap, + Stream *maskStr, + int maskWidth, int maskHeight, + GBool maskInvert, GBool interpolate) { + drawImage(state, ref, str, width, height, colorMap, + NULL, gFalse, interpolate); + drawImageMask(state, ref, maskStr, maskWidth, maskHeight, maskInvert, + gFalse, interpolate); +} + +void ImageOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, + Stream *str, + int width, int height, + GfxImageColorMap *colorMap, + Stream *maskStr, + int maskWidth, int maskHeight, + GfxImageColorMap *maskColorMap, + GBool interpolate) { + drawImage(state, ref, str, width, height, colorMap, + NULL, gFalse, interpolate); + drawImage(state, ref, maskStr, maskWidth, maskHeight, maskColorMap, + NULL, gFalse, interpolate); +} |