--!movie
global $
----------------------------------------
-- converts filmstrip image with alpha channel to animated WebP with alpha channel
----------------------------------------
on startMovie
-- CONFIG
DUR = 50 -- 50 ms = 20 fps
-- libs
$.import("console").show()
-- load strip BMP (with alpha channel and 29 frames of 100x100px) into image
m = new(#bitmap)
m.importFileInto($.PATH&"web_heart_strip_32bit_alpha.bmp", [#trimWhiteSpace: FALSE])
webHeart = m.image
webHeartMask = webHeart.extractAlpha().createMask()
-- create an instance of the AWEBP lib
awebp = $.include($.PATH&"awebp.ls").new()
ms = the milliseconds
-- initialize AWEBP (i.e. start creation of new WebP file)
awebp.init(0) -- 0 = loop forever
-- add frames in a loop
w = 100
h = 100
r = rect(0, 0, w, h)
frameImg = image(w, h, 32)
frameImg.setAlpha(0)
frameImg.useAlpha = 1
cnt = webHeart.width / w
repeat with i = 1 to cnt
-- extract next frame from strip
frameImg.fill(frameImg.rect, rgb(255,255,255))
frameImg.setAlpha(0)
frameImg.copyPixels(webHeart, r, r.offset((i-1)*w, 0), [#maskImage:webHeartMask])
-- add frame
awebp.addFrame(frameImg, DUR)
end repeat
ms = the milliseconds-ms
-- save the WebP file
awebp.writeFile($.PATH&"animation_web_heart.webp")
out("Done. Animated WebP file was generated in "&ms&" milliseconds.")
end