mirror of
https://github.com/javl/image2cpp.git
synced 2026-07-28 04:05:35 +00:00
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:
+6
-5
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user