sixpack handling of palettes for multiple images?

Talk about development tools here

Moderator: BigEvilCorporation

matthewnimmo
Very interested
Posts: 52
Joined: Thu Jan 07, 2021 8:04 pm

Re: sixpack handling of palettes for multiple images?

Post by matthewnimmo » Fri Jan 13, 2023 10:33 pm

Chilly Willy wrote:
Fri Jan 13, 2023 10:22 pm
Okay, probably the key thing to converting things to 256 colors and splitting them up correctly... use GIMP. :lol:

I'm not certain where you're having trouble with asesprite, but GIMP never gives me any trouble. Use a hex editor to double check the header your version of GIMP is saving. Even being off a few bytes will cause images to be whack. When I last updated the version of Xubuntu I use, GIMP also updated, and the header changed, meaning I had to change a number of offsets I use in dealing with GIMP bumps to make them look right.
Hmm alright ill keep monkeying with gimp. Are my other steps accurate? For example. Should i go back to sixpack at all for my single sprites and produce their corresponding.apx binaries?

Am i at least exporting correctly for indexed 256 colors in GIMP? Everywhere i check it seems that is true

Separate thread that ill start later perhaps if i have trouble. I recently added in your xmplayer example into my sandbox. Got it working. But not seeing how you were referencing audio files directly? So when i want to generate my own music and wav files for sound ill have to see what steps i go to do that. Im guessing its another set of tools like sixpack and have them refenced like my images.s files?

matthewnimmo
Very interested
Posts: 52
Joined: Thu Jan 07, 2021 8:04 pm

Re: sixpack handling of palettes for multiple images?

Post by matthewnimmo » Sun Jan 15, 2023 4:50 am

Ok, for anyone that see's this and was/is confused like i was I finally have it working. Chilly, unfortunately (for the life of me) just a simple create a RGB indexed bmp with everything in it, chop it up into the individual files, and use the master rgb file's .pal produced by sixpack never did work :( I'm not sure what the deal was... probably something i was still doing wrong.

But, I did finally get things to work with this updated sixpack tool. So below are the exact steps i did just incase someone get's lost themselves.

1) Create my one master RGB indexed bmp file like Chilly said in GIMP (so all my sprites, backgrounds, etc). Make sure its quanitzed to 256 colors with gimp (so you'd go to: Images -> mode -> indexed options within GIMP). Then export that as a BMP. So, as an example let's call it "Sprites.bmp"

2) Open up the sixpack tool (needs to be this update version that allows for -savepal and -palref options).

3) Now generate the .pal file of that one master RGB file that you created, but be sure to use the -savepal option to create a temp.pal file that can be used by all single files you create from the master file. Using the same example, here is the command I used "sixpack -image -target 32x -format l8 -width 320 -height 202 -savepal temp.pal -o sprites.apx images/sprites.bmp" This will yield three files (sprites.apx, sprites.pal, and temp.pal). You will not need the .apx file generated.

4) Now go back to gimp and pull out a single sprite or image or background from that orignal master file and make sure you keep your same palette (you can do this by just editing the current master by cropping out everything else yo DONT need and then exporting a new file from that). So, in our example i'm going to use "Sprite.bmp" as i pulled out a single sprite.

5) Now go back to sixpack tool and let's create the corresponding .apx and .pal files referencing the temp.pal file from earlier. In our example we'll use the following command "sixpack -image -target 32x -format l8 -width 32 -height 32 -palref temp.pal -o sprite.apx images/sprite.bmp" Now, we should have two new files (sprite.apx and sprite.pal). You will not be needing the sprite.pal file.

At this point you have a single sprite.apx file and the sprites.pal that will work as the palette for that file. For any other sprites and/or images (or backgrounds) just follow steps 4-5 for that corresponding images from the master file.

I hope this serves others well!

Chilly Willy
Very interested
Posts: 2962
Joined: Fri Aug 17, 2007 9:33 pm

Re: sixpack handling of palettes for multiple images?

Post by Chilly Willy » Sun Jan 15, 2023 10:22 pm

That sounds okay, but I usually just strip the palette straight from the BMP header with a hex-editor. You can also strip the headers from BMP files leaving just the data with a hex-editor. But if you get that other tool to work, that may be easier for some.

Another suggestion - if you need to mess with the 256 color palette, mtPaint is probably better for that than GIMP. Say, you wanted to change the transparent color from whatever it is after quantizing the colors down to 256 into 0 (the color the 32X assumes is transparent). I never could get the palette editing in GIMP to do that correctly. mtPaint is designed around pixel art in 256 or less colors, so it's better about stuff like that.

matthewnimmo
Very interested
Posts: 52
Joined: Thu Jan 07, 2021 8:04 pm

Re: sixpack handling of palettes for multiple images?

Post by matthewnimmo » Mon Jan 16, 2023 2:13 pm

Chilly Willy wrote:
Sun Jan 15, 2023 10:22 pm
That sounds okay, but I usually just strip the palette straight from the BMP header with a hex-editor. You can also strip the headers from BMP files leaving just the data with a hex-editor. But if you get that other tool to work, that may be easier for some.

Another suggestion - if you need to mess with the 256 color palette, mtPaint is probably better for that than GIMP. Say, you wanted to change the transparent color from whatever it is after quantizing the colors down to 256 into 0 (the color the 32X assumes is transparent). I never could get the palette editing in GIMP to do that correctly. mtPaint is designed around pixel art in 256 or less colors, so it's better about stuff like that.
Very cool! I haven’t heard of mtPaint! Im going to check that out! Right now, ive found myself in another pal issue lol as ive been working with vic’s tilemap example. The tilemap work is absolutely beautiful and is something very appealing to me to have in my game. However in his example he has a hardcoded smileface sprite that he draws, scales, and rotates. But the challenge im facing there is that when i generate a sprite from that same tileset using sixpack tool and load it instead of his smileface all the colors on the sprite are messed up

Seems like he is using a different means of loading a palette, so currently i can either have my tilemaps correctly colored or my sprite but not both

Chilly Willy
Very interested
Posts: 2962
Joined: Fri Aug 17, 2007 9:33 pm

Re: sixpack handling of palettes for multiple images?

Post by Chilly Willy » Mon Jan 16, 2023 8:23 pm

Sounds like the sixpack tool is changing the palette. Can't tell you how to fix that as I don't use it. Use GIMP or mtPaint and mess with BMPs directly.

matthewnimmo
Very interested
Posts: 52
Joined: Thu Jan 07, 2021 8:04 pm

Re: sixpack handling of palettes for multiple images?

Post by matthewnimmo » Tue Jan 17, 2023 5:35 am

Chilly Willy wrote:
Mon Jan 16, 2023 8:23 pm
Sounds like the sixpack tool is changing the palette. Can't tell you how to fix that as I don't use it. Use GIMP or mtPaint and mess with BMPs directly.
Thanks chilly! Maybe i'm just being dense, but how are you exporting your sprites if you're not using sixpack tool then? I can see in GIMP andmtPaint where to export .pal files (I can even do that in asesprite). But, i thought the toolchain needed a .apx or .ext file for any sprites/images you wanted to draw? When i try just loading up a raw .bmp it's just this pixelated square (doesn't even resemble the sprite).

Am I missing something that everyone is doing if you're not using sixpack?

Thanks again,

Chilly Willy
Very interested
Posts: 2962
Joined: Fri Aug 17, 2007 9:33 pm

Re: sixpack handling of palettes for multiple images?

Post by Chilly Willy » Tue Jan 17, 2023 11:32 pm

I tend to embed the BMP in the cart and read the pal and data straight from the BMP. :D
So for sprites, I simply have them in BMP format... and the background... and anything else...

It's a LITTLE wasteful of space since the palette is the same in all BMPs (if you did it right), and you don't need the header since you already know all that info as you are the one who made the BMPs. So you could use a hex editor to get the pal, and then strip the headers from all the files leaving just the data.

matthewnimmo
Very interested
Posts: 52
Joined: Thu Jan 07, 2021 8:04 pm

Re: sixpack handling of palettes for multiple images?

Post by matthewnimmo » Tue Jan 17, 2023 11:47 pm

Chilly Willy wrote:
Tue Jan 17, 2023 11:32 pm
I tend to embed the BMP in the cart and read the pal and data straight from the BMP. :D
So for sprites, I simply have them in BMP format... and the background... and anything else...

It's a LITTLE wasteful of space since the palette is the same in all BMPs (if you did it right), and you don't need the header since you already know all that info as you are the one who made the BMPs. So you could use a hex editor to get the pal, and then strip the headers from all the files leaving just the data.
My brain is slowly growing in power lol. Chilly I really appreciate this and i hope you stay patient with me in all my questions!

So if i was to mirror this back you simple have your .bmp files (lets say you have one master.bmp and sprite1.bmp and sprite2.bmp) loaded up during compile time and from the master.bmp (which contains all sprites/images/tilesets/etc) you pull the palette information out when you reference it and thats the one palette for all sprites and and everything else?

So would it be something like:

Image.s has this code

Glob _master
Glob _sprite1
Glob _sprite2

_master: incbin images/master.bmp
_sprite1: incbin images/sprite1.bmp
_sprite2: incbin images/sprite2.bmp


Then for simplicity sake lets say you have a loadpalette and drawsprite function within a main.c. I would potentially reference said objects in main.c like below

Extern u32 master, sprite1, sprite2;

But how do i distill the pal from the master.bmp to send to the load palette function and then im assuming i would simple just pass my sprite variables to the drawsprite routine as they are?

Chilly Willy
Very interested
Posts: 2962
Joined: Fri Aug 17, 2007 9:33 pm

Re: sixpack handling of palettes for multiple images?

Post by Chilly Willy » Wed Jan 18, 2023 11:05 pm

There are many resources detailing the format of BMP files. Here's wikipedia's:
https://en.wikipedia.org/wiki/BMP_file_ ... ile_header

Here's a demo I made of a BMP viewer on the MD (one of several I was testing to see how good I could make general BMPs look on the MD):
https://pastebin.com/n5qSART1

Note that I used helper functions for getting the BMP info from the files in rom. Note that this viewer is using RGB BMP rather than 256 color BMP, but the idea is the same - make helper functions (or macros) to get the info from the header.

Post Reply