mirror of
https://github.com/upscayl/upscayl.git
synced 2024-12-18 18:35:58 +01:00
Fixed sharpen code
This commit is contained in:
parent
18cbfd8b50
commit
d4ef6acca7
@ -13,7 +13,9 @@ const binariesPath = isDev
|
|||||||
? join(appRootDir.get(), "resources", getPlatform(), "bin")
|
? join(appRootDir.get(), "resources", getPlatform(), "bin")
|
||||||
: join(dirname(appRootDir.get()), "bin");
|
: join(dirname(appRootDir.get()), "bin");
|
||||||
|
|
||||||
const execPath = resolve(join(binariesPath, "./upscayl"));
|
const execPath = (execName) =>
|
||||||
|
resolve(join(binariesPath, `./upscayl-${execName}`));
|
||||||
|
|
||||||
const modelsPath = isDev
|
const modelsPath = isDev
|
||||||
? resolve(join(appRootDir.get(), "resources", "models"))
|
? resolve(join(appRootDir.get(), "resources", "models"))
|
||||||
: resolve(join(dirname(appRootDir.get()), "models"));
|
: resolve(join(dirname(appRootDir.get()), "models"));
|
||||||
|
@ -29,7 +29,7 @@ app.on("ready", async () => {
|
|||||||
|
|
||||||
console.log("🚀 Icon Path: ", join(__dirname, "icon.png"));
|
console.log("🚀 Icon Path: ", join(__dirname, "icon.png"));
|
||||||
console.log("🚀 Development Mode? :", isDev);
|
console.log("🚀 Development Mode? :", isDev);
|
||||||
console.log("🚀 RS Executable Path: ", execPath);
|
console.log("🚀 RS Executable Path: ", execPath(""));
|
||||||
console.log("🚀 Models: ", modelsPath);
|
console.log("🚀 Models: ", modelsPath);
|
||||||
|
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
@ -106,10 +106,8 @@ ipcMain.handle(commands.SELECT_FOLDER, async (event, message) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on(commands.SHARPEN, 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 inputDir = payload.imagePath.match(/(.*)[\/\\]/)[1] || "";
|
||||||
|
|
||||||
let outputDir = "./sharpened";
|
let outputDir = "./sharpened";
|
||||||
if (!fs.existsSync(outputDir)) {
|
if (!fs.existsSync(outputDir)) {
|
||||||
fs.mkdirSync(outputDir);
|
fs.mkdirSync(outputDir);
|
||||||
@ -125,29 +123,25 @@ ipcMain.on(commands.SHARPEN, async (event, payload) => {
|
|||||||
const fileExt = parse(fullfileName).ext;
|
const fileExt = parse(fullfileName).ext;
|
||||||
|
|
||||||
const inputFile = inputDir + "/" + fullfileName;
|
const inputFile = inputDir + "/" + fullfileName;
|
||||||
|
const copiedInputFile = outputDir + "/" + fullfileName;
|
||||||
const outFile = outputDir + "/" + fileName + "_sharpen" + fileExt;
|
const outFile = outputDir + "/" + fileName + "_sharpen" + fileExt;
|
||||||
|
|
||||||
fs.copyFile(inputFile, outFile, (err) => {
|
fs.copyFile(inputFile, copiedInputFile, (err) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
});
|
});
|
||||||
|
|
||||||
// UPSCALE
|
let sharpen = spawn(
|
||||||
if (fs.existsSync(outFile)) {
|
execPath("realsr"),
|
||||||
// If already upscayled, just output that file
|
|
||||||
return outFile;
|
|
||||||
} else {
|
|
||||||
let upscayl = spawn(
|
|
||||||
execPath + "-realsr",
|
|
||||||
[
|
[
|
||||||
"-i",
|
"-i",
|
||||||
inputDir + "/" + fullfileName,
|
copiedInputFile,
|
||||||
"-o",
|
"-o",
|
||||||
outFile,
|
outFile,
|
||||||
"-s",
|
"-s",
|
||||||
4,
|
4,
|
||||||
"-x",
|
"-x",
|
||||||
"-m",
|
"-m",
|
||||||
modelsPath + "/" + model,
|
modelsPath + "/models-DF2K",
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
cwd: null,
|
cwd: null,
|
||||||
@ -156,30 +150,26 @@ ipcMain.on(commands.SHARPEN, async (event, payload) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let failed = false;
|
let failed = false;
|
||||||
upscayl.stderr.on("data", (stderr) => {
|
sharpen.stderr.on("data", (data) => {
|
||||||
console.log(stderr.toString());
|
console.log(data.toString());
|
||||||
stderr = stderr.toString();
|
data = data.toString();
|
||||||
mainWindow.webContents.send(commands.SHARPEN_PROGRESS, stderr.toString());
|
mainWindow.webContents.send(commands.UPSCAYL_PROGRESS, data.toString());
|
||||||
if (stderr.includes("invalid gpu") || stderr.includes("failed")) {
|
if (data.includes("invalid gpu") || data.includes("failed")) {
|
||||||
failed = true;
|
failed = true;
|
||||||
return null;
|
sharpen.kill("SIGKILL");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
sharpen.on("close", (_) => {
|
||||||
// Send done comamnd when
|
|
||||||
upscayl.on("close", (code) => {
|
|
||||||
if (failed !== true) {
|
if (failed !== true) {
|
||||||
console.log("Done upscaling");
|
console.log("Done upscaling");
|
||||||
return outFile;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on(commands.UPSCAYL, async (event, payload) => {
|
ipcMain.on(commands.UPSCAYL, async (event, payload) => {
|
||||||
const model = payload.model;
|
const model = payload.model;
|
||||||
const scale = payload.scaleFactor;
|
const scale = payload.scaleFactor;
|
||||||
const sharpen = payload.sharpen;
|
|
||||||
|
|
||||||
let inputDir = payload.imagePath.match(/(.*)[\/\\]/)[1] || "";
|
let inputDir = payload.imagePath.match(/(.*)[\/\\]/)[1] || "";
|
||||||
let outputDir = payload.outputPath;
|
let outputDir = payload.outputPath;
|
||||||
@ -202,8 +192,7 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
|
|||||||
// If already upscayled, just output that file
|
// If already upscayled, just output that file
|
||||||
mainWindow.webContents.send(commands.UPSCAYL_DONE, outFile);
|
mainWindow.webContents.send(commands.UPSCAYL_DONE, outFile);
|
||||||
} else {
|
} else {
|
||||||
let upscayl = model.includes("realesrgan")
|
let upscayl = spawn(
|
||||||
? spawn(
|
|
||||||
execPath + "-realesrgan",
|
execPath + "-realesrgan",
|
||||||
[
|
[
|
||||||
"-i",
|
"-i",
|
||||||
@ -221,24 +210,6 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
|
|||||||
cwd: null,
|
cwd: null,
|
||||||
detached: false,
|
detached: false,
|
||||||
}
|
}
|
||||||
)
|
|
||||||
: spawn(
|
|
||||||
execPath + "-realsr",
|
|
||||||
[
|
|
||||||
"-i",
|
|
||||||
inputDir + "/" + fullfileName,
|
|
||||||
"-o",
|
|
||||||
outFile,
|
|
||||||
"-s",
|
|
||||||
4,
|
|
||||||
"-x",
|
|
||||||
"-m",
|
|
||||||
modelsPath + "/" + model,
|
|
||||||
],
|
|
||||||
{
|
|
||||||
cwd: null,
|
|
||||||
detached: false,
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let failed = false;
|
let failed = false;
|
||||||
@ -273,7 +244,6 @@ autoUpdater.on("update-available", (_event, releaseNotes, releaseName) => {
|
|||||||
};
|
};
|
||||||
dialog.showMessageBox(dialogOpts, (response) => {});
|
dialog.showMessageBox(dialogOpts, (response) => {});
|
||||||
});
|
});
|
||||||
|
|
||||||
autoUpdater.on("update-downloaded", (_event, releaseNotes, releaseName) => {
|
autoUpdater.on("update-downloaded", (_event, releaseNotes, releaseName) => {
|
||||||
const dialogOpts = {
|
const dialogOpts = {
|
||||||
type: "info",
|
type: "info",
|
||||||
|
@ -152,10 +152,7 @@ const Home = () => {
|
|||||||
|
|
||||||
if (sharpen) {
|
if (sharpen) {
|
||||||
const sharpenedImage = await window.electron.send(commands.SHARPEN, {
|
const sharpenedImage = await window.electron.send(commands.SHARPEN, {
|
||||||
scaleFactor: 4,
|
|
||||||
imagePath,
|
imagePath,
|
||||||
outputPath,
|
|
||||||
model: "models-DF2K",
|
|
||||||
});
|
});
|
||||||
console.log("🚀 => upscaylHandler => sharpenedImage", sharpenedImage);
|
console.log("🚀 => upscaylHandler => sharpenedImage", sharpenedImage);
|
||||||
} else {
|
} else {
|
||||||
@ -164,7 +161,6 @@ const Home = () => {
|
|||||||
imagePath,
|
imagePath,
|
||||||
outputPath,
|
outputPath,
|
||||||
model,
|
model,
|
||||||
sharpen,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} 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 |
Loading…
Reference in New Issue
Block a user