Skip to content

Commit

Permalink
Merge pull request mozilla#5204 from nnethercote/needsDecode
Browse files Browse the repository at this point in the history
Apply the GRAYSCALE_1BPP optimization when `needsDecode` is set.
  • Loading branch information
yurydelendik committed Aug 19, 2014
2 parents 0dbac15 + 48de765 commit 6969ed4
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/core/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;

Expand All @@ -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) {
Expand Down

0 comments on commit 6969ed4

Please sign in to comment.