-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhexParser.js
More file actions
53 lines (43 loc) · 1.77 KB
/
Copy pathhexParser.js
File metadata and controls
53 lines (43 loc) · 1.77 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
44
45
46
47
48
49
50
51
52
53
import { BitmapStructure } from "./bitmapStructure.js";
import { convertToBigEndian, getRasterData } from "./helper.js";
export function getData(rawHexData){
let keys = Object.keys(BitmapStructure);
console.log("rawHexData: " + rawHexData);
keys.forEach((attribute)=>{
if(attribute != "RasterData"){
let offset = BitmapStructure[attribute].offset * 2;
let size = BitmapStructure[attribute].size * 2;
let dataLittleEndian = rawHexData.substring(offset, offset + size);
let dataBigEndian = ("0x" + convertToBigEndian(dataLittleEndian));
BitmapStructure[attribute].data = dataBigEndian;
console.log(attribute + ": " + BitmapStructure[attribute].data);
}
});
BitmapStructure["RasterData"] = getRasterData(rawHexData, BitmapStructure.DataOffset.data, BitmapStructure.ImageSize.data);
console.log("RasterData: " + BitmapStructure.RasterData);
return BitmapStructure
}
export function rasterDataToRgb(rasterData){
let splitIntoColours = rasterData.match(/.{1,6}/g);
splitIntoColours.forEach((pixel, index)=>{
splitIntoColours[index] = convertToBigEndian(pixel);
});
return splitIntoColours;
}
export function removePadding(rawHex){
let width = BitmapStructure.Width.data;
let height = BitmapStructure.Height.data;
let rowLength = findRowLength(width * 3) * 2;
let dataWithoutPadding = ""
for(let i = 0; i < height; i++){
let offset = i*rowLength;
dataWithoutPadding += rawHex.substring(offset, (offset + width * 6));
}
return dataWithoutPadding;
}
function findRowLength(rowLength){
while((rowLength % 4) != 0){
rowLength++;
}
return rowLength;
}