|
30 | 30 | <button onclick="setImage('trontank_clean.six')">trontank</button>
|
31 | 31 | <button onclick="setImage('zx81_clean.six')">zx81</button>
|
32 | 32 | <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> |
34 | 36 | <br><br>
|
35 | 37 | <span id="stats"></span>
|
36 | 38 | <br><br>
|
|
40 | 42 | <script>
|
41 | 43 |
|
42 | 44 | let drawHandle = null;
|
| 45 | +let imgS = null; |
43 | 46 |
|
44 | 47 | /**
|
45 | 48 | * example how to get the img data
|
|
52 | 55 | canvas.height = img.height;
|
53 | 56 | // grab imagedata
|
54 | 57 | 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))); |
56 | 67 | ctx.putImageData(target, 0, 0);
|
57 | 68 | }
|
| 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 | +} |
58 | 84 |
|
59 | 85 | async function setImage(s) {
|
60 | 86 | clearInterval(drawHandle);
|
61 | 87 |
|
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; |
67 | 91 |
|
68 | 92 | // read in
|
69 | 93 | let start;
|
|
98 | 122 | }
|
99 | 123 |
|
100 | 124 | console.log('read & conversion time', (new Date()) - start);
|
101 |
| - window.imgS = img; |
102 | 125 |
|
103 | 126 | // output
|
104 | 127 | start = new Date();
|
|
0 commit comments