Skip to content

Commit

Permalink
Scale by 10% increments instead of halved resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
Codas committed Oct 25, 2024
1 parent adcf822 commit 43f4662
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/lib/spritesheets/FramePacker.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class FramePacker {
frames.map((frame, idx) => this.#combineFrames(frame, alphaFrames[idx], idx))
);

const packedData = await this.#packScaledFrames(combinedFrames, minimumScale);
const packedData = await this.scaleAndPackFrames(combinedFrames, minimumScale);
if (!packedData) {
return;
}
Expand Down Expand Up @@ -116,7 +116,7 @@ export class FramePacker {
* @param {number} minimumScale
* @return {Promise<PackedFramesContainer | undefined>}
*/
async #packScaledFrames(frameData, minimumScale) {
async scaleAndPackFrames(frameData, minimumScale) {
let scale = 1;

/**
Expand Down Expand Up @@ -179,7 +179,7 @@ export class FramePacker {
spriteWidth = Math.ceil(w / 4) * 4;
spriteHeight = Math.ceil(h / 4) * 4;
if (Math.max(spriteHeight, spriteWidth) > 8192) {
scale /= 2;
scale -= 0.1;
continue;
}

Expand Down
8 changes: 4 additions & 4 deletions src/lib/spritesheets/TextureCompressor.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ export class SpritesheetCompressor {
*/
constructor(basis, ktx2FileCache) {
this.#basis = basis;
this.#ktx2FileCache = ktx2FileCache
this.#ktx2FileCache = ktx2FileCache;
const canvas = new OffscreenCanvas(0, 0);
const gl = canvas.getContext("webgl2");
this.#supportedCodecs = {
astc: !!gl.getExtension("WEBGL_compressed_texture_astc"),
bc7: !!gl.getExtension("EXT_texture_compression_bptc"),
dxt: !!gl.getExtension("WEBGL_compressed_texture_s3tc"),
astc: !!gl?.getExtension("WEBGL_compressed_texture_astc"),
bc7: !!gl?.getExtension("EXT_texture_compression_bptc"),
dxt: !!gl?.getExtension("WEBGL_compressed_texture_s3tc"),
};
}
/**
Expand Down
9 changes: 3 additions & 6 deletions src/lib/spritesheets/ktx2FileCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
// cache version history:
// 1: initial
// 2: zstandard compressed ktx2 files and response metadata
const cacheVersion = 2;
// 3: Remove cache size limit and increase scaled spritesheet resolutions
const cacheVersion = 3;
const cacheName = `SequencerKTX2Cache-${cacheVersion}`;
/** @type {Promise<Cache | null>} */
let ktx2FileCache;
Expand Down Expand Up @@ -82,10 +83,6 @@ export class Ktx2FileCache {
* @returns {Promise<void>}
*/
async saveKtxFileToCache(id, sourceHash, ktx2FileBuffer) {
// only cache files <= 30MB
if (ktx2FileBuffer.byteLength > 30 * 1000 * 1000) {
return;
}
const cacheStorage = await ktx2FileCache.catch(() => null);
if (!cacheStorage) {
return;
Expand Down Expand Up @@ -156,5 +153,5 @@ export class Ktx2FileCache {
}

/**
* @typedef {{sprites: import("./FramePacker").SpriteData[], frameRate: number, scale: number}} CachedSpriteData
* @typedef {{sprites: import("./FramePacker.js").SpriteData[], frameRate: number, scale: number}} CachedSpriteData
*/

0 comments on commit 43f4662

Please sign in to comment.