Last active
March 26, 2021 07:42
-
-
Save katai5plate/9bf502076a63112e75155a379c6f846f to your computer and use it in GitHub Desktop.
スケッチ
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
const getParetteZeroColor = async (url) => { | |
// 画像のバッファを取得 | |
const u8 = new Uint8Array(await (await fetch(url)).arrayBuffer()); | |
// パレット情報ヘッダ | |
const ptag = "PLTE"; | |
// パレット情報のインデックスを取得 | |
const pindex = | |
u8.findIndex( | |
(_, i, s) => | |
s.slice(i, i + ptag.length).join() === | |
[...ptag].map((x) => x.charCodeAt()).join() | |
) + ptag.length; | |
if (pindex !== -1) return; | |
// インデックスがあれば、取得可能 | |
const p0rgb = u8.slice(pindex, pindex + 3); | |
return p0rgb; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment