From dd14b3051efe843ef757ae1b0ab27a2e22d2f977 Mon Sep 17 00:00:00 2001 From: sbarman Date: Fri, 8 Jun 2012 22:42:56 -0700 Subject: [PATCH 1/5] Fix for issue #1796 --- src/evaluator.js | 6 ++++-- src/image.js | 53 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/evaluator.js b/src/evaluator.js index 8849a994a..059ff113f 100644 --- a/src/evaluator.js +++ b/src/evaluator.js @@ -226,8 +226,10 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { insertDependency([objId]); args = [objId, w, h]; - var softMask = dict.get('SMask', 'IM') || false; - if (!softMask && image instanceof JpegStream && + var softMask = dict.get('SMask', 'SM') || false; + var mask = dict.get('Mask') || false; + + if (!softMask && !mask && image instanceof JpegStream && image.isNativelySupported(xref, resources)) { // These JPEGs don't need any more processing so we can just send it. fn = 'paintJpegXObject'; diff --git a/src/image.js b/src/image.js index c8c19f9e5..aa241dab9 100644 --- a/src/image.js +++ b/src/image.js @@ -1,4 +1,4 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ + /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ 'use strict'; @@ -33,7 +33,7 @@ var PDFImage = (function PDFImageClosure() { // Clamp the value to the range return value < 0 ? 0 : value > max ? max : value; } - function PDFImage(xref, res, image, inline, smask) { + function PDFImage(xref, res, image, inline, smask, mask) { this.image = image; if (image.getParams) { // JPX/JPEG2000 streams directly contain bits per component @@ -94,12 +94,11 @@ var PDFImage = (function PDFImageClosure() { } } - var mask = dict.get('Mask'); - - if (mask) { - TODO('masked images'); - } else if (smask) { + + if (smask) { this.smask = new PDFImage(xref, res, smask, false); + } else if (mask) { + this.mask = new PDFImage(xref, res, mask, false); } } /** @@ -110,21 +109,35 @@ var PDFImage = (function PDFImageClosure() { res, image, inline) { var imageDataPromise = new Promise(); var smaskPromise = new Promise(); + var maskPromise = new Promise(); // The image data and smask data may not be ready yet, wait till both are // resolved. - Promise.all([imageDataPromise, smaskPromise]).then(function(results) { - var imageData = results[0], smaskData = results[1]; - var image = new PDFImage(xref, res, imageData, inline, smaskData); + Promise.all([imageDataPromise, smaskPromise, maskPromise]).then( + function(results) { + var imageData = results[0], smaskData = results[1], maskData = results[2]; + var image = new PDFImage(xref, res, imageData, inline, smaskData, + maskData); callback(image); }); handleImageData(handler, xref, res, image, imageDataPromise); var smask = image.dict.get('SMask'); - if (smask) + var mask = image.dict.get('Mask'); + + if (smask) { handleImageData(handler, xref, res, smask, smaskPromise); - else + } else { smaskPromise.resolve(null); + if (mask && isStream(mask)) { + handleImageData(handler, xref, res, mask, maskPromise); + } else if (mask) { + TODO('handle color key masking') + maskPromise.resolve(null); + } else { + maskPromise.resolve(null); + } + } }; /** @@ -268,6 +281,7 @@ var PDFImage = (function PDFImageClosure() { }, getOpacity: function PDFImage_getOpacity(width, height) { var smask = this.smask; + var mask = this.mask; var originalWidth = this.width; var originalHeight = this.height; var buf; @@ -278,7 +292,20 @@ var PDFImage = (function PDFImageClosure() { buf = new Uint8Array(sw * sh); smask.fillGrayBuffer(buf); if (sw != width || sh != height) - buf = PDFImage.resize(buf, smask.bps, 1, sw, sh, width, height); + buf = PDFImage.resize(buf, smask.bpc, 1, sw, sh, width, height); + } else if (mask) { + var sw = mask.width; + var sh = mask.height; + buf = new Uint8Array(sw * sh); + mask.numComps = 1; + mask.fillGrayBuffer(buf); + + // Need to invert values in buffer + for (var i = 0, ii = sw * sh; i < ii; ++i) + buf[i] = 255 - buf[i] + + if (sw != width || sh != height) + buf = PDFImage.resize(buf, mask.bpc, 1, sw, sh, width, height); } else { buf = new Uint8Array(width * height); for (var i = 0, ii = width * height; i < ii; ++i) From c900dfeced5f1da4934a9f35b9f6d73e9a5064b4 Mon Sep 17 00:00:00 2001 From: sbarman Date: Mon, 11 Jun 2012 14:57:58 -0700 Subject: [PATCH 2/5] Updated lint errors --- src/image.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/image.js b/src/image.js index aa241dab9..4e403ca12 100644 --- a/src/image.js +++ b/src/image.js @@ -94,7 +94,6 @@ var PDFImage = (function PDFImageClosure() { } } - if (smask) { this.smask = new PDFImage(xref, res, smask, false); } else if (mask) { @@ -115,7 +114,7 @@ var PDFImage = (function PDFImageClosure() { Promise.all([imageDataPromise, smaskPromise, maskPromise]).then( function(results) { var imageData = results[0], smaskData = results[1], maskData = results[2]; - var image = new PDFImage(xref, res, imageData, inline, smaskData, + var image = new PDFImage(xref, res, imageData, inline, smaskData, maskData); callback(image); }); @@ -132,7 +131,7 @@ var PDFImage = (function PDFImageClosure() { if (mask && isStream(mask)) { handleImageData(handler, xref, res, mask, maskPromise); } else if (mask) { - TODO('handle color key masking') + TODO('handle color key masking'); maskPromise.resolve(null); } else { maskPromise.resolve(null); @@ -302,7 +301,7 @@ var PDFImage = (function PDFImageClosure() { // Need to invert values in buffer for (var i = 0, ii = sw * sh; i < ii; ++i) - buf[i] = 255 - buf[i] + buf[i] = 255 - buf[i]; if (sw != width || sh != height) buf = PDFImage.resize(buf, mask.bpc, 1, sw, sh, width, height); From 7c4829779445babd1bd7ccddfbe4070f2acf88d5 Mon Sep 17 00:00:00 2001 From: sbarman Date: Mon, 11 Jun 2012 15:05:06 -0700 Subject: [PATCH 3/5] Adding call to resolve unfulfilled promise --- src/image.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/image.js b/src/image.js index 4e403ca12..5f14868b7 100644 --- a/src/image.js +++ b/src/image.js @@ -126,6 +126,7 @@ var PDFImage = (function PDFImageClosure() { if (smask) { handleImageData(handler, xref, res, smask, smaskPromise); + maskPromise.resolve(null); } else { smaskPromise.resolve(null); if (mask && isStream(mask)) { From 7ec483a7fa08d38552e8d0931aaaf220e8aad0c4 Mon Sep 17 00:00:00 2001 From: sbarman Date: Wed, 13 Jun 2012 10:29:02 -0700 Subject: [PATCH 4/5] Added new test pdf to manifest --- test/pdfs/issue1796.pdf.link | 1 + test/test_manifest.json | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 test/pdfs/issue1796.pdf.link diff --git a/test/pdfs/issue1796.pdf.link b/test/pdfs/issue1796.pdf.link new file mode 100644 index 000000000..b6470b421 --- /dev/null +++ b/test/pdfs/issue1796.pdf.link @@ -0,0 +1 @@ +http://www.maxims6n.bget.ru/book3/viewer/t4.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index 25d2a2080..32bde988e 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -608,5 +608,13 @@ "md5": "cbc1988e4803f647fa83467a85f0e231", "rounds": 1, "type": "eq" + }, + { "id": "issue1796", + "file": "pdfs/issue1796.pdf", + "md5": "9b9b60dc2a4cc3ea05932785d71304fe", + "rounds": 1, + "pageLimit": 2, + "link": true, + "type": "eq" } ] From 5cbe3a517e1dc3e38d1e4a16acff2a6df0480b6e Mon Sep 17 00:00:00 2001 From: sbarman Date: Wed, 13 Jun 2012 16:09:57 -0700 Subject: [PATCH 5/5] Undo removal of Mode line --- src/image.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/image.js b/src/image.js index 5f14868b7..3495483e7 100644 --- a/src/image.js +++ b/src/image.js @@ -1,4 +1,4 @@ - +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ 'use strict';