Exemple #1
0
    def __init__(self, file_path, file_name_no_ext, build_folder_path, info):
        bmp = BMP(file_path)
        self.__file_path = file_path
        self.__file_name_no_ext = file_name_no_ext
        self.__build_folder_path = build_folder_path
        self.__colors_count = bmp.colors_count

        width = bmp.width
        height = bmp.height

        if width == 256 and height == 256:
            self.__sbb = False
        elif (width == 256
              and height == 512) or (width == 512
                                     and height == 256) or (width == 512
                                                            and height == 512):
            self.__sbb = True
        else:
            raise ValueError('Invalid regular BG size: (' + str(width) + 'x' +
                             str(height) + ')' +
                             RegularBgItem.valid_sizes_message())

        self.__width = int(width / 8)
        self.__height = int(height / 8)
        self.__bpp_8 = False

        try:
            self.__repeated_tiles_reduction = bool(
                info['repeated_tiles_reduction'])
        except KeyError:
            self.__repeated_tiles_reduction = True

        try:
            self.__flipped_tiles_reduction = bool(
                info['flipped_tiles_reduction'])
        except KeyError:
            self.__flipped_tiles_reduction = True

        if self.__colors_count > 16:
            try:
                bpp_mode = str(info['bpp_mode'])
            except KeyError:
                bpp_mode = 'bpp_8'

            if bpp_mode == 'bpp_8':
                self.__bpp_8 = True
            elif bpp_mode == 'bpp_4_auto':
                self.__file_path = self.__build_folder_path + '/' + file_name_no_ext + '.bn_quantized.bmp'
                print('    Generating bpp4 image in ' + self.__file_path +
                      '...')
                start = time.time()
                self.__colors_count = bmp.quantize(self.__file_path)
                end = time.time()
                print('    bpp4 image with ' + str(self.__colors_count) +
                      ' colors generated in ' +
                      str(int((end - start) * 1000)) + ' milliseconds')
            elif bpp_mode != 'bpp_4_manual':
                raise ValueError('Invalid BPP mode: ' + bpp_mode)
def process(input_file_path, output_file_path):
    bmp = BMP(input_file_path)
    bmp.quantize(output_file_path)