MCPcopy Create free account
hub / github.com/Lazack28/Lazack-Device / replaceFrame

Method replaceFrame

lib/webp.js:395–471  ·  view source on GitHub ↗
(path, frame)

Source from the content-addressed store, hash-verified

393 }
394
395 replaceFrame(path, frame) {
396 var _this3 = this;
397
398 return _asyncToGenerator(function* () {
399 if (!_this3.hasAnim) {
400 throw new Error("WebP isn't animated");
401 }
402
403 if (frame < 0 || frame >= _this3.frameCount) {
404 throw new Error(
405 `Frame index ${frame} out of bounds (0<=index<${_this3.frameCount})`
406 );
407 }
408
409 let r = new Image();
410 yield r.load(path);
411
412 switch (r.type) {
413 case constants.TYPE_LOSSY:
414 case constants.TYPE_LOSSLESS:
415 break;
416
417 case constants.TYPE_EXTENDED:
418 if (r.hasAnim) {
419 throw new Error("Merging animations not currently supported");
420 }
421
422 break;
423
424 default:
425 throw new Error("Unknown WebP type");
426 }
427
428 switch (_this3.anim.frames[frame].type) {
429 case constants.TYPE_LOSSY:
430 if (_this3.anim.frames[frame].vp8.alpha) {
431 delete _this3.anim.frames[frame].alph;
432 }
433
434 delete _this3.anim.frames[frame].vp8;
435 break;
436
437 case constants.TYPE_LOSSLESS:
438 delete _this3.anim.frames[frame].vp8l;
439 break;
440
441 default:
442 throw new Error("Unknown frame type");
443 }
444
445 switch (r.type) {
446 case constants.TYPE_LOSSY:
447 _this3.anim.frames[frame].vp8 = r.data.vp8;
448 break;
449
450 case constants.TYPE_LOSSLESS:
451 _this3.anim.frames[frame].vp8l = r.data.vp8l;
452 break;

Callers

nothing calls this directly

Calls 2

loadMethod · 0.95
_asyncToGeneratorFunction · 0.85

Tested by

no test coverage detected