mirror of
https://github.com/upscayl/upscayl.git
synced 2025-02-17 11:18:36 +01:00
Update model scale usage in code
This commit is contained in:
parent
a4b3ac2540
commit
68d3395cbe
17
common/check-model-scale.ts
Normal file
17
common/check-model-scale.ts
Normal 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;
|
||||||
|
}
|
@ -4,6 +4,6 @@ type FeatureFlags = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const featureFlags: FeatureFlags = {
|
export const featureFlags: FeatureFlags = {
|
||||||
APP_STORE_BUILD: false,
|
APP_STORE_BUILD: true,
|
||||||
SHOW_UPSCAYL_CLOUD_INFO: false,
|
SHOW_UPSCAYL_CLOUD_INFO: false,
|
||||||
};
|
};
|
||||||
|
@ -21,6 +21,7 @@ import convertAndScale from "../utils/convert-and-scale";
|
|||||||
import DEFAULT_MODELS from "../constants/models";
|
import DEFAULT_MODELS from "../constants/models";
|
||||||
import { BatchUpscaylPayload } from "../../common/types/types";
|
import { BatchUpscaylPayload } from "../../common/types/types";
|
||||||
import { ImageFormat } from "../utils/types";
|
import { ImageFormat } from "../utils/types";
|
||||||
|
import getModelScale from "../../common/check-model-scale";
|
||||||
|
|
||||||
const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
|
const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
|
||||||
const mainWindow = getMainWindow();
|
const mainWindow = getMainWindow();
|
||||||
@ -43,16 +44,8 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
|
|||||||
|
|
||||||
const isDefaultModel = DEFAULT_MODELS.includes(model);
|
const isDefaultModel = DEFAULT_MODELS.includes(model);
|
||||||
|
|
||||||
let initialScale = "4";
|
let initialScale = getModelScale(model);
|
||||||
if (model.includes("x1")) {
|
|
||||||
initialScale = "1";
|
|
||||||
} else if (model.includes("x2")) {
|
|
||||||
initialScale = "2";
|
|
||||||
} else if (model.includes("x3")) {
|
|
||||||
initialScale = "3";
|
|
||||||
} else {
|
|
||||||
initialScale = "4";
|
|
||||||
}
|
|
||||||
const desiredScale = payload.scale as string;
|
const desiredScale = payload.scale as string;
|
||||||
|
|
||||||
outputDir +=
|
outputDir +=
|
||||||
|
@ -24,6 +24,7 @@ import COMMAND from "../constants/commands";
|
|||||||
import convertAndScale from "../utils/convert-and-scale";
|
import convertAndScale from "../utils/convert-and-scale";
|
||||||
import { DoubleUpscaylPayload } from "../../common/types/types";
|
import { DoubleUpscaylPayload } from "../../common/types/types";
|
||||||
import { ImageFormat } from "../utils/types";
|
import { ImageFormat } from "../utils/types";
|
||||||
|
import getModelScale from "../../common/check-model-scale";
|
||||||
|
|
||||||
const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {
|
const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {
|
||||||
const mainWindow = getMainWindow();
|
const mainWindow = getMainWindow();
|
||||||
@ -50,16 +51,8 @@ const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {
|
|||||||
const fullfileName = imagePath.split(slash).slice(-1)[0] as string;
|
const fullfileName = imagePath.split(slash).slice(-1)[0] as string;
|
||||||
const fileName = parse(fullfileName).name;
|
const fileName = parse(fullfileName).name;
|
||||||
|
|
||||||
let initialScale = "4";
|
let initialScale = getModelScale(model);
|
||||||
if (model.includes("x1")) {
|
|
||||||
initialScale = "1";
|
|
||||||
} else if (model.includes("x2")) {
|
|
||||||
initialScale = "2";
|
|
||||||
} else if (model.includes("x3")) {
|
|
||||||
initialScale = "3";
|
|
||||||
} else {
|
|
||||||
initialScale = "4";
|
|
||||||
}
|
|
||||||
const desiredScale = parseInt(payload.scale) * parseInt(payload.scale);
|
const desiredScale = parseInt(payload.scale) * parseInt(payload.scale);
|
||||||
|
|
||||||
const outFile =
|
const outFile =
|
||||||
|
@ -24,6 +24,7 @@ import DEFAULT_MODELS from "../constants/models";
|
|||||||
import { getMainWindow } from "../main-window";
|
import { getMainWindow } from "../main-window";
|
||||||
import { ImageUpscaylPayload } from "../../common/types/types";
|
import { ImageUpscaylPayload } from "../../common/types/types";
|
||||||
import { ImageFormat } from "../utils/types";
|
import { ImageFormat } from "../utils/types";
|
||||||
|
import getModelScale from "../../common/check-model-scale";
|
||||||
|
|
||||||
const imageUpscayl = async (event, payload: ImageUpscaylPayload) => {
|
const imageUpscayl = async (event, payload: ImageUpscaylPayload) => {
|
||||||
const mainWindow = getMainWindow();
|
const mainWindow = getMainWindow();
|
||||||
@ -55,16 +56,7 @@ const imageUpscayl = async (event, payload: ImageUpscaylPayload) => {
|
|||||||
const fileName = parse(fullfileName).name;
|
const fileName = parse(fullfileName).name;
|
||||||
const fileExt = parse(fullfileName).ext;
|
const fileExt = parse(fullfileName).ext;
|
||||||
|
|
||||||
let initialScale = "4";
|
let initialScale = getModelScale(model);
|
||||||
if (model.includes("x1")) {
|
|
||||||
initialScale = "1";
|
|
||||||
} else if (model.includes("x2")) {
|
|
||||||
initialScale = "2";
|
|
||||||
} else if (model.includes("x3")) {
|
|
||||||
initialScale = "3";
|
|
||||||
} else {
|
|
||||||
initialScale = "4";
|
|
||||||
}
|
|
||||||
|
|
||||||
const desiredScale = payload.scale;
|
const desiredScale = payload.scale;
|
||||||
|
|
||||||
|
@ -82,6 +82,12 @@ const convertAndScale = async (
|
|||||||
}),
|
}),
|
||||||
compressionLevel: 9,
|
compressionLevel: 9,
|
||||||
}),
|
}),
|
||||||
|
...(saveImageAs === "webp" && {
|
||||||
|
quality: 100 - (compression === 100 ? 99 : compression),
|
||||||
|
alphaQuality: 100,
|
||||||
|
lossless: compression === 0,
|
||||||
|
smartSubsample: true,
|
||||||
|
}),
|
||||||
force: true,
|
force: true,
|
||||||
})
|
})
|
||||||
.withMetadata({
|
.withMetadata({
|
||||||
|
@ -12,6 +12,7 @@ import {
|
|||||||
scaleAtom,
|
scaleAtom,
|
||||||
} from "../../../atoms/userSettingsAtom";
|
} from "../../../atoms/userSettingsAtom";
|
||||||
import { featureFlags } from "@common/feature-flags";
|
import { featureFlags } from "@common/feature-flags";
|
||||||
|
import getModelScale from "@common/check-model-scale";
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
selectImageHandler: () => Promise<void>;
|
selectImageHandler: () => Promise<void>;
|
||||||
@ -123,16 +124,7 @@ function LeftPaneImageSteps({
|
|||||||
let singleScale = parseInt(scale);
|
let singleScale = parseInt(scale);
|
||||||
|
|
||||||
if (noImageProcessing) {
|
if (noImageProcessing) {
|
||||||
let initialScale = 4;
|
let initialScale = parseInt(getModelScale(model));
|
||||||
if (model.includes("x1")) {
|
|
||||||
initialScale = 1;
|
|
||||||
} else if (model.includes("x2")) {
|
|
||||||
initialScale = 2;
|
|
||||||
} else if (model.includes("x3")) {
|
|
||||||
initialScale = 3;
|
|
||||||
} else {
|
|
||||||
initialScale = 4;
|
|
||||||
}
|
|
||||||
doubleScale = initialScale * initialScale;
|
doubleScale = initialScale * initialScale;
|
||||||
singleScale = initialScale;
|
singleScale = initialScale;
|
||||||
}
|
}
|
||||||
|
@ -399,7 +399,7 @@ const Home = () => {
|
|||||||
setImagePath(filePath);
|
setImagePath(filePath);
|
||||||
var dirname = filePath.match(/(.*)[\/\\]/)[1] || "";
|
var dirname = filePath.match(/(.*)[\/\\]/)[1] || "";
|
||||||
logit("🗂 Setting output path: ", dirname);
|
logit("🗂 Setting output path: ", dirname);
|
||||||
setOutputPath(dirname);
|
if (!featureFlags.APP_STORE_BUILD) setOutputPath(dirname);
|
||||||
validateImagePath(filePath);
|
validateImagePath(filePath);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user