mirror of
https://github.com/upscayl/upscayl.git
synced 2024-11-28 01:10:52 +01:00
Fix double upscayl
This commit is contained in:
parent
f1d1e8353b
commit
0cb8814615
@ -20,6 +20,7 @@ import { modelsPath } from "../utils/get-resource-paths";
|
|||||||
import logit from "../utils/logit";
|
import logit from "../utils/logit";
|
||||||
import COMMAND from "../constants/commands";
|
import COMMAND from "../constants/commands";
|
||||||
import sharp from "sharp";
|
import sharp from "sharp";
|
||||||
|
import convertAndScale from "../utils/convert-and-scale";
|
||||||
|
|
||||||
const doubleUpscayl = async (event, payload) => {
|
const doubleUpscayl = async (event, payload) => {
|
||||||
const mainWindow = getMainWindow();
|
const mainWindow = getMainWindow();
|
||||||
@ -42,8 +43,6 @@ const doubleUpscayl = async (event, payload) => {
|
|||||||
|
|
||||||
const fullfileName = imagePath.split(slash).slice(-1)[0] as string;
|
const fullfileName = imagePath.split(slash).slice(-1)[0] as string;
|
||||||
const fileName = parse(fullfileName).name;
|
const fileName = parse(fullfileName).name;
|
||||||
const outFile =
|
|
||||||
outputDir + slash + fileName + "_upscayl_16x_" + model + "." + saveImageAs;
|
|
||||||
|
|
||||||
let scale = "4";
|
let scale = "4";
|
||||||
if (model.includes("x2")) {
|
if (model.includes("x2")) {
|
||||||
@ -54,6 +53,17 @@ const doubleUpscayl = async (event, payload) => {
|
|||||||
scale = "4";
|
scale = "4";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const outFile =
|
||||||
|
outputDir +
|
||||||
|
slash +
|
||||||
|
fileName +
|
||||||
|
"_upscayl_" +
|
||||||
|
parseInt(payload.scale) * parseInt(payload.scale) +
|
||||||
|
"x_" +
|
||||||
|
model +
|
||||||
|
"." +
|
||||||
|
saveImageAs;
|
||||||
|
|
||||||
// UPSCALE
|
// UPSCALE
|
||||||
let upscayl = spawnUpscayl(
|
let upscayl = spawnUpscayl(
|
||||||
"realesrgan",
|
"realesrgan",
|
||||||
@ -117,41 +127,14 @@ const doubleUpscayl = async (event, payload) => {
|
|||||||
logit("♻ Scaling and converting now...");
|
logit("♻ Scaling and converting now...");
|
||||||
mainWindow.webContents.send(COMMAND.SCALING_AND_CONVERTING);
|
mainWindow.webContents.send(COMMAND.SCALING_AND_CONVERTING);
|
||||||
try {
|
try {
|
||||||
const originalImage = await sharp(
|
await convertAndScale(
|
||||||
inputDir + slash + fullfileName
|
inputDir + slash + fullfileName,
|
||||||
).metadata();
|
isAlpha ? outFile + ".png" : outFile,
|
||||||
if (!mainWindow || !originalImage) {
|
outFile,
|
||||||
throw new Error("Could not grab the original image!");
|
payload.scale,
|
||||||
}
|
saveImageAs,
|
||||||
// Resize the image to the scale
|
onError
|
||||||
const newImage = sharp(isAlpha ? outFile + ".png" : outFile)
|
|
||||||
.resize(
|
|
||||||
originalImage.width &&
|
|
||||||
originalImage.width * parseInt(payload.scale),
|
|
||||||
originalImage.height &&
|
|
||||||
originalImage.height * parseInt(payload.scale)
|
|
||||||
)
|
|
||||||
.withMetadata(); // Keep metadata
|
|
||||||
// Change the output according to the saveImageAs
|
|
||||||
if (saveImageAs === "png") {
|
|
||||||
newImage.png({ quality: 100 - quality });
|
|
||||||
} else if (saveImageAs === "jpg") {
|
|
||||||
newImage.jpeg({ quality: 100 - quality });
|
|
||||||
}
|
|
||||||
// Save the image
|
|
||||||
await newImage
|
|
||||||
.toFile(isAlpha ? outFile + ".png" : outFile)
|
|
||||||
.then(() => {
|
|
||||||
logit(
|
|
||||||
"✅ Done converting to: ",
|
|
||||||
isAlpha ? outFile + ".png" : outFile
|
|
||||||
);
|
);
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
logit("❌ Error converting to: ", saveImageAs, error);
|
|
||||||
upscayl.kill();
|
|
||||||
onError(error);
|
|
||||||
});
|
|
||||||
mainWindow.setProgressBar(-1);
|
mainWindow.setProgressBar(-1);
|
||||||
mainWindow.webContents.send(
|
mainWindow.webContents.send(
|
||||||
COMMAND.DOUBLE_UPSCAYL_DONE,
|
COMMAND.DOUBLE_UPSCAYL_DONE,
|
||||||
|
@ -17,9 +17,11 @@ import { execPath, modelsPath } from "./utils/get-resource-paths";
|
|||||||
import batchUpscayl from "./commands/batch-upscayl";
|
import batchUpscayl from "./commands/batch-upscayl";
|
||||||
import doubleUpscayl from "./commands/double-upscayl";
|
import doubleUpscayl from "./commands/double-upscayl";
|
||||||
import autoUpdate from "./commands/auto-update";
|
import autoUpdate from "./commands/auto-update";
|
||||||
|
import sharp from "sharp";
|
||||||
|
|
||||||
// INITIALIZATION
|
// INITIALIZATION
|
||||||
log.initialize({ preload: true });
|
log.initialize({ preload: true });
|
||||||
|
sharp.cache(false);
|
||||||
logit("🚃 App Path: ", app.getAppPath());
|
logit("🚃 App Path: ", app.getAppPath());
|
||||||
|
|
||||||
app.whenReady().then(async () => {
|
app.whenReady().then(async () => {
|
||||||
|
@ -161,8 +161,8 @@ const Home = () => {
|
|||||||
// DOUBLE UPSCAYL DONE
|
// DOUBLE UPSCAYL DONE
|
||||||
window.electron.on(COMMAND.DOUBLE_UPSCAYL_DONE, (_, data: string) => {
|
window.electron.on(COMMAND.DOUBLE_UPSCAYL_DONE, (_, data: string) => {
|
||||||
setProgress("");
|
setProgress("");
|
||||||
|
setTimeout(() => setUpscaledImagePath(data), 500);
|
||||||
setDoubleUpscaylCounter(0);
|
setDoubleUpscaylCounter(0);
|
||||||
setUpscaledImagePath(data);
|
|
||||||
logit(`💯 DOUBLE_UPSCAYL_DONE: `, data);
|
logit(`💯 DOUBLE_UPSCAYL_DONE: `, data);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -595,7 +595,7 @@ const Home = () => {
|
|||||||
hideZoomOptions={true}
|
hideZoomOptions={true}
|
||||||
/>
|
/>
|
||||||
<img
|
<img
|
||||||
src={`file:///${imagePath}`}
|
src={"file:///" + imagePath}
|
||||||
onLoad={(e: any) => {
|
onLoad={(e: any) => {
|
||||||
setDimensions({
|
setDimensions({
|
||||||
width: e.target.naturalWidth,
|
width: e.target.naturalWidth,
|
||||||
|
Loading…
Reference in New Issue
Block a user