[poppler] 2 commits - poppler/PSOutputDev.cc poppler/Stream.cc poppler/Stream.h
Albert Astals Cid
aacid at kemper.freedesktop.org
Fri Jun 24 14:39:36 PDT 2011
poppler/PSOutputDev.cc | 85 ++++++++++++++++++++++++++++++++++++++++++++++---
poppler/Stream.cc | 43 ++++++++++++++++++++++++
poppler/Stream.h | 29 ++++++++++++++++
3 files changed, 152 insertions(+), 5 deletions(-)
New commits:
commit 7e244fde4ec03da08d81af3402b21646c803bd31
Author: William Bader <williambader at hotmail.com>
Date: Fri Jun 24 22:39:13 2011 +0100
patch to make -level2sep and -level3sep write gray instead of cmyk
If they are only gray of course :D
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index 25de8b8..0db9364 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -2986,6 +2986,7 @@ GBool PSOutputDev::checkPageSlice(Page *page, double /*hDPI*/, double /*vDPI*/,
GfxState *state;
SplashBitmap *bitmap;
Stream *str0, *str;
+ Stream *str1 = NULL;
Object obj;
Guchar *p;
Guchar col[4];
@@ -2995,6 +2996,8 @@ GBool PSOutputDev::checkPageSlice(Page *page, double /*hDPI*/, double /*vDPI*/,
char hexBuf[32*2 + 2]; // 32 values X 2 chars/value + line ending + null
Guchar digit;
GBool useBinary;
+ GBool isGray;
+ int compCyan;
if (!forceRasterize) {
scan = new PreScanOutputDev(xref);
@@ -3225,15 +3228,35 @@ GBool PSOutputDev::checkPageSlice(Page *page, double /*hDPI*/, double /*vDPI*/,
case psLevel3Sep:
obj.initNull();
str0 = new MemStream((char *)bitmap->getDataPtr(), 0, w * h * 4, &obj);
- processColors |= psProcessCMYK;
- writePS("/DeviceCMYK setcolorspace\n");
- str = new RunLengthEncoder(str0);
+ isGray = gTrue;
+ while ((compCyan = str0->getChar()) != EOF) {
+ if (str0->getChar() != compCyan ||
+ str0->getChar() != compCyan) {
+ isGray = gFalse;
+ break;
+ }
+ str0->getChar();
+ }
+ str0->reset();
+ if (isGray) {
+ writePS("/DeviceGray setcolorspace\n");
+ str1 = new CMKYGrayEncoder(str0);
+ str = new RunLengthEncoder(str1);
+ } else {
+ processColors |= psProcessCMYK;
+ writePS("/DeviceCMYK setcolorspace\n");
+ str = new RunLengthEncoder(str0);
+ }
writePS("<<\n /ImageType 1\n");
writePSFmt(" /Width {0:d}\n", bitmap->getWidth());
writePSFmt(" /Height {0:d}\n", bitmap->getHeight());
writePSFmt(" /ImageMatrix [{0:d} 0 0 {1:d} 0 {2:d}]\n", w, -h, h);
writePS(" /BitsPerComponent 8\n");
- writePS(" /Decode [0 1 0 1 0 1 0 1]\n");
+ if (isGray) {
+ writePS(" /Decode [1 0]\n");
+ } else {
+ writePS(" /Decode [0 1 0 1 0 1 0 1]\n");
+ }
writePS(" /DataSource currentfile\n");
useBinary = globalParams->getPSBinary();
if (useBinary) {
@@ -3267,9 +3290,12 @@ GBool PSOutputDev::checkPageSlice(Page *page, double /*hDPI*/, double /*vDPI*/,
}
if (useBinary) {
writePS("\n%%EndData\n");
+ } else if (isGray) {
+ writePSChar('\n');
}
str->close();
delete str;
+ // delete str1; // deleted by str0
delete str0;
break;
case psLevel2:
diff --git a/poppler/Stream.cc b/poppler/Stream.cc
index 11c92f3..7b46c01 100644
--- a/poppler/Stream.cc
+++ b/poppler/Stream.cc
@@ -4923,3 +4923,46 @@ GBool RunLengthEncoder::fillBuf() {
bufPtr = buf;
return gTrue;
}
+
+//------------------------------------------------------------------------
+// CMKYGrayEncoder
+//------------------------------------------------------------------------
+
+CMKYGrayEncoder::CMKYGrayEncoder(Stream *strA):
+ FilterStream(strA) {
+ bufPtr = bufEnd = buf;
+ eof = gFalse;
+}
+
+CMKYGrayEncoder::~CMKYGrayEncoder() {
+ if (str->isEncoder())
+ delete str;
+}
+
+void CMKYGrayEncoder::reset() {
+ str->reset();
+ bufPtr = bufEnd = buf;
+ eof = gFalse;
+}
+
+GBool CMKYGrayEncoder::fillBuf() {
+ int c0, c1, c2, c3;
+ int i;
+
+ if (eof) {
+ return gFalse;
+ }
+ c0 = str->getChar();
+ c1 = str->getChar();
+ c2 = str->getChar();
+ c3 = str->getChar();
+ if (c3 == EOF) {
+ eof = gTrue;
+ return gFalse;
+ }
+ i = (3 * c0 + 6 * c1 + c2) / 10 + c3;
+ if (i > 255) i = 255;
+ bufPtr = bufEnd = buf;
+ *bufEnd++ = (char) i;
+ return gTrue;
+}
diff --git a/poppler/Stream.h b/poppler/Stream.h
index de72f98..ee03f4e 100644
--- a/poppler/Stream.h
+++ b/poppler/Stream.h
@@ -1141,4 +1141,33 @@ private:
GBool fillBuf();
};
+//------------------------------------------------------------------------
+// CMKYGrayEncoder
+//------------------------------------------------------------------------
+
+class CMKYGrayEncoder: public FilterStream {
+public:
+
+ CMKYGrayEncoder(Stream *strA);
+ virtual ~CMKYGrayEncoder();
+ virtual StreamKind getKind() { return strWeird; }
+ virtual void reset();
+ virtual int getChar()
+ { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
+ virtual int lookChar()
+ { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
+ virtual GooString *getPSFilter(int /*psLevel*/, char * /*indent*/) { return NULL; }
+ virtual GBool isBinary(GBool /*last = gTrue*/) { return gFalse; }
+ virtual GBool isEncoder() { return gTrue; }
+
+private:
+
+ char buf[2];
+ char *bufPtr;
+ char *bufEnd;
+ GBool eof;
+
+ GBool fillBuf();
+};
+
#endif
commit abba8140a9972197faaca96ec590af7dc9408fb0
Author: William Bader <williambader at hotmail.com>
Date: Fri Jun 24 22:38:33 2011 +0100
patch to make -level2sep and -level3sep write cmyk instead of rgb
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index ca7c5cd..25de8b8 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -3016,13 +3016,13 @@ GBool PSOutputDev::checkPageSlice(Page *page, double /*hDPI*/, double /*vDPI*/,
splashOut = new SplashOutputDev(splashModeMono8, 1, gFalse,
paperColor, gTrue, gFalse);
#if SPLASH_CMYK
- } else if (level == psLevel1Sep) {
+ } else if (level == psLevel1Sep || level == psLevel2Sep || level == psLevel3Sep) {
paperColor[0] = paperColor[1] = paperColor[2] = paperColor[3] = 0;
splashOut = new SplashOutputDev(splashModeCMYK8, 1, gFalse,
paperColor, gTrue, gFalse);
#else
- } else if (level == psLevel1Sep) {
- error(-1, "pdftops was built without CMYK support, level1sep needs it to work in this file");
+ } else if (level == psLevel1Sep || level == psLevel2Sep || level == psLevel3Sep) {
+ error(-1, "pdftops was built without CMYK support, levelnsep needs it to work in this file");
return gFalse;
#endif
} else {
@@ -3221,10 +3221,59 @@ GBool PSOutputDev::checkPageSlice(Page *page, double /*hDPI*/, double /*vDPI*/,
processColors |= psProcessBlack;
}
break;
- case psLevel2:
case psLevel2Sep:
- case psLevel3:
case psLevel3Sep:
+ obj.initNull();
+ str0 = new MemStream((char *)bitmap->getDataPtr(), 0, w * h * 4, &obj);
+ processColors |= psProcessCMYK;
+ writePS("/DeviceCMYK setcolorspace\n");
+ str = new RunLengthEncoder(str0);
+ writePS("<<\n /ImageType 1\n");
+ writePSFmt(" /Width {0:d}\n", bitmap->getWidth());
+ writePSFmt(" /Height {0:d}\n", bitmap->getHeight());
+ writePSFmt(" /ImageMatrix [{0:d} 0 0 {1:d} 0 {2:d}]\n", w, -h, h);
+ writePS(" /BitsPerComponent 8\n");
+ writePS(" /Decode [0 1 0 1 0 1 0 1]\n");
+ writePS(" /DataSource currentfile\n");
+ useBinary = globalParams->getPSBinary();
+ if (useBinary) {
+ /* nothing to do */;
+ } else if (globalParams->getPSASCIIHex()) {
+ writePS(" /ASCIIHexDecode filter\n");
+ } else {
+ writePS(" /ASCII85Decode filter\n");
+ }
+ writePS(" /RunLengthDecode filter\n");
+ writePS(">>\n");
+ if (useBinary) {
+ /* nothing to do */;
+ } else if (globalParams->getPSASCIIHex()) {
+ str = new ASCIIHexEncoder(str);
+ } else {
+ str = new ASCII85Encoder(str);
+ }
+ str->reset();
+ if (useBinary) {
+ int len = 0;
+ while (str->getChar() != EOF) {
+ len++;
+ }
+ str->reset();
+ writePSFmt("%%BeginData: {0:d} Binary Bytes\n", len+6+1);
+ }
+ writePS("image\n");
+ while ((c = str->getChar()) != EOF) {
+ writePSChar(c);
+ }
+ if (useBinary) {
+ writePS("\n%%EndData\n");
+ }
+ str->close();
+ delete str;
+ delete str0;
+ break;
+ case psLevel2:
+ case psLevel3:
writePS("/DeviceRGB setcolorspace\n");
writePS("<<\n /ImageType 1\n");
writePSFmt(" /Width {0:d}\n", bitmap->getWidth());
More information about the poppler
mailing list