Skip to content

Instantly share code, notes, and snippets.

@katai5plate
Last active March 26, 2021 07:42
Show Gist options
  • Save katai5plate/9bf502076a63112e75155a379c6f846f to your computer and use it in GitHub Desktop.
Save katai5plate/9bf502076a63112e75155a379c6f846f to your computer and use it in GitHub Desktop.
スケッチ
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