Java Code Examples for com.google.gwt.typedarrays.shared.Uint8Array#set()

The following examples show how to use com.google.gwt.typedarrays.shared.Uint8Array#set() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsHttpProvider.java    From actor-platform with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Promise<HTTPResponse> putMethod(String url, byte[] contents) {
    return new Promise<>(resolver -> {
        JsHttpRequest request = JsHttpRequest.create();
        request.open("PUT", url);
        request.setRequestHeader("Content-Type", "application/octet-stream");
        request.setOnLoadHandler(request1 -> {
            if (request1.getReadyState() == 4) {
                if (request1.getStatus() >= 200 && request1.getStatus() < 300) {
                    resolver.result(new HTTPResponse(request1.getStatus(), null));
                } else {
                    resolver.error(new HTTPError(request1.getStatus()));
                }
            }
        });
        Uint8Array push = TypedArrays.createUint8Array(contents.length);
        for (int i = 0; i < contents.length; i++) {
            push.set(i, contents[i]);
        }
        request.send(push.buffer());
    });
}
 
Example 2
Source File: DataStore.java    From djvu-html5 with GNU General Public License v2.0 6 votes vote down vote up
public void setTile(TileInfo tileInfo, GMap bufferGMap) {
	if (bufferImageData == null || bufferImageData.getWidth() != bufferGMap.getDataWidth()
			|| bufferImageData.getHeight() != bufferGMap.getDataHeight()) {
		bufferImageData = bufferCanvas.getContext2d()
				.createImageData(bufferGMap.getDataWidth(), bufferGMap.getDataHeight());
	}
	Uint8Array imageArray = bufferImageData.getData().cast();
	imageArray.set(bufferGMap.getImageData());
	bufferCanvas.getContext2d().putImageData(bufferImageData, -bufferGMap.getBorder(), 0);

	CanvasElement tile = tiles.get(tileInfo);
	if (tile == null) {
		tile = createImage(bufferGMap.getDataWidth() - bufferGMap.getBorder(), bufferGMap.getDataHeight());
		tiles.put(new TileInfo(tileInfo), tile);
	}
	Context2d c = tile.getContext2d();
	c.setFillStyle("white");
	c.fillRect(0, 0, tileSize, tileSize);
	c.drawImage(bufferCanvas, 0, 0);
	for (Consumer<Integer> listener : tileListeners)
		listener.accept(tileInfo.page);
}
 
Example 3
Source File: WebSocketConnection.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void doSend(byte[] data) {
    // Log.d(TAG, "doSend");
    if (isClosed) {
        return;
    }
    Uint8Array push = TypedArrays.createUint8Array(data.length);
    for (int i = 0; i < data.length; i++) {
        push.set(i, data[i]);
    }
    send(push);
}
 
Example 4
Source File: Conversion.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
public static ArrayBuffer convertBytes(byte[] data) {
    Uint8Array push = TypedArrays.createUint8Array(data.length);
    for (int i = 0; i < data.length; i++) {
        push.set(i, data[i]);
    }
    return push.buffer();
}
 
Example 5
Source File: DjVuText.java    From djvu-html5 with GNU General Public License v2.0 4 votes vote down vote up
private Uint8Array convertArray(byte[] bytes) {
	Uint8Array result = TypedArrays.createUint8Array(bytes.length);
	for (int i = 0; i < bytes.length; i++)
		result.set(i, bytes[i]);
	return result;
}
 
Example 6
Source File: IWMap.java    From djvu-html5 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * DOCUMENT ME!
 *
 * @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);
    }
  }
}