1
0
mirror of https://github.com/upscayl/upscayl.git synced 2025-01-18 17:14:08 +01:00
This commit is contained in:
Feenix 2022-12-27 12:15:16 +05:30
parent 60d126b021
commit 779701e95f
3 changed files with 49 additions and 16 deletions

View File

@ -176,6 +176,8 @@ ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => {
);
let failed = false;
let isAlpha = false;
// TAKE UPSCAYL OUTPUT
upscayl.stderr.on("data", (data) => {
// CONVERT DATA TO STRING
@ -188,6 +190,9 @@ ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => {
if (data.includes("invalid gpu") || data.includes("failed")) {
failed = true;
}
if (data.includes("has alpha channel")) {
isAlpha = true;
}
});
// IF ERROR
@ -209,9 +214,9 @@ ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => {
execPath("realesrgan"),
[
"-i",
outFile,
isAlpha ? outFile + ".png" : outFile,
"-o",
outFile,
isAlpha ? outFile + ".png" : outFile,
"-s",
4,
"-m",
@ -220,7 +225,7 @@ ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => {
model,
gpuId ? `-g ${gpuId}` : "",
"-f",
saveImageAs,
isAlpha ? "" : saveImageAs,
],
{
cwd: undefined,
@ -256,7 +261,10 @@ ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => {
upscayl2.on("close", (code) => {
if (!failed2) {
console.log("Done upscaling");
mainWindow.webContents.send(commands.DOUBLE_UPSCAYL_DONE, outFile);
mainWindow.webContents.send(
commands.DOUBLE_UPSCAYL_DONE,
isAlpha ? outFile + ".png" : outFile
);
}
});
}
@ -275,14 +283,17 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
// COPY IMAGE TO TMP FOLDER
const fullfileName = payload.imagePath.replace(/^.*[\\\/]/, "");
console.log(fullfileName);
const fileName = parse(fullfileName).name;
console.log("🚀 => fileName", fileName);
const fileExt = parse(fullfileName).ext;
console.log("🚀 => fileExt", fileExt);
const outFile = model.includes("models-DF2K")
? outputDir +
"/" +
fileName +
"_upscayl_sharpened_" +
"_sharpened_" +
scale +
"x_" +
model +
@ -385,8 +396,10 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
break;
}
let isAlpha = false;
let failed = false;
upscayl?.stderr.on("data", (data) => {
upscayl?.stderr.on("data", (data: string) => {
console.log(
"🚀 => upscayl.stderr.on => stderr.toString()",
data.toString()
@ -396,6 +409,10 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
if (data.includes("invalid gpu") || data.includes("failed")) {
failed = true;
}
if (data.includes("has alpha channel")) {
console.log("INCLUDES ALPHA CHANNEL, CHANGING OUTFILE NAME!");
isAlpha = true;
}
});
upscayl?.on("error", (data) => {
@ -408,7 +425,10 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
upscayl?.on("close", (code) => {
if (failed !== true) {
console.log("Done upscaling");
mainWindow.webContents.send(commands.UPSCAYL_DONE, outFile);
mainWindow.webContents.send(
commands.UPSCAYL_DONE,
isAlpha ? outFile + ".png" : outFile
);
}
});
}

View File

@ -143,6 +143,7 @@ electron_1.ipcMain.on(commands_1.default.DOUBLE_UPSCAYL, (event, payload) => __a
});
console.log("🆙 COMMAND:", "-i", inputDir + "/" + fullfileName, "-o", outFile, "-s", 4, "-m", binaries_1.modelsPath, "-n", model, gpuId ? `-g ${gpuId}` : "", "-f", saveImageAs);
let failed = false;
let isAlpha = false;
// TAKE UPSCAYL OUTPUT
upscayl.stderr.on("data", (data) => {
// CONVERT DATA TO STRING
@ -155,6 +156,9 @@ electron_1.ipcMain.on(commands_1.default.DOUBLE_UPSCAYL, (event, payload) => __a
if (data.includes("invalid gpu") || data.includes("failed")) {
failed = true;
}
if (data.includes("has alpha channel")) {
isAlpha = true;
}
});
// IF ERROR
upscayl.on("error", (data) => {
@ -172,9 +176,9 @@ electron_1.ipcMain.on(commands_1.default.DOUBLE_UPSCAYL, (event, payload) => __a
// UPSCALE
let upscayl2 = (0, child_process_1.spawn)((0, binaries_1.execPath)("realesrgan"), [
"-i",
outFile,
isAlpha ? outFile + ".png" : outFile,
"-o",
outFile,
isAlpha ? outFile + ".png" : outFile,
"-s",
4,
"-m",
@ -183,7 +187,7 @@ electron_1.ipcMain.on(commands_1.default.DOUBLE_UPSCAYL, (event, payload) => __a
model,
gpuId ? `-g ${gpuId}` : "",
"-f",
saveImageAs,
isAlpha ? "" : saveImageAs,
], {
cwd: undefined,
detached: false,
@ -214,7 +218,7 @@ electron_1.ipcMain.on(commands_1.default.DOUBLE_UPSCAYL, (event, payload) => __a
upscayl2.on("close", (code) => {
if (!failed2) {
console.log("Done upscaling");
mainWindow.webContents.send(commands_1.default.DOUBLE_UPSCAYL_DONE, outFile);
mainWindow.webContents.send(commands_1.default.DOUBLE_UPSCAYL_DONE, isAlpha ? outFile + ".png" : outFile);
}
});
}
@ -230,14 +234,15 @@ electron_1.ipcMain.on(commands_1.default.UPSCAYL, (event, payload) => __awaiter(
let outputDir = payload.outputPath;
// COPY IMAGE TO TMP FOLDER
const fullfileName = payload.imagePath.replace(/^.*[\\\/]/, "");
console.log(fullfileName);
const fileName = (0, path_1.parse)(fullfileName).name;
console.log("🚀 => fileName", fileName);
const fileExt = (0, path_1.parse)(fullfileName).ext;
console.log("🚀 => fileExt", fileExt);
const outFile = model.includes("models-DF2K")
? outputDir +
"/" +
fileName +
"_upscayl_sharpened_" +
"_sharpened_" +
scale +
"x_" +
model +
@ -302,6 +307,7 @@ electron_1.ipcMain.on(commands_1.default.UPSCAYL, (event, payload) => __awaiter(
console.log("🆙 COMMAND: ", "-i", inputDir + "/" + fullfileName, "-o", outFile, "-s", scale, "-x", "-m", binaries_1.modelsPath + "/" + model, gpuId ? `-g ${gpuId}` : "", "-f", saveImageAs);
break;
}
let isAlpha = false;
let failed = false;
upscayl === null || upscayl === void 0 ? void 0 : upscayl.stderr.on("data", (data) => {
console.log("🚀 => upscayl.stderr.on => stderr.toString()", data.toString());
@ -310,6 +316,10 @@ electron_1.ipcMain.on(commands_1.default.UPSCAYL, (event, payload) => __awaiter(
if (data.includes("invalid gpu") || data.includes("failed")) {
failed = true;
}
if (data.includes("has alpha channel")) {
console.log("INCLUDES ALPHA CHANNEL, CHANGING OUTFILE NAME!");
isAlpha = true;
}
});
upscayl === null || upscayl === void 0 ? void 0 : upscayl.on("error", (data) => {
mainWindow.webContents.send(commands_1.default.UPSCAYL_PROGRESS, data.toString());
@ -320,7 +330,7 @@ electron_1.ipcMain.on(commands_1.default.UPSCAYL, (event, payload) => __awaiter(
upscayl === null || upscayl === void 0 ? void 0 : upscayl.on("close", (code) => {
if (failed !== true) {
console.log("Done upscaling");
mainWindow.webContents.send(commands_1.default.UPSCAYL_DONE, outFile);
mainWindow.webContents.send(commands_1.default.UPSCAYL_DONE, isAlpha ? outFile + ".png" : outFile);
}
});
}

View File

@ -189,7 +189,10 @@ function LeftPaneImageSteps({
IndicatorSeparator: () => null,
DropdownIndicator: () => null,
}}
onChange={handleModelChange}
onChange={(e) => {
handleModelChange(e);
setCurrentModel({ label: e.label, value: e.value });
}}
className="react-select-container"
classNamePrefix="react-select"
value={currentModel}