1
0
mirror of https://github.com/upscayl/upscayl.git synced 2025-02-25 22:47:59 +01:00

Updated arguments functions

This commit is contained in:
Nayam Amarshe 2023-03-18 17:45:48 +05:30
parent 8eacbef0a6
commit 22f49e5361
2 changed files with 182 additions and 133 deletions

View File

@ -1,3 +1,11 @@
import {
getBatchArguments,
getBatchSharpenArguments,
getDoubleUpscaleArguments,
getDoubleUpscaleSecondPassArguments,
getSingleImageArguments,
getSingleImageSharpenArguments,
} from "./utils/getArguments";
// Native // Native
import { join, parse } from "path"; import { join, parse } from "path";
import { format } from "url"; import { format } from "url";
@ -24,7 +32,6 @@ import isDev from "electron-is-dev";
import prepareNext from "electron-next"; import prepareNext from "electron-next";
import commands from "./commands"; import commands from "./commands";
import { spawnUpscayl } from "./upscayl"; import { spawnUpscayl } from "./upscayl";
import { getCommandArguments } from "./utils/getArguments";
// Prepare the renderer once the app is ready // Prepare the renderer once the app is ready
let mainWindow; let mainWindow;
@ -119,18 +126,18 @@ ipcMain.on(commands.OPEN_FOLDER, async (event, payload) => {
//------------------------Double Upscayl-----------------------------// //------------------------Double Upscayl-----------------------------//
ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => { ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => {
const model = payload.model; const model = payload.model as string;
let inputDir = payload.imagePath.match(/(.*)[\/\\]/)[1] || ""; let inputDir = (payload.imagePath.match(/(.*)[\/\\]/)[1] || "") as string;
let outputDir = payload.outputPath; let outputDir = payload.outputPath as string;
const gpuId = payload.gpuId; const gpuId = payload.gpuId as string;
const saveImageAs = payload.saveImageAs; const saveImageAs = payload.saveImageAs as string;
// COPY IMAGE TO TMP FOLDER // COPY IMAGE TO TMP FOLDER
const platform = getPlatform(); const platform = getPlatform();
const fullfileName = const fullfileName =
platform === "win" platform === "win"
? payload.imagePath.split("\\").slice(-1)[0] ? (payload.imagePath.split("\\").slice(-1)[0] as string)
: payload.imagePath.split("/").slice(-1)[0]; : (payload.imagePath.split("/").slice(-1)[0] as string);
const fileName = parse(fullfileName).name; const fileName = parse(fullfileName).name;
const fileExt = parse(fullfileName).ext; const fileExt = parse(fullfileName).ext;
const outFile = const outFile =
@ -139,11 +146,10 @@ ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => {
// UPSCALE // UPSCALE
let upscayl = spawnUpscayl( let upscayl = spawnUpscayl(
"realesrgan", "realesrgan",
getCommandArguments( getDoubleUpscaleArguments(
"doubleUpscayl",
inputDir, inputDir,
fullfileName, fullfileName,
outputDir, outFile,
modelsPath, modelsPath,
model, model,
gpuId, gpuId,
@ -216,15 +222,13 @@ ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => {
// UPSCALE // UPSCALE
let upscayl2 = spawnUpscayl( let upscayl2 = spawnUpscayl(
"realesrgan", "realesrgan",
getCommandArguments( getDoubleUpscaleSecondPassArguments(
"doubleUpscaylSecondPass", isAlpha,
null,
null,
outFile, outFile,
modelsPath, modelsPath,
model, model,
gpuId, gpuId,
isAlpha saveImageAs
) )
); );
@ -237,15 +241,15 @@ 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; const model = payload.model as string;
const scale = payload.scaleFactor; const scale = payload.scaleFactor;
const gpuId = payload.gpuId; const gpuId = payload.gpuId as string;
const saveImageAs = payload.saveImageAs; const saveImageAs = payload.saveImageAs as string;
let inputDir = payload.imagePath.match(/(.*)[\/\\]/)[1] || ""; let inputDir = (payload.imagePath.match(/(.*)[\/\\]/)[1] || "") as string;
let outputDir = payload.outputPath; let outputDir = payload.outputPath as string;
// COPY IMAGE TO TMP FOLDER // COPY IMAGE TO TMP FOLDER
const fullfileName = payload.imagePath.replace(/^.*[\\\/]/, ""); const fullfileName = payload.imagePath.replace(/^.*[\\\/]/, "") as string;
const fileName = parse(fullfileName).name; const fileName = parse(fullfileName).name;
console.log("🚀 => fileName", fileName); console.log("🚀 => fileName", fileName);
@ -284,8 +288,7 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
default: default:
upscayl = spawnUpscayl( upscayl = spawnUpscayl(
"realesrgan", "realesrgan",
getCommandArguments( getSingleImageArguments(
"singleImage",
inputDir, inputDir,
fullfileName, fullfileName,
outFile, outFile,
@ -293,15 +296,14 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
model, model,
scale, scale,
gpuId, gpuId,
false saveImageAs
) )
); );
break; break;
case "models-DF2K": case "models-DF2K":
upscayl = spawnUpscayl( upscayl = spawnUpscayl(
"realsr", "realsr",
getCommandArguments( getSingleImageSharpenArguments(
"singleImage",
inputDir, inputDir,
fullfileName, fullfileName,
outFile, outFile,
@ -309,7 +311,7 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
model, model,
scale, scale,
gpuId, gpuId,
false saveImageAs
) )
); );
break; break;
@ -380,14 +382,11 @@ ipcMain.on(commands.FOLDER_UPSCAYL, async (event, payload) => {
default: default:
upscayl = spawnUpscayl( upscayl = spawnUpscayl(
"realesrgan", "realesrgan",
getCommandArguments( getBatchArguments(
"batch",
inputDir, inputDir,
"",
outputDir, outputDir,
modelsPath, modelsPath,
model, model,
4,
gpuId, gpuId,
saveImageAs saveImageAs
) )
@ -396,14 +395,11 @@ ipcMain.on(commands.FOLDER_UPSCAYL, async (event, payload) => {
case "models-DF2K": case "models-DF2K":
upscayl = spawnUpscayl( upscayl = spawnUpscayl(
"realsr", "realsr",
getCommandArguments( getBatchSharpenArguments(
"batch",
inputDir, inputDir,
"",
outputDir, outputDir,
modelsPath, modelsPath,
model, model,
4,
gpuId, gpuId,
saveImageAs saveImageAs
) )

View File

@ -1,29 +1,20 @@
export const getCommandArguments = ( export const getSingleImageArguments = (
type: inputDir: string,
| "singleImage" fullfileName: string,
| "singleImageSharpen" outFile: string,
| "doubleUpscayl" modelsPath: string,
| "doubleUpscaylSecondPass" model: string,
| "batch", scale: any,
inputDir?: any, gpuId: string,
fullfileName?: any, saveImageAs: string
outFile?: any,
modelsPath?: any,
model?: any,
scale?: any,
gpuId?: any,
saveImageAs?: any,
isAlpha?: any
) => { ) => {
switch (type) {
case "singleImage":
return [ return [
"-i", "-i",
inputDir + "/" + fullfileName, inputDir + "/" + fullfileName,
"-o", "-o",
outFile, outFile,
"-s", "-s",
scale === 2 ? 4 : scale, scale == "2" ? "4" : scale,
"-m", "-m",
modelsPath, modelsPath,
"-n", "-n",
@ -32,7 +23,18 @@ export const getCommandArguments = (
"-f", "-f",
saveImageAs, saveImageAs,
]; ];
case "singleImageSharpen": };
export const getSingleImageSharpenArguments = (
inputDir: string,
fullfileName: string,
outFile: string,
modelsPath: string,
model: string,
scale: any,
gpuId: string,
saveImageAs: string
) => {
return [ return [
"-i", "-i",
inputDir + "/" + fullfileName, inputDir + "/" + fullfileName,
@ -47,14 +49,24 @@ export const getCommandArguments = (
"-f", "-f",
saveImageAs, saveImageAs,
]; ];
case "doubleUpscayl": };
export const getDoubleUpscaleArguments = (
inputDir: string,
fullfileName: string,
outFile: string,
modelsPath: string,
model: string,
gpuId: string,
saveImageAs: string
) => {
return [ return [
"-i", "-i",
inputDir + "/" + fullfileName, inputDir + "/" + fullfileName,
"-o", "-o",
outFile, outFile,
"-s", "-s",
4, "4",
"-m", "-m",
modelsPath, modelsPath,
"-n", "-n",
@ -63,14 +75,23 @@ export const getCommandArguments = (
"-f", "-f",
saveImageAs, saveImageAs,
]; ];
case "doubleUpscaylSecondPass": };
export const getDoubleUpscaleSecondPassArguments = (
isAlpha: boolean,
outFile: string,
modelsPath: string,
model: string,
gpuId: string,
saveImageAs: string
) => {
return [ return [
"-i", "-i",
isAlpha ? outFile + ".png" : outFile, isAlpha ? outFile + ".png" : outFile,
"-o", "-o",
isAlpha ? outFile + ".png" : outFile, isAlpha ? outFile + ".png" : outFile,
"-s", "-s",
4, "4",
"-m", "-m",
modelsPath, modelsPath,
"-n", "-n",
@ -79,14 +100,23 @@ export const getCommandArguments = (
"-f", "-f",
isAlpha ? "" : saveImageAs, isAlpha ? "" : saveImageAs,
]; ];
case "batch": };
export const getBatchArguments = (
inputDir: string,
outputDir: string,
modelsPath: string,
model: string,
gpuId: string,
saveImageAs: string
) => {
return [ return [
"-i", "-i",
inputDir, inputDir,
"-o", "-o",
outFile, outputDir,
"-s", "-s",
4, "4",
"-m", "-m",
modelsPath, modelsPath,
"-n", "-n",
@ -95,5 +125,28 @@ export const getCommandArguments = (
"-f", "-f",
saveImageAs, saveImageAs,
]; ];
} };
export const getBatchSharpenArguments = (
inputDir: string,
outputDir: string,
modelsPath: string,
model: string,
gpuId: string,
saveImageAs: string
) => {
return [
"-i",
inputDir,
"-o",
outputDir,
"-s",
"4",
"-x",
"-m",
modelsPath + "/" + model,
gpuId ? `-g ${gpuId}` : "",
"-f",
saveImageAs,
];
}; };