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:
parent
18cbfd8b50
commit
d4ef6acca7
@ -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"));
|
||||
|
@ -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,29 +123,25 @@ 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",
|
||||
let sharpen = spawn(
|
||||
execPath("realsr"),
|
||||
[
|
||||
"-i",
|
||||
inputDir + "/" + fullfileName,
|
||||
copiedInputFile,
|
||||
"-o",
|
||||
outFile,
|
||||
"-s",
|
||||
4,
|
||||
"-x",
|
||||
"-m",
|
||||
modelsPath + "/" + model,
|
||||
modelsPath + "/models-DF2K",
|
||||
],
|
||||
{
|
||||
cwd: null,
|
||||
@ -156,30 +150,26 @@ ipcMain.on(commands.SHARPEN, async (event, payload) => {
|
||||
);
|
||||
|
||||
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")) {
|
||||
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;
|
||||
return null;
|
||||
sharpen.kill("SIGKILL");
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
// Send done comamnd when
|
||||
upscayl.on("close", (code) => {
|
||||
sharpen.on("close", (_) => {
|
||||
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;
|
||||
@ -202,8 +192,7 @@ 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(
|
||||
let upscayl = spawn(
|
||||
execPath + "-realesrgan",
|
||||
[
|
||||
"-i",
|
||||
@ -221,24 +210,6 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
|
||||
cwd: null,
|
||||
detached: false,
|
||||
}
|
||||
)
|
||||
: spawn(
|
||||
execPath + "-realsr",
|
||||
[
|
||||
"-i",
|
||||
inputDir + "/" + fullfileName,
|
||||
"-o",
|
||||
outFile,
|
||||
"-s",
|
||||
4,
|
||||
"-x",
|
||||
"-m",
|
||||
modelsPath + "/" + model,
|
||||
],
|
||||
{
|
||||
cwd: null,
|
||||
detached: false,
|
||||
}
|
||||
);
|
||||
|
||||
let failed = false;
|
||||
@ -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",
|
||||
|
@ -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 |
Loading…
Reference in New Issue
Block a user