List of usage examples for com.google.gwt.typedarrays.shared Uint8Array get
short get(int index);
From source file:com.badlogic.gdx.backends.gwt.GwtGL20.java
License:Apache License
@Override public void glReadPixels(int x, int y, int width, int height, int format, int type, Buffer pixels) { // verify request if ((format != WebGLRenderingContext.RGBA) || (type != WebGLRenderingContext.UNSIGNED_BYTE)) { throw new GdxRuntimeException( "Only format RGBA and type UNSIGNED_BYTE are currently supported for glReadPixels(...)."); }/*from w ww . j a v a2s.co m*/ if (!(pixels instanceof ByteBuffer)) { throw new GdxRuntimeException( "Inputed pixels buffer needs to be of type ByteBuffer for glReadPixels(...)."); } // create new ArrayBufferView (4 bytes per pixel) int size = 4 * width * height; Uint8Array buffer = Uint8ArrayNative.create(size); // read bytes to ArrayBufferView gl.readPixels(x, y, width, height, format, type, buffer); // copy ArrayBufferView to our pixels array ByteBuffer pixelsByte = (ByteBuffer) pixels; for (int i = 0; i < size; i++) { pixelsByte.put((byte) (buffer.get(i) & 0x000000ff)); } }
From source file:com.lizardtech.djvu.IWPixmap.java
License:Open Source License
@Override public GPixmap getPixmap(int subsample, GRect rect, GPixmap retval) { if (ymap == null) { return null; }// www. j a v a 2 s .c o m if (retval == null) { retval = new GPixmap(); } final int w = rect.width(); final int h = rect.height(); final int pixsep = 4; final int rowsep = w * pixsep; final Uint8Array bytes = retval.init(h, w, null).data; ymap.image(subsample, rect, 0, bytes, rowsep, pixsep, false); if ((crmap != null) && (cbmap != null) && (crcb_delay >= 0)) { cbmap.image(subsample, rect, 1, bytes, rowsep, pixsep, crcb_half); crmap.image(subsample, rect, 2, bytes, rowsep, pixsep, crcb_half); } final GPixelReference pixel = retval.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 - bytes.get(pixel.getOffset())); } } } return retval; }
From source file:org.parallax3d.parallax.platforms.gwt.GwtGL20.java
License:Open Source License
@Override public void glReadPixels(int x, int y, int width, int height, int format, int type, Buffer pixels) { // verify request if ((format != WebGLRenderingContext.RGBA) || (type != WebGLRenderingContext.UNSIGNED_BYTE)) { throw new ParallaxRuntimeException( "Only format RGBA and type UNSIGNED_BYTE are currently supported for glReadPixels(...)."); }/*from w ww. j a v a 2s . com*/ if (!(pixels instanceof ByteBuffer)) { throw new ParallaxRuntimeException( "Inputed pixels buffer needs to be of type ByteBuffer for glReadPixels(...)."); } // create new ArrayBufferView (4 bytes per pixel) int size = 4 * width * height; Uint8Array buffer = Uint8ArrayNative.create(size); // read bytes to ArrayBufferView gl.readPixels(x, y, width, height, format, type, buffer); // copy ArrayBufferView to our pixels array ByteBuffer pixelsByte = (ByteBuffer) pixels; for (int i = 0; i < size; i++) { pixelsByte.put((byte) (buffer.get(i) & 0x000000ff)); } }