mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-08-02 04:17:24 +02:00
Use the convertBlackAndWhiteToRGBA helper with grayscale images in putBinaryImageData
This removes a little bit of code duplication, which only exist since the `src/display/canvas.js` code pre-dates the helper function by many years. *Note:* Given that `OffscreenCanvas` is enabled by default there's currently not a lot of test coverage for this code-path, hence the added browser-test.
This commit is contained in:
parent
ce08a803c4
commit
d1926fb179
@ -349,48 +349,16 @@ function putBinaryImageData(ctx, imgData) {
|
|||||||
// imgData.kind tells us which one this is.
|
// imgData.kind tells us which one this is.
|
||||||
if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
|
if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
|
||||||
// Grayscale, 1 bit per pixel (i.e. black-and-white).
|
// Grayscale, 1 bit per pixel (i.e. black-and-white).
|
||||||
const srcLength = src.byteLength;
|
|
||||||
const dest32 = new Uint32Array(dest.buffer, 0, dest.byteLength >> 2);
|
|
||||||
const dest32DataLength = dest32.length;
|
|
||||||
const fullSrcDiff = (width + 7) >> 3;
|
|
||||||
const white = 0xffffffff;
|
|
||||||
const black = FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff;
|
|
||||||
|
|
||||||
for (i = 0; i < totalChunks; i++) {
|
for (i = 0; i < totalChunks; i++) {
|
||||||
thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
|
thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
|
||||||
destPos = 0;
|
|
||||||
for (j = 0; j < thisChunkHeight; j++) {
|
|
||||||
const srcDiff = srcLength - srcPos;
|
|
||||||
let k = 0;
|
|
||||||
const kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
|
|
||||||
const kEndUnrolled = kEnd & ~7;
|
|
||||||
let mask = 0;
|
|
||||||
let srcByte = 0;
|
|
||||||
for (; k < kEndUnrolled; k += 8) {
|
|
||||||
srcByte = src[srcPos++];
|
|
||||||
dest32[destPos++] = srcByte & 128 ? white : black;
|
|
||||||
dest32[destPos++] = srcByte & 64 ? white : black;
|
|
||||||
dest32[destPos++] = srcByte & 32 ? white : black;
|
|
||||||
dest32[destPos++] = srcByte & 16 ? white : black;
|
|
||||||
dest32[destPos++] = srcByte & 8 ? white : black;
|
|
||||||
dest32[destPos++] = srcByte & 4 ? white : black;
|
|
||||||
dest32[destPos++] = srcByte & 2 ? white : black;
|
|
||||||
dest32[destPos++] = srcByte & 1 ? white : black;
|
|
||||||
}
|
|
||||||
for (; k < kEnd; k++) {
|
|
||||||
if (mask === 0) {
|
|
||||||
srcByte = src[srcPos++];
|
|
||||||
mask = 128;
|
|
||||||
}
|
|
||||||
|
|
||||||
dest32[destPos++] = srcByte & mask ? white : black;
|
({ srcPos } = convertBlackAndWhiteToRGBA({
|
||||||
mask >>= 1;
|
src,
|
||||||
}
|
srcPos,
|
||||||
}
|
dest,
|
||||||
// We ran out of input. Make all remaining pixels transparent.
|
width,
|
||||||
while (destPos < dest32DataLength) {
|
height: thisChunkHeight,
|
||||||
dest32[destPos++] = 0;
|
}));
|
||||||
}
|
|
||||||
|
|
||||||
ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
|
ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5389,6 +5389,14 @@
|
|||||||
"rounds": 1,
|
"rounds": 1,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "images_1bit_grayscale-disable-isOffscreenCanvasSupported",
|
||||||
|
"file": "pdfs/images_1bit_grayscale.pdf",
|
||||||
|
"md5": "e1c36a19563944891bd30cfc0199d07f",
|
||||||
|
"rounds": 1,
|
||||||
|
"type": "eq",
|
||||||
|
"isOffscreenCanvasSupported": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "html5checker",
|
"id": "html5checker",
|
||||||
"file": "pdfs/html5checker.pdf",
|
"file": "pdfs/html5checker.pdf",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user