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, 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, Stream *str, int width,
90 int height, GfxImageColorMap *colorMap,
99 if (dumpJPEG && str->getKind() == strDCT) {
101 // open the image file
102 sprintf(fileName, "%s-%03d.jpg", fileRoot, imgNum);
104 if (!(f = fopen(fileName, "wb"))) {
105 error(-1, "Couldn't open image file '%s'", fileName);
110 str = ((DCTStream *)str)->getRawStream();
114 while ((c = str->getChar()) != EOF)
122 // open the image file and write the PPM header
123 sprintf(fileName, "%s-%03d.ppm", fileRoot, imgNum);
125 if (!(f = fopen(fileName, "wb"))) {
126 error(-1, "Couldn't open image file '%s'", fileName);
130 fprintf(f, "%d %d\n", width, height);
134 str->resetImage(width, colorMap->getNumPixelComps(), colorMap->getBits());
137 for (y = 0; y < height; ++y) {
140 for (x = 0; x < width; ++x) {
141 str->getImagePixel(pixBuf);
142 colorMap->getColor(pixBuf, &color);
143 fputc((int)(color.getR() * 255 + 0.5), f);
144 fputc((int)(color.getG() * 255 + 0.5), f);
145 fputc((int)(color.getB() * 255 + 0.5), f);