1
0
mirror of https://github.com/upscayl/upscayl.git synced 2025-01-18 17:14:08 +01:00

Add support for alpha channel in batch upscayl

This commit is contained in:
Nayam Amarshe 2024-01-15 18:39:46 +05:30
parent 3ed4638aa5
commit f7803f7c9e
2 changed files with 17 additions and 12 deletions

View File

@ -84,6 +84,7 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
setStopped(false);
let failed = false;
let isAlpha = false;
const onData = (data: any) => {
if (!mainWindow) return;
@ -97,6 +98,9 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
failed = true;
upscayl.kill();
}
if (data.includes("has alpha channel")) {
isAlpha = true;
}
};
const onError = (data: any) => {
if (!mainWindow) return;
@ -138,9 +142,11 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
console.log("Filename: ", removeFileExtension(file));
await convertAndScale(
inputDir + slash + file,
`${outputFolderPath}${slash}${removeFileExtension(
file
)}.${saveImageAs}`,
isAlpha
? `${outputFolderPath}${slash}${removeFileExtension(file)}.png`
: `${outputFolderPath}${slash}${removeFileExtension(
file
)}.${saveImageAs}`,
`${outputFolderPath}${slash}${removeFileExtension(
file
)}.${saveImageAs}`,

View File

@ -26,6 +26,7 @@ import { DoubleUpscaylPayload } from "../../common/types/types";
import { ImageFormat } from "../utils/types";
import getModelScale from "../../common/check-model-scale";
import showNotification from "../utils/show-notification";
import { unlinkSync } from "fs";
const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {
const mainWindow = getMainWindow();
@ -162,16 +163,14 @@ const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {
mainWindow.setProgressBar(-1);
mainWindow.webContents.send(
COMMAND.DOUBLE_UPSCAYL_DONE,
isAlpha
? (outFile + ".png").replace(
/([^/\\]+)$/i,
encodeURIComponent((outFile + ".png").match(/[^/\\]+$/i)![0])
)
: outFile.replace(
/([^/\\]+)$/i,
encodeURIComponent(outFile.match(/[^/\\]+$/i)![0])
)
outFile.replace(
/([^/\\]+)$/i,
encodeURIComponent(outFile.match(/[^/\\]+$/i)![0])
)
);
if (isAlpha && saveImageAs === "jpg") {
unlinkSync(outFile + ".png");
}
showNotification("Upscayled", "Image upscayled successfully!");
} catch (error) {
logit("❌ Error reading original image metadata", error);