diff --git a/js/skinParser.js b/js/skinParser.js index eb0b7480..d431446b 100644 --- a/js/skinParser.js +++ b/js/skinParser.js @@ -51,31 +51,8 @@ const CURSORS = [ */ ]; -async function genImgFromFilename(zip, fileName) { - // Winamp only supports .bmp images, but WACUP set a precidence of supporting - // .png as well to reduce size. Since we care about size as well, we follow - // suit. Our default skin uses .png to save 14kb. - const file = await SkinParserUtils.getFileFromZip( - zip, - fileName, - "(png|bmp)", - "blob" - ); - if (!file) { - return null; - } - - const mimeType = `image/${SkinParserUtils.getFileExtension(file.name) || - "*"}`; - // The spec for createImageBitmap() says the browser should try to sniff the - // mime type, but it looks like Firefox does not. So we specify it here - // explicitly. - const typedBlob = new Blob([file.contents], { type: mimeType }); - return SkinParserUtils.getImgFromBlob(typedBlob); -} - async function genSpriteUrisFromFilename(zip, fileName) { - const img = await genImgFromFilename(zip, fileName); + const img = await SkinParserUtils.getImgFromFilename(zip, fileName); if (img == null) { return {}; } @@ -162,7 +139,7 @@ async function genRegion(zip) { } async function genGenTextSprites(zip) { - const img = await genImgFromFilename(zip, "GEN"); + const img = await SkinParserUtils.getImgFromFilename(zip, "GEN"); if (img == null) { return null; } @@ -208,7 +185,7 @@ async function genGenTextSprites(zip) { } async function genGenExColors(zip) { - const img = await genImgFromFilename(zip, "GENEX"); + const img = await SkinParserUtils.getImgFromFilename(zip, "GENEX"); if (img == null) { return null; } diff --git a/js/skinParserUtils.ts b/js/skinParserUtils.ts index d3a7ebb0..8aaa2de4 100644 --- a/js/skinParserUtils.ts +++ b/js/skinParserUtils.ts @@ -75,3 +75,23 @@ export function getSpriteUrisFromImg( }); return images; } + +export async function getImgFromFilename( + zip: JSZip, + fileName: string +): Promise { + // Winamp only supports .bmp images, but WACUP set a precidence of supporting + // .png as well to reduce size. Since we care about size as well, we follow + // suit. Our default skin uses .png to save 14kb. + const file = await getFileFromZip(zip, fileName, "(png|bmp)", "blob"); + if (!file) { + return null; + } + + const mimeType = `image/${getFileExtension(file.name) || "*"}`; + // The spec for createImageBitmap() says the browser should try to sniff the + // mime type, but it looks like Firefox does not. So we specify it here + // explicitly. + const typedBlob = new Blob([file.contents], { type: mimeType }); + return getImgFromBlob(typedBlob); +}