mirror of
https://github.com/GuerillaStudio/souvenir.git
synced 2025-01-20 21:50:22 +00:00
feat(encoding): add boomerang effect to encoder
This commit is contained in:
parent
69ccbc780d
commit
0ab14263ac
4 changed files with 12 additions and 7 deletions
|
@ -22,7 +22,7 @@ class OutputStream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function write (imageWidth, imageHeight, delay, indexedColorImages) {
|
export function write (imageWidth, imageHeight, delay, indexedColorImages, boomerangEffect = false) {
|
||||||
const emitter = new EventEmitter()
|
const emitter = new EventEmitter()
|
||||||
|
|
||||||
// yup, this is the browser nextTick implementation we are waiting for :facepalm:
|
// yup, this is the browser nextTick implementation we are waiting for :facepalm:
|
||||||
|
@ -41,7 +41,11 @@ export function write (imageWidth, imageHeight, delay, indexedColorImages) {
|
||||||
|
|
||||||
writer.writeLoopControlInfo(0)
|
writer.writeLoopControlInfo(0)
|
||||||
|
|
||||||
indexedColorImages.forEach((indexedColorImage, index, { length }) => {
|
const frames = boomerangEffect
|
||||||
|
? [...indexedColorImages, ...indexedColorImages.slice(1, indexedColorImages.length - 1).reverse()]
|
||||||
|
: indexedColorImages
|
||||||
|
|
||||||
|
frames.forEach((indexedColorImage, index, { length }) => {
|
||||||
writer.writeTableBasedImageWithGraphicControl(indexedColorImage, { delayTimeInMS: delay })
|
writer.writeTableBasedImageWithGraphicControl(indexedColorImage, { delayTimeInMS: delay })
|
||||||
emitter.emit('progress', calcProgress(0, 0.99, (index + 1) / length))
|
emitter.emit('progress', calcProgress(0, 0.99, (index + 1) / length))
|
||||||
})
|
})
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { promisesProgress, calcProgress } from '/services/util.js'
|
||||||
|
|
||||||
import { GIF_PALETTE_SIZE } from '/constants.js'
|
import { GIF_PALETTE_SIZE } from '/constants.js'
|
||||||
|
|
||||||
export function encode ({ imageDataList, imageWidth, imageHeight, delayTime }) {
|
export function encode ({ imageDataList, imageWidth, imageHeight, delayTime }, { boomerangEffect }) {
|
||||||
const emitter = new EventEmitter()
|
const emitter = new EventEmitter()
|
||||||
|
|
||||||
const quantizeColorWorkerPool = genericPool.createPool({
|
const quantizeColorWorkerPool = genericPool.createPool({
|
||||||
|
@ -74,7 +74,8 @@ export function encode ({ imageDataList, imageWidth, imageHeight, delayTime }) {
|
||||||
imageWidth,
|
imageWidth,
|
||||||
imageHeight,
|
imageHeight,
|
||||||
indexedColorImages,
|
indexedColorImages,
|
||||||
delayTime
|
delayTime,
|
||||||
|
boomerangEffect
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.catch(error => emitter.emit('error', error))
|
.catch(error => emitter.emit('error', error))
|
||||||
|
|
|
@ -3,9 +3,9 @@ import { write } from '/services/encode-core.js'
|
||||||
onmessage = handleMessage
|
onmessage = handleMessage
|
||||||
|
|
||||||
async function handleMessage (event) {
|
async function handleMessage (event) {
|
||||||
const { imageWidth, imageHeight, delayTime, indexedColorImages } = event.data
|
const { imageWidth, imageHeight, delayTime, indexedColorImages, boomerangEffect } = event.data
|
||||||
|
|
||||||
const writing = write(imageWidth, imageHeight, delayTime, indexedColorImages)
|
const writing = write(imageWidth, imageHeight, delayTime, indexedColorImages, boomerangEffect)
|
||||||
|
|
||||||
writing.on('progress', value => postMessage({
|
writing.on('progress', value => postMessage({
|
||||||
type: 'progress',
|
type: 'progress',
|
||||||
|
|
|
@ -76,7 +76,7 @@ export default {
|
||||||
},
|
},
|
||||||
startEncoding () {
|
startEncoding () {
|
||||||
this.encoding = true
|
this.encoding = true
|
||||||
const encoding = encode(this.capture)
|
const encoding = encode(this.capture, { boomerangEffect: false })
|
||||||
|
|
||||||
encoding.once('error', error => {
|
encoding.once('error', error => {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
|
Loading…
Reference in a new issue