Page 1 of 1

Getting the R, G, B components of a palette color

Posted: Sat Jan 16, 2021 4:10 pm
by McValdemar
Hi,
given an array of u16 that has the 64 colors for the 4 palettes, I wanted to read the R, G, B components of each color.
I thought that PRed=palette&&VDPPALETTE_REDMASK; would work, for instance, to read the RED component.
But seems I am wrong... :/

Any suggestion?

Re: Getting the R, G, B components of a palette color

Posted: Sat Jan 16, 2021 6:22 pm
by cero
Hint: && is the "logical and" operator. It produces a true/false value.

Re: Getting the R, G, B components of a palette color

Posted: Sat Jan 16, 2021 8:47 pm
by Miquel
.

Re: Getting the R, G, B components of a palette color

Posted: Sun Jan 17, 2021 6:59 am
by Sik
It's 0000BBB0GGG0RRR0 actually

blue = (color >> 9) & 7;
green = (color >> 5) & 7;
red = (color >> 1) & 7;

Re: Getting the R, G, B components of a palette color

Posted: Sun Jan 17, 2021 9:30 am
by McValdemar
Thanks alot!
This way was solved.

BTW I made a mistake in putting &&, mistake that I corrected but the real problem, as you guys hinted, was in the bit operation.
Adding:
PRed >>= 1;
PGreen >>= 5;
PBlue >>= 9;

After the "&" masking solved the problem.
Thanks again for the prompt feedback!
:)

Re: Getting the R, G, B components of a palette color

Posted: Sun Jan 17, 2021 4:33 pm
by Miquel
(Sorry but people is throwing objects to my house, firecrackers it seems by the amount of damage: deleting messages)

Re: Getting the R, G, B components of a palette color

Posted: Mon Jan 18, 2021 8:27 am
by McValdemar
Sik wrote:
Sun Jan 17, 2021 6:59 am
It's 0000BBB0GGG0RRR0 actually

blue = (color >> 9) & 7;
green = (color >> 5) & 7;
red = (color >> 1) & 7;
BTW you are the dev of Arkagis and the new "drilling game"?