@marcan42
Then what?
Custom animation format
Use <canvas>
to draw frames on the screen
Supported by all modern browsers
But how do we package up the frames?
JPEG or PNG frames inside an uncompressed ZIP archive
Not a new idea (e.g. Android boot animations are JPEGs in a ZIP)
They start at the end
HTML5 provides ways of handling binary data in JS
ArrayBuffer
to store the ZIP fileUint8Array
to access byte rangesDataView
to parse ZIP fields (Uint16, Uint32, etc.)Blob
to represent embedded PNG/JPEG filesURL
to map them to a virtual URLImage
to load them<canvas>
to display themWe don't want to wait for the whole ZIP to load before starting playback
HTML5 would support progressive/partial XHR
Only Firefox does (nonstandard extension)
Use the Range
HTTP header to load the ZIP one chunk at a time
(and speed it up by queuing two chunks to be loaded simultaneously)
Not as ideal, but it works well
Pixiv's ugoira player library
<canvas>
Alongside the ZIP file, metadata provides frame durations
{
mime_type: "image/jpeg",
frames: [
{file: "000001.jpg", delay: 40},
{file: "000002.jpg", delay: 40},
{file: "000003.jpg", delay: 40},
// ...
]
}
Currently delivered out of band, in the page HTML
var options = {
canvas: document.getElementById("katakata"),
source: "img/katakata.zip",
metadata: katakata_meta,
chunkSize: 300000,
loop: true,
autoStart: true,
autosize: true
}
var p = new ZipImagePlayer(options);
「動くチルノちゃん」/「モフモフ」
pixiv.net/i/44524589
Browsers...
ArrayBuffer
Range
headers
ArrayBuffer.slice()
Uint8Array.subarray()
(slower)data:
URLs (very slow)