mirror of
https://github.com/upscayl/upscayl.git
synced 2024-11-12 01:40:53 +01:00
Updated arguments functions
This commit is contained in:
parent
8eacbef0a6
commit
22f49e5361
@ -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
|
||||||
)
|
)
|
||||||
|
@ -1,99 +1,152 @@
|
|||||||
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) {
|
return [
|
||||||
case "singleImage":
|
"-i",
|
||||||
return [
|
inputDir + "/" + fullfileName,
|
||||||
"-i",
|
"-o",
|
||||||
inputDir + "/" + fullfileName,
|
outFile,
|
||||||
"-o",
|
"-s",
|
||||||
outFile,
|
scale == "2" ? "4" : scale,
|
||||||
"-s",
|
"-m",
|
||||||
scale === 2 ? 4 : scale,
|
modelsPath,
|
||||||
"-m",
|
"-n",
|
||||||
modelsPath,
|
model,
|
||||||
"-n",
|
gpuId ? `-g ${gpuId}` : "",
|
||||||
model,
|
"-f",
|
||||||
gpuId ? `-g ${gpuId}` : "",
|
saveImageAs,
|
||||||
"-f",
|
];
|
||||||
saveImageAs,
|
};
|
||||||
];
|
|
||||||
case "singleImageSharpen":
|
export const getSingleImageSharpenArguments = (
|
||||||
return [
|
inputDir: string,
|
||||||
"-i",
|
fullfileName: string,
|
||||||
inputDir + "/" + fullfileName,
|
outFile: string,
|
||||||
"-o",
|
modelsPath: string,
|
||||||
outFile,
|
model: string,
|
||||||
"-s",
|
scale: any,
|
||||||
scale,
|
gpuId: string,
|
||||||
"-x",
|
saveImageAs: string
|
||||||
"-m",
|
) => {
|
||||||
modelsPath + "/" + model,
|
return [
|
||||||
gpuId ? `-g ${gpuId}` : "",
|
"-i",
|
||||||
"-f",
|
inputDir + "/" + fullfileName,
|
||||||
saveImageAs,
|
"-o",
|
||||||
];
|
outFile,
|
||||||
case "doubleUpscayl":
|
"-s",
|
||||||
return [
|
scale,
|
||||||
"-i",
|
"-x",
|
||||||
inputDir + "/" + fullfileName,
|
"-m",
|
||||||
"-o",
|
modelsPath + "/" + model,
|
||||||
outFile,
|
gpuId ? `-g ${gpuId}` : "",
|
||||||
"-s",
|
"-f",
|
||||||
4,
|
saveImageAs,
|
||||||
"-m",
|
];
|
||||||
modelsPath,
|
};
|
||||||
"-n",
|
|
||||||
model,
|
export const getDoubleUpscaleArguments = (
|
||||||
gpuId ? `-g ${gpuId}` : "",
|
inputDir: string,
|
||||||
"-f",
|
fullfileName: string,
|
||||||
saveImageAs,
|
outFile: string,
|
||||||
];
|
modelsPath: string,
|
||||||
case "doubleUpscaylSecondPass":
|
model: string,
|
||||||
return [
|
gpuId: string,
|
||||||
"-i",
|
saveImageAs: string
|
||||||
isAlpha ? outFile + ".png" : outFile,
|
) => {
|
||||||
"-o",
|
return [
|
||||||
isAlpha ? outFile + ".png" : outFile,
|
"-i",
|
||||||
"-s",
|
inputDir + "/" + fullfileName,
|
||||||
4,
|
"-o",
|
||||||
"-m",
|
outFile,
|
||||||
modelsPath,
|
"-s",
|
||||||
"-n",
|
"4",
|
||||||
model,
|
"-m",
|
||||||
gpuId ? `-g ${gpuId}` : "",
|
modelsPath,
|
||||||
"-f",
|
"-n",
|
||||||
isAlpha ? "" : saveImageAs,
|
model,
|
||||||
];
|
gpuId ? `-g ${gpuId}` : "",
|
||||||
case "batch":
|
"-f",
|
||||||
return [
|
saveImageAs,
|
||||||
"-i",
|
];
|
||||||
inputDir,
|
};
|
||||||
"-o",
|
|
||||||
outFile,
|
export const getDoubleUpscaleSecondPassArguments = (
|
||||||
"-s",
|
isAlpha: boolean,
|
||||||
4,
|
outFile: string,
|
||||||
"-m",
|
modelsPath: string,
|
||||||
modelsPath,
|
model: string,
|
||||||
"-n",
|
gpuId: string,
|
||||||
model,
|
saveImageAs: string
|
||||||
gpuId ? `-g ${gpuId}` : "",
|
) => {
|
||||||
"-f",
|
return [
|
||||||
saveImageAs,
|
"-i",
|
||||||
];
|
isAlpha ? outFile + ".png" : outFile,
|
||||||
}
|
"-o",
|
||||||
|
isAlpha ? outFile + ".png" : outFile,
|
||||||
|
"-s",
|
||||||
|
"4",
|
||||||
|
"-m",
|
||||||
|
modelsPath,
|
||||||
|
"-n",
|
||||||
|
model,
|
||||||
|
gpuId ? `-g ${gpuId}` : "",
|
||||||
|
"-f",
|
||||||
|
isAlpha ? "" : saveImageAs,
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getBatchArguments = (
|
||||||
|
inputDir: string,
|
||||||
|
outputDir: string,
|
||||||
|
modelsPath: string,
|
||||||
|
model: string,
|
||||||
|
gpuId: string,
|
||||||
|
saveImageAs: string
|
||||||
|
) => {
|
||||||
|
return [
|
||||||
|
"-i",
|
||||||
|
inputDir,
|
||||||
|
"-o",
|
||||||
|
outputDir,
|
||||||
|
"-s",
|
||||||
|
"4",
|
||||||
|
"-m",
|
||||||
|
modelsPath,
|
||||||
|
"-n",
|
||||||
|
model,
|
||||||
|
gpuId ? `-g ${gpuId}` : "",
|
||||||
|
"-f",
|
||||||
|
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,
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user