Convert r-g-b to pal for the x16

All aspects of programming on the Commander X16.
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: Convert r-g-b to pal for the x16

Post by funkheld »

These are the original values that I converted from the gimp.
the first color starts at 0 0 0.

i have "pure basic"

https://github.com/hstubbs3/CommanderX1 ... x16pal.txt

gruss

Code: Select all

JASC-PAL
0100
256
0 0 0
255 255 255
136 0 0
170 255 238
204 68 204
0 204 85
0 0 170
238 238 119
221 136 85
102 68 0
255 119 119
51 51 51
119 119 119
170 255 102
0 136 255
187 187 187
0 0 0
17 17 17
34 34 34
51 51 51
68 68 68
85 85 85
102 102 102
119 119 119
136 136 136
153 153 153
170 170 170
187 187 187
204 204 204
221 221 221
238 238 238
255 255 255
34 17 17
68 51 51
102 68 68
136 102 102
170 136 136
204 153 153
255 187 187
34 17 17
68 34 34
102 51 51
136 68 68
170 85 85
204 102 102
255 119 119
34 0 0
68 17 17
102 17 17
136 34 34
170 34 34
204 51 51
255 51 51
34 0 0
68 0 0
102 0 0
136 0 0
170 0 0
204 0 0
255 0 0
34 34 17
68 68 51
102 102 68
136 136 102
170 170 136
204 204 153
255 238 187
34 17 17
68 51 34
102 85 51
136 119 68
170 153 85
204 187 102
255 221 119
34 17 0
68 51 17
102 85 17
136 102 34
170 136 34
204 170 51
255 204 51
34 17 0
68 51 0
102 68 0
136 102 0
170 136 0
204 153 0
255 187 0
17 34 17
51 68 51
85 102 68
119 136 102
153 170 136
187 204 153
221 255 187
17 34 17
51 68 34
68 102 51
102 136 68
136 170 85
153 204 102
187 255 119
17 34 0
34 68 17
68 102 17
85 136 34
102 170 34
136 204 51
153 255 51
17 34 0
34 68 0
51 102 0
68 136 0
85 170 0
102 204 0
119 255 0
17 34 17
51 68 51
68 102 85
102 136 102
136 170 136
153 204 170
187 255 204
17 34 17
34 68 34
51 102 68
68 136 85
85 170 102
102 204 136
119 255 153
0 34 0
17 68 17
17 102 34
34 136 51
34 170 68
51 204 85
51 255 102
0 34 0
0 68 17
0 102 17
0 136 34
0 170 34
0 204 51
0 255 51
17 34 34
51 68 68
68 102 102
102 136 136
136 170 170
153 204 204
187 255 255
17 34 34
34 68 68
51 102 102
68 136 136
85 170 170
102 204 204
119 255 255
0 34 34
17 68 68
17 102 102
34 136 136
34 170 170
51 204 204
51 255 255
0 34 34
0 68 68
0 102 102
0 136 136
0 170 170
0 204 204
0 255 255
17 17 34
51 51 68
68 85 102
102 102 136
136 136 170
153 170 204
187 204 255
17 17 34
34 34 68
51 68 102
68 85 136
85 102 170
102 136 204
119 153 255
0 0 34
17 17 68
17 34 102
34 51 136
34 68 170
51 85 204
51 102 255
0 0 34
0 17 68
0 17 102
0 34 136
0 34 170
0 51 204
0 51 255
17 17 34
51 51 68
85 68 102
119 102 136
153 136 170
187 153 204
221 187 255
17 17 34
51 34 68
68 51 102
102 68 136
136 85 170
153 102 204
187 119 255
17 0 34
34 17 68
68 17 102
85 34 136
102 34 170
136 51 204
153 51 255
17 0 34
34 0 68
51 0 102
68 0 136
85 0 170
102 0 204
119 0 255
34 17 34
68 51 68
102 68 102
136 102 136
170 136 170
204 153 204
255 187 238
34 17 17
68 34 51
102 51 85
136 68 119
170 85 153
204 102 187
255 119 221
34 0 17
68 17 51
102 17 85
136 34 102
170 34 136
204 51 170
255 51 204
34 0 17
68 0 51
102 0 68
136 0 102
170 0 136
204 0 153
255 0 187
User avatar
ahenry3068
Posts: 1151
Joined: Tue Apr 04, 2023 9:57 pm

Re: Convert r-g-b to pal for the x16

Post by ahenry3068 »

funkheld wrote: Wed Mar 20, 2024 8:21 am Hi good afternoon.

ahenry3068 , what kind of pal do you have please?
Does it look a little different than the picture above with your bas?

Thanks.
greeting
In the archive
FUNK.TXT --> The values you posted, I just cut and pasted
FUNKPTXT.BAS --> Text processor --> adds Palette index and commas to FUNK.TXT
FUNKOUT.TXT --> The Output file from above

FUNKPAL.BAS/FUNKPAL.PRG --> Processes your values to X16 Palette format and sets them to the VERA Palette.


Also Created FUNKPAL.PAL --> Binary output Palette can be loaded with BVLOAD "FUNKPAL.PAL",8,1,$FA00
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: Convert r-g-b to pal for the x16

Post by funkheld »

I have now learned a lot from you about how to write and read data in basic with the funk....pal.

Thanks.
greeting
User avatar
ahenry3068
Posts: 1151
Joined: Tue Apr 04, 2023 9:57 pm

Re: Convert r-g-b to pal for the x16

Post by ahenry3068 »

funkheld wrote: Wed Mar 20, 2024 8:43 am I have now learned a lot from you about how to write and read data in basic with the funk....pal.

Thanks.
greeting
I'm assuming that the values you posted should be read as

R G B R G B ....etc
if you had them in a different order than my program will not be setting the Palette correctly .
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: Convert r-g-b to pal for the x16

Post by funkheld »

my values are written as RGB.
your program works great.

In the original pal from the x16 I can't find any 255 0 255 for the transparency of the sprite.

Thanks.
greeting
User avatar
ahenry3068
Posts: 1151
Joined: Tue Apr 04, 2023 9:57 pm

Re: Convert r-g-b to pal for the x16

Post by ahenry3068 »

funkheld wrote: Wed Mar 20, 2024 9:25 am my values are written as RGB.
your program works great.

In the original pal from the x16 I can't find any 255 0 255 for the transparency of the sprite.

Thanks.
greeting
For Sprites and Layers. Palette Index 0 is Transparent. It doesn't matter what the R G B Values are unless it's the very Bottom Layer (or Sprite) in Z order.
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: Convert r-g-b to pal for the x16

Post by funkheld »

Thanks for the info.

I haven't been able to try this yet because I'm looking for help on how to create a sprite.bin in basic with 16 colors and a sprite.bin with 255 colors and use the pal or this color in the x16 system.

Thanks.

greeting
User avatar
ahenry3068
Posts: 1151
Joined: Tue Apr 04, 2023 9:57 pm

Re: Convert r-g-b to pal for the x16

Post by ahenry3068 »

funkheld wrote: Thu Mar 21, 2024 8:08 am Thanks for the info.

I haven't been able to try this yet because I'm looking for help on how to create a sprite.bin in basic with 16 colors and a sprite.bin with 255 colors and use the pal or this color in the x16 system.

Thanks.

greeting
If you've installed Jestin's GIMP Plugin just make a BIN in the proper resolution and that will work for a 256 color sprite.
(Must be a proper resolution though, 16x16, 32x32 or 64x64.
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: Convert r-g-b to pal for the x16

Post by funkheld »

Hello thanks for the information.
plugin and gimp on windows is too difficult for me to compile.
I would prefer phyton or x16 basic.


Thanks.
greeting
hstubbs3
Posts: 72
Joined: Thu Oct 26, 2023 12:14 pm

Re: Convert r-g-b to pal for the x16

Post by hstubbs3 »

Hello,
Python? did you say Python??

If you can make the image in PNG format, reading the pixels as an array of R8,G8,B8 is simple enough using the python png lib -> https://pypi.org/project/pypng/

Now you have access to raw pixel data in Python, you need to decide 2 things :
1. 16 or 256 color
2. using standard X16 palette or a custom palette?

If 16 color, there's effectively 16 different 16-color palettes in the standard 256 colors - each palette offset offers access to 15 at a time (as color 0 is always considered transparent ).

Then -> if using the standard palette(s), if 256 color -> for each R8,G8,B8 pixel, find the 'closest' value in the standard palette ( which, handily, you could use the PNG from the VERA docs and fetch the pixel color every so many cols/ every so many rows to get the 256 values from that image )


For 16 color - is sorta same thing, but either you are trying to figure out which palette offset is best... OR you decide and then it is 15 color variant of the distance checking.

then for each pixel in source you write to list of lists or directly to file, formatted as BIN if raw binary or ready to be included into prog8 or basic source..

shouldn't chug along too badly for images small enough to be X16 sprites.

one way to check "closest color" is euclidean distance - which color in the palette is the closest in 3D space... which has least value for (Rp-Ri)^2 + (Gp-Gi)^2 + (Bp-Bi)^2 ... where p is palette color component and i is image color component..
just remember that color 0 = transparent, so only check palette colors 1-255 unless you need transparent that pixel.

other methods would involve perhaps HSV or other color spaces ... color quantization can get complicated... and we aren't even talking about dithering here at all... which would be whole other layer of stuff..




I probably wouldn't get chance until this weekend to work on it, so maybe either someone else can, already did, or you could tackle it based on the outline above.
Post Reply