mirror of
https://github.com/GuerillaStudio/souvenir.git
synced 2025-01-20 22:30:20 +00:00
refact(gif effects): extract boomerang effect
This commit is contained in:
parent
bcf0c8947d
commit
63a9c8df27
4 changed files with 14 additions and 10 deletions
1
src/services/effects.js
vendored
Normal file
1
src/services/effects.js
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export const boomerang = xs => [...xs, ...xs.slice(1, xs.length - 1).reverse()]
|
|
@ -6,7 +6,8 @@ import {
|
||||||
IndexedColorImage
|
IndexedColorImage
|
||||||
} from 'gif-writer'
|
} from 'gif-writer'
|
||||||
|
|
||||||
import { calcProgress } from '/services/util.js'
|
import { boomerang } from '/services/effects.js'
|
||||||
|
import { pipe, calcProgress } from '/services/util.js'
|
||||||
|
|
||||||
class OutputStream {
|
class OutputStream {
|
||||||
constructor () {
|
constructor () {
|
||||||
|
@ -41,9 +42,9 @@ export function write (imageWidth, imageHeight, delay, indexedColorImages, boome
|
||||||
|
|
||||||
writer.writeLoopControlInfo(0)
|
writer.writeLoopControlInfo(0)
|
||||||
|
|
||||||
const frames = boomerangEffect
|
const frames = pipe(indexedColorImages, [
|
||||||
? [...indexedColorImages, ...indexedColorImages.slice(1, indexedColorImages.length - 1).reverse()]
|
(images) => boomerangEffect ? boomerang(images) : images
|
||||||
: indexedColorImages
|
])
|
||||||
|
|
||||||
frames.forEach((indexedColorImage, index, { length }) => {
|
frames.forEach((indexedColorImage, index, { length }) => {
|
||||||
writer.writeTableBasedImageWithGraphicControl(indexedColorImage, { delayTimeInMS: delay })
|
writer.writeTableBasedImageWithGraphicControl(indexedColorImage, { delayTimeInMS: delay })
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
export const pipe = (x, fs) => fs.reduce((a, f) => f(a), x)
|
||||||
|
|
||||||
export function * cycle (xs) {
|
export function * cycle (xs) {
|
||||||
while (true) {
|
while (true) {
|
||||||
yield * xs
|
yield * xs
|
||||||
|
|
|
@ -16,7 +16,8 @@
|
||||||
import { encode } from '/services/encode.js'
|
import { encode } from '/services/encode.js'
|
||||||
import encodingOverlay from '/views/components/encoding'
|
import encodingOverlay from '/views/components/encoding'
|
||||||
import captureOptions from '/views/components/capture-options'
|
import captureOptions from '/views/components/capture-options'
|
||||||
import { cycle } from '/services/util.js'
|
import { boomerang } from '/services/effects.js'
|
||||||
|
import { pipe, cycle } from '/services/util.js'
|
||||||
|
|
||||||
import { mapState } from 'vuex'
|
import { mapState } from 'vuex'
|
||||||
|
|
||||||
|
@ -54,11 +55,10 @@ export default {
|
||||||
canvas.height = this.capture.imageHeight
|
canvas.height = this.capture.imageHeight
|
||||||
const canvasContext = canvas.getContext('2d')
|
const canvasContext = canvas.getContext('2d')
|
||||||
|
|
||||||
const frames = this.boomerang
|
const imagesIterator = pipe(this.capture.imageDataList, [
|
||||||
? [...this.capture.imageDataList, ...this.capture.imageDataList.slice(1, this.capture.imageDataList.length - 1).reverse()]
|
(images) => this.boomerang ? boomerang(images) : images,
|
||||||
: this.capture.imageDataList
|
cycle
|
||||||
|
])
|
||||||
const imagesIterator = cycle(frames)
|
|
||||||
const delay = this.capture.delayTime
|
const delay = this.capture.delayTime
|
||||||
|
|
||||||
this.previewInterval = setInterval(() => {
|
this.previewInterval = setInterval(() => {
|
||||||
|
|
Loading…
Reference in a new issue