Esempio n. 1
0
    def __fix_waifu2x_converter_cpp_names(self):
        """
            Waifu2x-Conveter-Cpp (legacy) will output the file names in a format that needs to be fixed for
            dandere2x to work. I believe this is fixed in later versions, hence the TODO
        """

        file_names = []
        for x in range(1, self.context.frame_count):
            file_names.append("output_" + get_lexicon_value(6, x))

        for file in file_names:
            dirty_name = self.context.residual_upscaled_dir + file + '_[NS-L' + str(
                self.context.service_request.denoise_level) + '][x' + str(
                    self.context.service_request.scale_factor
                ) + '.000000]' + ".png"
            clean_name = self.context.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
Esempio n. 2
0
    def __fix_waifu2x_ncnn_vulkan_names(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.context.frame_count):
            file_names.append("output_" + get_lexicon_value(6, x))

        for file in file_names:
            dirty_name = self.context.residual_upscaled_dir + file + ".png.png"
            clean_name = self.context.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
Esempio n. 3
0
    def save_image_temp(self, out_location, temp_location):
        """
        Save an image in the "temp_location" folder to prevent another program from accessing the file
        until it's done writing.

        This is done to prevent other parts from using an image until it's entirely done writing.
        """

        self.save_image(temp_location)
        wait_on_file(temp_location)
        rename_file(temp_location, out_location)
Esempio n. 4
0
    def save_image(self, out_location):
        """
        Save an image with specific instructions depending on it's extension type.
        """
        extension = os.path.splitext(os.path.basename(out_location))[1]

        if 'jpg' in extension:
            jpegsave = self.get_pil_image()
            jpegsave.save(out_location + "temp" + extension,
                          format='JPEG',
                          subsampling=0,
                          quality=100)
            wait_on_file(out_location + "temp" + extension)
            rename_file(out_location + "temp" + extension, out_location)

        else:
            save_image = self.get_pil_image()
            save_image.save(out_location + "temp" + extension, format='PNG')
            wait_on_file(out_location + "temp" + extension)
            rename_file(out_location + "temp" + extension, out_location)
Esempio n. 5
0
    def save_image_quality(self, out_location, quality_per):
        """
        Save an image with JPEG using the JPEG quality-compression ratio. 100 will be the best, while 0 will
        be the worst.
        """

        extension = os.path.splitext(os.path.basename(out_location))[1]

        if 'jpg' in extension:
            jpegsave = Image.fromarray(self.frame.astype(np.uint8))
            jpegsave.save(out_location + "temp" + extension,
                          format='JPEG',
                          subsampling=0,
                          quality=quality_per)
            wait_on_file(out_location + "temp" + extension)
            rename_file(out_location + "temp" + extension, out_location)
        else:
            # todo, fix this
            self.logger.error(
                "Aka-katto has removed this customization you added - he's going to re-add it later."
            )
            self.logger.error('Sorry about that : \\')
            raise ValueError('See Console')