1 //========================================================================
5 // Copyright 1998 Derek B. Noonburg
7 //========================================================================
10 #pragma implementation
23 #include "ImageOutputDev.h"
25 ImageOutputDev::ImageOutputDev(char *fileRoot1, GBool dumpJPEG1) {
26 fileRoot = copyString(fileRoot1);
27 fileName = (char *)gmalloc(strlen(fileRoot) + 20);
33 ImageOutputDev::~ImageOutputDev() {
38 void ImageOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
39 int width, int height, GBool invert,
45 if (dumpJPEG && str->getKind() == strDCT) {
47 // open the image file
48 sprintf(fileName, "%s-%03d.jpg", fileRoot, imgNum);
50 if (!(f = fopen(fileName, "wb"))) {
51 error(-1, "Couldn't open image file '%s'", fileName);
56 str = ((DCTStream *)str)->getRawStream();
60 while ((c = str->getChar()) != EOF)
68 // open the image file and write the PBM header
69 sprintf(fileName, "%s-%03d.pbm", fileRoot, imgNum);
71 if (!(f = fopen(fileName, "wb"))) {
72 error(-1, "Couldn't open image file '%s'", fileName);
76 fprintf(f, "%d %d\n", width, height);
82 while ((c = str->getChar()) != EOF)
89 void ImageOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
90 int width, int height,
91 GfxImageColorMap *colorMap, GBool inlineImg) {
100 if (dumpJPEG && str->getKind() == strDCT &&
101 colorMap->getNumPixelComps() == 3) {
103 // open the image file
104 sprintf(fileName, "%s-%03d.jpg", fileRoot, imgNum);
106 if (!(f = fopen(fileName, "wb"))) {
107 error(-1, "Couldn't open image file '%s'", fileName);
112 str = ((DCTStream *)str)->getRawStream();
116 while ((c = str->getChar()) != EOF)
124 // open the image file and write the PPM header
125 sprintf(fileName, "%s-%03d.ppm", fileRoot, imgNum);
127 if (!(f = fopen(fileName, "wb"))) {
128 error(-1, "Couldn't open image file '%s'", fileName);
132 fprintf(f, "%d %d\n", width, height);
136 imgStr = new ImageStream(str, width, colorMap->getNumPixelComps(),
137 colorMap->getBits());
141 for (y = 0; y < height; ++y) {
144 for (x = 0; x < width; ++x) {
145 imgStr->getPixel(pixBuf);
146 colorMap->getRGB(pixBuf, &rgb);
147 fputc((int)(rgb.r * 255 + 0.5), f);
148 fputc((int)(rgb.g * 255 + 0.5), f);
149 fputc((int)(rgb.b * 255 + 0.5), f);