Low level jit.gen and jit.gl.pix pixel access question

Mar 23, 2013 at 6:07am

Low level jit.gen and jit.gl.pix pixel access question

I am wondering if it is possible to do pixel-by-pixel serial operations on a Jitter matrix using the new jit.gen or jit.gl.pix objects. I would like to use some algorithms that cannot operate purely in parallel. For a specific example, I would like to implement 1-bit Floyd-Steinberg dither in a Max patch. In Processing code it looks like this:

for(int x=1; x
for(int y=1; y
quantizedVal = (pixArray[x][y] > 0.5) ? 1.0 : 0.0; //1.0 is black, 0.0 is white
quantError = pixArray[x][y] – quantizedVal;
pixArray[x][y] = quantizedVal;

pixArray[x+1][y ] += quantError * 7/16;
pixArray[x-1][y+1] += quantError * 3/16;
pixArray[x ][y+1] += quantError * 5/16;
pixArray[x+1][y+1] += quantError * 1/16;
}
}

Can that be implemented in code inside jit.gen or jit.gl.pix? I heard that gen supports for loops now, but I do not see a clear way to access individual pixels in a matrix for both reading and writing. Is there a way?

#67272
Mar 23, 2013 at 1:23pm

For getting any pixel’s value you can use the ‘sample’ gen object. For output, AFAIK, you’re bound to the gen structure which means you can only write the current pixel, no neighboring ones. You can have multiple matrix outputs though, so maybe there’s a workaround possible if you really need it. But chances are an algorithm can be adapted to work inside gen’s structure.

#242069
Apr 14, 2014 at 11:07am

Hi Skrasms did you manage to get a Floyd Steinberg dithering algorithm working with jit.gen or with jit.gl.slab as a glsl shader code ?
This is just what I am looking for and I accidentally found your topics in the forum.
Thanks to let me know if you managed to work out something !

#286632

You must be logged in to reply to this topic.