-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_loadbmp.js
45 lines (35 loc) · 951 Bytes
/
demo_loadbmp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* A simple bmp file viewer
* Copyright (c) 2016 Crystalline Emerald
* This software is distrbuted under MIT license, see LICENSE for details
*/
load('bmp.js');
var bmpObj = decodeBMP(readFile("tests/js_logo.bmp"));
print(bmpObj);
screenWidth = (bmpObj && bmpObj.width) || 640;
screenHeight = (bmpObj && bmpObj.height) || 480;
function init() {
print("Init");
}
function setpix(x, y, red, green, blue) {
var offset = ((y*screenWidth)+x)<<2;
screen[offset] = red;
screen[offset+1] = green;
screen[offset+2] = blue;
screen[offset+3] = 255;
}
function update(events) {
if(!screenHeight) {
quit=1;
return;
}
for (var y=0; y<screenHeight; y++) {
for (var x=0; x<screenWidth; x++) {
var off = (y*screenWidth+x)*4;
var data = bmpObj.data;
setpix(x, y, data[off], data[off+1], data[off+2]);
}
}
}
function exit() {
print("Exit");
}