ã¿ã¤ãã«ã®éãã
Chrome1 ä¸ã§PNGç»åãã¯ãªãããã¼ãã«ã³ãã¼ããããã navigator.clipboard.read()
ã§èªã¿åã£ã¦å¾ãããç»åãã¼ã¿ã¯ãå
ç»åã®ã¢ã«ãã¡ãã£ãã«ããã¹ã¦255ï¼ä¸ééï¼ã®ã¨ãã« ã¢ã«ãã¡ãã£ãã«ããªãPNGãã¼ã¿ ã¨ãã¦æ±ããã¦ãã¾ãã
æ¤è¨¼
æºå
次ã®2æã®ç»åãç¨æããã
ç»åå |
ç»å |
説æ |
sample.png |
|
å
¨ãã¯ã»ã«ã®ã¢ã«ãã¡ãã£ãã«ã255 (ä¸éé) |
sample_2.png |
|
æåé¨åã®ã¿ã¢ã«ãã¡ãã£ãã«ã0 (éé) |
æ¤è¨¼ç¨ã®HTMLã¯æ¬¡ã®éãã
ã¯ãªãããã¼ãã«PNGç»åãæ ¼ç´ããã¦ãããã¨ãåæã¨ãã¦ããreadããã¿ã³ãæ¼ãã¨ä»¥ä¸ã®2ã¤ã®ãã¼ã¿ãhexå½¢å¼ã§ã³ã³ã½ã¼ã«ãã°ã«åºåããããã«ãã¦ããã
- PNGã·ã°ããã£
- PNG ã® IHDRãããã¼
詳細㯠PNG ã®ä»æ§ãåç
§ãããã¨ã
www.libpng.org
<html lang="ja">
<head>
<style>
</style>
</head>
<body>
<img src="./sample.png"/>
<img src="./sample_2.png"/>
<div>
<input type="button" id="read" value="read"/>
</div>
<script>
function createSliceTracker(array) {
let currentIndex = 0;
return {
slice: (count) => {
const slice = array.slice(currentIndex, currentIndex + count);
currentIndex += count;
return slice;
},
reset: () => {
currentIndex = 0;
},
hasMore: () => {
return currentIndex < array.length;
}
};
}
function uint8ArrayToHexArray(uint8Array) {
return Array.from(uint8Array)
.map(byte => byte.toString(16).padStart(2, '0'))
}
document.getElementById("read").addEventListener("click", async () => {
const cb = (await navigator.clipboard.read())[0];
const imageblob = await cb.getType("image/png");
const bytedata = new Uint8Array(await imageblob.arrayBuffer());
const hex = uint8ArrayToHexArray(bytedata);
const t = createSliceTracker(hex);
console.log('PNGã·ã°ããã£\t', t.slice(8).join(' '))
console.log('IHDRãã£ã³ã¯é·ã\t', t.slice(4).join(' '))
console.log('IHDRãã£ã³ã¯å\t', t.slice(4).join(' '), '(ASCIIã§"IHDR")')
console.log('å¹
\t', t.slice(4).join(' '))
console.log('é«ã\t',t.slice(4).join(' '))
console.log('ããã深度\t',t.slice(1).join(' '))
console.log('è²ã®ç¨®é¡\t',t.slice(1).join(' '))
console.log('å§ç¸®æ¹æ³\t',t.slice(1).join(' '))
console.log('ãã£ã«ã¿æ¹å¼\t',t.slice(1).join(' '))
console.log('ã¤ã³ã¿ã¼ã¬ã¼ã¹æ¹å¼\t',t.slice(1).join(' '))
console.log('CRC\t',t.slice(4).join(' '))
})
</script>
</body>
</html>
ãã©ã¦ã¶ä¸ã§ã¯ããã®ããã«2æã®ç»åã¨ãã¯ãªãããã¼ããèªã¿åããreadããã¿ã³ã表示ãããã
ãã¼ã¸ä¸ã®sample.png
ã®æ¹ãã³ãã¼ãã¦ãreadããã¿ã³ãæ¼ãã¨2ãã³ã³ã½ã¼ã«ã«ã¯æ¬¡ã®è¡¨ç¤ºãåºãã
PNGã·ã°ãã㣠89 50 4e 47 0d 0a 1a 0a
IHDRãã£ã³ã¯é·ã 00 00 00 0d
IHDRãã£ã³ã¯å 49 48 44 52 (ASCIIã§"IHDR")
å¹
00 00 00 96
é«ã 00 00 00 96
ããã深度 08
è²ã®ç¨®é¡ 02
å§ç¸®æ¹æ³ 00
ãã£ã«ã¿æ¹å¼ 00
ã¤ã³ã¿ã¼ã¬ã¼ã¹æ¹å¼ 00
CRC b3 63 e6 b5
è²ã®ç¨®é¡ã 02
ã§ããããã¯ã»ã«ã«ã¢ã«ãã¡ãã£ãã«ããªã R,G,B å½¢å¼ã®ç»åã§ãããã¨ã表ãã¦ããã
ããããã¯ãªãããã¼ããçµç±ããã«ç´æ¥ sample.png
ã®ç»åãã¡ã¤ã«èªä½ã解æããã¨ãå®éã«ã¯è²ã®ç¨®é¡ã¯06
ã§ããã¢ã«ãã¡ãã£ãã«ãå«ã¾ãã¦ãããã¨ãããã£ãã
åèï¼ ãã©ã¦ã¶ã¨åæ§ã«ããããèªã¿è¾¼ãã¹ã¯ãªããã¯æ¬¡ã®éãã node.js v23.6.0 ã§åä½ç¢ºèªæ¸ã¿ã
const fs = require('fs');
function createSliceTracker(array) {
let currentIndex = 0;
return {
slice: (count) => {
const slice = array.slice(currentIndex, currentIndex + count);
currentIndex += count;
return slice;
},
reset: () => {
currentIndex = 0;
},
hasMore: () => {
return currentIndex < array.length;
}
};
}
function uint8ArrayToHexArray(uint8Array) {
return Array.from(uint8Array)
.map(byte => byte.toString(16).padStart(2, '0'))
}
function uint8ArrayToHex(uint8Array) {
return uint8ArrayToHexArray(uint8Array).join('');
}
const buf = fs.readFileSync('./sample.png')
const bytedata = new Uint8Array(buf);
const hex = uint8ArrayToHexArray(bytedata);
const t = createSliceTracker(hex);
console.log('PNGã·ã°ããã£\t', t.slice(8).join(' '))
console.log('IHDRãã£ã³ã¯é·ã\t', t.slice(4).join(' '))
console.log('IHDRãã£ã³ã¯å\t', t.slice(4).join(' '), '(ASCIIã§"IHDR")')
console.log('å¹
\t', t.slice(4).join(' '))
console.log('é«ã\t',t.slice(4).join(' '))
console.log('ããã深度\t',t.slice(1).join(' '))
console.log('è²ã®ç¨®é¡\t',t.slice(1).join(' '))
console.log('å§ç¸®æ¹æ³\t',t.slice(1).join(' '))
console.log('ãã£ã«ã¿æ¹å¼\t',t.slice(1).join(' '))
console.log('ã¤ã³ã¿ã¼ã¬ã¼ã¹æ¹å¼\t',t.slice(1).join(' '))
console.log('CRC\t',t.slice(4).join(' '))
ä¸æ¹ãã¢ã«ãã¡ãã£ãã«ã255以å¤ã®ãã¯ã»ã«ãå«ã sample_2.png
ãã³ãã¼ãã¦ãreadããã¿ã³ãæ¼ãã¨ãè²ã®ç¨®é¡ã¯06
ã¨ãã¦èªã¿åããããã¨ã確èªããã
PNGã·ã°ãã㣠89 50 4e 47 0d 0a 1a 0a
IHDRãã£ã³ã¯é·ã 00 00 00 0d
IHDRãã£ã³ã¯å 49 48 44 52 (ASCIIã§"IHDR")
å¹
00 00 00 96
é«ã 00 00 00 96
ããã深度 08
è²ã®ç¨®é¡ 06
å§ç¸®æ¹æ³ 00
ãã£ã«ã¿æ¹å¼ 00
ã¤ã³ã¿ã¼ã¬ã¼ã¹æ¹å¼ 00
CRC 3c 01 71 e2
Firefox3 ã§ã¯ãã©ã¡ãã®ç»åãè²ã®ç¨®é¡ã¯ 06
ã¨ãã¦èªã¿åãããã
端æ«ã®ç»åãã¥ã¼ã¢çã§ã³ãã¼ãããã©ã¦ã¶ã§èªã¿åã£ãå ´å
è²ã®ç¨®é¡ã¯ 06
ã¨ãã¦èªã¿åãããã
æ¤è¨¼çµæããæ¨æ¸¬ããããã¨
- Chromeä¸ã§ç»åãã³ãã¼ããå ´å
- å
¨ãã¯ã»ã«ã®ã¢ã«ãã¡ãã£ãã«ã255ã®å ´åãã¯ãªãããã¼ãä¸ã®ãã¼ã¿ã¯ã¢ã«ãã¡ãã£ãã«ãç¡ããªãã
- ã¢ã«ãã¡ãã£ãã«ã255以å¤ã®ãã¯ã»ã«ãå«ãå ´åãã¯ãªãããã¼ãä¸ã®ãã¼ã¿ã«ã¯ã¢ã«ãã¡ãã£ãã«ãå«ã¾ãããï¼å
ç»åã¨åããã¤ããªã«ãªãï¼
- Firefoxä¸ãã端æ«ã®ç»åãã¥ã¼ã¢çã§ç»åãã³ãã¼ããå ´å
- å
ç»åã¨åããã¤ããªã«ãªã
ã¢ã«ãã¡ãã£ãã«ã255ã§ããã°ãRGBã®3è²ã§æ±ã£ã¦ãä½ãåé¡ããªããããã¡ã¢ãªæ¶è²»ãæããå¦çã®ä¸ç°ã§ãã®ãããªå¦çãããã¦ããã®ãããããªãã