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.
This commit is contained in:
Nicholas Nethercote 2014-08-17 18:53:50 -07:00
parent b06dc8d363
commit 48de7651ce

View File

@ -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) {