mirror of
https://github.com/upscayl/upscayl.git
synced 2024-11-12 01:40:53 +01:00
Add jimp and scaled image
This commit is contained in:
parent
4663bafe5a
commit
6f9efe6972
@ -12,6 +12,7 @@ import { join, parse } from "path";
|
|||||||
import log from "electron-log";
|
import log from "electron-log";
|
||||||
import { format } from "url";
|
import { format } from "url";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
import Jimp from "jimp";
|
||||||
|
|
||||||
import { execPath, modelsPath } from "./binaries";
|
import { execPath, modelsPath } from "./binaries";
|
||||||
// Packages
|
// Packages
|
||||||
@ -22,6 +23,7 @@ import {
|
|||||||
dialog,
|
dialog,
|
||||||
shell,
|
shell,
|
||||||
MessageBoxOptions,
|
MessageBoxOptions,
|
||||||
|
protocol,
|
||||||
} from "electron";
|
} from "electron";
|
||||||
|
|
||||||
import { spawnUpscayl } from "./upscayl";
|
import { spawnUpscayl } from "./upscayl";
|
||||||
@ -71,6 +73,7 @@ app.on("ready", async () => {
|
|||||||
backgroundColor: "#171717",
|
backgroundColor: "#171717",
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
nodeIntegration: true,
|
nodeIntegration: true,
|
||||||
|
nodeIntegrationInWorker: true,
|
||||||
webSecurity: false,
|
webSecurity: false,
|
||||||
preload: join(__dirname, "preload.js"),
|
preload: join(__dirname, "preload.js"),
|
||||||
},
|
},
|
||||||
@ -96,6 +99,13 @@ app.on("ready", async () => {
|
|||||||
mainWindow.webContents.setZoomFactor(1);
|
mainWindow.webContents.setZoomFactor(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.whenReady().then(() => {
|
||||||
|
protocol.registerFileProtocol("file", (request, callback) => {
|
||||||
|
const pathname = decodeURI(request.url.replace("file:///", ""));
|
||||||
|
callback(pathname);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
if (!isDev) {
|
if (!isDev) {
|
||||||
autoUpdater.checkForUpdates();
|
autoUpdater.checkForUpdates();
|
||||||
}
|
}
|
||||||
@ -473,7 +483,6 @@ ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => {
|
|||||||
//------------------------Image Upscayl-----------------------------//
|
//------------------------Image Upscayl-----------------------------//
|
||||||
ipcMain.on(commands.UPSCAYL, async (event, payload) => {
|
ipcMain.on(commands.UPSCAYL, async (event, payload) => {
|
||||||
const model = payload.model as string;
|
const model = payload.model as string;
|
||||||
const scale = payload.scale as string;
|
|
||||||
const gpuId = payload.gpuId as string;
|
const gpuId = payload.gpuId as string;
|
||||||
const saveImageAs = payload.saveImageAs as string;
|
const saveImageAs = payload.saveImageAs as string;
|
||||||
|
|
||||||
@ -490,12 +499,21 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
|
|||||||
const fileName = parse(fullfileName).name;
|
const fileName = parse(fullfileName).name;
|
||||||
const fileExt = parse(fullfileName).ext;
|
const fileExt = parse(fullfileName).ext;
|
||||||
|
|
||||||
|
let scale = "4";
|
||||||
|
if (model.includes("x2")) {
|
||||||
|
scale = "2";
|
||||||
|
} else if (model.includes("x3")) {
|
||||||
|
scale = "3";
|
||||||
|
} else {
|
||||||
|
scale = "4";
|
||||||
|
}
|
||||||
|
|
||||||
const outFile =
|
const outFile =
|
||||||
outputDir +
|
outputDir +
|
||||||
slash +
|
slash +
|
||||||
fileName +
|
fileName +
|
||||||
"_upscayl_" +
|
"_upscayl_" +
|
||||||
scale +
|
payload.scale +
|
||||||
"x_" +
|
"x_" +
|
||||||
model +
|
model +
|
||||||
"." +
|
"." +
|
||||||
@ -522,19 +540,6 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
|
|||||||
logit
|
logit
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(
|
|
||||||
"BRUH: " +
|
|
||||||
getSingleImageArguments(
|
|
||||||
inputDir,
|
|
||||||
fullfileName,
|
|
||||||
outFile,
|
|
||||||
isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath,
|
|
||||||
model,
|
|
||||||
scale,
|
|
||||||
gpuId,
|
|
||||||
saveImageAs
|
|
||||||
)
|
|
||||||
);
|
|
||||||
childProcesses.push(upscayl);
|
childProcesses.push(upscayl);
|
||||||
|
|
||||||
stopped = false;
|
stopped = false;
|
||||||
@ -563,10 +568,24 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
|
|||||||
const onClose = () => {
|
const onClose = () => {
|
||||||
if (!failed && !stopped) {
|
if (!failed && !stopped) {
|
||||||
logit("💯 Done upscaling");
|
logit("💯 Done upscaling");
|
||||||
mainWindow.setProgressBar(-1);
|
logit("♻ Scaling and converting now...");
|
||||||
mainWindow.webContents.send(
|
Jimp.read(
|
||||||
commands.UPSCAYL_DONE,
|
isAlpha ? outFile + ".png" : outFile,
|
||||||
isAlpha ? outFile + ".png" : outFile
|
(err: any, image: any) => {
|
||||||
|
if (err) {
|
||||||
|
logit("❌ Error converting to PNG: ", err);
|
||||||
|
onError(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
image
|
||||||
|
.scale(parseInt(payload.scale as string))
|
||||||
|
.write(isAlpha ? outFile + ".png" : outFile);
|
||||||
|
mainWindow.setProgressBar(-1);
|
||||||
|
mainWindow.webContents.send(
|
||||||
|
commands.UPSCAYL_DONE,
|
||||||
|
isAlpha ? outFile + ".png" : outFile
|
||||||
|
);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
1423
package-lock.json
generated
1423
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -179,6 +179,7 @@
|
|||||||
"electron-next": "^3.1.5",
|
"electron-next": "^3.1.5",
|
||||||
"electron-updater": "^5.3.0",
|
"electron-updater": "^5.3.0",
|
||||||
"image-size": "^1.0.2",
|
"image-size": "^1.0.2",
|
||||||
|
"jimp": "^0.22.8",
|
||||||
"jotai": "^2.0.4",
|
"jotai": "^2.0.4",
|
||||||
"react-compare-slider": "^2.2.0",
|
"react-compare-slider": "^2.2.0",
|
||||||
"react-dropzone": "^14.2.3",
|
"react-dropzone": "^14.2.3",
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useAtom, useAtomValue } from "jotai";
|
import { useAtomValue } from "jotai";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import Select from "react-select";
|
import Select from "react-select";
|
||||||
import ReactTooltip from "react-tooltip";
|
import ReactTooltip from "react-tooltip";
|
||||||
|
@ -125,7 +125,7 @@ const Home = () => {
|
|||||||
window.electron.on(commands.UPSCAYL_DONE, (_, data: string) => {
|
window.electron.on(commands.UPSCAYL_DONE, (_, data: string) => {
|
||||||
setProgress("");
|
setProgress("");
|
||||||
setUpscaledImagePath(data);
|
setUpscaledImagePath(data);
|
||||||
logit("upscaledImagePath: ", upscaledImagePath);
|
logit("upscaledImagePath: ", data);
|
||||||
logit(`💯 UPSCAYL_DONE: `, data);
|
logit(`💯 UPSCAYL_DONE: `, data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user