コード例 #1
0
ファイル: image_editor.py プロジェクト: kimwnasptd/OWM-Qt
    def repoint_palette_table(self):

        num_of_palettes = self.get_palette_num()
        # 9 = 8[palette end] + 1[table end]
        space_needed = (num_of_palettes * 8) + (256 * 8) + 9
        new_table_addr = rom.find_free_space(space_needed, rom.FREE_SPC, 4)

        # Insert 00s in the new table addr
        rom.fill_with_data(new_table_addr, space_needed + 2, 0)
        # Move the table's data
        rom.move_data(self.table_addr, new_table_addr,
                      (num_of_palettes * 8) + 8)
        # Write the end of table
        rom.write_bytes(new_table_addr + (num_of_palettes * 8) + 4,
                        [0xFF, 0x11])

        # Change the ptrs pointing the table
        for ptr_addr in rom.PAL_TBL_PTRS:
            rom.write_ptr(new_table_addr, ptr_addr)

        # Change the OBJ's table_addr var
        self.table_addr = new_table_addr
        self.set_used_palettes()
        log.info("Palette Table was repointed at {}".format(
            conv.HEX(self.table_addr)))
コード例 #2
0
    def initPaletteIdComboBox(self):

        self.paletteIDComboBox.setEnabled(True)
        # Create the list with the palette IDs
        self.paletteIDComboBox.clear()
        for pal_id in self.sprite_manager.used_palettes:
            self.paletteIDComboBox.addItem(conv.HEX(pal_id))
コード例 #3
0
def update_palette_info(ui):
    if ui.selected_table is not None:
        ui.paletteIDComboBox.setEnabled(False)
        ui.textColorComboBox.setEnabled(False)
        ui.footprintComboBox.setEnabled(False)
        ui.paletteSlotComboBox.setEnabled(False)

        if ui.selected_ow is not None:
            ui.paletteIDComboBox.setEnabled(True)
            ui.textColorComboBox.setEnabled(True)
            ui.footprintComboBox.setEnabled(True)
            ui.paletteSlotComboBox.setEnabled(True)

            # Sync the TextColor/Footprint ComboBox
            ow_data_addr = ui.root.getOW(ui.selected_table, ui.selected_ow)\
                .ow_data_addr
            ui.textColorComboBox.setCurrentIndex(
                core.get_text_color(ow_data_addr))
            ui.footprintComboBox.setCurrentIndex(
                core.get_footprint(ow_data_addr))

            # Sync the Palette Id ComboBox
            id_list = [conv.HEX(pal_id) for pal_id in
                       ui.sprite_manager.used_palettes]
            palette_id = core.get_ow_palette_id(ow_data_addr)

            index = id_list.index(conv.HEX(palette_id))
            ui.paletteIDComboBox.setCurrentIndex(index)

            # Sync the Palette Slot Combobox
            ui.paletteSlotComboBox.setCurrentIndex(
                core.get_palette_slot(ow_data_addr))

            ui.paletteAddressLabel.setText(
                conv.capitalized_hex(
                    ui.sprite_manager.get_palette_addr(palette_id)))
        else:
            ui.paletteAddressLabel.setText("")

        ui.paletteTableAddressLabel.setText(
            conv.capitalized_hex(ui.sprite_manager.table_addr))
        ui.usedPalettesLabel.setText(str(ui.sprite_manager.get_palette_num()))
コード例 #4
0
ファイル: image_editor.py プロジェクト: kimwnasptd/OWM-Qt
    def import_pokemon(self, pokemon_image, working_table, working_ow):
        '''
        Import a pokemon that is taken from Spriter's Resource sheets.
        The pokemon_image will be a square that has all the different sides
        of the pokemon. This function will map the tiles of the image to the
        correct OW's images/sides.
        '''
        log.info("Importing pokemon from Spriter's Resource")
        # Check if the image is indexed
        palette = pokemon_image.getpalette()
        if palette is None:
            pokemon = pokemon_image.convert('P',
                                            palette=Image.ADAPTIVE,
                                            colors=16)
        else:
            pokemon = pokemon_image

        make_bg_color_first(pokemon)
        palette = pokemon.getpalette()

        # Insert the palette
        palette_id = self.import_palette(palette)

        ow = self.root.getOW(working_table, working_ow)
        core.write_ow_palette_id(ow.ow_data_addr, palette_id)

        # Insert the frames
        working_addr = ow.frames.frames_addr
        positions = [(3, 0), (0, 0), (1, 1), (3, 0), (2, 0), (1, 0), (0, 0),
                     (1, 1), (0, 1)]
        for pos in positions:
            row = pos[0] * 32
            column = pos[1] * 32
            import_frame(pokemon, working_addr, core.T32x32, row, column)
            working_addr += core.get_frame_size(core.T32x32)

        log.info("Inserted the image data at {}-{} ({} bytes)".format(
            conv.HEX(ow.frames.frames_addr), conv.HEX(working_addr),
            9 * core.get_frame_size(core.T32x32)))
        self.set_used_palettes()
コード例 #5
0
    def find_rom_offsets(self):
        # Find OW Offsets
        self.statusbar.showMessage("Searching for OW Offsets")
        for addr in range(0, rom.rom.rom_size, 4):
            if core.is_jpan_ptr(addr):
                table_ptrs = rom.ptr_to_addr(addr)
                break
            elif core.is_orig_table_ptr(addr):
                table_ptrs = addr

        log.info("Found the OW Tables Pointers at " + conv.HEX(table_ptrs))
        # Find Palette Offsets
        self.statusbar.showMessage("Searching for Palette Offsets")
        for addr in range(0, rom.rom.rom_size, 4):
            # Search for the first Palette Pointer
            if (rom.is_ptr(addr)
                    and img.is_palette_ptr(rom.ptr_to_addr(addr))):
                palette_table = rom.ptr_to_addr(addr)
                palette_table_ptrs = rom.find_ptr_in_rom(palette_table, True)
                log.info("Found the Palette Table at " +
                         conv.HEX(palette_table))
                break

        return [table_ptrs, palette_table_ptrs]
コード例 #6
0
ファイル: image_editor.py プロジェクト: kimwnasptd/OWM-Qt
    def palette_cleanup(self):
        orig_pals_num = get_orig_palette_num()
        palette_num = self.get_palette_num()
        users_palettes = palette_num - orig_pals_num
        used_palettes = self.get_used_pals()

        # Find the addresses of the unused palettes
        unused_palettes_addres = []
        working_addr = self.table_addr + (orig_pals_num * 8)
        for i in range(0, users_palettes):
            palette_id = get_palette_id(working_addr + (i * 8))
            # Check every palette to see if it is used
            if palette_id not in used_palettes:
                log.info("Removing unused Palette: " + conv.HEX(palette_id))
                unused_palettes_addres.append(working_addr + (i * 8))

        # Delete all the unused palettes
        for addr in reversed(unused_palettes_addres):
            remove_palette(addr)

        self.set_used_palettes()
コード例 #7
0
ファイル: image_editor.py プロジェクト: kimwnasptd/OWM-Qt
    def import_palette(self, palette):
        log.info("Importing new palette")
        # Import the palette in the ROM
        colors_addr = self.insert_rgb_to_gba_palette(palette)

        # Import the palette in the palette table
        table_end = self.get_table_end()
        rom.move_data(table_end, table_end + 8, 8, 0)
        new_pal_addr = table_end

        palette_id = self.get_max_palette_id() + 1
        # Make sure that the palette id is NOT
        # 0x11FF -> FF 11 (Palette Table End)
        if palette_id == 0x11FF:
            palette_id += 1
        log.info("The new palette ID will be " + conv.HEX(palette_id))

        rom.write_ptr(colors_addr, new_pal_addr)
        write_palette_id(new_pal_addr, palette_id)
        rom.write_bytes(new_pal_addr + 6, [0x0, 0x0])

        return palette_id