Created
July 11, 2023 12:08
-
-
Save antom/c5f33fd4b4fbc1b1c0dab312dedfc53a to your computer and use it in GitHub Desktop.
BMP Hex String Converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Source Image: https://pixeljoint.com/pixelart/34353.htm | |
* | |
* How to source hexStr data: | |
* - Download image. | |
* - Resave as `input.bmp` in suitable bitmap editor (e.g. Aseprite) if necessary. | |
* - Rename to `input.txt`. | |
* - Open up & format with `([^ \n]{2})([^ \n]{2})( |\n)` -> `\1 \2 ` replacement regex. | |
* - Trim off trailing space. | |
* - Profit?! | |
*/ | |
const hexStr = '42 4d 76 02 00 00 00 00 00 00 76 00 00 00 28 00 00 00 20 00 00 00 20 00 00 00 01 00 04 00 00 00 00 00 00 02 00 00 12 0b 00 00 12 0b 00 00 10 00 00 00 10 00 00 00 08 18 29 00 29 21 21 00 00 31 52 00 10 4a 5a 00 21 63 7b 00 42 39 39 00 63 5a 52 00 73 73 6b 00 18 73 9c 00 39 ad ce 00 8c 8c 84 00 d6 d6 c6 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 56 1a 76 7a 76 7a 76 76 66 66 67 7a a7 a7 66 77 65 1a 65 55 55 55 55 55 55 55 65 67 66 65 67 a7 75 17 51 11 51 11 11 11 11 11 51 76 55 66 67 aa 75 16 51 84 15 11 11 15 55 11 11 65 15 67 a6 77 65 17 51 98 21 51 11 51 11 51 11 55 11 76 6a 66 65 1a 51 12 83 15 55 13 32 15 11 11 11 66 67 65 75 17 51 11 34 21 11 38 43 15 11 11 11 56 76 66 a5 16 51 11 12 31 23 42 11 51 11 11 11 11 15 56 75 17 51 11 11 13 44 21 55 11 11 11 11 11 11 56 a5 16 51 11 11 24 98 35 55 11 11 11 11 11 55 67 a5 16 51 11 11 44 8b 92 65 51 11 11 11 11 56 76 75 16 51 11 14 82 39 94 56 55 11 11 11 11 11 15 75 16 51 11 38 25 52 48 25 75 51 11 11 11 11 56 65 16 51 11 49 11 56 52 55 67 55 11 11 11 11 15 65 16 51 11 24 11 15 76 66 56 a5 51 11 11 11 15 65 16 51 11 11 11 11 5a 76 75 6a 55 11 11 11 15 65 16 51 11 11 11 11 15 a7 67 66 a5 51 11 11 15 65 16 65 11 11 11 11 11 5b 76 a6 6b 55 11 11 15 65 17 51 11 11 11 11 11 15 b7 67 66 a5 51 11 15 65 17 67 65 11 11 11 11 11 5b 77 76 6b 55 11 15 65 1a 76 55 11 11 11 11 11 15 b7 7a 66 b5 51 15 65 1a 65 11 11 11 11 11 11 11 5b 77 a6 6b 55 15 75 17 65 51 11 11 11 11 11 11 15 b7 77 6a 75 55 65 1a 66 67 65 11 11 11 11 11 11 5b 66 66 b6 55 75 17 56 76 66 11 11 11 11 11 11 15 ba 77 aa 55 a5 16 66 a6 67 11 55 11 11 11 11 11 57 ba ab 55 75 16 77 6a 76 51 56 11 11 11 11 11 15 6a bb 55 65 17 aa 76 66 55 67 15 11 11 11 11 11 11 15 55 75 17 7a 76 56 66 76 56 55 55 55 55 55 55 55 56 a5 16 77 66 7a 7a a7 76 66 66 76 67 a7 67 a7 67 a5 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 15'; | |
const bmp = new File( | |
[ | |
new Uint8Array( | |
hexStr.split(' ').map( | |
x => parseInt(x, 16) | |
) | |
) | |
], | |
'output.bmp', | |
{type: 'image/bmp'} | |
); | |
const a = document.createElement('a'); | |
a.href = URL.createObjectURL(bmp); | |
a.download = bmp.name; | |
document.body.appendChild(a); | |
a.click(); | |
document.body.removeChild(a); | |
URL.revokeObjectURL(bmp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment