Added sharpen and batch mode

This commit is contained in:
Nayam Amarshe
2022-09-10 20:22:53 +05:30
parent 956f96481a
commit fca812aabe
9 changed files with 124 additions and 1013 deletions

View File

@@ -4,6 +4,8 @@ const commands = {
UPSCAYL: "Upscale the Image",
UPSCAYL_DONE: "Upscaling Done",
UPSCAYL_PROGRESS: "Send Progress from Main to Renderer",
SHARPEN: "Sharpen the Image First",
SHARPEN_PROGRESS: "Send Sharpening Progress from Main to Renderer",
};
module.exports = commands;

View File

@@ -105,12 +105,85 @@ ipcMain.handle(commands.SELECT_FOLDER, async (event, message) => {
}
});
ipcMain.on(commands.UPSCAYL, async (event, payload) => {
ipcMain.on(commands.SHARPEN, async (event, payload) => {
const model = payload.model;
const scale = payload.scaleFactor;
let inputDir = payload.imagePath.match(/(.*)[\/\\]/)[1] || "";
let outputDir = "./sharpened";
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir);
}
// COPY IMAGE TO TMP FOLDER
const platform = getPlatform();
const fullfileName =
platform === "win"
? payload.imagePath.split("\\").slice(-1)[0]
: payload.imagePath.split("/").slice(-1)[0];
const fileName = parse(fullfileName).name;
const fileExt = parse(fullfileName).ext;
const inputFile = inputDir + "/" + fullfileName;
const outFile = outputDir + "/" + fileName + "_sharpen" + fileExt;
fs.copyFile(inputFile, outFile, (err) => {
if (err) throw err;
});
// UPSCALE
if (fs.existsSync(outFile)) {
// If already upscayled, just output that file
return outFile;
} else {
let upscayl = spawn(
execPath + "-realesr",
[
"-i",
inputDir + "/" + fullfileName,
"-o",
outFile,
"-s",
4,
"-x",
"-m",
modelsPath + "/" + model,
],
{
cwd: null,
detached: false,
}
);
let failed = false;
upscayl.stderr.on("data", (stderr) => {
console.log(stderr.toString());
stderr = stderr.toString();
mainWindow.webContents.send(commands.SHARPEN_PROGRESS, stderr.toString());
if (stderr.includes("invalid gpu") || stderr.includes("failed")) {
failed = true;
return null;
}
});
// Send done comamnd when
upscayl.on("close", (code) => {
if (failed !== true) {
console.log("Done upscaling");
return outFile;
}
});
}
});
ipcMain.on(commands.UPSCAYL, async (event, payload) => {
const model = payload.model;
const scale = payload.scaleFactor;
const sharpen = payload.sharpen;
let inputDir = payload.imagePath.match(/(.*)[\/\\]/)[1] || "";
let outputDir = payload.outputPath;
console.log("🚀 => ipcMain => outputDir", outputDir);
// COPY IMAGE TO TMP FOLDER