RGB int values to OpenGL or Jitter matrix

May 5, 2011 at 5:42pm

RGB int values to OpenGL or Jitter matrix

Hello!

I am using Java to read video into Jitter, but Java represents pixels as a single integer for the ARGB components, like this:

-8360914 -7374019 -6785989 -6785989 -6589893

which I don’t know how to use in Jitter.

I am looking for a fast way to either translate this data into 4 separate ARGB numbers per pixel or even better, send them right to a Jitter OpenGL object for subsequent use with other Jitter objects.

Any ideas for a computationally fast way to do this?

#56899
May 6, 2011 at 4:17pm

A quick search (hint – Google: Java ARGB) reveals an algorithm for deriving 8 bit ARGB values from a 32 bit int as:

int alpha = (pixel >> 24) & 0xff;
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel) & 0xff;

from here: http://download.oracle.com/javase/tutorial/java/nutsandbolts/op3.html

Translated simply into max to illustrate the process and get the ball rolling…(but there are no doubt more elegant and efficient ways than this):

– Pasted Max Patch, click to expand. –

No guarantees for either the code i stole, or may max implementation of it, but it may help you on the right track…

#203962
May 8, 2011 at 9:35pm

Thank you. You are exactly right about needing to extract individual bytes.

However I have to do this for relatively huge arrays (76800 length just for 320×240 video), so I think I need a faster way then doing the byte extraction on each element of the arrays.

Do you, or anyone else know if it’s possible to send RGB int arrays directly to an OpenGL texture? Or a fast way to byte extract these arrays.

#203963
May 9, 2011 at 2:14pm

Not sure about sending RGB ints to OpenGL. However processing a matrix of that size or larger is fairly typical in Jitter and a matrix version of the algorithm I posted earlier might go something like the patch attached (say that five times fast!). I’m too lazy to actually encode an image to test the patch so the usual caveats apply…

– Pasted Max Patch, click to expand. –
#203964

You must be logged in to reply to this topic.