Browse Source

Cleaner putBinaryImageData

p01 11 years ago
parent
commit
83cd530f45
  1. 29
      src/display/canvas.js

29
src/display/canvas.js

@ -512,24 +512,33 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
} else if (imgData.kind === ImageKind.RGBA_32BPP) { } else if (imgData.kind === ImageKind.RGBA_32BPP) {
// RGBA, 32-bits per pixel. // RGBA, 32-bits per pixel.
for (i = 0; i < totalChunks; i++) { j = 0;
thisChunkHeight = elemsInThisChunk = width * fullChunkHeight * 4;
(i < fullChunks) ? fullChunkHeight : partialChunkHeight; for (i = 0; i < fullChunks; i++) {
elemsInThisChunk = imgData.width * thisChunkHeight * 4;
dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk)); dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
srcPos += elemsInThisChunk; srcPos += elemsInThisChunk;
ctx.putImageData(chunkImgData, 0, i * fullChunkHeight); ctx.putImageData(chunkImgData, 0, j);
j += fullChunkHeight;
}
if (i < totalChunks) {
elemsInThisChunk = width * partialChunkHeight * 4;
dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
ctx.putImageData(chunkImgData, 0, j);
} }
} else if (imgData.kind === ImageKind.RGB_24BPP) { } else if (imgData.kind === ImageKind.RGB_24BPP) {
// RGB, 24-bits per pixel. // RGB, 24-bits per pixel.
thisChunkHeight = fullChunkHeight;
elemsInThisChunk = width * thisChunkHeight;
for (i = 0; i < totalChunks; i++) { for (i = 0; i < totalChunks; i++) {
thisChunkHeight = if (i >= fullChunks) {
(i < fullChunks) ? fullChunkHeight : partialChunkHeight; thisChunkHeight =partialChunkHeight;
elemsInThisChunk = imgData.width * thisChunkHeight * 3; elemsInThisChunk = width * thisChunkHeight;
}
destPos = 0; destPos = 0;
for (j = 0; j < elemsInThisChunk; j += 3) { for (j = elemsInThisChunk; j--;) {
dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++];
dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++];
dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++];

Loading…
Cancel
Save