Skip to content

Commit

Permalink
Clean up of code
Browse files Browse the repository at this point in the history
  • Loading branch information
reindernijhoff committed Jan 6, 2025
1 parent 167b62c commit 5d8b240
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
6 changes: 2 additions & 4 deletions src/lib/FastImageSequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
64 changes: 32 additions & 32 deletions src/lib/Frame.ts
Original file line number Diff line number Diff line change
@@ -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<CanvasImageSource> {
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<CanvasImageSource> {
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<CanvasImageSource | undefined> {
return this.images.find(image => image.available)?.fetchImage();
}
public async fetchImage(): Promise<CanvasImageSource | undefined> {
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());
}
}

0 comments on commit 5d8b240

Please sign in to comment.