1
0
mirror of https://github.com/upscayl/upscayl.git synced 2025-01-18 17:14:08 +01:00

Fix noImageProcessing

This commit is contained in:
Nayam Amarshe 2023-09-19 20:34:31 +05:30
parent de2c7c501b
commit 6b6d42fadc
3 changed files with 68 additions and 40 deletions

View File

@ -3,6 +3,7 @@ import { getMainWindow } from "../main-window";
import {
childProcesses,
customModelsFolderPath,
noImageProcessing,
outputFolderPath,
saveOutputFolder,
setStopped,
@ -115,6 +116,12 @@ const batchUpscayl = async (event, payload) => {
logit("♻ Scaling and converting now...");
upscayl.kill();
mainWindow && mainWindow.webContents.send(COMMAND.SCALING_AND_CONVERTING);
if (noImageProcessing) {
logit("🚫 Skipping scaling and converting");
mainWindow.setProgressBar(-1);
mainWindow.webContents.send(COMMAND.FOLDER_UPSCAYL_DONE, outputDir);
return;
}
// Get number of files in output folder
const files = fs.readdirSync(inputDir);
try {

View File

@ -3,6 +3,7 @@ import { getMainWindow } from "../main-window";
import {
childProcesses,
customModelsFolderPath,
noImageProcessing,
outputFolderPath,
saveOutputFolder,
setStopped,
@ -42,21 +43,24 @@ const doubleUpscayl = async (event, payload) => {
const fullfileName = imagePath.split(slash).slice(-1)[0] as string;
const fileName = parse(fullfileName).name;
let scale = "4";
let initialScale = "4";
if (model.includes("x2")) {
scale = "2";
initialScale = "2";
} else if (model.includes("x3")) {
scale = "3";
initialScale = "3";
} else {
scale = "4";
initialScale = "4";
}
const desiredScale = parseInt(payload.scale) * parseInt(payload.scale);
const outFile =
outputDir +
slash +
fileName +
"_upscayl_" +
parseInt(payload.scale) * parseInt(payload.scale) +
(noImageProcessing
? parseInt(initialScale) * parseInt(initialScale)
: desiredScale) +
"x_" +
model +
"." +
@ -73,7 +77,7 @@ const doubleUpscayl = async (event, payload) => {
model,
gpuId,
saveImageAs,
scale
initialScale
),
logit
);
@ -124,6 +128,24 @@ const doubleUpscayl = async (event, payload) => {
logit("💯 Done upscaling");
logit("♻ Scaling and converting now...");
mainWindow.webContents.send(COMMAND.SCALING_AND_CONVERTING);
if (noImageProcessing) {
logit("🚫 Skipping scaling and converting");
mainWindow.setProgressBar(-1);
mainWindow.webContents.send(
COMMAND.DOUBLE_UPSCAYL_DONE,
isAlpha
? (outFile + ".png").replace(
/([^/\\]+)$/i,
encodeURIComponent((outFile + ".png").match(/[^/\\]+$/i)![0])
)
: outFile.replace(
/([^/\\]+)$/i,
encodeURIComponent(outFile.match(/[^/\\]+$/i)![0])
)
);
return;
}
try {
await convertAndScale(
inputDir + slash + fullfileName,
@ -173,7 +195,7 @@ const doubleUpscayl = async (event, payload) => {
model,
gpuId,
saveImageAs,
scale
initialScale
),
logit
);

View File

@ -146,39 +146,7 @@ const imageUpscayl = async (event, payload) => {
if (!failed && !stopped) {
logit("💯 Done upscaling");
logit("♻ Scaling and converting now...");
if (noImageProcessing === false) {
mainWindow.webContents.send(COMMAND.SCALING_AND_CONVERTING);
// Free up memory
upscayl.kill();
try {
await convertAndScale(
inputDir + slash + fullfileName,
isAlpha ? outFile + ".png" : outFile,
outFile,
desiredScale,
saveImageAs,
onError
);
mainWindow.setProgressBar(-1);
mainWindow.webContents.send(
COMMAND.UPSCAYL_DONE,
outFile.replace(
/([^/\\]+)$/i,
encodeURIComponent(outFile.match(/[^/\\]+$/i)![0])
)
);
} catch (error) {
logit(
"❌ Error processing (scaling and converting) the image. Please report this error on GitHub.",
error
);
upscayl.kill();
mainWindow.webContents.send(
COMMAND.UPSCAYL_ERROR,
"Error processing (scaling and converting) the image. Please report this error on Upscayl GitHub Issues page."
);
}
} else {
if (noImageProcessing) {
logit("🚫 Skipping scaling and converting");
mainWindow.setProgressBar(-1);
mainWindow.webContents.send(
@ -189,6 +157,37 @@ const imageUpscayl = async (event, payload) => {
)
);
}
mainWindow.webContents.send(COMMAND.SCALING_AND_CONVERTING);
// Free up memory
upscayl.kill();
try {
await convertAndScale(
inputDir + slash + fullfileName,
isAlpha ? outFile + ".png" : outFile,
outFile,
desiredScale,
saveImageAs,
onError
);
mainWindow.setProgressBar(-1);
mainWindow.webContents.send(
COMMAND.UPSCAYL_DONE,
outFile.replace(
/([^/\\]+)$/i,
encodeURIComponent(outFile.match(/[^/\\]+$/i)![0])
)
);
} catch (error) {
logit(
"❌ Error processing (scaling and converting) the image. Please report this error on GitHub.",
error
);
upscayl.kill();
mainWindow.webContents.send(
COMMAND.UPSCAYL_ERROR,
"Error processing (scaling and converting) the image. Please report this error on Upscayl GitHub Issues page."
);
}
}
};