Example usage for com.google.gwt.typedarrays.shared Int8Array get

List of usage examples for com.google.gwt.typedarrays.shared Int8Array get

Introduction

In this page you can find the example usage for com.google.gwt.typedarrays.shared Int8Array get.

Prototype

byte get(int index);

Source Link

Document

Retrieve one element of this view.

Usage

From source file:com.lizardtech.djvu.IWCodec.java

License:Open Source License

/**
 * DOCUMENT ME!// w  w w  .  j av  a 2 s.  c om
 *
 * @param zp DOCUMENT ME!
 * @param bit DOCUMENT ME!
 * @param band DOCUMENT ME!
 * @param blk DOCUMENT ME!
 * @param fbucket DOCUMENT ME!
 * @param nbucket DOCUMENT ME!
 *
 * @throws IOException DOCUMENT ME!
 */
void decode_buckets(ZPCodec zp, int bit, int band, IWBlock blk, int fbucket, int nbucket) throws IOException {
    int thres = quant_hi.get(band);
    int bbstate = 0;
    Int8Array cstate = coeffstate;
    int cidx = 0;

    for (int buckno = 0; buckno < nbucket;) {
        int bstatetmp = 0;
        Block pcoeff = blk.getBlock(fbucket + buckno);

        if (pcoeff == null) {
            bstatetmp = 8;
        } else {
            for (int i = 0; i < 16; i++) {
                int cstatetmp = cstate.get(cidx + i) & 1;
                if (cstatetmp == 0) {
                    cstatetmp = pcoeff.get(i) != 0 ? 2 : 8;
                    cstate.set(cidx + i, cstatetmp);
                }
                bstatetmp |= cstatetmp;
            }
        }

        bucketstate.set(buckno, bstatetmp);
        bbstate |= bstatetmp;
        buckno++;
        cidx += 16;
    }

    if ((nbucket < 16) || ((bbstate & 2) != 0)) {
        bbstate |= 4;
    } else if ((bbstate & 8) != 0) {
        if (zp.decoder(ctxRoot) != 0) {
            bbstate |= 4;
        }
    }

    if ((bbstate & 4) != 0) {
        for (int buckno = 0; buckno < nbucket; buckno++) {
            if ((bucketstate.get(buckno) & 8) != 0) {
                int ctx = 0;

                if (!DjVuOptions.NOCTX_BUCKET_UPPER && (band > 0)) {
                    int k = (fbucket + buckno) << 2;
                    Block b = blk.getBlock(k >> 4);

                    if (b != null) {
                        k &= 0xf;

                        if (b.get(k) != 0) {
                            ctx++;
                        }

                        if (b.get(k + 1) != 0) {
                            ctx++;
                        }

                        if (b.get(k + 2) != 0) {
                            ctx++;
                        }

                        if ((ctx < 3) && (b.get(k + 3) != 0)) {
                            ctx++;
                        }
                    }
                }

                if (!DjVuOptions.NOCTX_BUCKET_ACTIVE && ((bbstate & 2) != 0)) {
                    ctx |= 4;
                }

                if (zp.decoder(ctxBucket[band][ctx]) != 0) {
                    bucketstate.set(buckno, bucketstate.get(buckno) | 4);
                }
            }
        }
    }

    if ((bbstate & 4) != 0) {
        cstate = coeffstate;
        cidx = 0;

        for (int buckno = 0; buckno < nbucket;) {
            if ((bucketstate.get(buckno) & 4) != 0) {
                Block pcoeff = blk.getBlock(fbucket + buckno);

                if (pcoeff == null) {
                    pcoeff = blk.getInitializedBlock(fbucket + buckno);

                    for (int i = 0; i < 16; i++) {
                        if ((cstate.get(cidx + i) & 1) == 0) {
                            cstate.set(cidx + i, 8);
                        }
                    }
                }

                int gotcha = 0;
                int maxgotcha = 7;

                if (!DjVuOptions.NOCTX_EXPECT) {
                    for (int i = 0; i < 16; i++) {
                        if ((cstate.get(cidx + i) & 8) != 0) {
                            gotcha++;
                        }
                    }
                }

                for (int i = 0; i < 16; i++) {
                    if ((cstate.get(cidx + i) & 8) != 0) {
                        if (band == 0) {
                            thres = quant_lo.get(i);
                        }

                        int ctx = 0;

                        if (!DjVuOptions.NOCTX_EXPECT) {
                            if (gotcha >= maxgotcha) {
                                ctx = maxgotcha;
                            } else {
                                ctx = gotcha;
                            }
                        }

                        if (!DjVuOptions.NOCTX_ACTIVE && ((bucketstate.get(buckno) & 2) != 0)) {
                            ctx |= 8;
                        }

                        if (zp.decoder(ctxStart[ctx]) != 0) {
                            cstate.set(cidx + i, cstate.get(cidx + i) | 4);

                            int halfthres = thres >> 1;
                            int coeff = (thres + halfthres) - (halfthres >> 2);

                            if (zp.IWdecoder() != 0) {
                                pcoeff.set(i, (short) (-coeff));
                            } else {
                                pcoeff.set(i, (short) coeff);
                            }
                        }

                        if (!DjVuOptions.NOCTX_EXPECT) {
                            if ((cstate.get(cidx + i) & 4) != 0) {
                                gotcha = 0;
                            } else if (gotcha > 0) {
                                gotcha--;
                            }
                        }
                    }
                }
            }

            buckno++;
            cidx += 16;
        }
    }

    if ((bbstate & 2) != 0) {
        cstate = coeffstate;
        cidx = 0;

        for (int buckno = 0; buckno < nbucket;) {
            if ((bucketstate.get(buckno) & 2) != 0) {
                Block pcoeff = blk.getBlock(fbucket + buckno);

                for (int i = 0; i < 16; i++) {
                    if ((cstate.get(cidx + i) & 2) != 0) {
                        int coeff = pcoeff.get(i);

                        if (coeff < 0) {
                            coeff = -coeff;
                        }

                        if (band == 0) {
                            thres = quant_lo.get(i);
                        }

                        if (coeff <= (3 * thres)) {
                            coeff += (thres >> 2);

                            if (zp.decoder(ctxMant) != 0) {
                                coeff += (thres >> 1);
                            } else {
                                coeff = (coeff - thres) + (thres >> 1);
                            }
                        } else {
                            if (zp.IWdecoder() != 0) {
                                coeff += (thres >> 1);
                            } else {
                                coeff = (coeff - thres) + (thres >> 1);
                            }
                        }

                        if (pcoeff.get(i) > 0) {
                            pcoeff.set(i, (short) coeff);
                        } else {
                            pcoeff.set(i, (short) (-coeff));
                        }
                    }
                }
            }

            buckno++;
            cidx += 16;
        }
    }
}