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

SGDK only sub forum

Moderator: Stef

Post Reply
McValdemar
Interested
Posts: 10
Joined: Fri Mar 20, 2020 6:59 pm

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

Post by McValdemar » Sat Jan 16, 2021 4:10 pm

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?

cero
Very interested
Posts: 291
Joined: Mon Nov 30, 2015 1:55 pm

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

Post by cero » Sat Jan 16, 2021 6:22 pm

Hint: && is the "logical and" operator. It produces a true/false value.

Miquel
Very interested
Posts: 505
Joined: Sat Jul 30, 2016 12:33 am

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

Post by Miquel » Sat Jan 16, 2021 8:47 pm

.
Last edited by Miquel on Mon Jan 18, 2021 6:23 pm, edited 1 time in total.
Help. Spanish TVs are brain washing people to be hostile to me.

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

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

Post by Sik » Sun Jan 17, 2021 6:59 am

It's 0000BBB0GGG0RRR0 actually

blue = (color >> 9) & 7;
green = (color >> 5) & 7;
red = (color >> 1) & 7;
Sik is pronounced as "seek", not as "sick".

McValdemar
Interested
Posts: 10
Joined: Fri Mar 20, 2020 6:59 pm

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

Post by McValdemar » Sun Jan 17, 2021 9:30 am

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!
:)

Miquel
Very interested
Posts: 505
Joined: Sat Jul 30, 2016 12:33 am

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

Post by Miquel » Sun Jan 17, 2021 4:33 pm

(Sorry but people is throwing objects to my house, firecrackers it seems by the amount of damage: deleting messages)
Last edited by Miquel on Mon Jan 18, 2021 6:25 pm, edited 1 time in total.
Help. Spanish TVs are brain washing people to be hostile to me.

McValdemar
Interested
Posts: 10
Joined: Fri Mar 20, 2020 6:59 pm

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

Post by McValdemar » Mon Jan 18, 2021 8:27 am

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"?

Post Reply