Java Code Examples for com.google.gwt.typedarrays.shared.TypedArrays#createUint8Array()

The following examples show how to use com.google.gwt.typedarrays.shared.TypedArrays#createUint8Array() . 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: BSInputStream.java    From djvu-html5 with GNU General Public License v2.0 6 votes vote down vote up
/**
  * Creates a new BSInputStream object.
* @param bsInputStream 
  */
 public BSInputStream(BSInputStream toCopy) {
  this.zp = new ZPCodec(toCopy.zp);
  for (int i = 0; i < toCopy.ctx.length; i++) {
	  if (toCopy.ctx[i] != null) {
		  ctx[i] = new BitContext((short) (toCopy.ctx[i].get() & 0xFF));
	  }
  }
  if (toCopy.data != null) {
	  data = TypedArrays.createUint8Array(toCopy.data.length());
	  data.set(toCopy.data);
  }
  eof = toCopy.eof;
  blocksize = toCopy.blocksize;
  bptr = toCopy.bptr;
  size = toCopy.size;
 }
 
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 byte[] convertBytes(ArrayBuffer buffer) {
    Uint8Array array = TypedArrays.createUint8Array(buffer);
    byte[] res = new byte[array.length()];
    for (int i = 0; i < res.length; i++) {
        res[i] = (byte) (array.get(i));
    }
    return res;
}
 
Example 5
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 6
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 7
Source File: IWPixmap.java    From djvu-html5 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
public GPixmap getPixmap()
{
  if(ymap == null)
  {
    return null;
  }

  final int w      = ymap.iw;
  final int h      = ymap.ih;
  final int pixsep = 4;
  final int rowsep = w * pixsep;
  Uint8Array bytes = TypedArrays.createUint8Array(h * rowsep);

  ymap.image(0, bytes, rowsep, pixsep, false);

  if((crmap != null) && (cbmap != null) && (crcb_delay >= 0))
  {
    cbmap.image(1, bytes, rowsep, pixsep, crcb_half);
    crmap.image(2, bytes, rowsep, pixsep, crcb_half);
  }

  // Convert image to RGB
  final GPixmap         ppm   =
    new GPixmap().init(bytes, h, w);
  final GPixelReference pixel = ppm.createGPixelReference(0);

  for(int i = 0; i < h;)
  {
    pixel.setOffset(i++, 0);

    if((crmap != null) && (cbmap != null) && (crcb_delay >= 0))
    {
      pixel.YCC_to_RGB(w);
    }
    else
    {
      for(int x = w; x-- > 0; pixel.incOffset())
      {
        pixel.setGray(127 - pixel.getBlue());
      }
    }
  }

  return ppm;
}
 
Example 8
Source File: GMap.java    From djvu-html5 with GNU General Public License v2.0 4 votes vote down vote up
protected void createImageData(int columns, int rows) {
  data = TypedArrays.createUint8Array(columns * rows * BYTES_PER_PIXEL);
  dataBuffer = data.buffer();
  dataWidth = columns;
  dataHeight = rows;
}