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
This commit is contained in:
javl
2018-10-08 14:50:47 +02:00
parent b35bb67725
commit ee872fd590
+6 -5
View File
@@ -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;
}