Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Colour Values

Author
Message
Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 14th Feb 2013 05:07 Edited at: 15th Feb 2013 01:24
Coming from DBC I'm used to colour values being calculated like so:
(red * 65536) + (green * 256) + blue
This seems to work for DBP but printing the colour value to screen gives a negative number! What the hell is going on?

Attachments

Login to view attachments
pcRaider
13
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 14th Feb 2013 05:18 Edited at: 14th Feb 2013 05:23
do not negative number.

Phaelax
DBPro Master
17
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Feb 2013 08:05
You gotta make it a dword, not integer. Both 4 bytes, but the high bit for integers is used for sign. Dwords are unsigned and therefore hold higher values.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 14th Feb 2013 08:09
Thanks guys, I probably should have guessed that since I do stuff like ink -1,0 for white ink.

^ That's what she said.
Phaelax
DBPro Master
17
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Feb 2013 08:14
Quote: " I do stuff like ink -1,0 for white ink"

I never thought about that before.

You can also use hex values just like web stuff.

ink 0xFF0000, 0

"You're all wrong. You're all idiots." ~Fluffy Rabbit
TheComet
12
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 14th Feb 2013 10:17
You should probably check this before blindly believing me, but I think bitwise operators might be faster than multiplications. If not, they are definitely more readable.

(red << 16) || (green << 8) || blue

TheComet

http://blankflankstudios.tumblr.com/
"ZIP files are such a retarded format!" - Phaelax
Rudolpho
14
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 14th Feb 2013 17:11
Don't forget col = alpha << 24 || red << 16 || green << 8 || blue.

Not supplying the alpha value will have it default to 0, thus making your colour completely transparent. To add to the confusion some functions only seem to use 24-bit colours and skip the alpha byte, while some others doesn't.


"Why do programmers get Halloween and Christmas mixed up?"
Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 14th Feb 2013 21:10
Ah yeah I forgot DBP can do bit-shifting.

^ That's what she said.
Phaelax
DBPro Master
17
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Feb 2013 23:55
I think awhile back we tested the speed of using multiplication versus bit shifting, and for this particular example we didn't really see any difference.

Also, is there a reason you're not simply using RBG()?

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 15th Feb 2013 00:38 Edited at: 15th Feb 2013 00:59
@Phaelax
I am drawing sprites (my procedural spaceships) and was testing for colours >0 to avoid drawing the transparent parts of the image, that's how I stumbled on the negative values.

^ That's what she said.

Attachments

Login to view attachments
Rudolpho
14
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 15th Feb 2013 03:08
Quote: "Also, is there a reason you're not simply using RBG()?"

I don't know how DBP implements bit shifting, but RGB, unless optimized and translated into something similar during compilation, will yield function calling overheads which you probably don't want if you're editing each pixel on a large bitmap etc.


"Why do programmers get Halloween and Christmas mixed up?"
Phaelax
DBPro Master
17
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 15th Feb 2013 05:55
Good point.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
pcRaider
13
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 19th Feb 2013 08:48
Quote: "
Don't forget col = alpha << 24 || red << 16 || green << 8 || blue.
"


It's a BOX command only.
TheComet
12
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 19th Feb 2013 13:38
@ pcRaider - I don't get how that's relevant.

TheComet

http://blankflankstudios.tumblr.com/
"You're all wrong. You're all idiots." - Fluffy Rabbit
"Bottom line, people are retarded." - Fluffy Rabbit
Phaelax
DBPro Master
17
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 19th Feb 2013 17:41
Only using color values in conjunction with the BOX command will make use of the alpha channel.

"You're all wrong. You're all idiots." ~Fluffy Rabbit

Login to post a reply

Server time is: 2020-08-12 08:23:40
Your offset time is: 2020-08-12 08:23:40