From ee872fd590f8983cca7ac5acf88557afb4ef4246 Mon Sep 17 00:00:00 2001 From: javl Date: Mon, 8 Oct 2018 14:50:47 +0200 Subject: [PATCH] Fixes problem with small images This should finally fix the problem with small images getting distorted. Problem appears to have been that with some sizes (basically everything that wasn't divisible by 8) the last part of a row would be merged with the first part of the last row, creating an offset that increased with every next row. This update pads every last byte of a row with zeros to fill out to 8 bits. Closing #21 --- index.html | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 6680c6e..28197ee 100644 --- a/index.html +++ b/index.html @@ -778,11 +778,12 @@ } byteIndex--; - // If we are at the last set, fill up our byte to 8 bits - if (index == imageData.data.length-4){ - for(var i=byteIndex;i>-1;i--){ - number += Math.pow(2, i); - } + // if this was the last pixel of a row or the last pixel of the + // image, fill up the rest of our byte with zeros so it always contains 8 bits + if ((index != 0 && (((index/4)+1)%(canvas.width)) == 0 ) || (index == imageData.data.length-4)) { + // for(var i=byteIndex;i>-1;i--){ + // number += Math.pow(2, i); + // } byteIndex = -1; }