tav-media
Version:
Cross platform media editing framework
124 lines (123 loc) • 4.52 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import { tav } from '../tav';
import { Effect } from './tav-effect';
import { FileSystem } from '../io/file-system';
import { Path } from '../io/path';
/**
* Change the video color with a LUT file.
* @category Effects
*/
export class LUTEffect extends Effect {
constructor() {
super(...arguments);
this.type = 'LUTEffect';
this._strength = 1;
}
/**
* Make a LUTEffect from a LUT file.
* @param path The path of the LUT file.
* @param strength The strength of the LUT effect, the value is between 0 and 1.
* @returns new LUTEffect object
*/
static MakeFromPath(path, strength = 1) {
return __awaiter(this, void 0, void 0, function* () {
if (!path) {
return null;
}
const lutEffect = new LUTEffect();
lutEffect._path = path;
yield lutEffect.prepare();
return lutEffect;
});
}
clone() {
const newColorTuningEffect = new LUTEffect();
const _a = this, { _nativeObject: _nativeClip, parent, id, nativeInvalidated } = _a, otherProperties = __rest(_a, ["_nativeObject", "parent", "id", "nativeInvalidated"]);
return Object.assign(newColorTuningEffect, otherProperties);
}
doPrepare() {
const _super = Object.create(null, {
doPrepare: { get: () => super.doPrepare }
});
return __awaiter(this, void 0, void 0, function* () {
yield _super.doPrepare.call(this);
if (!this.path)
return;
if (tav.PLATFORM === 'wx' || tav.PLATFORM === 'browser') {
this.localPath = Path.getLocalFileName(this.path);
yield FileSystem.download(this.localPath, this.path);
}
else {
this.localPath = this.path;
}
});
}
createClip() {
return __awaiter(this, void 0, void 0, function* () {
if (!this.localPath)
return undefined;
const pag = tav.LUTEffect.MakeFromPath(this.localPath, this.strength);
return pag;
});
}
updateClip(effect) {
const _super = Object.create(null, {
updateClip: { get: () => super.updateClip }
});
return __awaiter(this, void 0, void 0, function* () {
yield _super.updateClip.call(this, effect);
effect.setStrength(this.strength);
});
}
/**
* The strength of the LUT effect, the value is between 0 and 1.
*/
get strength() {
return this._strength;
}
set strength(val) {
var _a;
this._strength = val;
if (!this.nativeClip) {
this.invalidated();
;
return;
}
tav.webAssemblyQueue.exec((_a = this.nativeClip) === null || _a === void 0 ? void 0 : _a.setStrength, this.nativeClip, val);
}
/**
* The path of the LUT file.
*/
get path() {
return this._path;
}
set path(newPath) {
var _a;
this._path = newPath;
if (!this.nativeClip) {
this.invalidated();
;
return;
}
tav.webAssemblyQueue.exec((_a = this.nativeClip) === null || _a === void 0 ? void 0 : _a.setPath, this.nativeClip, newPath);
}
}