From 5a2b387b9d32859dd0849400147d153b7da1a6cf Mon Sep 17 00:00:00 2001 From: sat3ll <37741639+sat3ll@users.noreply.github.com> Date: Wed, 10 Jul 2019 01:34:56 +0100 Subject: [PATCH] deduplicate code --- bin/waifu2x_ncnn_vulkan.py | 70 +++++++++++++------------------------- 1 file changed, 24 insertions(+), 46 deletions(-) diff --git a/bin/waifu2x_ncnn_vulkan.py b/bin/waifu2x_ncnn_vulkan.py index caeb9bb..38f188b 100644 --- a/bin/waifu2x_ncnn_vulkan.py +++ b/bin/waifu2x_ncnn_vulkan.py @@ -70,56 +70,34 @@ class Waifu2xNcnnVulkan: 'gpu': '-g' } - # waifu2x_ncnn_vulkan does not accept an arbitrary scale ratio, max is 2 - if scale_ratio == 1: - for raw_frame in os.listdir(input_directory): - execute = [self.waifu2x_settings['waifu2x_ncnn_vulkan_path']] - for key in self.waifu2x_settings.keys(): - value = self.waifu2x_settings[key] - if key == 'waifu2x_ncnn_vulkan_path': - continue - elif key == 'input': - execute.append(waifu2x_ncnn_vulkan_opt_flag[key]) - execute.append(os.path.join(input_directory, raw_frame)) - elif key == 'output': - execute.append(waifu2x_ncnn_vulkan_opt_flag[key]) - execute.append(os.path.join(output_directory, raw_frame)) - elif key == 'scale-ratio': - execute.append(waifu2x_ncnn_vulkan_opt_flag[key]) + for raw_frame in os.listdir(input_directory): + execute = [self.waifu2x_settings['waifu2x_ncnn_vulkan_path']] + for key in self.waifu2x_settings.keys(): + value = self.waifu2x_settings[key] + if key == 'waifu2x_ncnn_vulkan_path': + continue + elif key == 'input': + execute.append(waifu2x_ncnn_vulkan_opt_flag[key]) + execute.append(os.path.join(input_directory, raw_frame)) + elif key == 'output': + execute.append(waifu2x_ncnn_vulkan_opt_flag[key]) + execute.append(os.path.join(output_directory, raw_frame)) + elif key == 'scale-ratio': + execute.append(waifu2x_ncnn_vulkan_opt_flag[key]) + # waifu2x_ncnn_vulkan does not accept an arbitrary scale ratio, max is 2 + if scale_ratio == 1: execute.append('1') - # allow upper if cases to take precedence - elif value is None or value is False: - continue else: - execute.append(waifu2x_ncnn_vulkan_opt_flag[key]) - execute.append(str(value)) - - Avalon.debug_info(f'Executing: {execute}') - subprocess.run(execute, check=True, stderr=subprocess.DEVNULL) - else: - for raw_frame in os.listdir(input_directory): - execute = [self.waifu2x_settings['waifu2x_ncnn_vulkan_path']] - for key in self.waifu2x_settings.keys(): - value = self.waifu2x_settings[key] - if key == 'waifu2x_ncnn_vulkan_path': - continue - elif key == 'input': - execute.append(waifu2x_ncnn_vulkan_opt_flag[key]) - execute.append(os.path.join(input_directory, raw_frame)) - elif key == 'output': - execute.append(waifu2x_ncnn_vulkan_opt_flag[key]) - execute.append(os.path.join(output_directory, raw_frame)) - elif key == 'scale-ratio': - execute.append(waifu2x_ncnn_vulkan_opt_flag[key]) execute.append('2') - elif value is None or value is False: - continue - else: - execute.append(waifu2x_ncnn_vulkan_opt_flag[key]) - execute.append(str(value)) + # allow upper if cases to take precedence + elif value is None or value is False: + continue + else: + execute.append(waifu2x_ncnn_vulkan_opt_flag[key]) + execute.append(str(value)) - Avalon.debug_info(f'Executing: {execute}') - subprocess.run(execute, check=True, stderr=subprocess.DEVNULL) + Avalon.debug_info(f'Executing: {execute}') + subprocess.run(execute, check=True, stderr=subprocess.DEVNULL) # print thread exiting message self.print_lock.acquire()