plane flattening and interleaving with Gen?

    Nov 19 2012 | 5:49 am
    I've been trying to optimize something for awhile and have had various approaches, and was hoping Gen could do this in an easy and high-performance way. I need to take a standard 4 plane "video" matrix and create a "flattened' list of consecutive r, g and b bytes (no alpha) so that I can send this data out of a serial port to hardware that is expecting data in this format. I've tried iterating through the matrix with getcell and I've also tried using 3 jit.spills with r g b and then interleaving the three lists with javascript, both of which work but I can't help but think that there is some way to do this in Gen that is super simple and lightening fast. I know that there are some more optimized list processing objects using mxj but I'm sending this utility to customers that may not have Java installed, so don't want to go that route.
    I'm slogging my way through tutorials but maybe somebody could give me some direction or guidance! I think what I want to do is swiz the matrix into rgb and then combine the values sequentially into a 1 char matrix, which I can then jit.spill. But I think all matrices in Gen are 4 plane, and maybe its not possible to sequence the r, g and b in the right order because of the "synchronicity" of Gen. I was also thinking maybe I could take the swizzed r, g, b data and pack it into, say, the alpha channel of a matrix (that is 3 times the duration of the source matrix) so that I could jit.spill it out once all properly interleaved.
    Any ideas would be much appreciated!
    thx, bob

    • Nov 19 2012 | 4:44 pm
      Hi Robert,
      Gen as it stands right now only works with inputs and outputs that have the same matrix format. For example, if you send a [4 char 320 240] matrix to jit.gen, you'll get a [4 char 320 240] matrix out. There's no way to get a [1 char 960 240] matrix, which is what it seems like you want.
      The fastest way to flatten a matrix is to use jit.coerce. The other option is to use jit.multiplex and jit.unpack. Here are both solutions:
    • Nov 20 2012 | 3:32 am
      Thanks Wesley, looks like jit.coerce has been the easy way to do this all along ;) Always wondered what it did ("header munging" ?!??)