From 493853031b4ad6d372c36555819afa7d3ebdbb23 Mon Sep 17 00:00:00 2001 From: jazzchipc Date: Sun, 4 Dec 2016 19:44:12 +0000 Subject: [PATCH] Fixes issue #6071. Corrects readBlockTiff() case for 1-bit depth and 1 color TIFF images incorporated in the PDF. Adds reference test for PDF used to fix this issue. --- src/core/stream.js | 17 +++++++++-------- test/pdfs/issue6071.pdf.link | 1 + test/test_manifest.json | 7 +++++++ 3 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 test/pdfs/issue6071.pdf.link diff --git a/src/core/stream.js b/src/core/stream.js index 9d8f14850..a7da21c1e 100644 --- a/src/core/stream.js +++ b/src/core/stream.js @@ -739,15 +739,16 @@ var PredictorStream = (function PredictorStreamClosure() { var pos = bufferLength; var i; - if (bits === 1) { + if (bits === 1 && colors === 1) { + // Optimized version of the loop in the "else"-branch + // for 1 bit-per-component and 1 color TIFF images. for (i = 0; i < rowBytes; ++i) { - var c = rawBytes[i]; - inbuf = (inbuf << 8) | c; - // bitwise addition is exclusive or - // first shift inbuf and then add - buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF; - // truncate inbuf (assumes colors < 16) - inbuf &= 0xFFFF; + var c = rawBytes[i] ^ inbuf; + c ^= c >> 1; + c ^= c >> 2; + c ^= c >> 4; + inbuf = (c & 1) << 7; + buffer[pos++] = c; } } else if (bits === 8) { for (i = 0; i < colors; ++i) { diff --git a/test/pdfs/issue6071.pdf.link b/test/pdfs/issue6071.pdf.link new file mode 100644 index 000000000..2e2cd690c --- /dev/null +++ b/test/pdfs/issue6071.pdf.link @@ -0,0 +1 @@ +https://web.archive.org/web/20170107214304/https://www.pdf-archive.com/2017/01/07/issue6071/issue6071.pdf \ No newline at end of file diff --git a/test/test_manifest.json b/test/test_manifest.json index 5d669044e..55c4e0c24 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -1146,6 +1146,13 @@ "lastPage": 2, "type": "eq" }, + { "id": "issue6071", + "file": "pdfs/issue6071.pdf", + "md5": "2e08526d8e7c9ba4269fc12ef488d3eb", + "rounds": 1, + "link": true, + "type": "eq" + }, { "id": "issue1905", "file": "pdfs/issue1905.pdf", "md5": "b1bbd72ca6522ae1502aa26320f81994",