From 5d8b240a217385a1272064d2cfb260b524ca3e22 Mon Sep 17 00:00:00 2001 From: Reinder Nijhoff Date: Mon, 6 Jan 2025 13:05:53 +0100 Subject: [PATCH] Clean up of code --- src/lib/FastImageSequence.ts | 6 ++-- src/lib/Frame.ts | 64 ++++++++++++++++++------------------ 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/lib/FastImageSequence.ts b/src/lib/FastImageSequence.ts index 0239228..250b258 100644 --- a/src/lib/FastImageSequence.ts +++ b/src/lib/FastImageSequence.ts @@ -502,8 +502,7 @@ export class FastImageSequence { const canvasWidth = (containerAspect > imageAspect ? this.height * containerAspect : this.width) | 0; const canvasHeight = (containerAspect > imageAspect ? this.height : this.width / containerAspect) | 0; - if (this.canvas.width < canvasWidth || this.canvas.height < this.height || this.canvas.width / this.canvas.height !== canvasWidth / canvasHeight) { - // if (this.canvas.width !== canvasWidth || this.canvas.height !== canvasHeight) { + if (this.canvas.width !== canvasWidth || this.canvas.height !== canvasHeight) { this.canvas.width = canvasWidth; this.canvas.height = canvasHeight; } @@ -512,8 +511,7 @@ export class FastImageSequence { const canvasWidth = (containerAspect > imageAspect ? this.width : this.height * containerAspect) | 0; const canvasHeight = (containerAspect > imageAspect ? this.width / containerAspect : this.height) | 0; - if (this.canvas.width < canvasWidth || this.canvas.height < this.height || this.canvas.width / this.canvas.height !== canvasWidth / canvasHeight) { - // if (this.canvas.width !== canvasWidth || this.canvas.height !== canvasHeight) { + if (this.canvas.width !== canvasWidth || this.canvas.height !== canvasHeight) { this.canvas.width = canvasWidth; this.canvas.height = canvasHeight; } diff --git a/src/lib/Frame.ts b/src/lib/Frame.ts index 195b3f9..584614e 100644 --- a/src/lib/Frame.ts +++ b/src/lib/Frame.ts @@ -1,42 +1,42 @@ import type ImageElement from "./ImageElement.js"; export default class Frame { - public index: number; - public images: ImageElement[] = []; - public priority: number = 0; + public index: number; + public images: ImageElement[] = []; + public priority: number = 0; - constructor(index: number) { - this.index = index; - } + constructor(index: number) { + this.index = index; + } - public get image(): CanvasImageSource | undefined { - return this.images.find(image => image.image !== undefined)?.image; - } + public get image(): CanvasImageSource | undefined { + return this.images.find(image => image.image !== undefined)?.image; + } - public async getImage(): Promise { - return new Promise(async (resolve, reject) => { - if (this.image !== undefined) { - resolve(this.image); - } else { - const lastImage = this.images[this.images.length - 1]; - if (lastImage) { - lastImage.fetchImage().then(img => resolve(img)).catch(() => reject()); - } else { - reject(); - } - } - }); - } + public async getImage(): Promise { + return new Promise(async (resolve, reject) => { + if (this.image !== undefined) { + resolve(this.image); + } else { + const lastImage = this.images[this.images.length - 1]; + if (lastImage) { + lastImage.fetchImage().then(img => resolve(img)).catch(() => reject()); + } else { + reject(); + } + } + }); + } - public async fetchImage(): Promise { - return this.images.find(image => image.available)?.fetchImage(); - } + public async fetchImage(): Promise { + return this.images.find(image => image.available)?.fetchImage(); + } - public releaseImage() { - this.images.forEach(image => image.releaseImage()); - } + public releaseImage() { + this.images.forEach(image => image.releaseImage()); + } - public reset() { - this.images.forEach(image => image.reset()); - } + public reset() { + this.images.forEach(image => image.reset()); + } } \ No newline at end of file