def fix_names_all(self): """ Waifu2x-ncnn-vulkan will accept a file as "file.jpg" and output as "file.jpg.png". Unfortunately, dandere2x wouldn't recognize this, so this function renames each name to the correct naming convention. This function will iteratiate through every file needing to be upscaled waifu2x-ncnn-vulkan, and change it's name after it's done saving Comments: - There's a really complicated try / except that exists because, even though a file may exist, the file handle may still be used by waifu2x-ncnn-vulkan (it hasn't released it yet). As a result, we need to try / except it until it's released, allowing us to rename it. """ file_names = [] for x in range(1, self.frame_count): file_names.append("output_" + get_lexicon_value(6, x)) for file in file_names: dirty_name = self.residual_upscaled_dir + file + ".jpg.png" clean_name = self.residual_upscaled_dir + file + ".png" wait_on_either_file(clean_name, dirty_name) if file_exists(clean_name): pass elif file_exists(dirty_name): while file_exists(dirty_name): try: rename_file(dirty_name, clean_name) except PermissionError: pass
def run(self): """ Upscale every image that will *eventually* appear in the residuals_dir folder by waifu2x. """ logger = logging.getLogger(__name__) differences_dir = self.context.residual_images_dir upscaled_dir = self.context.residual_upscaled_dir exec = copy.copy(self.waifu2x_vulkan_legacy_upscale_frame) for x in range(1, self.frame_count): wait_on_either_file( differences_dir + "output_" + get_lexicon_value(6, x) + ".jpg", upscaled_dir + "output_" + get_lexicon_value(6, x) + ".png") if file_exists(differences_dir + "output_" + get_lexicon_value(6, x) + ".jpg") \ and not file_exists(upscaled_dir + "output_" + get_lexicon_value(6, x) + ".png"): self.upscale_file( differences_dir + "output_" + get_lexicon_value(6, x) + ".jpg", upscaled_dir + "output_" + get_lexicon_value(6, x) + ".png") elif not file_exists(differences_dir + "output_" + get_lexicon_value(6, x) + ".jpg") \ and file_exists(upscaled_dir + "output_" + get_lexicon_value(6, x) + ".png"): continue
def fix_names_all(self): file_names = [] for x in range(1, self.frame_count): file_names.append("output_" + get_lexicon_value(6, x)) for file in file_names: dirty_name = self.upscaled_dir + file + ".jpg.png" clean_name = self.upscaled_dir + file + ".png" wait_on_either_file(clean_name, dirty_name) if file_exists(clean_name): pass elif file_exists(dirty_name): while file_exists(dirty_name): try: rename_file(dirty_name, clean_name) except PermissionError: pass
def fix_names_all(self): file_names = [] for x in range(1, self.frame_count): file_names.append("output_" + get_lexicon_value(6, x)) for file in file_names: dirty_name = self.residual_upscaled_dir + file + '_[NS-L' + str( self.noise_level) + '][x' + str( self.scale_factor) + '.000000]' + ".png" clean_name = self.residual_upscaled_dir + file + ".png" wait_on_either_file(clean_name, dirty_name) if file_exists(clean_name): pass elif file_exists(dirty_name): while file_exists(dirty_name): try: rename_file(dirty_name, clean_name) except PermissionError: pass