Example usage for com.google.gwt.typedarrays.shared TypedArrays createInt16Array

List of usage examples for com.google.gwt.typedarrays.shared TypedArrays createInt16Array

Introduction

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

Prototype

public static Int16Array createInt16Array(int length) 

Source Link

Document

Create a Int16Array instance of length elements, backed by a new ArrayBuffer .

Usage

From source file:com.badlogic.gdx.backends.gwt.GwtGL20.java

License:Apache License

private void ensureCapacity(ShortBuffer buffer) {
    if (buffer.remaining() > shortBuffer.length()) {
        shortBuffer = TypedArrays.createInt16Array(buffer.remaining());
    }//www  .  j  a  va  2s. co m
}

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

License:Open Source License

/**
 * DOCUMENT ME!//from w ww  . j  a v  a 2  s  . c om
 *
 * @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);
        }
    }
}

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

License:Open Source License

/**
 * DOCUMENT ME!//from www . j a  v  a 2  s .  com
 *
 * @param subsample DOCUMENT ME!
 * @param rect DOCUMENT ME!
 * @param index DOCUMENT ME!
 * @param img8 DOCUMENT ME!
 * @param rowsize DOCUMENT ME!
 * @param pixsep DOCUMENT ME!
 * @param fast DOCUMENT ME!
 *
 * @throws IllegalArgumentException DOCUMENT ME!
 */
void image(int subsample, GRect rect, int index, final Uint8Array img8, int rowsize, int pixsep, boolean fast) {
    int nlevel = 0;

    while ((nlevel < 5) && ((32 >> nlevel) > subsample)) {
        nlevel++;
    }

    final int boxsize = 1 << nlevel;

    if (subsample != (32 >> nlevel)) {
        throw new IllegalArgumentException("(IWMap::image) Unsupported subsampling factor");
    }

    if (rect.isEmpty()) {
        throw new IllegalArgumentException("(IWMap::image) GRect is empty");
    }

    GRect irect = new GRect(0, 0, ((iw + subsample) - 1) / subsample, ((ih + subsample) - 1) / subsample);

    if ((rect.xmin < 0) || (rect.ymin < 0) || (rect.xmax > irect.xmax) || (rect.ymax > irect.ymax)) {
        throw new IllegalArgumentException("(IWMap::image) GRect is out of bounds: " + rect.xmin + ","
                + rect.ymin + "," + rect.xmax + "," + rect.ymax + "," + irect.xmax + "," + irect.ymax);
    }

    GRect[] needed = new GRect[8];
    GRect[] recomp = new GRect[8];

    for (int i = 0; i < 8;) {
        needed[i] = new GRect();
        recomp[i++] = new GRect();
    }

    int r = 1;
    needed[nlevel] = new GRect(rect);
    recomp[nlevel] = new GRect(rect);

    for (int i = nlevel - 1; i >= 0; i--) {
        needed[i] = recomp[i + 1];
        needed[i].inflate(3 * r, 3 * r);
        needed[i].intersect(needed[i], irect);
        r += r;
        recomp[i].xmin = ((needed[i].xmin + r) - 1) & ~(r - 1);
        recomp[i].xmax = needed[i].xmax & ~(r - 1);
        recomp[i].ymin = ((needed[i].ymin + r) - 1) & ~(r - 1);
        recomp[i].ymax = needed[i].ymax & ~(r - 1);
    }

    GRect work = new GRect();
    work.xmin = needed[0].xmin & ~(boxsize - 1);
    work.ymin = needed[0].ymin & ~(boxsize - 1);
    work.xmax = ((needed[0].xmax - 1) & ~(boxsize - 1)) + boxsize;
    work.ymax = ((needed[0].ymax - 1) & ~(boxsize - 1)) + boxsize;

    final int dataw = work.width();
    final Int16Array data = TypedArrays.createInt16Array(dataw * work.height());
    int blkw = bw >> 5;
    int lblock = ((work.ymin >> nlevel) * blkw) + (work.xmin >> nlevel);

    final Int16Array liftblock = TypedArrays.createInt16Array(1024);

    for (int by = work.ymin, ldata = 0; by < work.ymax; by += boxsize, ldata += (dataw << nlevel), lblock += blkw) {
        for (int bx = work.xmin, bidx = lblock, rdata = ldata; bx < work.xmax; bx += boxsize, bidx++, rdata += boxsize) {
            IWBlock block = blocks[bidx];
            int mlevel = nlevel;

            if ((nlevel > 2) && (((bx + 31) < needed[2].xmin) || (bx > needed[2].xmax)
                    || ((by + 31) < needed[2].ymin) || (by > needed[2].ymax))) {
                mlevel = 2;
            }

            final int bmax = ((1 << (mlevel + mlevel)) + 15) >> 4;
            final int ppinc = 1 << (nlevel - mlevel);
            final int ppmod1 = dataw << (nlevel - mlevel);
            final int ttmod0 = 32 >> mlevel;
            final int ttmod1 = ttmod0 << 5;
            block.write_liftblock(liftblock, 0, bmax);

            for (int ii = 0, tt = 0, pp = rdata; ii < boxsize; ii += ppinc, pp += ppmod1, tt += (ttmod1 - 32)) {
                for (int jj = 0; jj < boxsize; jj += ppinc, tt += ttmod0) {
                    data.set(pp + jj, liftblock.get(tt));
                }
            }
        }
    }

    r = boxsize;

    for (int i = 0; i < nlevel; i++) {
        GRect comp = needed[i];
        comp.xmin = comp.xmin & ~(r - 1);
        comp.ymin = comp.ymin & ~(r - 1);
        comp.translate(-work.xmin, -work.ymin);

        if (fast && (i >= 4)) {
            workaround(dataw, data, comp);

            break;
        }

        backward(data, (comp.ymin * dataw) + comp.xmin, comp.width(), comp.height(), dataw, r, r >> 1);
        r >>= 1;
    }

    GRect nrect = new GRect(rect);
    nrect.translate(-work.xmin, -work.ymin);

    for (int i = nrect.ymin, pidx = (nrect.ymin
            * dataw), ridx = index; i++ < nrect.ymax; ridx += rowsize, pidx += dataw) {
        for (int j = nrect.xmin, pixidx = ridx; j < nrect.xmax; j++, pixidx += pixsep) {
            int x = (data.get(pidx + j) + 32) >> 6;

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

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