1
0
mirror of https://github.com/upscayl/upscayl.git synced 2025-01-31 04:03:51 +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 failed = false;
let isAlpha = false;
// TAKE UPSCAYL OUTPUT // TAKE UPSCAYL OUTPUT
upscayl.stderr.on("data", (data) => { upscayl.stderr.on("data", (data) => {
// CONVERT DATA TO STRING // CONVERT DATA TO STRING
@ -188,6 +190,9 @@ ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => {
if (data.includes("invalid gpu") || data.includes("failed")) { if (data.includes("invalid gpu") || data.includes("failed")) {
failed = true; failed = true;
} }
if (data.includes("has alpha channel")) {
isAlpha = true;
}
}); });
// IF ERROR // IF ERROR
@ -209,9 +214,9 @@ ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => {
execPath("realesrgan"), execPath("realesrgan"),
[ [
"-i", "-i",
outFile, isAlpha ? outFile + ".png" : outFile,
"-o", "-o",
outFile, isAlpha ? outFile + ".png" : outFile,
"-s", "-s",
4, 4,
"-m", "-m",
@ -220,7 +225,7 @@ ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => {
model, model,
gpuId ? `-g ${gpuId}` : "", gpuId ? `-g ${gpuId}` : "",
"-f", "-f",
saveImageAs, isAlpha ? "" : saveImageAs,
], ],
{ {
cwd: undefined, cwd: undefined,
@ -256,7 +261,10 @@ ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => {
upscayl2.on("close", (code) => { upscayl2.on("close", (code) => {
if (!failed2) { if (!failed2) {
console.log("Done upscaling"); 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 // COPY IMAGE TO TMP FOLDER
const fullfileName = payload.imagePath.replace(/^.*[\\\/]/, ""); const fullfileName = payload.imagePath.replace(/^.*[\\\/]/, "");
console.log(fullfileName);
const fileName = parse(fullfileName).name; const fileName = parse(fullfileName).name;
console.log("🚀 => fileName", fileName);
const fileExt = parse(fullfileName).ext; const fileExt = parse(fullfileName).ext;
console.log("🚀 => fileExt", fileExt);
const outFile = model.includes("models-DF2K") const outFile = model.includes("models-DF2K")
? outputDir + ? outputDir +
"/" + "/" +
fileName + fileName +
"_upscayl_sharpened_" + "_sharpened_" +
scale + scale +
"x_" + "x_" +
model + model +
@ -385,8 +396,10 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
break; break;
} }
let isAlpha = false;
let failed = false; let failed = false;
upscayl?.stderr.on("data", (data) => {
upscayl?.stderr.on("data", (data: string) => {
console.log( console.log(
"🚀 => upscayl.stderr.on => stderr.toString()", "🚀 => upscayl.stderr.on => stderr.toString()",
data.toString() data.toString()
@ -396,6 +409,10 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
if (data.includes("invalid gpu") || data.includes("failed")) { if (data.includes("invalid gpu") || data.includes("failed")) {
failed = true; failed = true;
} }
if (data.includes("has alpha channel")) {
console.log("INCLUDES ALPHA CHANNEL, CHANGING OUTFILE NAME!");
isAlpha = true;
}
}); });
upscayl?.on("error", (data) => { upscayl?.on("error", (data) => {
@ -408,7 +425,10 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
upscayl?.on("close", (code) => { upscayl?.on("close", (code) => {
if (failed !== true) { if (failed !== true) {
console.log("Done upscaling"); 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); 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 failed = false;
let isAlpha = false;
// TAKE UPSCAYL OUTPUT // TAKE UPSCAYL OUTPUT
upscayl.stderr.on("data", (data) => { upscayl.stderr.on("data", (data) => {
// CONVERT DATA TO STRING // 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")) { if (data.includes("invalid gpu") || data.includes("failed")) {
failed = true; failed = true;
} }
if (data.includes("has alpha channel")) {
isAlpha = true;
}
}); });
// IF ERROR // IF ERROR
upscayl.on("error", (data) => { upscayl.on("error", (data) => {
@ -172,9 +176,9 @@ electron_1.ipcMain.on(commands_1.default.DOUBLE_UPSCAYL, (event, payload) => __a
// UPSCALE // UPSCALE
let upscayl2 = (0, child_process_1.spawn)((0, binaries_1.execPath)("realesrgan"), [ let upscayl2 = (0, child_process_1.spawn)((0, binaries_1.execPath)("realesrgan"), [
"-i", "-i",
outFile, isAlpha ? outFile + ".png" : outFile,
"-o", "-o",
outFile, isAlpha ? outFile + ".png" : outFile,
"-s", "-s",
4, 4,
"-m", "-m",
@ -183,7 +187,7 @@ electron_1.ipcMain.on(commands_1.default.DOUBLE_UPSCAYL, (event, payload) => __a
model, model,
gpuId ? `-g ${gpuId}` : "", gpuId ? `-g ${gpuId}` : "",
"-f", "-f",
saveImageAs, isAlpha ? "" : saveImageAs,
], { ], {
cwd: undefined, cwd: undefined,
detached: false, detached: false,
@ -214,7 +218,7 @@ electron_1.ipcMain.on(commands_1.default.DOUBLE_UPSCAYL, (event, payload) => __a
upscayl2.on("close", (code) => { upscayl2.on("close", (code) => {
if (!failed2) { if (!failed2) {
console.log("Done upscaling"); 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; let outputDir = payload.outputPath;
// COPY IMAGE TO TMP FOLDER // COPY IMAGE TO TMP FOLDER
const fullfileName = payload.imagePath.replace(/^.*[\\\/]/, ""); const fullfileName = payload.imagePath.replace(/^.*[\\\/]/, "");
console.log(fullfileName);
const fileName = (0, path_1.parse)(fullfileName).name; const fileName = (0, path_1.parse)(fullfileName).name;
console.log("🚀 => fileName", fileName);
const fileExt = (0, path_1.parse)(fullfileName).ext; const fileExt = (0, path_1.parse)(fullfileName).ext;
console.log("🚀 => fileExt", fileExt);
const outFile = model.includes("models-DF2K") const outFile = model.includes("models-DF2K")
? outputDir + ? outputDir +
"/" + "/" +
fileName + fileName +
"_upscayl_sharpened_" + "_sharpened_" +
scale + scale +
"x_" + "x_" +
model + 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); console.log("🆙 COMMAND: ", "-i", inputDir + "/" + fullfileName, "-o", outFile, "-s", scale, "-x", "-m", binaries_1.modelsPath + "/" + model, gpuId ? `-g ${gpuId}` : "", "-f", saveImageAs);
break; break;
} }
let isAlpha = false;
let failed = false; let failed = false;
upscayl === null || upscayl === void 0 ? void 0 : upscayl.stderr.on("data", (data) => { upscayl === null || upscayl === void 0 ? void 0 : upscayl.stderr.on("data", (data) => {
console.log("🚀 => upscayl.stderr.on => stderr.toString()", data.toString()); 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")) { if (data.includes("invalid gpu") || data.includes("failed")) {
failed = true; 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) => { upscayl === null || upscayl === void 0 ? void 0 : upscayl.on("error", (data) => {
mainWindow.webContents.send(commands_1.default.UPSCAYL_PROGRESS, data.toString()); 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) => { upscayl === null || upscayl === void 0 ? void 0 : upscayl.on("close", (code) => {
if (failed !== true) { if (failed !== true) {
console.log("Done upscaling"); 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, IndicatorSeparator: () => null,
DropdownIndicator: () => null, DropdownIndicator: () => null,
}} }}
onChange={handleModelChange} onChange={(e) => {
handleModelChange(e);
setCurrentModel({ label: e.label, value: e.value });
}}
className="react-select-container" className="react-select-container"
classNamePrefix="react-select" classNamePrefix="react-select"
value={currentModel} value={currentModel}