Skip to content

Commit

Permalink
butano: background palettes bits per pixel mode can be specified by t…
Browse files Browse the repository at this point in the history
…he user
  • Loading branch information
GValiente committed Dec 9, 2020
1 parent 126d797 commit 1ff596c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
7 changes: 6 additions & 1 deletion butano/include/bn_documentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -1016,12 +1016,16 @@
*
* @code{.json}
* {
* "type": "bg_palette"
* "type": "bg_palette",
* "bpp_mode": "bpp_8"
* }
* @endcode
*
* The fields for background palettes are the following:
* * `"type"`: must be `"bg_palette"` for background palettes.
* * `"bpp_mode"`: optional field which specifies the bits per pixel of the background palette:
* * `"bpp_8"`: up to 256 colors per @ref tile "tile".
* * `"bpp_4"`: up to 16 colors per @ref tile "tile".
*
* If the conversion process has finished successfully,
* a bn::bg_palette_item should have been generated in the `build` folder.
Expand Down Expand Up @@ -1089,6 +1093,7 @@
* @section changelog_4_4_0 4.4.0 (next release)
*
* * bn::sprite_font allows to specify space between characters.
* * Background palettes bits per pixel mode can be specified by the user.
* * Palettes change optimized.
* * Unused palette colors are not exported anymore.
* * bn::sprite_ptr::set_tiles() validation fixed.
Expand Down
22 changes: 17 additions & 5 deletions butano/tools/butano-graphics-tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,24 @@ def process(self):

class BgPaletteItem:

def __init__(self, file_path, file_name_no_ext, build_folder_path):
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
self.__bpp_8 = False

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':
raise ValueError('Invalid BPP mode: ' + bpp_mode)

def write_header(self):
name = self.__file_name_no_ext
Expand All @@ -513,10 +525,10 @@ def write_header(self):

remove_file(grit_file_path)

if self.__colors_count == 16:
bpp_mode_label = 'bpp_mode::BPP_4'
else:
if self.__bpp_8:
bpp_mode_label = 'bpp_mode::BPP_8'
else:
bpp_mode_label = 'bpp_mode::BPP_4'

with open(header_file_path, 'w') as header_file:
include_guard = 'BN_BG_PALETTE_ITEMS_' + name.upper() + '_H'
Expand Down Expand Up @@ -579,7 +591,7 @@ def process(self, build_folder_path):
elif self.__graphics_type == 'affine_bg':
item = AffineBgItem(self.__file_path, self.__file_name_no_ext, build_folder_path, self.__info)
elif self.__graphics_type == 'bg_palette':
item = BgPaletteItem(self.__file_path, self.__file_name_no_ext, build_folder_path)
item = BgPaletteItem(self.__file_path, self.__file_name_no_ext, build_folder_path, self.__info)
else:
raise ValueError('Unknown graphics type: ' + str(self.__graphics_type))

Expand Down
Loading

0 comments on commit 1ff596c

Please sign in to comment.