[Pkg-javascript-commits] [pdf.js] 234/246: Apply the GRAYSCALE_1BPP optimization when `needsDecode` is set.
David Prévot
taffit at moszumanska.debian.org
Sun Sep 7 15:36:44 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository pdf.js.
commit 48de7651cee7b240de267e4491186f39eb64f4cd
Author: Nicholas Nethercote <nnethercote at mozilla.com>
Date: Sun Aug 17 18:53:50 2014 -0700
Apply the GRAYSCALE_1BPP optimization when `needsDecode` is set.
The scanned, black-and-white document at
https://bugzilla.mozilla.org/show_bug.cgi?id=835380 doesn't benefit from
the critical GRAYSCALE_1BPP optimization because the optimization is
skipped if `needsDecode` is set.
This change addresses that, and reduces both rendering time and memory
usage for that document by almost 10x.
---
src/core/image.js | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/src/core/image.js b/src/core/image.js
index fbcce33..ec01437 100644
--- a/src/core/image.js
+++ b/src/core/image.js
@@ -14,8 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-/* globals ColorSpace, DecodeStream, error, info, isArray, ImageKind, isStream,
- JpegStream, JpxImage, Name, Promise, Stream, warn */
+/* globals assert, ColorSpace, DecodeStream, error, info, isArray, ImageKind,
+ isStream, JpegStream, JpxImage, Name, Promise, Stream, warn */
'use strict';
@@ -531,10 +531,11 @@ var PDFImage = (function PDFImageClosure() {
var kind;
if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
kind = ImageKind.GRAYSCALE_1BPP;
- } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8) {
+ } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
+ !this.needsDecode) {
kind = ImageKind.RGB_24BPP;
}
- if (kind && !this.smask && !this.mask && !this.needsDecode &&
+ if (kind && !this.smask && !this.mask &&
drawWidth === originalWidth && drawHeight === originalHeight) {
imgData.kind = kind;
@@ -551,6 +552,14 @@ var PDFImage = (function PDFImageClosure() {
newArray.set(imgArray);
imgData.data = newArray;
}
+ if (this.needsDecode) {
+ // Invert the buffer (which must be grayscale if we reached here).
+ assert(kind === ImageKind.GRAYSCALE_1BPP);
+ var buffer = imgData.data;
+ for (var i = 0, ii = buffer.length; i < ii; i++) {
+ buffer[i] ^= 0xff;
+ }
+ }
return imgData;
}
if (this.image instanceof JpegStream && !this.smask && !this.mask) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git
More information about the Pkg-javascript-commits
mailing list