src/main/java/org/jcodec/codecs/vpx/VPXBitstream.java
public void encodeCoeffs(VPXBooleanEncoder bc, int[] coeffs, int firstCoeff, int nCoeff, int blkType, int ctx) {
        boolean prevZero = false;

        int i;
        for (i = firstCoeff; i < nCoeff; i++) {
            int[] probs = tokenBinProbs[blkType][coeffBandMapping[i]][ctx];

            int coeffAbs = MathUtil.abs(coeffs[i]);
            if (!prevZero)
                bc.writeBit(probs[0], 1);
            if (coeffAbs == 0) {
                bc.writeBit(probs[1], 0);
                ctx = 0;
            } else {
                bc.writeBit(probs[1], 1);
                if (coeffAbs == 1) {
                    bc.writeBit(probs[2], 0);
                    ctx = 1;
                } else {
                    ctx = 2;
                    bc.writeBit(probs[2], 1);
                    if (coeffAbs <= 4) {
                        bc.writeBit(probs[3], 0);
                        if (coeffAbs == 2)
                            bc.writeBit(probs[4], 0);
                        else {
                            bc.writeBit(probs[4], 1);
                            bc.writeBit(probs[5], coeffAbs - 3);
                        }
                    } else {
                        bc.writeBit(probs[3], 1);
                        if (coeffAbs <= 10) {
                            bc.writeBit(probs[6], 0);
                            if (coeffAbs <= 6) {
                                bc.writeBit(probs[7], 0);
                                bc.writeBit(159, coeffAbs - 5);
                            } else {
                                bc.writeBit(probs[7], 1);
                                int d = coeffAbs - 7;
                                bc.writeBit(165, d >> 1);
                                bc.writeBit(145, d & 1);
                            }
                        } else {
                            bc.writeBit(probs[6], 1);
                            if (coeffAbs <= 34) {
                                bc.writeBit(probs[8], 0);
                                if (coeffAbs <= 18) {
                                    bc.writeBit(probs[9], 0);
                                    writeCat3Ext(bc, coeffAbs);
                                } else {
                                    bc.writeBit(probs[9], 1);
                                    writeCat4Ext(bc, coeffAbs);
                                }
                            } else {
                                bc.writeBit(probs[8], 1);
                                if (coeffAbs <= 66) {
                                    bc.writeBit(probs[10], 0);
                                    writeCatExt(bc, coeffAbs, 35, VPXConst.probCoeffExtCat5);
                                } else {
                                    bc.writeBit(probs[10], 1);
                                    writeCatExt(bc, coeffAbs, 67, VPXConst.probCoeffExtCat6);
                                }
                            }
                        }
                    }
                }
                bc.writeBit(128, MathUtil.sign(coeffs[i]));
            }

            prevZero = coeffAbs == 0;
        }
        if (nCoeff < 16) {
            int[] probs = tokenBinProbs[blkType][coeffBandMapping[i]][ctx];
            bc.writeBit(probs[0], 0);
        }
    }
public void encodeCoeffs(VPXBooleanEncoder bc, int[] coeffs, int firstCoeff, int nCoeff, int blkType, int ctx) {
        boolean prevZero = false;

        int i;
        for (i = firstCoeff; i < nCoeff; i++) {
            int[] probs = tokenBinProbs[blkType][coeffBandMapping[i]][ctx];

            int coeffAbs = MathUtil.abs(coeffs[i]);
            if (!prevZero)
                bc.writeBit(probs[0], 1);
            if (coeffAbs == 0) {
                bc.writeBit(probs[1], 0);
                ctx = 0;
            } else {
                bc.writeBit(probs[1], 1);
                if (coeffAbs == 1) {
                    bc.writeBit(probs[2], 0);
                    ctx = 1;
                } else {
                    ctx = 2;
                    bc.writeBit(probs[2], 1);
                    if (coeffAbs <= 4) {
                        bc.writeBit(probs[3], 0);
                        if (coeffAbs == 2)
                            bc.writeBit(probs[4], 0);
                        else {
                            bc.writeBit(probs[4], 1);
                            bc.writeBit(probs[5], coeffAbs - 3);
                        }
                    } else {
                        bc.writeBit(probs[3], 1);
                        if (coeffAbs <= 10) {
                            bc.writeBit(probs[6], 0);
                            if (coeffAbs <= 6) {
                                bc.writeBit(probs[7], 0);
                                bc.writeBit(159, coeffAbs - 5);
                            } else {
                                bc.writeBit(probs[7], 1);
                                int d = coeffAbs - 7;
                                bc.writeBit(165, d >> 1);
                                bc.writeBit(145, d & 1);
                            }
                        } else {
                            bc.writeBit(probs[6], 1);
                            if (coeffAbs <= 34) {
                                bc.writeBit(probs[8], 0);
                                if (coeffAbs <= 18) {
                                    bc.writeBit(probs[9], 0);
                                    writeCat3Ext(bc, coeffAbs);
                                } else {
                                    bc.writeBit(probs[9], 1);
                                    writeCat4Ext(bc, coeffAbs);
                                }
                            } else {
                                bc.writeBit(probs[8], 1);
                                if (coeffAbs <= 66) {
                                    bc.writeBit(probs[10], 0);
                                    writeCatExt(bc, coeffAbs, 35, VPXConst.probCoeffExtCat5);
                                } else {
                                    bc.writeBit(probs[10], 1);
                                    writeCatExt(bc, coeffAbs, 67, VPXConst.probCoeffExtCat6);
                                }
                            }
                        }
                    }
                }
                bc.writeBit(128, MathUtil.sign(coeffs[i]));
            }

            prevZero = coeffAbs == 0;
        }
        if (nCoeff < 16) {
            int[] probs = tokenBinProbs[blkType][coeffBandMapping[i]][ctx];
            bc.writeBit(probs[0], 0);
        }
    }
public void encodeCoeffs ( VPXBooleanEncoder bc , int [ ] coeffs , int firstCoeff , int nCoeff , int blkType , int ctx ) { boolean prevZero = false ; int i ; for ( i = firstCoeff ; i < nCoeff ; i ++ ) { int [ ] probs = tokenBinProbs [ blkType ] [ coeffBandMapping [ i ] ] [ ctx ] ; int coeffAbs = MathUtil . abs ( coeffs [ i ] ) ; if ( ! prevZero ) bc . writeBit ( probs [ 0 ] , 1 ) ; if ( coeffAbs == 0 ) { bc . writeBit ( probs [ 1 ] , 0 ) ; ctx = 0 ; } else { bc . writeBit ( probs [ 1 ] , 1 ) ; if ( coeffAbs == 1 ) { bc . writeBit ( probs [ 2 ] , 0 ) ; ctx = 1 ; } else { ctx = 2 ; bc . writeBit ( probs [ 2 ] , 1 ) ; if ( coeffAbs <= 4 ) { bc . writeBit ( probs [ 3 ] , 0 ) ; if ( coeffAbs == 2 ) bc . writeBit ( probs [ 4 ] , 0 ) ; else { bc . writeBit ( probs [ 4 ] , 1 ) ; bc . writeBit ( probs [ 5 ] , coeffAbs - 3 ) ; } } else { bc . writeBit ( probs [ 3 ] , 1 ) ; if ( coeffAbs <= 10 ) { bc . writeBit ( probs [ 6 ] , 0 ) ; if ( coeffAbs <= 6 ) { bc . writeBit ( probs [ 7 ] , 0 ) ; bc . writeBit ( 159 , coeffAbs - 5 ) ; } else { bc . writeBit ( probs [ 7 ] , 1 ) ; int d = coeffAbs - 7 ; bc . writeBit ( 165 , d >> 1 ) ; bc . writeBit ( 145 , d & 1 ) ; } } else { bc . writeBit ( probs [ 6 ] , 1 ) ; if ( coeffAbs <= 34 ) { bc . writeBit ( probs [ 8 ] , 0 ) ; if ( coeffAbs <= 18 ) { bc . writeBit ( probs [ 9 ] , 0 ) ; writeCat3Ext ( bc , coeffAbs ) ; } else { bc . writeBit ( probs [ 9 ] , 1 ) ; writeCat4Ext ( bc , coeffAbs ) ; } } else { bc . writeBit ( probs [ 8 ] , 1 ) ; if ( coeffAbs <= 66 ) { bc . writeBit ( probs [ 10 ] , 0 ) ; writeCatExt ( bc , coeffAbs , 35 , VPXConst . probCoeffExtCat5 ) ; } else { bc . writeBit ( probs [ 10 ] , 1 ) ; writeCatExt ( bc , coeffAbs , 67 , VPXConst . probCoeffExtCat6 ) ; } } } } } bc . writeBit ( 128 , MathUtil . sign ( coeffs [ i ] ) ) ; } prevZero = coeffAbs == 0 ; } if ( nCoeff < 16 ) { int [ ] probs = tokenBinProbs [ blkType ] [ coeffBandMapping [ i ] ] [ ctx ] ; bc . writeBit ( probs [ 0 ] , 0 ) ; } }
Encodes DCT/WHT coefficients into the provided instance of a boolean
encoder

@param bc
@param coeffs
Encodes DCT / WHT coefficients into the provided instance of a boolean encoder