FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   pixels[] doubt
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: pixels[] doubt  (Read 3057 times)
Dimitre

WWW
pixels[] doubt
« on: Nov 14th, 2002, 8:03pm »

Hello! I have a doubt about mixing color numbers.
I am working with the built-in pixels[] array and another (pixels2[]) that I created.
Do you a way to "add" one to another, creating Multiply effect?
pixels[] Multiply pixels2[]
 
fry


WWW
Re: pixels[] doubt
« Reply #1 on: Nov 15th, 2002, 1:24am »

there isn't a way to do this for free.. you'll just have to iterate over the pixel array, unpack the r/g/b components with some bit-shifting, then add, then re-pack.
 
and please follor up if you 1) don't know what i mean and need an example or 2) write the example for yourself, so you can share it with the rest of us.
 
Dimitre

WWW
Re: pixels[] doubt
« Reply #2 on: Nov 18th, 2002, 9:37pm »

Thanks fry. This worked fine for me:
Code:
red = pixels2[index] >> 16;
green = (pixels2[index] - (red << 16)) >> 8;
blue = pixels2[index] - (green << 8) - (red << 16);

 
I also found this blending modes reference, very interesting to play with it: http://pegtop.net/delphi/blendmodes/
« Last Edit: Nov 18th, 2002, 10:19pm by Dimitre »  
fry


WWW
Re: pixels[] doubt
« Reply #3 on: Nov 18th, 2002, 11:16pm »

that's a great reference. thanks for posting the link.
 
the following code may be more straightforward/correct (faster in the case of the blue component) for unpacking numbers.
 
Code:
red   = (pixels2[index] >> 16) & 0xff;
green = (pixels2[index] >> 8) & 0xff;
blue  =  pixels2[index] & 0xff;

 
some explanation, for the folks that might not know about this stuff...  
 
Code:
the bits in a pixel look like this:
AAAAAAAARRRRRRRRGGGGGGGGBBBBBBBB
(where A is alpha, R is red.. etc)
 
so when you shift the red 16 to the right (>> 16 above) then the pixel looks like this:
 
0000000000000000AAAAAAAARRRRRRRR
 
and you use the & 0xff to hack off the other bits, and just save the 8 bits that you need for the color component itself. 0xff is 8 bits, all set to 1. so:
 
0000000000000000AAAAAAAARRRRRRRR
"and"
00000000000000000000000011111111
will be
000000000000000000000000RRRRRRRR
 
because the "and" operation only lets through the bits that are set in both numbers.

 
(sorry for the tiny monospaced font, but the text makes more sense in mono so the letters line up)
 
[ ANOTHER METHOD, for the beginners, or those more obsessed with clarity than speed ]
 
for those who don't need the speed of using ints and unpacking things like this, you can use something like:
 
Code:
color pixel = getPixel(4, 5);
float r = red(pixel);
float g = green(pixel);
float b = blue(pixel);

 
the numbers for r, g, b will be scaled to the current colorMode. i.e. if you're using colorMode(RGB, 1), all the numbers will be between 0..1. useful for sane, simpler coding, but a bit slower because of the extra work to turn the colors into something more like the current color mode.
« Last Edit: Nov 18th, 2002, 11:18pm by fry »  
Dimitre

WWW
Re: pixels[] doubt
« Reply #4 on: Nov 19th, 2002, 5:45pm »

Thanks fry! very fine the "& 0xff" use.
I updated my code and put one multiply mode experiment at http://dmtr.org/generative.
Soon I will post more.
« Last Edit: May 18th, 2004, 10:17pm by Dimitre »  
hurlbot


Re: pixels[] doubt
« Reply #5 on: Jan 23rd, 2003, 7:52am »

I get this error with all the processing applets on your page:
 
Connecting http://dimitre.locaweb.com.br/jars/sereia.jar with no proxy
 
Downloading http://dimitre.locaweb.com.br/jars/sereia.jar to cache
 
java.lang.IllegalArgumentException
 
 at java.util.zip.ZipInputStream.getUTF8String(Unknown Source)
 
 at java.util.zip.ZipInputStream.readLOC(Unknown Source)
 
 at java.util.zip.ZipInputStream.getNextEntry(Unknown Source)
 
 at sun.plugin.cache.CachedJarLoader.decompress(Unknown Source)
 
 at sun.plugin.cache.CachedJarLoader.access$500(Unknown Source)
 
 at sun.plugin.cache.CachedJarLoader$5.run(Unknown Source)
 
 at java.security.AccessController.doPrivileged(Native Method)
 
 at sun.plugin.cache.Cache.privileged(Unknown Source)
 
 at sun.plugin.cache.CachedJarLoader.download(Unknown Source)
 
 at sun.plugin.cache.CachedJarLoader.load(Unknown Source)
 
 at sun.plugin.cache.JarCache.get(Unknown Source)
 
 at sun.plugin.net.protocol.jar.CachedJarURLConnection.connect(Unknown Source)
 
 at sun.plugin.net.protocol.jar.CachedJarURLConnection.getJarFile(Unknown Source)
 
 at sun.misc.URLClassPath$JarLoader.getJarFile(Unknown Source)
 
 at sun.misc.URLClassPath$JarLoader.<init>(Unknown Source)
 
 at sun.misc.URLClassPath$3.run(Unknown Source)
 
 at java.security.AccessController.doPrivileged(Native Method)
 
 at sun.misc.URLClassPath.getLoader(Unknown Source)
 
 at sun.misc.URLClassPath.getLoader(Unknown Source)
 
 at sun.misc.URLClassPath.getResource(Unknown Source)
 
 at java.net.URLClassLoader$1.run(Unknown Source)
 
 at java.security.AccessController.doPrivileged(Native Method)
 
 at java.net.URLClassLoader.findClass(Unknown Source)
 
 at sun.applet.AppletClassLoader.findClass(Unknown Source)
 
 at sun.plugin.security.PluginClassLoader.findClass(Unknown Source)
 
 at java.lang.ClassLoader.loadClass(Unknown Source)
 
 at sun.applet.AppletClassLoader.loadClass(Unknown Source)
 
 at java.lang.ClassLoader.loadClass(Unknown Source)
 
 at sun.applet.AppletClassLoader.loadCode(Unknown Source)
 
 at sun.applet.AppletPanel.createApplet(Unknown Source)
 
 at sun.plugin.AppletViewer.createApplet(Unknown Source)
 
 at sun.applet.AppletPanel.runLoader(Unknown Source)
 
 at sun.applet.AppletPanel.run(Unknown Source)
 
 at java.lang.Thread.run(Unknown Source)
 
Exception: java.lang.IllegalArgumentException
 
benelek

35160983516098 WWW Email
Re: pixels[] doubt
« Reply #6 on: Jan 23rd, 2003, 3:16pm »

i also get this error with all the p5 applets on ur page.
 
Dimitre

WWW
Re: pixels[] doubt
« Reply #7 on: Feb 3rd, 2003, 8:41pm »

Thanks Guys!  
I will check this.  
 
I decompressed all the jar files, for proce55ing cache reutilization, but maybe this only worked in Microsoft VM.
 
Do you use Microsoft Virtual Machine, or Java Plugin?
 
Glen Murphy

WWW Email
Re: pixels[] doubt
« Reply #8 on: Feb 3rd, 2003, 11:51pm »

I use the Java plugin, and they weren't working. ARr.
 
Dimitre

WWW
Re: pixels[] doubt
« Reply #9 on: Feb 19th, 2003, 9:30pm »

thanks. Now it is fixed
 
Pages: 1 

« Previous topic | Next topic »