--- poppler-0.15.3-mask/poppler/PSOutputDev.cc- 2010-11-26 20:32:40.000000000 +0100 +++ poppler-0.15.3-mask/poppler/PSOutputDev.cc 2010-12-15 18:25:38.538431297 +0100 @@ -567,6 +567,7 @@ " not { pop exit } if", " (%-EOD-) eq { exit } if } loop", "} def", + "~123sn", "/pr { 2 index 2 index 3 2 roll putinterval 4 add } def", "/pdfImClip {", " gsave", @@ -4417,7 +4418,8 @@ switch (level) { case psLevel1: case psLevel1Sep: - doImageL1(ref, NULL, invert, inlineImg, str, width, height, len); + doImageL1(ref, NULL, invert, inlineImg, str, width, height, len, + NULL, NULL, 0, 0, gFalse); break; case psLevel2: case psLevel2Sep: @@ -4442,11 +4444,13 @@ colorMap->getBits() + 7) / 8); switch (level) { case psLevel1: - doImageL1(ref, colorMap, gFalse, inlineImg, str, width, height, len); + doImageL1(ref, colorMap, gFalse, inlineImg, str, + width, height, len, maskColors, NULL, 0, 0, gFalse); break; case psLevel1Sep: //~ handle indexed, separation, ... color spaces - doImageL1Sep(colorMap, gFalse, inlineImg, str, width, height, len); + doImageL1Sep(ref, colorMap, gFalse, inlineImg, str, + width, height, len, maskColors, NULL, 0, 0, gFalse); break; case psLevel2: case psLevel2Sep: @@ -4475,11 +4479,13 @@ colorMap->getBits() + 7) / 8); switch (level) { case psLevel1: - doImageL1(ref, colorMap, gFalse, gFalse, str, width, height, len); + doImageL1(ref, colorMap, gFalse, gFalse, str, width, height, len, + NULL, maskStr, maskWidth, maskHeight, maskInvert); break; case psLevel1Sep: //~ handle indexed, separation, ... color spaces - doImageL1Sep(colorMap, gFalse, gFalse, str, width, height, len); + doImageL1Sep(ref, colorMap, gFalse, gFalse, str, width, height, len, + NULL, maskStr, maskWidth, maskHeight, maskInvert); break; case psLevel2: case psLevel2Sep: @@ -4497,11 +4503,20 @@ void PSOutputDev::doImageL1(Object *ref, GfxImageColorMap *colorMap, GBool invert, GBool inlineImg, - Stream *str, int width, int height, int len) { + Stream *str, int width, int height, int len, + int *maskColors, Stream *maskStr, + int maskWidth, int maskHeight, GBool maskInvert) { ImageStream *imgStr; Guchar pixBuf[gfxColorMaxComps]; GfxGray gray; int col, x, y, c, i; + char hexBuf[ 32*2 + 2 ]; // 32 values X 2 chars/value + line ending + null + Guchar digit, grayValue; + + // explicit masking + if (maskStr && !(maskColors && colorMap)) { + maskToClippingPath(maskStr, maskWidth, maskHeight, maskInvert); + } if ((inType3Char || preload) && !colorMap) { if (inlineImg) { @@ -4574,15 +4589,22 @@ for (x = 0; x < width; ++x) { imgStr->getPixel(pixBuf); colorMap->getGray(pixBuf, &gray); - writePSFmt("{0:02x}", colToByte(gray)); - if (++i == 32) { - writePSChar('\n'); + // writePSFmt("{0:02x}", colToByte(gray)); + grayValue = colToByte(gray); + digit = grayValue / 16; + hexBuf[i++] = digit + ((digit >= 10)? 'a'-10: '0'); + digit = grayValue % 16; + hexBuf[i++] = digit + ((digit >= 10)? 'a'-10: '0'); + if (i >= 64) { + hexBuf[i++] = '\n'; + writePSBuf(hexBuf, i); i = 0; } } } if (i != 0) { - writePSChar('\n'); + hexBuf[i++] = '\n'; + writePSBuf(hexBuf, i); } str->close(); delete imgStr; @@ -4593,29 +4615,50 @@ i = 0; for (y = 0; y < height; ++y) { for (x = 0; x < width; x += 8) { - writePSFmt("{0:02x}", str->getChar() & 0xff); - if (++i == 32) { - writePSChar('\n'); + // writePSFmt("{0:02x}", str->getChar() & 0xff); + grayValue = str->getChar(); + digit = grayValue / 16; + hexBuf[i++] = digit + ((digit >= 10)? 'a'-10: '0'); + digit = grayValue % 16; + hexBuf[i++] = digit + ((digit >= 10)? 'a'-10: '0'); + if (i >= 64) { + hexBuf[i++] = '\n'; + writePSBuf(hexBuf, i); i = 0; } } } if (i != 0) { - writePSChar('\n'); + hexBuf[i++] = '\n'; + writePSBuf(hexBuf, i); } str->close(); } } + + if (maskStr && !(maskColors && colorMap)) { + writePS("pdfImClipEnd\n"); + } } -void PSOutputDev::doImageL1Sep(GfxImageColorMap *colorMap, +void PSOutputDev::doImageL1Sep(Object *ref, GfxImageColorMap *colorMap, GBool invert, GBool inlineImg, - Stream *str, int width, int height, int len) { + Stream *str, int width, int height, int len, + int *maskColors, Stream *maskStr, + int maskWidth, int maskHeight, GBool maskInvert) { ImageStream *imgStr; Guchar *lineBuf; Guchar pixBuf[gfxColorMaxComps]; GfxCMYK cmyk; int x, y, i, comp; + GBool checkProcessColor; + char hexBuf[ 32*2 + 2 ]; // 32 values X 2 chars/value + line ending + null + Guchar digit; + + // explicit masking + if (maskStr && !(maskColors && colorMap)) { + maskToClippingPath(maskStr, maskWidth, maskHeight, maskInvert); + } // width, height, matrix, bits per component writePSFmt("{0:d} {1:d} 8 [{2:d} 0 0 {3:d} 0 {4:d}] pdfIm1Sep\n", @@ -4631,27 +4674,47 @@ imgStr->reset(); // process the data stream + checkProcessColor = gTrue; i = 0; for (y = 0; y < height; ++y) { // read the line - for (x = 0; x < width; ++x) { - imgStr->getPixel(pixBuf); - colorMap->getCMYK(pixBuf, &cmyk); - lineBuf[4*x+0] = colToByte(cmyk.c); - lineBuf[4*x+1] = colToByte(cmyk.m); - lineBuf[4*x+2] = colToByte(cmyk.y); - lineBuf[4*x+3] = colToByte(cmyk.k); - addProcessColor(colToDbl(cmyk.c), colToDbl(cmyk.m), - colToDbl(cmyk.y), colToDbl(cmyk.k)); + if (checkProcessColor) { + checkProcessColor = (((psProcessCyan | psProcessMagenta | psProcessYellow | psProcessBlack) & ~processColors) != 0); + } + if (checkProcessColor) { + for (x = 0; x < width; ++x) { + imgStr->getPixel(pixBuf); + colorMap->getCMYK(pixBuf, &cmyk); + lineBuf[4*x+0] = colToByte(cmyk.c); + lineBuf[4*x+1] = colToByte(cmyk.m); + lineBuf[4*x+2] = colToByte(cmyk.y); + lineBuf[4*x+3] = colToByte(cmyk.k); + addProcessColor(colToDbl(cmyk.c), colToDbl(cmyk.m), + colToDbl(cmyk.y), colToDbl(cmyk.k)); + } + } else { + for (x = 0; x < width; ++x) { + imgStr->getPixel(pixBuf); + colorMap->getCMYK(pixBuf, &cmyk); + lineBuf[4*x+0] = colToByte(cmyk.c); + lineBuf[4*x+1] = colToByte(cmyk.m); + lineBuf[4*x+2] = colToByte(cmyk.y); + lineBuf[4*x+3] = colToByte(cmyk.k); + } } // write one line of each color component for (comp = 0; comp < 4; ++comp) { for (x = 0; x < width; ++x) { - writePSFmt("{0:02x}", lineBuf[4*x + comp]); - if (++i == 32) { - writePSChar('\n'); + // writePSFmt("{0:02x}", lineBuf[4*x + comp]); + digit = lineBuf[4*x + comp] / 16; + hexBuf[i++] = digit + ((digit >= 10)? 'a'-10: '0'); + digit = lineBuf[4*x + comp] % 16; + hexBuf[i++] = digit + ((digit >= 10)? 'a'-10: '0'); + if (i >= 64) { + hexBuf[i++] = '\n'; + writePSBuf(hexBuf, i); i = 0; } } @@ -4659,12 +4722,17 @@ } if (i != 0) { - writePSChar('\n'); + hexBuf[i++] = '\n'; + writePSBuf(hexBuf, i); } str->close(); delete imgStr; gfree(lineBuf); + + if (maskStr && !(maskColors && colorMap)) { + writePS("pdfImClipEnd\n"); + } } void PSOutputDev::maskToClippingPath(Stream *maskStr, int maskWidth, int maskHeight, GBool maskInvert) { @@ -4804,6 +4872,7 @@ GfxCMYK cmyk; int c; int col, i, j, x0, x1, y; + char dataBuf[ 4096 ]; rectsOutLen = 0; @@ -5202,8 +5271,16 @@ // copy the stream data str->reset(); + i = 0; while ((c = str->getChar()) != EOF) { - writePSChar(c); + dataBuf[i++] = c; + if (i >= sizeof(dataBuf)) { + writePSBuf(dataBuf, i); + i = 0; + } + } + if (i > 0) { + writePSBuf(dataBuf, i); } str->close(); @@ -6440,6 +6517,17 @@ } } +void PSOutputDev::writePSBuf(char *s, int len) { + if (t3String) { + int i; + for (i = 0; i < len; i++) { + t3String->append(s[i]); + } + } else { + (*outputFunc)(outputStream, s, len); + } +} + void PSOutputDev::writePSFmt(const char *fmt, ...) { va_list args; GooString *buf; --- poppler-0.15.3-mask/poppler/PSOutputDev.h- 2010-11-10 23:32:14.000000000 +0100 +++ poppler-0.15.3-mask/poppler/PSOutputDev.h 2010-12-15 18:21:48.728613006 +0100 @@ -317,10 +317,14 @@ void maskToClippingPath(Stream *maskStr, int maskWidth, int maskHeight, GBool maskInvert); void doImageL1(Object *ref, GfxImageColorMap *colorMap, GBool invert, GBool inlineImg, - Stream *str, int width, int height, int len); - void doImageL1Sep(GfxImageColorMap *colorMap, + Stream *str, int width, int height, int len, + int *maskColors, Stream *maskStr, + int maskWidth, int maskHeight, GBool maskInvert); + void doImageL1Sep(Object *ref, GfxImageColorMap *colorMap, GBool invert, GBool inlineImg, - Stream *str, int width, int height, int len); + Stream *str, int width, int height, int len, + int *maskColors, Stream *maskStr, + int maskWidth, int maskHeight, GBool maskInvert); void doImageL2(Object *ref, GfxImageColorMap *colorMap, GBool invert, GBool inlineImg, Stream *str, int width, int height, int len, @@ -347,6 +351,7 @@ void writePSChar(char c); void writePS(char *s); + void writePSBuf(char *s, int len); void writePSFmt(const char *fmt, ...); void writePSString(GooString *s); void writePSName(char *s);