diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc
index 17541a2..22f2b9a 100644
--- a/utils/HtmlOutputDev.cc
+++ b/utils/HtmlOutputDev.cc
@@ -1322,7 +1322,80 @@ void HtmlOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
drawJpegImage(state, str);
}
else {
- OutputDev::drawImageMask(state, ref, str, width, height, invert, interpolate, inlineImg);
+#ifdef ENABLE_LIBPNG
+ FILE *f1;
+ GooString *fName=new GooString(Docname);
+ fName->append("-");
+ GooString *pgNum= GooString::fromInt(pageNum);
+ GooString *imgnum= GooString::fromInt(pages->getNumImages()+1);
+
+ // open the image file
+ fName->append(pgNum)->append("_")->append(imgnum)->append(".png");
+ delete pgNum;
+ delete imgnum;
+
+ if (!(f1 = fopen(fName->getCString(), "wb"))) {
+ error(errIO, -1, "Couldn't open image file '%s'", fName->getCString());
+ delete fName;
+ return;
+ }
+
+ PNGWriter *writer = new PNGWriter( PNGWriter::MONOCHROME );
+ if (!writer->init(f1, width, height, 72, 72)) {
+ error(errInternal, -1, "Can't init PNG for image '%s'", fName->getCString());
+ delete writer;
+ fclose(f1);
+ return;
+ }
+
+ int bytes_per_row = ((width + 7) / 8);
+ Guchar *bit_row = (Guchar *)gmalloc( bytes_per_row );
+ Guchar *png_row = (Guchar *)gmalloc( width );
+
+ str->reset();
+ for (int ri = 0; ri < height; ++ri)
+ {
+ // read the row bits of the mask
+ for (int i = 0; i < bytes_per_row; ++i) {
+ if ((bit_row[i] = str->getChar()) != EOF) {
+ } else {
+ error(errIO, -1, "Image mask stream is corrupt for image '%s'", fName->getCString());
+ delete writer;
+ fclose(f1);
+ gfree(bit_row);
+ gfree(png_row);
+ return;
+ }
+ }
+
+ // convert bits into a bytes for PNG
+ for(int i = 0; i < width; i++)
+ png_row[i] = ((bit_row[i/8]) & (1<<(7-(i%8)))) ? 0x00 : 0xff ; // invert for PNG
+
+ if (!writer->writeRow( &png_row ))
+ {
+ error(errIO, -1, "Failed to write into PNG '%s'", fName->getCString());
+ delete writer;
+ fclose(f1);
+ gfree(bit_row);
+ gfree(png_row);
+ return;
+ }
+ }
+ str->close();
+
+ writer->close();
+ delete writer;
+ fclose(f1);
+
+ gfree(bit_row);
+ gfree(png_row);
+
+ pages->addImage(fName, state);
+#else
+ OutputDev::drawImage(state, ref, str, width, height, colorMap, interpolate,
+ maskColors, inlineImg);
+#endif
}
}