We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › how to increment color data
Page Index Toggle Pages: 1
how to increment color data (Read 1555 times)
how to increment color data
Aug 13th, 2007, 6:47am
 
I want to transform a color into other, but i don't know how to deal (increment or decrement) a color until a target. The data is in hexa? bits? where could i learn (very basic) some about that? I dont undestand shifiting or the (? : >>) stuff also .
So how do i get started?

thanks

vk



Re: how to increment color data
Reply #1 - Aug 13th, 2007, 7:58am
 
I cover it in Appendix B in http://friendsofed.com/book.html?isbn=159059617X

Of course you could also google: bitwise operations
Re: how to increment color data
Reply #2 - Aug 13th, 2007, 1:37pm
 
Knowing the gory details of the bitwise stuff isn't entirely necessary.  (I don't)  You can use red() green() blue() and the other color representation conversion functions to go back and forth to values you can increment more intuitively.

You'll suffer a performance hit no doubt.  Incentive to learn the bitwise eventually.
Re: how to increment color data
Reply #3 - Aug 13th, 2007, 1:40pm
 
the bitwise stuff is covered in the reference:
http://processing.org/reference/leftshift.html
http://processing.org/reference/rightshift.html

or you can use lerpColor():
http://processing.org/reference/lerpColor_.html
Re: how to increment color data
Reply #4 - Aug 15th, 2007, 3:39am
 
Thanks everybody for help.
I was using lerpColor already, but i'd like to try more control over the change.
I still like to understand the bitwise stuff (i know the name already, that's more than i knew). Can one add and subtract binaries numbers, how? And in hex.
How to change just one part of the number, for instance the Red portion?
shifting is just for multiply and divide?
I mean, more than the syntax, I'd like to find good texts about how to deal with this data.
thanks again.
Re: how to increment color data
Reply #5 - Aug 15th, 2007, 4:21am
 
This seems to be one article for it many cite as a great reference:

Bitwise Operations in C
http://www.gamedev.net/reference/articles/article1563.asp

Examples are in C language, but should be pretty easy to map them to java/processing.

Just found this too, not extensive but Java.
http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Tech/Chapter10/bits.html
Re: how to increment color data
Reply #6 - Aug 15th, 2007, 11:06pm
 
vicente wrote on Aug 15th, 2007, 3:39am:
Can one add and subtract binaries numbers, how And in hex.
How to change just one part of the number, for instance the Red portion
shifting is just for multiply and divide
I mean, more than the syntax, I'd like to find good texts about how to deal with this data.
thanks again.

again, read the reference links i posted. the second half of the examples (below the line) cover how to get the red, green, blue, and alpha components out, and then re-assemble them for other uses. you can't really manipulate a color directly by addition and subtraction--you have to break it into red/green/blue, change those values, and then assemble red/green/blue back into an int/color variable.

technically, bit shifting does multiplication and division, but it's not helpful to think about it that way with color data. just think about it as a way to pack and unpack colors into a int/color variable.

...or if you're really stuck, just use red(), green(), blue() and color().
Re: how to increment color data
Reply #7 - Aug 17th, 2007, 7:23am
 
hummmmm. i see. Thanks Fry. Thanks clickykbd.
A little reading there, a little re-reading here and i start to get it.
So, argb >> 16 & 0xFF are two operations? I mean shifting 16 places and ANDing the shifted number with a mask  ? This specifc mask (11111111) will always extract the lower part of the dword, right? This is why we shift the data before ANDing, ok so far? So we clear the whole dword but red information (in this case). Then the new dword (is it the correct name) when assigned to an int will give me the red value in decimal so i can work with it. right?
I will need to change the way things in my sketch were build so far to use this.

How much difference in performance should i get? Noticeable?
I'm doing big 2D arrays (like800*600)  and changing each object to different color targets (using lerpColor so far).

Re: how to increment color data
Reply #8 - Aug 17th, 2007, 3:02pm
 
yes, that's correct. it's just an int, not a dword.. the reference should actually use parens:

int r = (c >> 24) & 0xff;

because & may bind later than >>, i can't recall offhand but will change it for the next rev.

the change in speed from using red(), green(), blue() etc will be significant. the change from using lerpColor() depends on how you're using it. internally, this is what lerpColor() does, you'd have to compare the source of PApplet.lerpColor from dev.processing.org against what you're doing to get an idea.
Re: how to increment color data
Reply #9 - Aug 17th, 2007, 4:10pm
 
thanks again. So every int is 32-bits?
Page Index Toggle Pages: 1