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,
100 if (dumpJPEG && str->getKind() == strDCT) {
102 // open the image file
103 sprintf(fileName, "%s-%03d.jpg", fileRoot, imgNum);
105 if (!(f = fopen(fileName, "wb"))) {
106 error(-1, "Couldn't open image file '%s'", fileName);
111 str = ((DCTStream *)str)->getRawStream();
115 while ((c = str->getChar()) != EOF)
123 // open the image file and write the PPM header
124 sprintf(fileName, "%s-%03d.ppm", fileRoot, imgNum);
126 if (!(f = fopen(fileName, "wb"))) {
127 error(-1, "Couldn't open image file '%s'", fileName);
131 fprintf(f, "%d %d\n", width, height);
135 imgStr = new ImageStream(str, width, colorMap->getNumPixelComps(),
136 colorMap->getBits());
140 for (y = 0; y < height; ++y) {
143 for (x = 0; x < width; ++x) {
144 imgStr->getPixel(pixBuf);
145 colorMap->getColor(pixBuf, &color);
146 fputc((int)(color.getR() * 255 + 0.5), f);
147 fputc((int)(color.getG() * 255 + 0.5), f);
148 fputc((int)(color.getB() * 255 + 0.5), f);