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

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

Introduction

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

Prototype

short get(int index);

Source Link

Document

Retrieve one element of this view.

Usage

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

License:Open Source License

/**
 * DOCUMENT ME!/*from  w w  w  . j av  a  2  s.co m*/
 *
 * @param p DOCUMENT ME!
 * @param pidx DOCUMENT ME!
 * @param b DOCUMENT ME!
 * @param e DOCUMENT ME!
 * @param z DOCUMENT ME!
 * @param s DOCUMENT ME!
 */
static void backward_filter(Int16Array p, int pidx, int b, int e, int z, int s) {
    final int s3 = 3 * s;

    if ((z < b) || (z > e)) {
        Utils.logError("(_IWCoeff::backward_filter) Out of bounds [b<=z<=e]");
    }

    int n = z;
    int bb;
    int cc;
    int aa = bb = cc = 0;
    int dd = ((n + s) >= e) ? 0 : ((int) (p.get(pidx + n + s)));

    for (; (n + s3) < e; n = (n + s3) - s) {
        aa = bb;
        bb = cc;
        cc = dd;
        dd = p.get(pidx + n + s3);
        p.set(pidx + n, p.get(pidx + n) - ((((9 * (bb + cc)) - (aa + dd)) + 16) >> 5));
    }

    for (; n < e; n = n + s + s) {
        aa = bb;
        bb = cc;
        cc = dd;
        dd = 0;
        p.set(pidx + n, p.get(pidx + n) - ((((9 * (bb + cc)) - (aa + dd)) + 16) >> 5));
        ;
    }

    n = z + s;
    aa = 0;
    bb = p.get((pidx + n) - s);
    cc = ((n + s) >= e) ? 0 : ((int) (p.get(pidx + n + s)));
    dd = ((n + s3) >= e) ? 0 : ((int) (p.get(pidx + n + s3)));

    if (n < e) {
        int x = bb;

        if ((n + s) < e) {
            x = (bb + cc + 1) >> 1;
        }

        p.set(pidx + n, p.get(pidx + n) + x);
        n = n + s + s;
    }

    for (; (n + s3) < e; n = (n + s3) - s) {
        aa = bb;
        bb = cc;
        cc = dd;
        dd = p.get(pidx + n + s3);

        int x = (((9 * (bb + cc)) - (aa + dd)) + 8) >> 4;
        p.set(pidx + n, p.get(pidx + n) + x);
    }

    if ((n + s) < e) {
        aa = bb;
        bb = cc;
        cc = dd;
        dd = 0;

        int x = (bb + cc + 1) >> 1;
        p.set(pidx + n, p.get(pidx + n) + x);
        n = n + s + s;
    }

    if (n < e) {
        aa = bb;
        bb = cc;
        cc = dd;
        dd = 0;

        int x = bb;
        p.set(pidx + n, p.get(pidx + n) + x);
    }
}

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

License:Open Source License

/**
 * DOCUMENT ME!// w  w  w  .  jav a  2 s.co  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);
        }
    }
}

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

License:Open Source License

/**
 * DOCUMENT ME!// w w w.j a  va 2 s.c  o m
 *
 * @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);
        }
    }
}

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

License:Open Source License

/**
* This must be a separate method to work around issue
* https://code.google.com/p/google-web-toolkit/issues/detail?id=9184
*//* w w w.j a va 2  s.  co m*/
private void workaround(final int dataw, final Int16Array data, GRect comp) {
    int pp = (comp.ymin * dataw);
    for (int ii = comp.ymin; ii < comp.ymax; ii += 2) {
        for (int jj = comp.xmin; jj < comp.xmax; jj += 2) {
            short s = data.get(pp + jj);
            data.set(pp + jj + dataw, s);
            data.set(pp + jj + dataw + 1, s);
            data.set(pp + jj + 1, s);
        }
        pp += (dataw + dataw);
    }
}

From source file:thothbot.parallax.core.shared.core.GeometryBuffer.java

License:Open Source License

@Override
public void computeVertexNormals() {
    if (getWebGlVertexArray() != null && getWebGlIndexArray() != null) {
        int nVertexElements = getWebGlVertexArray().length();

        if (getWebGlNormalArray() == null) {
            setWebGlNormalArray(TypedArrays.createFloat64Array(nVertexElements));
        } else {//  w w  w.  j ava2  s  .  com
            // reset existing normals to zero

            for (int i = 0, il = getWebGlNormalArray().length(); i < il; i++) {
                getWebGlNormalArray().set(i, 0);
            }
        }

        List<GeometryBuffer.Offset> offsets = this.offsets;

        Int16Array indices = getWebGlIndexArray();
        Float64Array positions = getWebGlVertexArray();
        Float64Array normals = getWebGlNormalArray();

        Vector3 pA = new Vector3();
        Vector3 pB = new Vector3();
        Vector3 pC = new Vector3();

        Vector3 cb = new Vector3();
        Vector3 ab = new Vector3();

        for (int j = 0, jl = offsets.size(); j < jl; ++j) {
            int start = offsets.get(j).start;
            int count = offsets.get(j).count;
            int index = offsets.get(j).index;

            for (int i = start, il = start + count; i < il; i += 3) {

                int vA = index + indices.get(i);
                int vB = index + indices.get(i + 1);
                int vC = index + indices.get(i + 2);

                pA.set(positions.get(vA * 3), positions.get(vA * 3 + 1), positions.get(vA * 3 + 2));

                pB.set(positions.get(vB * 3), positions.get(vB * 3 + 1), positions.get(vB * 3 + 2));

                pC.set(positions.get(vC * 3), positions.get(vC * 3 + 1), positions.get(vC * 3 + 2));

                cb.sub(pC, pB);
                ab.sub(pA, pB);
                cb.cross(ab);

                normals.set(vA * 3, normals.get(vA * 3) + cb.x);
                normals.set(vA * 3 + 1, normals.get(vA * 3 + 1) + cb.y);
                normals.set(vA * 3 + 2, normals.get(vA * 3 + 2) + cb.z);

                normals.set(vB * 3, normals.get(vB * 3) + cb.x);
                normals.set(vB * 3 + 1, normals.get(vB * 3 + 1) + cb.y);
                normals.set(vB * 3 + 2, normals.get(vB * 3 + 2) + cb.z);

                normals.set(vC * 3, normals.get(vC * 3) + cb.x);
                normals.set(vC * 3 + 1, normals.get(vC * 3 + 1) + cb.y);
                normals.set(vC * 3 + 2, normals.get(vC * 3 + 2) + cb.z);
            }
        }

        // normalize normals

        for (int i = 0, il = normals.length(); i < il; i += 3) {
            double x = normals.get(i);
            double y = normals.get(i + 1);
            double z = normals.get(i + 2);

            double n = 1.0 / Math.sqrt(x * x + y * y + z * z);

            normals.set(i, normals.get(i) * n);
            normals.set(i + 1, normals.get(i + 1) * n);
            normals.set(i + 2, normals.get(i + 2) * n);
        }

        setNormalsNeedUpdate(true);
    }
}

From source file:thothbot.parallax.core.shared.core.GeometryBuffer.java

License:Open Source License

/**
 *    Based on < href="http://www.terathon.com/code/tangent.html">terathon.com</a>
 * (per vertex tangents)/*  w  w  w. j av  a  2 s.  c  om*/
 */
@Override
public void computeTangents() {
    if (getWebGlIndexArray() == null || getWebGlVertexArray() == null || getWebGlNormalArray() == null
            || getWebGlUvArray() == null) {
        Log.warn(
                "Missing required attributes (index, position, normal or uv) in BufferGeometry.computeTangents()");
        return;
    }

    Int16Array indices = getWebGlIndexArray();
    Float64Array positions = getWebGlVertexArray();
    getWebGlNormalArray();
    getWebGlUvArray();

    int nVertices = positions.length() / 3;

    if (getWebGlTangentArray() == null) {
        int nTangentElements = 4 * nVertices;

        setWebGlTangentArray(TypedArrays.createFloat64Array(nTangentElements));
    }

    getWebGlTangentArray();

    List<Vector3> tan1 = new ArrayList<Vector3>();
    List<Vector3> tan2 = new ArrayList<Vector3>();

    for (int k = 0; k < nVertices; k++) {
        tan1.add(new Vector3());
        tan2.add(new Vector3());
    }

    List<GeometryBuffer.Offset> offsets = this.offsets;

    for (int j = 0, jl = offsets.size(); j < jl; ++j) {
        int start = offsets.get(j).start;
        int count = offsets.get(j).count;
        int index = offsets.get(j).index;

        for (int i = start, il = start + count; i < il; i += 3) {
            int iA = index + indices.get(i);
            int iB = index + indices.get(i + 1);
            int iC = index + indices.get(i + 2);

            handleTriangle(tan1, tan2, iA, iB, iC);
        }
    }

    for (int j = 0, jl = offsets.size(); j < jl; ++j) {
        int start = offsets.get(j).start;
        int count = offsets.get(j).count;
        int index = offsets.get(j).index;

        for (int i = start, il = start + count; i < il; i += 3) {
            int iA = index + indices.get(i);
            int iB = index + indices.get(i + 1);
            int iC = index + indices.get(i + 2);

            handleVertex(tan1, tan2, iA);
            handleVertex(tan1, tan2, iB);
            handleVertex(tan1, tan2, iC);
        }
    }

    this.setHasTangents(true);
    this.setTangentsNeedUpdate(true);

}