1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-11-23 23:21:05 +01:00

Update model scale usage in code

This commit is contained in:
Nayam Amarshe 2024-01-15 14:55:29 +05:30
parent a4b3ac2540
commit 68d3395cbe
8 changed files with 35 additions and 42 deletions

View File

@ -0,0 +1,17 @@
/**
* Get the scale of the model based on the model name
* @param model The model name
* @returns The initial scale of the model
*/
export default function getModelScale(model: string) {
const modelName = model.toLowerCase();
let initialScale = "4";
if (modelName.includes("x2") || modelName.includes("2x")) {
initialScale = "2";
} else if (modelName.includes("x3") || modelName.includes("3x")) {
initialScale = "3";
} else {
initialScale = "4";
}
return initialScale;
}

View File

@ -4,6 +4,6 @@ type FeatureFlags = {
};
export const featureFlags: FeatureFlags = {
APP_STORE_BUILD: false,
APP_STORE_BUILD: true,
SHOW_UPSCAYL_CLOUD_INFO: false,
};

View File

@ -21,6 +21,7 @@ import convertAndScale from "../utils/convert-and-scale";
import DEFAULT_MODELS from "../constants/models";
import { BatchUpscaylPayload } from "../../common/types/types";
import { ImageFormat } from "../utils/types";
import getModelScale from "../../common/check-model-scale";
const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
const mainWindow = getMainWindow();
@ -43,16 +44,8 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
const isDefaultModel = DEFAULT_MODELS.includes(model);
let initialScale = "4";
if (model.includes("x1")) {
initialScale = "1";
} else if (model.includes("x2")) {
initialScale = "2";
} else if (model.includes("x3")) {
initialScale = "3";
} else {
initialScale = "4";
}
let initialScale = getModelScale(model);
const desiredScale = payload.scale as string;
outputDir +=

View File

@ -24,6 +24,7 @@ import COMMAND from "../constants/commands";
import convertAndScale from "../utils/convert-and-scale";
import { DoubleUpscaylPayload } from "../../common/types/types";
import { ImageFormat } from "../utils/types";
import getModelScale from "../../common/check-model-scale";
const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {
const mainWindow = getMainWindow();
@ -50,16 +51,8 @@ const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {
const fullfileName = imagePath.split(slash).slice(-1)[0] as string;
const fileName = parse(fullfileName).name;
let initialScale = "4";
if (model.includes("x1")) {
initialScale = "1";
} else if (model.includes("x2")) {
initialScale = "2";
} else if (model.includes("x3")) {
initialScale = "3";
} else {
initialScale = "4";
}
let initialScale = getModelScale(model);
const desiredScale = parseInt(payload.scale) * parseInt(payload.scale);
const outFile =

View File

@ -24,6 +24,7 @@ import DEFAULT_MODELS from "../constants/models";
import { getMainWindow } from "../main-window";
import { ImageUpscaylPayload } from "../../common/types/types";
import { ImageFormat } from "../utils/types";
import getModelScale from "../../common/check-model-scale";
const imageUpscayl = async (event, payload: ImageUpscaylPayload) => {
const mainWindow = getMainWindow();
@ -55,16 +56,7 @@ const imageUpscayl = async (event, payload: ImageUpscaylPayload) => {
const fileName = parse(fullfileName).name;
const fileExt = parse(fullfileName).ext;
let initialScale = "4";
if (model.includes("x1")) {
initialScale = "1";
} else if (model.includes("x2")) {
initialScale = "2";
} else if (model.includes("x3")) {
initialScale = "3";
} else {
initialScale = "4";
}
let initialScale = getModelScale(model);
const desiredScale = payload.scale;

View File

@ -82,6 +82,12 @@ const convertAndScale = async (
}),
compressionLevel: 9,
}),
...(saveImageAs === "webp" && {
quality: 100 - (compression === 100 ? 99 : compression),
alphaQuality: 100,
lossless: compression === 0,
smartSubsample: true,
}),
force: true,
})
.withMetadata({

View File

@ -12,6 +12,7 @@ import {
scaleAtom,
} from "../../../atoms/userSettingsAtom";
import { featureFlags } from "@common/feature-flags";
import getModelScale from "@common/check-model-scale";
interface IProps {
selectImageHandler: () => Promise<void>;
@ -123,16 +124,7 @@ function LeftPaneImageSteps({
let singleScale = parseInt(scale);
if (noImageProcessing) {
let initialScale = 4;
if (model.includes("x1")) {
initialScale = 1;
} else if (model.includes("x2")) {
initialScale = 2;
} else if (model.includes("x3")) {
initialScale = 3;
} else {
initialScale = 4;
}
let initialScale = parseInt(getModelScale(model));
doubleScale = initialScale * initialScale;
singleScale = initialScale;
}

View File

@ -399,7 +399,7 @@ const Home = () => {
setImagePath(filePath);
var dirname = filePath.match(/(.*)[\/\\]/)[1] || "";
logit("🗂 Setting output path: ", dirname);
setOutputPath(dirname);
if (!featureFlags.APP_STORE_BUILD) setOutputPath(dirname);
validateImagePath(filePath);
}
};