From e59e7f510170528ad189043fa0ab495f35037e4c Mon Sep 17 00:00:00 2001 From: Janis Hutz Date: Wed, 24 May 2023 12:34:35 +0200 Subject: [PATCH] add documentation for plugins & refactor more --- bin/__pycache__/handler.cpython-311.pyc | Bin 11004 -> 11186 bytes bin/__pycache__/probe.cpython-311.pyc | Bin 3777 -> 3781 bytes bin/engines/fsr.py | 85 ++++-------------------- bin/handler.py | 4 +- imagevideoupscaler-cli.py | 2 +- website/plugins.md | 11 +++ 6 files changed, 26 insertions(+), 76 deletions(-) create mode 100644 website/plugins.md diff --git a/bin/__pycache__/handler.cpython-311.pyc b/bin/__pycache__/handler.cpython-311.pyc index 352b8fcc8a9b945b0abd6630d835e5e0974185f3..97e96ea9a68cd19db4a7e0bff47a7f13ac2e50d7 100644 GIT binary patch delta 667 zcmewpx+$D@IWI340}zzo&P|Em$g9T8=sMYi*@z|HFSUGg8goA%69doY?}7(dnHI=T zoTkK=BAd+wQeSLP!wD6UgNjH%MI=(>AtFTvB@Q695U@aT@@;WVMuo|&659NVP!$n1 z+{Jn&E|X_V7)~yb(BgH0sb*kUpfcH8LUr;P2{~SGglLM=c7WkfJh|X&EB}!)hRg07ixqP8gekAxmwtuym@RY7Ijc*!3V8kgmy{(&ku1FG?5k zs{z$Y!c0g}pByNoZmWST2Gp;KW}a3J2T+u)h6Rh9%H*wBOwdL%K?iJtE)EkUWiuJ| zHaE+rF|soz-(t=vOy2xPPJoe7eez%VH|)1qbMnhmizdHR*vr_xdAZ^#Cdcc%@|Sq! zFY+p0;ZN#D}b2^ZGNze0wp67{}>%Q@qeB&?rCSLJP zypWo8$v5kQZ`S5!l^x6~=Y?$o1Q;#|I9dnsF<;_k1d(cn!4eFYCAflBnJ=p_2CGhv z*LW-E4h*m&Hz09~CpkYaEi=6!v8Xt;s3-s=Za+Co(~dE8@=8rZsaTMJ0EplN62CZX Ta`RJ4b5iY!GB1T0XP94?{BC_lMTLR(q^sv@F>yI8Np38sdDVS&=*;}ZUiPLp>_ z7*6((l+*S^$fYPQV`N}h4a5-8#8|=)V>2+MC~cl7d6ZF76(&@}kOg)Uh(DVlMR{_* zv^=Bg`xflGsuhf*CY*H~*JSV`OIX^V^&wFTlvCHn~>e z&Ex{by^JxN^^{IA3C#$-#H)0HS7|}chLlTcRu|N)He0IhU{*ONZsRY)a9+gGI#7uD zq97xP)G`c`VYnp26{N|0NrN#+bF!%BTRAtN=Zjo{#4VoW{JgZx^n%2q;?$xde~`G{ cWCbld#^A~ET850#lP79PFs5%_rNzMr09FEbs{jB1 diff --git a/bin/__pycache__/probe.cpython-311.pyc b/bin/__pycache__/probe.cpython-311.pyc index bdb75f549180e265101047f72d077a5c5ab6bb05..2fca37df29bf3072f80e190971d14f7cd40947fc 100644 GIT binary patch delta 36 qcmX>odsLQtIWI340}w=AR@}&aikZ=Q@-=27mUzF^^35D9JGlV5p$cCB delta 31 lcmX>qdr+2pIWI340}$vc3UA~-#ms0w`5Lp)W*(NETmX8h2ju_& diff --git a/bin/engines/fsr.py b/bin/engines/fsr.py index 551a921..b55c1b7 100644 --- a/bin/engines/fsr.py +++ b/bin/engines/fsr.py @@ -58,9 +58,9 @@ class FSRScaler: self.threads = multiprocessing.cpu_count(); if ( not scaling ): - engines = { 'NN': 'NearestNeighbor', 'fsr':'FidelityFX Super Resolution' } + engines = { 'c': 'Cubic', 'hqc': 'High Quality Cubic', 'fsr':'FidelityFX Super Resolution' } print( f'\n\n==> Upscaling using { self.threads } threads <==\n\n' ); - print( f'\n\n==> Upscaling Engine is { engines[ mode ] } <==\n\n' ); + print( f'\n\n==> Upscaling Engine is { engines[ mode.lower() ] } <==\n\n' ); time.sleep( 2 ); @@ -74,13 +74,10 @@ class FSRScaler: if ( i == self.threads - 1 ): for element in self.file_list: self.files += element; - self.command_list.append( ( self.files, fsrpath, quality_setting, i, self.maxlength, self.os_type ) ) + self.command_list.append( ( self.files, fsrpath, quality_setting, i, self.maxlength, self.os_type, mode ) ) self.pool = multiprocessing.Pool( self.threads ) - if ( mode == 'B' ): - self.pool.starmap( bilinearEngine, self.command_list ); - elif ( mode == 'fsr' ): - self.pool.starmap( upscalerEngine, self.command_list ); + self.pool.starmap( upscalerEngine, self.command_list ); self.pool.close(); self.pool.join(); @@ -140,8 +137,12 @@ class FSRScaler: # Add return values - -def upscalerEngine ( files, fsrpath, quality_setting, number, maxlength, os_type ): +def upscalerEngine ( files, fsrpath, quality_setting, number, maxlength, os_type, version ): + scaler = 'FSR' + if ( version.upper() == 'HQC' ): + scaler = 'HighQualityCubic' + elif ( version.upper() == 'C' ): + scaler = 'Cubic' files = files; # Refactoring of commands that are longer than 32K characters fileout = []; @@ -190,9 +191,9 @@ def upscalerEngine ( files, fsrpath, quality_setting, number, maxlength, os_type while len( fileout ) > 0: files_handle = fileout.pop(0) if os_type == 'linux': - command_us = f'wine {fsrpath} -Scale {quality_setting} {quality_setting} {files_handle}' + command_us = f'wine {fsrpath} -Mode { scaler } -Scale {quality_setting} {quality_setting} {files_handle}' elif os_type == 'win32': - command_us = f'FidelityFX_CLI -Scale {quality_setting} {quality_setting} {files_handle}' + command_us = f'FidelityFX_CLI -Mode { scaler } -Scale {quality_setting} {quality_setting} {files_handle}' else: print( 'OS CURRENTLY UNSUPPORTED!' ) return False @@ -202,68 +203,6 @@ def upscalerEngine ( files, fsrpath, quality_setting, number, maxlength, os_type print( '\n\nCompleted executing Job\n\n\n PROCESS: ', number, '\n\n\n' ); -def bilinearEngine ( files, fsrpath, quality_setting, number, maxlength, os_type, version ): - if ( version == 'HQC' ): - scaler = 'HighQualityCubic' - files = files; - # Refactoring of commands that are longer than 32K characters - fileout = []; - pos = 0; - if len( files ) > maxlength: - while files[maxlength - pos:maxlength - pos + 1] != ' ': - pos += 1 - file_processing = files[:maxlength - pos] - if file_processing[len(file_processing) - 14:len(file_processing) - 12] == 'ig': - pos += 5 - while files[maxlength - pos:maxlength - pos + 1] != ' ': - pos += 1 - fileout.append(files[:maxlength - pos]) - filesopt = files[maxlength - pos:] - posx = 0 - posy = maxlength - - # Command refactoring for commands that are longer than 64K characters - if len(filesopt) > maxlength: - while len(filesopt) > maxlength: - posx += maxlength - pos - posy += maxlength - pos - pos = 1 - while files[posy - pos:posy - pos + 1] != ' ': - pos += 1 - file_processing = files[posx:posy - pos] - if file_processing[len(file_processing) - 14:len(file_processing) - 12] == 'ig': - pos += 5 - else: - pass - while files[posy - pos:posy - pos + 1] != ' ': - pos += 1 - - file_processing = files[posx:posy - pos] - fileout.append(file_processing) - filesopt = files[posy - pos:] - fileout.append(filesopt) - else: - fileout.append(files[maxlength - pos:]) - else: - fileout.append(files) - - # Upscaling images - print( '\n\n\nUpscaling images... \n\n\n\n\n\n PROCESS: ', number, '\n\n\n' ) - - while len( fileout ) > 0: - files_handle = fileout.pop(0) - if os_type == 'linux': - command_us = f'wine {fsrpath} -Mode NearestNeighbor -Scale {quality_setting} {quality_setting} {files_handle}' - elif os_type == 'win32': - command_us = f'FidelityFX_CLI -Mode NearestNeighbor -Scale {quality_setting} {quality_setting} {files_handle}' - else: - print( 'OS CURRENTLY UNSUPPORTED!' ) - return False - sub = subprocess.Popen( command_us, shell=True ); - sub.wait(); - time.sleep(3) - print( '\n\nCompleted executing Job\n\n\n PROCESS: ', number, '\n\n\n' ); - ######################## # # Sharpening diff --git a/bin/handler.py b/bin/handler.py index 315e7d6..10eacbc 100644 --- a/bin/handler.py +++ b/bin/handler.py @@ -136,9 +136,9 @@ class Handler: self.lastUsedPath = '' - if ( scalerEngine == 'fsr' or scalerEngine == 'NN' ): + if ( scalerEngine.lower() == 'fsr' or scalerEngine.lower() == 'c' or scalerEngine.lower() == 'hqc' ): self.lastUsedPath = fsr.fsrScaler( self.tmppath, filepath, threads, fsrpath, quality_setting + 'x', sharpening, scaling, filetype, scalerEngine ) - elif ( scalerEngine == 'SS' ): + elif ( scalerEngine.upper() == 'SS' ): if ( not useSpecialModeSS ): self.lastUsedPath = ss.superScaler( self.tmppath, threads, quality_setting, self.os_type, model ) else: diff --git a/imagevideoupscaler-cli.py b/imagevideoupscaler-cli.py index d285aeb..ddff270 100644 --- a/imagevideoupscaler-cli.py +++ b/imagevideoupscaler-cli.py @@ -49,7 +49,7 @@ if __name__ == '__main__': go = False if ( args.engine != None ): - if ( args.engine == 'fsr' or args.engine == 'SS' or args.engine == 'NN' ): + if ( args.engine == 'fsr' or args.engine == 'SS' or args.engine.lower() == 'c' or args.engine.lower() == 'hqc' ): engine = args.engine; else: print( 'Invalid argument for engine' ) diff --git a/website/plugins.md b/website/plugins.md new file mode 100644 index 0000000..2183845 --- /dev/null +++ b/website/plugins.md @@ -0,0 +1,11 @@ +# Writing plugins for ImageVideoUpscaler + +Your plugin has to fulfill the following requirements: +- Name of class it exposes has to be [name of engine]Scaler. The name of the file should be just the name of the engine in all lower case. +- It has to support a folder or an individual file as an input and the function, has to take the following arguments: + +Argument | Variable type +---------|--------------- +x | y + +- The function has to return the path to the folder where the final resulting images are located. \ No newline at end of file