Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
·
058800c
1
Parent(s):
63a66b5
add a new upscalingFactor when upscaling images
Browse files
src/production/renderImageUpscaling.mts
CHANGED
@@ -8,12 +8,12 @@ export async function renderImageUpscaling(
|
|
8 |
|
9 |
try {
|
10 |
// note: this converts a base64 PNG to a base64 JPG (which is good, actually!)
|
11 |
-
response.assetUrl = await upscaleImage(response.assetUrl)
|
12 |
console.log(`upscaling worked on the first try!`)
|
13 |
} catch (err) {
|
14 |
console.error(`upscaling failed the first time.. let's try again..`)
|
15 |
try {
|
16 |
-
response.assetUrl = await upscaleImage(response.assetUrl)
|
17 |
console.log(`upscaling worked on the second try!`)
|
18 |
} catch (err) {
|
19 |
console.error(`upscaling failed on the second attempt.. let's keep the low-res image then :|`)
|
|
|
8 |
|
9 |
try {
|
10 |
// note: this converts a base64 PNG to a base64 JPG (which is good, actually!)
|
11 |
+
response.assetUrl = await upscaleImage(response.assetUrl, request.upscalingFactor)
|
12 |
console.log(`upscaling worked on the first try!`)
|
13 |
} catch (err) {
|
14 |
console.error(`upscaling failed the first time.. let's try again..`)
|
15 |
try {
|
16 |
+
response.assetUrl = await upscaleImage(response.assetUrl, request.upscalingFactor)
|
17 |
console.log(`upscaling worked on the second try!`)
|
18 |
} catch (err) {
|
19 |
console.error(`upscaling failed on the second attempt.. let's keep the low-res image then :|`)
|
src/types.mts
CHANGED
@@ -303,6 +303,14 @@ export interface RenderRequest {
|
|
303 |
width: number
|
304 |
height: number
|
305 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
306 |
projection: ProjectionMode
|
307 |
|
308 |
cache: CacheMode
|
|
|
303 |
width: number
|
304 |
height: number
|
305 |
|
306 |
+
// upscaling factor
|
307 |
+
// 0: no upscaling
|
308 |
+
// 1: no upscaling
|
309 |
+
// 2: 2x larger
|
310 |
+
// 3: 3x larger
|
311 |
+
// 4x: 4x larger, up to 4096x4096 (warning: a PNG of this size can be 50 Mb!)
|
312 |
+
upscalingFactor: number
|
313 |
+
|
314 |
projection: ProjectionMode
|
315 |
|
316 |
cache: CacheMode
|
src/utils/parseRenderRequest.mts
CHANGED
@@ -20,6 +20,8 @@ export function parseRenderRequest(request: RenderRequest) {
|
|
20 |
|
21 |
// but obviously we will treat 0 as the random seed at a later stage
|
22 |
|
|
|
|
|
23 |
request.nbSteps = getValidNumber(request.nbSteps, 5, 50, 10)
|
24 |
|
25 |
if (isVideo) {
|
|
|
20 |
|
21 |
// but obviously we will treat 0 as the random seed at a later stage
|
22 |
|
23 |
+
request.upscaling = getValidNumber(request.upscaling, 0, 4, 0)
|
24 |
+
|
25 |
request.nbSteps = getValidNumber(request.nbSteps, 5, 50, 10)
|
26 |
|
27 |
if (isVideo) {
|
src/utils/upscaleImage.mts
CHANGED
@@ -16,9 +16,15 @@ const instances: string[] = [
|
|
16 |
// at processTicksAndRejections (node:internal/process/task_queues:95:5)
|
17 |
export async function upscaleImage(src: string, factor?: number) {
|
18 |
|
19 |
-
//
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
const instance = instances.shift()
|
23 |
instances.push(instance)
|
24 |
|
|
|
16 |
// at processTicksAndRejections (node:internal/process/task_queues:95:5)
|
17 |
export async function upscaleImage(src: string, factor?: number) {
|
18 |
|
19 |
+
// by default we do a 2X scale
|
20 |
+
// VideoQuest will use 4X
|
21 |
+
// 4 is really the max/limit, as this can generate PNGs of 50 Mb..
|
22 |
+
const scaleFactor = getValidNumber(factor, 0, 4, 2)
|
23 |
+
|
24 |
+
if (scaleFactor < 2) {
|
25 |
+
return src
|
26 |
+
}
|
27 |
+
|
28 |
const instance = instances.shift()
|
29 |
instances.push(instance)
|
30 |
|