mirror of
https://github.com/GuerillaStudio/souvenir.git
synced 2025-01-20 18:50:21 +00:00
refactor(configuration): centralize constants
This commit is contained in:
parent
388a1f4bb5
commit
c762f35fde
3 changed files with 18 additions and 12 deletions
4
src/constants.js
Normal file
4
src/constants.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
export const GIF_WIDTH = 200
|
||||
export const GIF_HEIGHT = GIF_WIDTH
|
||||
export const GIF_FRAME_RATE = 10
|
||||
export const GIF_PALETTE_SIZE = 255
|
|
@ -1,12 +1,14 @@
|
|||
import {
|
||||
GIF_WIDTH,
|
||||
GIF_HEIGHT,
|
||||
GIF_FRAME_RATE
|
||||
} from '/constants.js'
|
||||
|
||||
import {
|
||||
makeRectangle,
|
||||
crop
|
||||
} from '/services/rectangle.js'
|
||||
|
||||
const FRAMES_PER_SECOND = 10
|
||||
const WIDTH = 200
|
||||
const HEIGHT = WIDTH
|
||||
|
||||
export function capture (commit, mediaStream, duration) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const video = document.createElement('video')
|
||||
|
@ -15,18 +17,18 @@ export function capture (commit, mediaStream, duration) {
|
|||
video.setAttribute('webkit-playsinline', '')
|
||||
|
||||
const canvas = document.createElement('canvas')
|
||||
canvas.width = WIDTH
|
||||
canvas.height = HEIGHT
|
||||
canvas.width = GIF_WIDTH
|
||||
canvas.height = GIF_HEIGHT
|
||||
|
||||
const canvasContext = canvas.getContext('2d')
|
||||
|
||||
const totalFrames = duration / 1000 * FRAMES_PER_SECOND
|
||||
const totalFrames = duration / 1000 * GIF_FRAME_RATE
|
||||
|
||||
if (totalFrames < 1) {
|
||||
resolve([])
|
||||
}
|
||||
|
||||
const delayTime = 1000 / FRAMES_PER_SECOND
|
||||
const delayTime = 1000 / GIF_FRAME_RATE
|
||||
|
||||
video.srcObject = mediaStream
|
||||
|
||||
|
@ -67,8 +69,8 @@ export function capture (commit, mediaStream, duration) {
|
|||
|
||||
resolve({
|
||||
imageDataList,
|
||||
imageWidth: WIDTH,
|
||||
imageHeight: HEIGHT,
|
||||
imageWidth: GIF_WIDTH,
|
||||
imageHeight: GIF_HEIGHT,
|
||||
delayTime
|
||||
})
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import pEvent from 'p-event'
|
|||
import { write } from '/services/encode-core.js'
|
||||
import { promisesProgress, calcProgress } from '/services/util.js'
|
||||
|
||||
const PALETTE_SIZE = 255
|
||||
import { GIF_PALETTE_SIZE } from '/constants.js'
|
||||
|
||||
export function encode ({ imageDataList, imageWidth, imageHeight, delayTime }) {
|
||||
const emitter = new EventEmitter()
|
||||
|
@ -31,7 +31,7 @@ export function encode ({ imageDataList, imageWidth, imageHeight, delayTime }) {
|
|||
|
||||
worker.postMessage({
|
||||
imageData,
|
||||
paletteSize: PALETTE_SIZE
|
||||
paletteSize: GIF_PALETTE_SIZE
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue