Example usage for com.google.gwt.typedarrays.shared Int16Array subarray

List of usage examples for com.google.gwt.typedarrays.shared Int16Array subarray

Introduction

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

Prototype

Int16Array subarray(int begin, int end);

Source Link

Document

Create a new view from the same array, from offset to (but not including) end in this view.

Usage

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

License:Open Source License

/**
 * DOCUMENT ME!/* w ww. ja  v  a 2s .  c  o m*/
 *
 * @param index DOCUMENT ME!
 * @param img8 DOCUMENT ME!
 * @param rowsize DOCUMENT ME!
 * @param pixsep DOCUMENT ME!
 * @param fast DOCUMENT ME!
 */
void image(int index, final Uint8Array img8, int rowsize, int pixsep, boolean fast) {
    final Int16Array data16 = TypedArrays.createInt16Array(bw * bh);
    final Int16Array liftblock = TypedArrays.createInt16Array(1024);
    int pidx = 0;
    IWBlock[] block = blocks;
    int blockidx = 0;
    int ppidx = 0;

    for (int i = 0; i < bh; i += 32, pidx += (32 * bw)) {
        for (int j = 0; j < bw; j += 32) {
            block[blockidx].write_liftblock(liftblock, 0, 64);
            blockidx++;

            ppidx = pidx + j;

            for (int ii = 0, p1idx = 0; ii++ < 32; p1idx += 32, ppidx += bw) {
                Int16Array src = liftblock.subarray(p1idx, p1idx + 32);
                data16.set(src, ppidx);
            }
        }
    }

    if (fast) {
        backward(data16, 0, iw, ih, bw, 32, 2);
        pidx = 0;

        for (int i = 0; i < bh; i += 2, pidx += bw) {
            for (int jj = 0; jj < bw; jj += 2, pidx += 2) {
                short s = data16.get(pidx);
                data16.set(pidx + bw, s);
                data16.set(pidx + bw + 1, s);
                data16.set(pidx + 1, s);
            }
        }
    } else {
        backward(data16, 0, iw, ih, bw, 32, 1);
    }

    pidx = 0;

    for (int i = 0, rowidx = index; i++ < ih; rowidx += rowsize, pidx += bw) {
        for (int j = 0, pixidx = rowidx; j < iw; pixidx += pixsep) {
            int x = (data16.get(pidx + (j++)) + 32) >> 6;

            if (x < -128) {
                x = -128;
            } else if (x > 127) {
                x = 127;
            }

            img8.set(pixidx, x);
        }
    }
}