Skip to content

πŸ†™ Upscayl - #1 Free and Open Source AI Image Upscaler for Linux, MacOS and Windows.

Update model scale usage in code

Nayam Amarshe68d3395cbe1d
diff --git a/common/check-model-scale.ts b/common/check-model-scale.ts
new file mode 100644
index 0000000..d114096
--- /dev/null
+++ b/common/check-model-scale.ts
@@ -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;
+}
diff --git a/common/feature-flags.ts b/common/feature-flags.ts
index 39e5241..7436ffb 100644
--- a/common/feature-flags.ts
+++ b/common/feature-flags.ts
@@ -4,6 +4,6 @@ type FeatureFlags = {
};
export const featureFlags: FeatureFlags = {
- APP_STORE_BUILD: false,
+ APP_STORE_BUILD: true,
SHOW_UPSCAYL_CLOUD_INFO: false,
};
diff --git a/electron/commands/batch-upscayl.ts b/electron/commands/batch-upscayl.ts
index 3a57f31..0b28321 100644
--- a/electron/commands/batch-upscayl.ts
+++ b/electron/commands/batch-upscayl.ts
@@ -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 +=
diff --git a/electron/commands/double-upscayl.ts b/electron/commands/double-upscayl.ts
index b9b12c1..a021639 100644
--- a/electron/commands/double-upscayl.ts
+++ b/electron/commands/double-upscayl.ts
@@ -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 =
diff --git a/electron/commands/image-upscayl.ts b/electron/commands/image-upscayl.ts
index 73a12b1..667b5d1 100644
--- a/electron/commands/image-upscayl.ts
+++ b/electron/commands/image-upscayl.ts
@@ -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;
diff --git a/electron/utils/convert-and-scale.ts b/electron/utils/convert-and-scale.ts
index c82c3e2..e0c3a75 100644
--- a/electron/utils/convert-and-scale.ts
+++ b/electron/utils/convert-and-scale.ts
@@ -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({
diff --git a/renderer/components/upscayl-tab/config/LeftPaneImageSteps.tsx b/renderer/components/upscayl-tab/config/LeftPaneImageSteps.tsx
index dcc55f9..a060e30 100644
--- a/renderer/components/upscayl-tab/config/LeftPaneImageSteps.tsx
+++ b/renderer/components/upscayl-tab/config/LeftPaneImageSteps.tsx
@@ -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;
}
diff --git a/renderer/pages/index.tsx b/renderer/pages/index.tsx
index 4b23eef..72072ae 100644
--- a/renderer/pages/index.tsx
+++ b/renderer/pages/index.tsx
@@ -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);
}
};