Skip to content

Commit

Permalink
init: added execution block
Browse files Browse the repository at this point in the history
Since we're now at execution block layer, we can proceed to draft
its logic structure first. Hence, let's do this.

This patch adds execution block in init/ directory.

Co-authored-by: Shuralyov, Jean <jean.shuralyov@proton.me>
Co-authored-by: Galyna, Cory <cory.galyna@gmail.com>
Co-authored-by: (Holloway) Chew, Kean Ho <hollowaykeanho@gmail.com>
Signed-off-by: (Holloway) Chew, Kean Ho <hollowaykeanho@gmail.com>
  • Loading branch information
3 people committed Feb 9, 2024
1 parent 5f9d241 commit b9130b3
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 2 deletions.
65 changes: 65 additions & 0 deletions init/services/compilers/upscaler.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,71 @@ function UPSCALER-Format-Validate {



function UPSCALER-Output-Filename-Image {
param(
[string]$___output,
[string]$___input,
[string]$___format
)


# validate input
if ((STRINGS-IS-Empty "${___output}") -ne 0) {
return "${___output}"
}

if ((STRINGS-IS-Empty "${___input}") -eq 0) {
return ""
}


# execute
$___output = FS-Extension-Remove "$(Split-Path -Leaf -Path "${___input}")" "*"
$___output = "$(Split-Path -Parent -Path "${___input}")\${___output}-upscaled"

switch ($___format) {
"jpg" {
$___output = "${___output}.jpg"
} "webp" {
$___output = "${___output}.webp"
} default {
$___output = "${___output}.png"
}}

return $___output
}




function UPSCALER-Output-Filename-Video {
param(
[string]$___output,
[string]$___input
)


# validate input
if ((STRINGS-IS-Empty "${___output}") -ne 0) {
return "${___output}"
}

if ((STRINGS-IS-Empty "${___input}") -eq 0) {
return ""
}


# execute
$___output = FS-Extension-Remove "$(Split-Path -Leaf -Path "${___input}" "*")" "*"
$___output = "$(Split-Path -Parent -Path "${___input}")\${___output}-upscaled"
$___output = "${___output}.$((Split-Path -Path ${___input} -Leaf).Split(".")[1])"

return $___output
}




function UPSCALER-GPU-Scan {
# validate input
$___program = UPSCALER-Program-Get
Expand Down
73 changes: 73 additions & 0 deletions init/services/compilers/upscaler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,79 @@ UPSCALER_Format_Validate() {



UPSCALER_Output_Filename_Image() {
#___output="$1"
#___input="$2"
#___format="$3"


# validate input
if [ ! -z "$1" ]; then
printf -- "%b" "$1"
return 0
fi

if [ -z "$2" ]; then
printf -- ""
return 1
fi


# execute
___output="$(FS_Extension_Remove "${2##*/}" "*")"
___output="${2%/*}/${___output}-upscaled"

case "$3" in
jpg)
___output="${___output}.jpg"
;;
webp)
___output="${___output}.webp"
;;
*)
___output="${___output}.png"
;;
esac
printf -- "%b" "$___output"


# report status
return 0
}




UPSCALER_Output_Filename_Video() {
#___output="$1"
#___input="$2"


# validate input
if [ ! -z "$1" ]; then
printf -- "%b" "$1"
return 0
fi

if [ -z "$2" ]; then
printf -- ""
return 1
fi


# execute
___output="$(FS_Extension_Remove "${2##*/}" "*")"
___output="${2%/*}/${___output}-upscaled.${2##*.}"
printf -- "%b" "$___output"


# report status
return 0
}




UPSCALER_GPU_Scan() {
# validate input
___program="$(UPSCALER_Program_Get)"
Expand Down
10 changes: 10 additions & 0 deletions init/start.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,16 @@ if ((STRINGS-Is-Empty "${__format}") -eq 0) {



# execute
if ((${__video} -eq 0) -and (${__batch} -eq 0)) {
$__output = UPSCALER-Output-Filename-Image "${__output}" "${__input}" "${__format}"
} elseif (${__video} -eq 1) {
$__output = UPSCALER-Output-Filename-Video "${__output}" "${__input}"
} elseif (${__batch} -eq 1) {
}



# placeholder
Write-Host "DEBUG: Model='${__model}' Scale='${__scale}' Format='${__format}' Parallel='${__parallel}' Video='${__video}' Batch='${__batch}' Input='${__input}' Output='${__output}' GPU='${__gpu}'"

Expand Down
11 changes: 11 additions & 0 deletions init/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,17 @@ fi



# execute
if [ "$__video" = "0" ] && [ "$__batch" = "0" ]; then
__output="$(UPSCALER_Output_Filename_Image "$__output" "$__input" "$__format")"
elif [ "$__video" = "1" ]; then
__output="$(UPSCALER_Output_Filename_Video "$__output" "$__input")"
elif [ "$__batch" = "1" ]; then
:
fi



# placeholder
printf "DEBUG model='%s' scale='%s' format='%s' parallel='%s' video='%s' batch='%s' input='%s' output='%s' gpu='%s' \n" \
"$__model" \
Expand Down
6 changes: 4 additions & 2 deletions tests/01_test_upscale_image_single.sh.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ $__process = . "${env:LIBS_UPSCALER}\start.ps1" `
"--model" "upscayl-nmkd-4x-superscale-sd-178000-g" `
"--scale" "4" `
"--parallel" "2" `
"--input" "${env:UPSCALER_PATH_ROOT}/tests/image/sample-01.jpeg"
"--input" "${env:UPSCALER_PATH_ROOT}\tests\image\sample-01.jpeg" `
"--output" "${env:UPSCALER_PATH_ROOT}\tmp\test-01\sample-01-upscaled.png"
if ($__process -ne 0) {
$null = I18N-Status-Print "error" "Failed.`n`n"
$__verdict = $false
Expand Down Expand Up @@ -172,7 +173,8 @@ I18N_Status_Print "note" "test single image upscale...\n"
--model upscayl-nmkd-4x-superscale-sd-178000-g \
--scale 4 \
--parallel 2 \
--input "${UPSCALER_PATH_ROOT}/tests/image/sample-01.jpeg"
--input "${UPSCALER_PATH_ROOT}/tests/image/sample-01.jpeg" \
"--output" "${UPSCALER_PATH_ROOT}/tmp/test-01/sample-01-upscaled.png"
if [ $? -ne 0 ]; then
I18N_Status_Print "error" "Failed.\n\n"
__verdict=1
Expand Down

0 comments on commit b9130b3

Please sign in to comment.