diff --git a/electron/index.ts b/electron/index.ts index 7e26cdf..e4e8fd5 100644 --- a/electron/index.ts +++ b/electron/index.ts @@ -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 + ); } }); } diff --git a/main/index.js b/main/index.js index 14bc340..4840e50 100644 --- a/main/index.js +++ b/main/index.js @@ -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); } }); } diff --git a/renderer/components/LeftPaneImageSteps.tsx b/renderer/components/LeftPaneImageSteps.tsx index 15b1197..7f452a1 100644 --- a/renderer/components/LeftPaneImageSteps.tsx +++ b/renderer/components/LeftPaneImageSteps.tsx @@ -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}