-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewer.js
More file actions
43 lines (34 loc) · 1.35 KB
/
Copy pathviewer.js
File metadata and controls
43 lines (34 loc) · 1.35 KB
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
import { BitmapStructure } from "./bitmapStructure.js";
import { getData, rasterDataToRgb, removePadding } from "./hexParser.js";
const inputtedImage = document.getElementById("imageInput");
let imageData;
let fileReader = new FileReader();
inputtedImage.addEventListener("change", (event)=>{
let file = event.target.files[0];
fileReader.readAsArrayBuffer(file);
fileReader.onload = (event)=>{
let arrayBuffer = event.target.result;
let byteArray = new Uint8Array(arrayBuffer);
let hexString = '';
for (let byte of byteArray) {
hexString += byte.toString(16).padStart(2, "0");
}
imageData = getData(hexString);
}
});
fileReader.onloadend = ()=>{
const canvas = document.getElementById("viewer");
const ctx = canvas.getContext("2d");
canvas.width = imageData.Width.data;
canvas.height = imageData.Height.data;
let pixelData = rasterDataToRgb(removePadding(BitmapStructure.RasterData));
let rowOffset = canvas.height;
pixelData.forEach((pixel, index) => {
ctx.fillStyle = "#" + pixel;
if((index % canvas.width) == 0){
rowOffset--;
}
ctx.fillRect(index % canvas.width, rowOffset, 1, 1);
});
document.getElementById("hexData").innerText = imageData.RasterData;
}