mirror of
https://github.com/captbaritone/webamp.git
synced 2026-08-03 23:43:28 +00:00
Type getImgFromFilename
This commit is contained in:
parent
8b49b5fa6a
commit
f56e707a16
2 changed files with 23 additions and 26 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,3 +75,23 @@ export function getSpriteUrisFromImg(
|
|||
});
|
||||
return images;
|
||||
}
|
||||
|
||||
export async function getImgFromFilename(
|
||||
zip: JSZip,
|
||||
fileName: string
|
||||
): Promise<HTMLImageElement | ImageBitmap | null> {
|
||||
// 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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue