X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=pdf%2Fxpdf%2FImageOutputDev.cc;h=5ca14ac5a1b6d4e3192ae1c0d568b5a5e35f7f35;hb=f36af012943a93a0c8e1f2d36c4f5b9e1ac1b8e5;hp=00782fb590e2821d7bfe9aa128177dee637e3ef0;hpb=d9f9a6449f377b4c933b75d57541b19c6d088994;p=evince.git diff --git a/pdf/xpdf/ImageOutputDev.cc b/pdf/xpdf/ImageOutputDev.cc index 00782fb5..5ca14ac5 100644 --- a/pdf/xpdf/ImageOutputDev.cc +++ b/pdf/xpdf/ImageOutputDev.cc @@ -2,11 +2,13 @@ // // ImageOutputDev.cc // -// Copyright 1998 Derek B. Noonburg +// Copyright 1998-2003 Glyph & Cog, LLC // //======================================================================== -#ifdef __GNUC__ +#include + +#ifdef USE_GCC_PRAGMAS #pragma implementation #endif @@ -15,17 +17,17 @@ #include #include #include "gmem.h" -#include "config.h" +#include "xpdfconfig.h" #include "Error.h" #include "GfxState.h" #include "Object.h" #include "Stream.h" #include "ImageOutputDev.h" -ImageOutputDev::ImageOutputDev(char *fileRoot1, GBool dumpJPEG1) { - fileRoot = copyString(fileRoot1); +ImageOutputDev::ImageOutputDev(char *fileRootA, GBool dumpJPEGA) { + fileRoot = copyString(fileRootA); fileName = (char *)gmalloc(strlen(fileRoot) + 20); - dumpJPEG = dumpJPEG1; + dumpJPEG = dumpJPEGA; imgNum = 0; ok = gTrue; } @@ -35,14 +37,15 @@ ImageOutputDev::~ImageOutputDev() { gfree(fileRoot); } -void ImageOutputDev::drawImageMask(GfxState *state, Stream *str, +void ImageOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, GBool invert, GBool inlineImg) { FILE *f; int c; + int size, i; // dump JPEG file - if (dumpJPEG && str->getKind() == strDCT) { + if (dumpJPEG && str->getKind() == strDCT && !inlineImg) { // open the image file sprintf(fileName, "%s-%03d.jpg", fileRoot, imgNum); @@ -60,6 +63,7 @@ void ImageOutputDev::drawImageMask(GfxState *state, Stream *str, while ((c = str->getChar()) != EOF) fputc(c, f); + str->close(); fclose(f); // dump PBM file @@ -79,24 +83,32 @@ void ImageOutputDev::drawImageMask(GfxState *state, Stream *str, str->reset(); // copy the stream - while ((c = str->getChar()) != EOF) - fputc(c, f); + size = height * ((width + 7) / 8); + for (i = 0; i < size; ++i) { + fputc(str->getChar(), f); + } + str->close(); fclose(f); } } -void ImageOutputDev::drawImage(GfxState *state, Stream *str, int width, - int height, GfxImageColorMap *colorMap, - GBool inlineImg) { +void ImageOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, + int width, int height, + GfxImageColorMap *colorMap, + int *maskColors, GBool inlineImg) { FILE *f; - Guchar pixBuf[4]; - GfxColor color; + ImageStream *imgStr; + Guchar *p; + GfxRGB rgb; int x, y; int c; + int size, i; // dump JPEG file - if (dumpJPEG && str->getKind() == strDCT) { + if (dumpJPEG && str->getKind() == strDCT && + colorMap->getNumPixelComps() == 3 && + !inlineImg) { // open the image file sprintf(fileName, "%s-%03d.jpg", fileRoot, imgNum); @@ -114,6 +126,33 @@ void ImageOutputDev::drawImage(GfxState *state, Stream *str, int width, while ((c = str->getChar()) != EOF) fputc(c, f); + str->close(); + fclose(f); + + // dump PBM file + } else if (colorMap->getNumPixelComps() == 1 && + colorMap->getBits() == 1) { + + // open the image file and write the PBM header + sprintf(fileName, "%s-%03d.pbm", fileRoot, imgNum); + ++imgNum; + if (!(f = fopen(fileName, "wb"))) { + error(-1, "Couldn't open image file '%s'", fileName); + return; + } + fprintf(f, "P4\n"); + fprintf(f, "%d %d\n", width, height); + + // initialize stream + str->reset(); + + // copy the stream + size = height * ((width + 7) / 8); + for (i = 0; i < size; ++i) { + fputc(str->getChar() ^ 0xff, f); + } + + str->close(); fclose(f); // dump PPM file @@ -131,20 +170,24 @@ void ImageOutputDev::drawImage(GfxState *state, Stream *str, int width, fprintf(f, "255\n"); // initialize stream - str->resetImage(width, colorMap->getNumPixelComps(), colorMap->getBits()); + imgStr = new ImageStream(str, width, colorMap->getNumPixelComps(), + colorMap->getBits()); + imgStr->reset(); // for each line... for (y = 0; y < height; ++y) { // write the line + p = imgStr->getLine(); for (x = 0; x < width; ++x) { - str->getImagePixel(pixBuf); - colorMap->getColor(pixBuf, &color); - fputc((int)(color.getR() * 255 + 0.5), f); - fputc((int)(color.getG() * 255 + 0.5), f); - fputc((int)(color.getB() * 255 + 0.5), f); + colorMap->getRGB(p, &rgb); + fputc((int)(rgb.r * 255 + 0.5), f); + fputc((int)(rgb.g * 255 + 0.5), f); + fputc((int)(rgb.b * 255 + 0.5), f); + p += colorMap->getNumPixelComps(); } } + delete imgStr; fclose(f); }