Skip to content

Commit 1ffed06

Browse files
committedJan 25, 2019
test background setting
1 parent aa5d41e commit 1ffed06

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed
 

‎index.html

+31-8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
<button onclick="setImage('trontank_clean.six')">trontank</button>
3131
<button onclick="setImage('zx81_clean.six')">zx81</button>
3232
<br><br>
33-
<label><input type="checkbox" name="slow" id="slow" value="value">Simulate slow chunks</label>
33+
<label><input type="checkbox" name="slow" id="slow" value="value"> Simulate slow chunks</label>
34+
<br>
35+
<label><input type="color" name="fillColor" id="fillColor" value="#000000" onchange="redraw()"> background color</label>
3436
<br><br>
3537
<span id="stats"></span>
3638
<br><br>
@@ -40,6 +42,7 @@
4042
<script>
4143

4244
let drawHandle = null;
45+
let imgS = null;
4346

4447
/**
4548
* example how to get the img data
@@ -52,18 +55,39 @@
5255
canvas.height = img.height;
5356
// grab imagedata
5457
const target = ctx.getImageData(0, 0, img.width, img.height);
55-
img.toImageData(target.data, img.width, img.height);
58+
img.toImageData(
59+
// target metrics
60+
target.data, img.width, img.height,
61+
// dx, dy
62+
0, 0,
63+
// sx, sy, width, height
64+
0, 0, img.width, img.height,
65+
// fill color
66+
true, sixel.toRGBA8888(...hexColorToRGB(document.getElementById('fillColor').value)));
5667
ctx.putImageData(target, 0, 0);
5768
}
69+
70+
function hexColorToRGB(color) {
71+
const value = parseInt(color.slice(1), 16);
72+
console.log();
73+
return [
74+
(value >> 16) & 0xFF,
75+
(value >> 8) & 0xFF,
76+
value & 0xFF,
77+
255
78+
]
79+
}
80+
81+
function redraw() {
82+
if (imgS) drawImage(imgS);
83+
}
5884

5985
async function setImage(s) {
6086
clearInterval(drawHandle);
6187

62-
let fillColor = sixel.toRGBA8888(0, 0, 0, 255);
63-
if (s === 'cat2_clean.six') {
64-
fillColor = sixel.toRGBA8888(36, 143, 107, 255);
65-
}
66-
const img = new sixel.SixelImage(fillColor);
88+
// create image
89+
const img = new sixel.SixelImage();
90+
imgS = img;
6791

6892
// read in
6993
let start;
@@ -98,7 +122,6 @@
98122
}
99123

100124
console.log('read & conversion time', (new Date()) - start);
101-
window.imgS = img;
102125

103126
// output
104127
start = new Date();

0 commit comments

Comments
 (0)