1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-11-30 18:24:27 +01:00
upscayl/electron/utils/get-arguments.ts
Nayam Amarshe 6f8df14ed9 Fix #787
2024-04-24 16:04:32 +05:30

192 lines
3.4 KiB
TypeScript

import getModelScale from "@common/check-model-scale";
import { getPlatform } from "./get-device-specs";
import { ImageFormat } from "../types/types";
const slash: string = getPlatform() === "win" ? "\\" : "/";
export const getSingleImageArguments = ({
inputDir,
fullfileName,
outFile,
modelsPath,
model,
scale,
gpuId,
saveImageAs,
customWidth,
}: {
inputDir: string;
fullfileName: string;
outFile: string;
modelsPath: string;
model: string;
scale: string;
gpuId: string;
saveImageAs: ImageFormat;
customWidth: string;
}) => {
const modelScale = getModelScale(model);
let includeScale = modelScale !== scale && !customWidth;
return [
// INPUT IMAGE
"-i",
inputDir + slash + fullfileName,
// OUTPUT IMAGE
"-o",
outFile,
// OUTPUT SCALE
includeScale ? "-s" : "",
includeScale ? scale : "",
// MODELS PATH
"-m",
modelsPath,
// MODEL NAME
"-n",
model,
// GPU ID
gpuId ? "-g" : "",
gpuId ? gpuId : "",
// FORMAT
"-f",
saveImageAs,
// CUSTOM WIDTH
customWidth ? `-w` : "",
customWidth ? customWidth : "",
];
};
export const getDoubleUpscaleArguments = ({
inputDir,
fullfileName,
outFile,
modelsPath,
model,
gpuId,
saveImageAs,
}: {
inputDir: string;
fullfileName: string;
outFile: string;
modelsPath: string;
model: string;
gpuId: string;
saveImageAs: ImageFormat;
}) => {
return [
// INPUT IMAGE
"-i",
inputDir + slash + fullfileName,
// OUTPUT IMAGE
"-o",
outFile,
// MODELS PATH
"-m",
modelsPath,
// MODEL NAME
"-n",
model,
// GPU ID
gpuId ? `-g` : "",
gpuId ? gpuId : "",
// FORMAT
"-f",
saveImageAs,
];
};
export const getDoubleUpscaleSecondPassArguments = ({
outFile,
modelsPath,
model,
gpuId,
saveImageAs,
scale,
customWidth,
}: {
outFile: string;
modelsPath: string;
model: string;
gpuId: string;
saveImageAs: ImageFormat;
scale: string;
customWidth: string;
}) => {
const modelScale = getModelScale(model);
let includeScale = modelScale !== scale && !customWidth;
return [
// INPUT IMAGE
"-i",
outFile,
// OUTPUT IMAGE
"-o",
outFile,
// OUTPUT SCALE
includeScale ? "-s" : "",
includeScale ? scale : "",
// MODELS PATH
"-m",
modelsPath,
// MODEL NAME
"-n",
model,
// GPU ID
gpuId ? `-g` : "",
gpuId ? gpuId : "",
// FORMAT
"-f",
saveImageAs,
// CUSTOM WIDTH
customWidth ? `-w` : "",
customWidth ? customWidth : "",
];
};
export const getBatchArguments = ({
inputDir,
outputDir,
modelsPath,
model,
gpuId,
saveImageAs,
scale,
customWidth,
}: {
inputDir: string;
outputDir: string;
modelsPath: string;
model: string;
gpuId: string;
saveImageAs: ImageFormat;
scale: string;
customWidth: string;
}) => {
const modelScale = getModelScale(model);
let includeScale = modelScale !== scale && !customWidth;
return [
// INPUT IMAGE
"-i",
inputDir,
// OUTPUT IMAGE
"-o",
outputDir,
// OUTPUT SCALE
includeScale ? "-s" : "",
includeScale ? scale : "",
// MODELS PATH
"-m",
modelsPath,
// MODEL NAME
"-n",
model,
// GPU ID
gpuId ? `-g` : "",
gpuId ? gpuId : "",
// FORMAT
"-f",
saveImageAs,
// CUSTOM WIDTH
customWidth ? `-w` : "",
customWidth ? customWidth : "",
];
};