GValiente / butano

Modern C++ high level GBA engine

Repository from Github https://github.comGValiente/butanoRepository from Github https://github.comGValiente/butano

There should be an option to disable asset image import optimization

ultrasuperpingu opened this issue · comments

When you import a bpp_8 image, if the image only use less than 16 colors, its palette will be automatically switched to bpp_4. I totally understand why and you can force to use a 256 colors by using the palette_item option, it works fine.

Doing that, it is possible to use the same image to switch between a 16 colors image to 256 colors image just with a palette switch but it would be easier if it was possible to disable this optimization.

But my main problem is, if multiple color "slots" in the palette are the same, it seams that the import process "merge" all those colors in the image. I can't see any workaround for this (I tried to slightly change the color but they are 24bits, and I guess, when translated to 15bits, they are still the same, I guess it would work by changing them more so they are not the same in 15bits, but I don't really want to).

Again here, I totally understand why the behaviour is like this but it a problem for what I try to do.

It would be great to have an option to disable this optimization.

With the "bpp_mode" field you can override default BPP mode for all graphic asset types (sprites one was missing, I have just added support for it).

I'm not sure to understand. I have a bg with "bpp_mode": "bpp_8" with a palette > 16 colors but using only < 16 colors in that palette, and, once imported, its palette is 16 colors (without using "palette_item" option, because, if you do that, it's ok).

Edit: Maybe, it is because in my palette, many colors are the same. I have to check.

graphics.zip
Just tried with those files.

bn::regular_bg_ptr bg = bn::regular_bg_items::test_256c_all_diff.create_bg(0, 0);
bn::bg_palette_ptr palette=bg.palette();
bn::span<const bn::color> colors_const = palette.colors();
BN_LOG("test_256c_all_diff palette size: ", colors_const.size());

bg = bn::regular_bg_items::test_18c_all_same.create_bg(0, 0);
palette=bg.palette();
colors_const = palette.colors();
BN_LOG("test_18c_all_same palette size: ", colors_const.size());

I got:

[WARN] GBA Debug:	test_256c_all_diff palette size: 16
[WARN] GBA Debug:	test_18c_all_same palette size: 16

256c_all_diff and 18c_all_same refers to the number of colors in palettes, in the images, only one color is use anyway.

I have updated the graphics tool to allow to specify colors count for almost all graphic asset types.

I tried but I still have the same behaviour with the files I provided. Am I missing something?

Have you updated butano?

If it still doesn't work after updating (and specifying colors count in the json of the bmp you want to import), please upload a minimal reproducible example of the issue.

test.zip

I took the zip file of the project (In the main page, Code->Download ZIP).
I tried with the files and code I provided.
This is a full project.
I saw a difference, bpp is now BPP_8 but the color count is still not correct.

test_256c_all_diff : 256 colors in the palette, all the pixel use the same color "slot" (pure blue). Result in the log: [WARN] GBA Debug: test_256c_all_diff palette size: 16, bpp:1

test_18c_all_same: 18 colors in the palette, all the same (pure red), all the pixel use the same color "slot". Result in the log: [WARN] GBA Debug: test_18c_all_same palette size: 16, bpp:1

And to try to find how it works, I built test_256c_all_diff_gradient (which in fact has 255 colors in the palette) and use only few colors of it but more than 16 colors and I got:
[WARN] GBA Debug: test_256c_all_diff_gradient palette size: 240, bpp:1

I don't understand why there is 240 colors, I imagine some of the colors (15 of them??) in the palette are the same once converted to 15bit...

Hope this helps

You have not specified "colors_count" field in the json of the affected bmp files.

As I said, please make sure to update Butano and specify colors count in the json of the bmp you want to import.

Just tried and it seams to work. Sorry for the "colors_count" but it was not specified in the "Importing assets" doc page in the bg or sprite part (but indeed, it was in the palettes part). When you said "(and specifying colors count in the json of the bmp you want to import)", I thought you were talking about the bpp field...
I still have to see if it still merging colors which are the same in the image. I'll try tomorrow.
Thanks a lot. Your project is really great :)

"colors_count" field shows in the sprites section, at least for me: https://gvaliente.github.io/butano/import.html#import_sprite

By the way, can I close this issue?

You're right, clearing the browser's caching, the text appears in the others sections 😕, sorry.
Can you wait I test if the identical colors in the image are still merged to use the same "palette slot" before closing it ? I don't think I would be able to do that today but I'll try tomorrow.

I'll close this issue now.

If you have issues with palettes merging, since it is unrelated to this issue, please feel free to create a new one.

Here's a bit of extra info about color palettes, by the way: https://gvaliente.github.io/butano/faq.html#faq_color

Ok, finally, I had time to test. It's working, it's great. Thanks.
Here is the result of what I was trying to achieve (WIP).
output1
output2

Thanks again

Edit: It's WIP, fade time is too short I guess. Not that obvious on mGBA...