1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-12-18 02:16:01 +01:00

Fixed sharpen code

This commit is contained in:
Nayam Amarshe 2022-09-11 15:57:47 +05:30
parent 18cbfd8b50
commit d4ef6acca7
6 changed files with 60 additions and 92 deletions

View File

@ -13,7 +13,9 @@ const binariesPath = isDev
? join(appRootDir.get(), "resources", getPlatform(), "bin")
: join(dirname(appRootDir.get()), "bin");
const execPath = resolve(join(binariesPath, "./upscayl"));
const execPath = (execName) =>
resolve(join(binariesPath, `./upscayl-${execName}`));
const modelsPath = isDev
? resolve(join(appRootDir.get(), "resources", "models"))
: resolve(join(dirname(appRootDir.get()), "models"));

View File

@ -29,7 +29,7 @@ app.on("ready", async () => {
console.log("🚀 Icon Path: ", join(__dirname, "icon.png"));
console.log("🚀 Development Mode? :", isDev);
console.log("🚀 RS Executable Path: ", execPath);
console.log("🚀 RS Executable Path: ", execPath(""));
console.log("🚀 Models: ", modelsPath);
mainWindow = new BrowserWindow({
@ -106,10 +106,8 @@ ipcMain.handle(commands.SELECT_FOLDER, async (event, message) => {
});
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);
@ -125,61 +123,53 @@ ipcMain.on(commands.SHARPEN, async (event, payload) => {
const fileExt = parse(fullfileName).ext;
const inputFile = inputDir + "/" + fullfileName;
const copiedInputFile = outputDir + "/" + fullfileName;
const outFile = outputDir + "/" + fileName + "_sharpen" + fileExt;
fs.copyFile(inputFile, outFile, (err) => {
fs.copyFile(inputFile, copiedInputFile, (err) => {
if (err) throw err;
});
// UPSCALE
if (fs.existsSync(outFile)) {
// If already upscayled, just output that file
return outFile;
} else {
let upscayl = spawn(
execPath + "-realsr",
[
"-i",
inputDir + "/" + fullfileName,
"-o",
outFile,
"-s",
4,
"-x",
"-m",
modelsPath + "/" + model,
],
{
cwd: null,
detached: false,
}
);
let sharpen = spawn(
execPath("realsr"),
[
"-i",
copiedInputFile,
"-o",
outFile,
"-s",
4,
"-x",
"-m",
modelsPath + "/models-DF2K",
],
{
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;
}
});
}
let failed = false;
sharpen.stderr.on("data", (data) => {
console.log(data.toString());
data = data.toString();
mainWindow.webContents.send(commands.UPSCAYL_PROGRESS, data.toString());
if (data.includes("invalid gpu") || data.includes("failed")) {
failed = true;
sharpen.kill("SIGKILL");
return;
}
});
sharpen.on("close", (_) => {
if (failed !== true) {
console.log("Done upscaling");
}
});
});
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;
@ -202,44 +192,25 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
// If already upscayled, just output that file
mainWindow.webContents.send(commands.UPSCAYL_DONE, outFile);
} else {
let upscayl = model.includes("realesrgan")
? spawn(
execPath + "-realesrgan",
[
"-i",
inputDir + "/" + fullfileName,
"-o",
outFile,
"-s",
scale === 2 ? 4 : scale,
"-m",
modelsPath,
"-n",
model,
],
{
cwd: null,
detached: false,
}
)
: spawn(
execPath + "-realsr",
[
"-i",
inputDir + "/" + fullfileName,
"-o",
outFile,
"-s",
4,
"-x",
"-m",
modelsPath + "/" + model,
],
{
cwd: null,
detached: false,
}
);
let upscayl = spawn(
execPath + "-realesrgan",
[
"-i",
inputDir + "/" + fullfileName,
"-o",
outFile,
"-s",
scale === 2 ? 4 : scale,
"-m",
modelsPath,
"-n",
model,
],
{
cwd: null,
detached: false,
}
);
let failed = false;
upscayl.stderr.on("data", (stderr) => {
@ -273,7 +244,6 @@ autoUpdater.on("update-available", (_event, releaseNotes, releaseName) => {
};
dialog.showMessageBox(dialogOpts, (response) => {});
});
autoUpdater.on("update-downloaded", (_event, releaseNotes, releaseName) => {
const dialogOpts = {
type: "info",

View File

@ -152,10 +152,7 @@ const Home = () => {
if (sharpen) {
const sharpenedImage = await window.electron.send(commands.SHARPEN, {
scaleFactor: 4,
imagePath,
outputPath,
model: "models-DF2K",
});
console.log("🚀 => upscaylHandler => sharpenedImage", sharpenedImage);
} else {
@ -164,7 +161,6 @@ const Home = () => {
imagePath,
outputPath,
model,
sharpen,
});
}
} else {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB