git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

commit a54a099a56139b289e28c8a3779887b28f612305
parent 7d0e3891836c50fc551341fba38d2ab1ca96756e
Author: Toxa <untoxa@mail.ru>
Date:   Tue, 29 Jul 2025 17:48:51 +0300

PNG2ASSET: export binary palettes when -bin

Diffstat:
Mgbdk-support/png2asset/export_binary.cpp39++++++++++++++++++++++++++++++++++++++-
Mgbdk-support/png2asset/process_arguments.cpp1+
Mgbdk-support/png2asset/process_arguments.h1+
3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/gbdk-support/png2asset/export_binary.cpp b/gbdk-support/png2asset/export_binary.cpp @@ -34,7 +34,7 @@ static exportOptions_t exportOpt; static void export_map_binary_tile_data(PNG2AssetData* assetData); static void export_map_binary_map_data(PNG2AssetData* assetData); - +static void export_map_binary_palette_data(PNG2AssetData* assetData); bool export_map_binary(PNG2AssetData* assetData) { @@ -46,6 +46,9 @@ bool export_map_binary(PNG2AssetData* assetData) { if (assetData->args->includedMapOrMetaspriteData) export_map_binary_map_data(assetData); + if (assetData->args->include_palettes) + export_map_binary_palette_data(assetData); + return true; // success } @@ -118,3 +121,37 @@ static void export_map_binary_map_data(PNG2AssetData* assetData) { mapAttributesBinaryfile.close(); } } + +static void export_map_binary_palette_data(PNG2AssetData* assetData) { + + std::ofstream paletteBinaryFile; + paletteBinaryFile.open(assetData->args->output_filename_palettes_bin, std::ios_base::binary); + + const size_t palette_start = exportOpt.color_start / assetData->image.colors_per_pal; + const size_t total_palette_count = assetData->image.total_color_count / assetData->image.colors_per_pal; + int cur_color = exportOpt.color_start; + + for (size_t i = palette_start; i < total_palette_count; ++i) + { + unsigned char* pal_ptr = &assetData->image.palette[i * (assetData->image.colors_per_pal * RGBA32_SZ)]; + for (int c = 0; c < (int)assetData->image.colors_per_pal; ++c, pal_ptr += RGBA32_SZ) + { + if (assetData->args->convert_rgb_to_nes) { + size_t rgb222 = (((pal_ptr[2] >> 6) & 0x3) << 4) | + (((pal_ptr[1] >> 6) & 0x3) << 2) | + (((pal_ptr[0] >> 6) & 0x3) << 0); + paletteBinaryFile.write((const char *)&rgb_to_nes[rgb222], sizeof(rgb_to_nes[0])); + } else { + // TODO: implement formats other than RGB555, depending on the pack mode + uint16_t rgb555 = (((pal_ptr[2] >> 3) & 0b00011111) << 10) | + (((pal_ptr[1] >> 3) & 0b00011111) << 5) | + (((pal_ptr[0] >> 3) & 0b00011111) << 0); + paletteBinaryFile.write((const char *)&rgb555, sizeof(rgb555)); + } + + cur_color++; + } + } + // Finalize the files + paletteBinaryFile.close(); +} diff --git a/gbdk-support/png2asset/process_arguments.cpp b/gbdk-support/png2asset/process_arguments.cpp @@ -339,6 +339,7 @@ int processPNG2AssetArguments(int argc, char* argv[], PNG2AssetArguments* args) args->output_filename_bin = args->output_filename.substr(0, dot_pos) + "_map.bin"; args->output_filename_attributes_bin = args->output_filename.substr(0, dot_pos) + "_map_attributes.bin"; args->output_filename_tiles_bin = args->output_filename.substr(0, dot_pos) + "_tiles.bin"; + args->output_filename_palettes_bin = args->output_filename.substr(0, dot_pos) + "_palettes.bin"; args->data_name = args->output_filename.substr(slash_pos + 1, dot_pos - 1 - slash_pos); replace(args->data_name.begin(), args->data_name.end(), '-', '_'); diff --git a/gbdk-support/png2asset/process_arguments.h b/gbdk-support/png2asset/process_arguments.h @@ -30,6 +30,7 @@ struct PNG2AssetArguments { string output_filename_bin; string output_filename_attributes_bin; string output_filename_tiles_bin; + string output_filename_palettes_bin; string data_name; string output_filename; string input_filename;

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.