From 83cd530f45b8716b89997cc552106294491832b6 Mon Sep 17 00:00:00 2001 From: p01 Date: Mon, 28 Apr 2014 17:19:56 +0200 Subject: [PATCH] Cleaner putBinaryImageData --- src/display/canvas.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/display/canvas.js b/src/display/canvas.js index 355f7a354..350dfb955 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -512,24 +512,33 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { } else if (imgData.kind === ImageKind.RGBA_32BPP) { // RGBA, 32-bits per pixel. - for (i = 0; i < totalChunks; i++) { - thisChunkHeight = - (i < fullChunks) ? fullChunkHeight : partialChunkHeight; - elemsInThisChunk = imgData.width * thisChunkHeight * 4; - + j = 0; + elemsInThisChunk = width * fullChunkHeight * 4; + for (i = 0; i < fullChunks; i++) { dest.set(src.subarray(srcPos, 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) { // RGB, 24-bits per pixel. + thisChunkHeight = fullChunkHeight; + elemsInThisChunk = width * thisChunkHeight; for (i = 0; i < totalChunks; i++) { - thisChunkHeight = - (i < fullChunks) ? fullChunkHeight : partialChunkHeight; - elemsInThisChunk = imgData.width * thisChunkHeight * 3; + if (i >= fullChunks) { + thisChunkHeight =partialChunkHeight; + elemsInThisChunk = width * thisChunkHeight; + } + 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++];