1 //========================================================================
5 // Copyright 1998-2002 Glyph & Cog, LLC
7 //========================================================================
10 #pragma implementation
24 #include "ImageOutputDev.h"
26 ImageOutputDev::ImageOutputDev(char *fileRootA, GBool dumpJPEGA) {
27 fileRoot = copyString(fileRootA);
28 fileName = (char *)gmalloc(strlen(fileRoot) + 20);
34 ImageOutputDev::~ImageOutputDev() {
39 void ImageOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
40 int width, int height, GBool invert,
47 if (dumpJPEG && str->getKind() == strDCT && !inlineImg) {
49 // open the image file
50 sprintf(fileName, "%s-%03d.jpg", fileRoot, imgNum);
52 if (!(f = fopen(fileName, "wb"))) {
53 error(-1, "Couldn't open image file '%s'", fileName);
58 str = ((DCTStream *)str)->getRawStream();
62 while ((c = str->getChar()) != EOF)
71 // open the image file and write the PBM header
72 sprintf(fileName, "%s-%03d.pbm", fileRoot, imgNum);
74 if (!(f = fopen(fileName, "wb"))) {
75 error(-1, "Couldn't open image file '%s'", fileName);
79 fprintf(f, "%d %d\n", width, height);
85 size = height * ((width + 7) / 8);
86 for (i = 0; i < size; ++i) {
87 fputc(str->getChar(), f);
95 void ImageOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
96 int width, int height,
97 GfxImageColorMap *colorMap,
98 int *maskColors, GBool inlineImg) {
108 if (dumpJPEG && str->getKind() == strDCT &&
109 colorMap->getNumPixelComps() == 3 &&
112 // open the image file
113 sprintf(fileName, "%s-%03d.jpg", fileRoot, imgNum);
115 if (!(f = fopen(fileName, "wb"))) {
116 error(-1, "Couldn't open image file '%s'", fileName);
121 str = ((DCTStream *)str)->getRawStream();
125 while ((c = str->getChar()) != EOF)
132 } else if (colorMap->getNumPixelComps() == 1 &&
133 colorMap->getBits() == 1) {
135 // open the image file and write the PBM header
136 sprintf(fileName, "%s-%03d.pbm", fileRoot, imgNum);
138 if (!(f = fopen(fileName, "wb"))) {
139 error(-1, "Couldn't open image file '%s'", fileName);
143 fprintf(f, "%d %d\n", width, height);
149 size = height * ((width + 7) / 8);
150 for (i = 0; i < size; ++i) {
151 fputc(str->getChar(), f);
160 // open the image file and write the PPM header
161 sprintf(fileName, "%s-%03d.ppm", fileRoot, imgNum);
163 if (!(f = fopen(fileName, "wb"))) {
164 error(-1, "Couldn't open image file '%s'", fileName);
168 fprintf(f, "%d %d\n", width, height);
172 imgStr = new ImageStream(str, width, colorMap->getNumPixelComps(),
173 colorMap->getBits());
177 for (y = 0; y < height; ++y) {
180 for (x = 0; x < width; ++x) {
181 imgStr->getPixel(pixBuf);
182 colorMap->getRGB(pixBuf, &rgb);
183 fputc((int)(rgb.r * 255 + 0.5), f);
184 fputc((int)(rgb.g * 255 + 0.5), f);
185 fputc((int)(rgb.b * 255 + 0.5), f);