com.google.gwt.typedarrays.shared.TypedArrays Java Examples

The following examples show how to use com.google.gwt.typedarrays.shared.TypedArrays. 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: UrlDownloaderTest.java    From gdx-fireapp with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    PowerMockito.mockStatic(XMLHttpRequest.class);
    PowerMockito.mockStatic(TypedArrays.class);
    xmlHttpRequest = PowerMockito.mock(XMLHttpRequest.class);
    Mockito.when(XMLHttpRequest.create()).thenReturn(xmlHttpRequest);
    Mockito.doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) {
            ((ReadyStateChangeHandler) invocation.getArgument(0)).onReadyStateChange(xmlHttpRequest);
            return null;
        }
    }).when(xmlHttpRequest).setOnReadyStateChange(Mockito.any(ReadyStateChangeHandler.class));
    Uint8Array uint8Array = Mockito.mock(Uint8Array.class);
    Mockito.when(xmlHttpRequest.getResponseArrayBuffer()).thenReturn(Mockito.mock(ArrayBuffer.class));
    Mockito.when(uint8Array.length()).thenReturn(10);
    Mockito.when(TypedArrays.createUint8Array(Mockito.any(ArrayBuffer.class))).thenReturn(uint8Array);
}
 
Example #2
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 #3
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 #4
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 #5
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 #6
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 #7
Source File: JsFileInput.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Promise<FilePart> read(int fileOffset, int len) {
    return new Promise<>(resolver -> {
        JsFileReader fileReader = JsFileReader.create();
        fileReader.setOnLoaded(message -> {
            Uint8Array array = TypedArrays.createUint8Array(message);
            byte[] data = new byte[len];
            for (int i = 0; i < len; i++) {
                data[i] = (byte) (array.get(i));
            }
            resolver.result(new FilePart(fileOffset, len, data));
        });
        fileReader.readAsArrayBuffer(jsFile.slice(fileOffset, fileOffset + len));
    });
}
 
Example #8
Source File: PageDecoder.java    From djvu-html5 with GNU General Public License v2.0 5 votes vote down vote up
private void downloadFile(final String url) {
	XMLHttpRequest request = XMLHttpRequest.create();
	request.open("GET", url);
	request.setResponseType(ResponseType.ArrayBuffer);
	request.setOnReadyStateChange(new ReadyStateChangeHandler() {
		@Override
		public void onReadyStateChange(XMLHttpRequest xhr) {
			if (xhr.getReadyState() == XMLHttpRequest.DONE) {
				downloadsInProgress--;
				if (xhr.getStatus() == 200) {
					FileItem entry = getCachedFile(url);
					entry.data = TypedArrays.createUint8Array(xhr.getResponseArrayBuffer());
					entry.dataSize = entry.data.byteLength();
					filesMemoryUsage += entry.dataSize;
					checkFilesMemory();
					context.startProcessing();
					fireReady(url);
					continueDownload();
				} else {
					GWT.log("Error downloading " + url);
					GWT.log("response status: " + xhr.getStatus() + " " + xhr.getStatusText());
					context.setStatus(ProcessingContext.STATUS_ERROR);
					fileCache.get(url).downloadStarted = false;
				}
			}
		}
	});
	request.send();
	fileCache.get(url).downloadStarted = true;
	downloadsInProgress++;
}
 
Example #9
Source File: IWCodec.java    From djvu-html5 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new IWCodec object.
 */
public IWCodec()
{
  ctxStart = new BitContext[32];

  for(int i = 0; i < 32; i++)
  {
    ctxStart[i] = new BitContext();
  }

  ctxBucket = new BitContext[10][8];

  for(int i = 0; i < 10; i++)
  {
    for(int j = 0; j < 8; j++)
    {
      ctxBucket[i][j] = new BitContext();
    }
  }

  quant_hi      = TypedArrays.createInt32Array(10);
  quant_lo      = TypedArrays.createInt32Array(16);
  coeffstate    = TypedArrays.createInt8Array(256);
  bucketstate   = TypedArrays.createInt8Array(16);
  curband       = 0;
  curbit        = 1;
  ctxMant       = new BitContext();
  ctxRoot       = new BitContext();
}
 
Example #10
Source File: GPixmap.java    From djvu-html5 with GNU General Public License v2.0 4 votes vote down vote up
/**
   * Initialize this pixmap to the specified size and fill in the specified color.
   *
   * @param arows number of rows
   * @param acolumns number of columns
   * @param filler fill color
   *
   * @return the initialized pixmap
   */
  public GPixmap init(
    int    arows,
    int    acolumns,
    GPixel filler)
  {
//    boolean needFill=false;
    if((arows != nrows) || (acolumns != ncolumns))
    {
      data   = null;
      nrows       = arows;
      ncolumns    = acolumns;
    }

    final int npix = rowOffset(rows());

    if(npix > 0)
    {
      if(data == null)
      {
    	  createImageData(ncolumns, nrows);
    	  if (filler == null) {
    		  for (int i = 0; i < npix; i++)
    			  data.set(i * BYTES_PER_PIXEL + 3, 0xFF);
    	  }
      }

      if(filler != null)
      {
    	  data.set(redOffset, filler.redByte());
    	  data.set(greenOffset, filler.greenByte());
    	  data.set(blueOffset, filler.blueByte());
    	  data.set(3, 0xFF);
    	  Int32Array fillBuffer = TypedArrays.createInt32Array(data.buffer());
    	  int fillValue = fillBuffer.get(0);
    	  for (int i = 0; i < npix; i++)
    		  fillBuffer.set(i, fillValue);
      }
    }

    return this;
  }
 
Example #11
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 #12
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 #13
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);
    }
  }
}
 
Example #14
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;
}