I've been trying to dump a bmp file in to an array as follows:
an array of 32 arrays of 32 arrays of 4 byte values, but have not been able to make it work, I would appreciate any help, this is what I've been trying:
The first 54 bytes have header information:
var img = new Array();
function rcolor(x){
return (TONES*x/256);
}
function readbmp(myfile){
try{
var i=0;
var k=0;
var x=0;
var flag=0;
var px = new Array();
px[0] = 0;
px[1] = 0;
px[2] = 0;
px[3] = 0;
var line=new Array();
if (myfile.length==4096){
flag=4;
}
else {
flag =3;
}
for (var byte in myfile){
z= myfile[byte];
console.log(z);
k+=1;
if(k==1){
px[0]=myfile[byte];
}
if(k==2){
px[1]=myfile[byte];
}
if(k==3){
px[2]=myfile[byte];
}
if(k==4){
px[3]=myfile[byte];
}
if(k==flag){
k=0;
line.push(px);
x+=1;
if(x==32){
img.push(line);
line.splice(0, line.length);
x=0;
}
}
}
console.log(img);
return x;
}
catch(err){
return 0;
}
}
var image = require("fs").readFile("GIF/wizardcity00001.bmp", "binary");
image = image.substr(54,image.length);
readbmp(image);
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hi,
I've been trying to dump a bmp file in to an array as follows:
an array of 32 arrays of 32 arrays of 4 byte values, but have not been able to make it work, I would appreciate any help, this is what I've been trying:
The first 54 bytes have header information:
I would really appreciate any help.
Bests