binary matrix compression

Federaik's icon

I am trying to compress a matrix made only of zeroes and ones, any suggestions?

import com.cycling74.max.*;
import com.cycling74.jitter.*;

public class m_runlenght extends MaxObject
{
    private int  dalist[];
    private JitterMatrix ciccio;
    private int dimArray[];
    private    int contaR;
    private    int contaC;
    private int contaUg = 1;
    private int contaElem = 0;
    private int contaRows = 0;
    private int memo = 0;
    private int val[]= new int[1];
    private int matIn[];
    private int theRows = 8;
    private int matOut[];

    private static final String[] INLET_ASSIST = new String[]{
        "inlet 1 Feed with a binary matrix (0-255)"
    };
    private static final String[] OUTLET_ASSIST = new String[]{
        "outlet 1 run-lenght compressed list"
    };

    public m_runlenght(Atom[] args)
    {
        declareInlets(new int[]{DataTypes.ALL});
        declareOutlets(new int[]{DataTypes.ALL});

        setInletAssist(INLET_ASSIST);
        setOutletAssist(OUTLET_ASSIST);
        dalist= new int[255];
        ciccio = new JitterMatrix("compre",1,"long",255,theRows);
        matIn  = new int[320*240];
        matOut = new int[255*theRows];
    }

    public void jit_matrix(String inname)
    {
        contaUg = 1;
        contaElem=0;
        contaRows=0;
        JitterMatrix foo = new JitterMatrix(inname);
        foo.copyMatrixToArray(matIn);
        ciccio.setall(Atom.newAtom(0));
        ciccio.copyMatrixToArray(matOut);
        for (contaR = 0 ; contaR < 240*320; contaR++){
            if (contaRows
Max Patch
Copy patch and select New From Clipboard in Max.

karl krach's icon

hello federaik,
are you still around?
and did you develop this any further? i did get your code to work but having no idea of java at all i do understand very little of its workings...

i'm asking since the thing i would like to do, is to compress full colour+alpha images (of which 4/5th are transparent/black though). as far as i understand your patch, i would need to change this to:
- switch from encoding 0/1 to only encode zeros and leave the rest as is.
- have a possibility to resize/adjust the incoming and resulting output matrix - so i could handover these matrix-dimensions to the mxj object.
- ideally perform this over 5 planes (halfres uyuv+alpha) - but ok, i could as well just do this for each plane separately and then pack these together afterwards.

do you think that could work?
like, is there any possibilitie that might perform well with large matrixes too (about 1024x576 @50fps but i only care about decompression speed)?
best
k