Skip to content

Commit

Permalink
init: added format validator
Browse files Browse the repository at this point in the history
Since the output format is selectable, we have to add its validator
function. Let's do this.

This patcha dds format validator into 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 d7c62ef commit 14f7d03
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 0 deletions.
30 changes: 30 additions & 0 deletions init/services/compilers/upscaler.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,36 @@



function UPSCALER-Format-Validate {
param(
[string]$___format
)


# valdiate input
if ((STRINGS-Is-Empty "${___format}") -eq 0) {
return ""
}


# execute
switch ($(STRINGS-To-Lowercase "${___format}")) {
{ $_ -in "jpeg", "jpg" } {
return "jpg"
} "png" {
return "png"
} "webp" {
return "webp"
} "native" {
return "native"
} default {
return ""
}}
}




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



UPSCALER_Format_Validate() {
#___format="$1"


# validate input
if [ "$(STRINGS_Is_Empty "$1")" = "0" ]; then
printf -- ""
return 1
fi


# execute
case "$(STRINGS_To_Lowercase "$1")" in
jpeg|jpg)
printf -- "jpg"
;;
png)
printf -- "png"
;;
webp)
printf -- "webp"
;;
native)
printf -- "native"
;;
*)
printf -- ""
return 1
;;
esac


# report status
return 0
}




UPSCALER_GPU_Scan() {
# validate input
___program="$(UPSCALER_Program_Get)"
Expand Down
50 changes: 50 additions & 0 deletions init/services/i18n/error-format-unsupported.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# BSD 3-Clause License
#
# Copyright (c) 2024 (Holloway) Chew, Kean Ho
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. "${env:LIBS_UPSCALER}\services\i18n\__printer.ps1"




function I18N-Status-Error-Format-Unsupported {
# execute
switch (${env:UPSCALER_LANG}) {
{ $_ -in "DE", "de" } {
# german
$null = I18N-Status-Print "error" `
"Nicht unterstütztes festgelegtes Ausgabeformat.`n"
} default {
# fallback to default english
$null = I18N-Status-Print "error" "Unsupported designated output format.`n"
}}


# report status
return 0
}
51 changes: 51 additions & 0 deletions init/services/i18n/error-format-unsupported.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# BSD 3-Clause License
#
# Copyright (c) 2024 (Holloway) Chew, Kean Ho
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
. "${LIBS_UPSCALER}/services/i18n/__printer.sh"




I18N_Status_Error_Format_Unsupported() {
# execute
case "$UPSCALER_LANG" in
DE|de)
# German
I18N_Status_Print "error" "Nicht unterstütztes festgelegtes Ausgabeformat.\n"
;;
*)
# fallback to default english
I18N_Status_Print "error" "Unsupported designated output format.\n"
;;
esac


# report status
return 0
}
14 changes: 14 additions & 0 deletions init/start.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ ${env:LIBS_UPSCALER} = "${env:UPSCALER_PATH_ROOT}\${env:UPSCALER_PATH_SCRIPTS}"
# import fundamental libraries
. "${env:LIBS_UPSCALER}\services\io\strings.ps1"
. "${env:LIBS_UPSCALER}\services\compilers\upscaler.ps1"
. "${env:LIBS_UPSCALER}\services\i18n\error-format-unsupported.ps1"
. "${env:LIBS_UPSCALER}\services\i18n\error-gpu-unsupported.ps1"
. "${env:LIBS_UPSCALER}\services\i18n\error-input-unknown.ps1"
. "${env:LIBS_UPSCALER}\services\i18n\error-input-unsupported.ps1"
Expand Down Expand Up @@ -256,6 +257,19 @@ if (-not ($__parallel -match "^[\d]+$")) {



# process format
if ((STRINGS-Is-Empty "${__format}") -eq 0) {
$__format = "native"
}
$__format = UPSCALER-Format-Validate "${__format}"
if ((STRINGS-Is-Empty "${__format}") -eq 0) {
$null = I18N-Status-Error-Format-Unsupported
return 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 @@ -84,6 +84,7 @@ export LIBS_UPSCALER="${UPSCALER_PATH_ROOT}/${UPSCALER_PATH_SCRIPTS}"
# import fundamental libraries
. "${LIBS_UPSCALER}/services/io/strings.sh"
. "${LIBS_UPSCALER}/services/compilers/upscaler.sh"
. "${LIBS_UPSCALER}/services/i18n/error-format-unsupported.sh"
. "${LIBS_UPSCALER}/services/i18n/error-gpu-unsupported.sh"
. "${LIBS_UPSCALER}/services/i18n/error-input-unknown.sh"
. "${LIBS_UPSCALER}/services/i18n/error-input-unsupported.sh"
Expand Down Expand Up @@ -258,6 +259,16 @@ fi



# process format
__format="$(UPSCALER_Format_Validate "${__format:-native}")"
if [ "$(STRINGS_Is_Empty "$__format")" = "0" ]; then
I18N_Status_Error_Format_Unsupported
return 1
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

0 comments on commit 14f7d03

Please sign in to comment.