List of usage examples for java.nio ShortBuffer rewind
public final Buffer rewind()
From source file:Main.java
public static void main(String[] args) { ShortBuffer shortBuffer = ShortBuffer.allocate(10); shortBuffer.put((short) 100); shortBuffer.rewind(); ShortBuffer shortBuffer2 = shortBuffer.compact(); System.out.println(shortBuffer2.compareTo(shortBuffer2)); }
From source file:Main.java
public static ShortBuffer createShortBuffer(ShortBuffer buf, final int size) { if (buf != null && buf.limit() == size) { buf.rewind(); return buf; }/*from w ww . j a va 2s .c o m*/ buf = createShortBuffer(size); return buf; }
From source file:Main.java
public static ShortBuffer clone(final ShortBuffer buf) { if (buf == null) { return null; }// w ww .java2s . c om buf.rewind(); final ShortBuffer copy; if (buf.isDirect()) { copy = createShortBuffer(buf.limit()); } else { copy = createShortBufferOnHeap(buf.limit()); } copy.put(buf); return copy; }
From source file:com.google.android.apps.body.LayersLoader.java
private static ShortBuffer decodeIndexBuffer(DrawGroup drawGroup, char[] data, int start, int length) { ByteBuffer byteBuffer = ByteBuffer.allocateDirect(length * 2); byteBuffer.order(ByteOrder.nativeOrder()); ShortBuffer indexData = byteBuffer.asShortBuffer(); int prev = 0; for (int i = 0; i < length;) { int limit = Math.min(length - i, BUFSIZE); int s = start + i; for (int j = 0; j < limit; ++j) { int word = data[s + j]; prev += (word >> 1) ^ (-(word & 1)); mBuffer[j] = (short) prev; }//from w ww . j av a2s .c o m i += limit; indexData.put(mBuffer, 0, limit); } indexData.rewind(); return indexData; }
From source file:org.nuras.mcpha.Client.java
/** * /*from w w w . j av a 2 s .c om*/ * @param user * @param channels * @param trigger_mode * @param trigger_level * @param trigger_slope * @param trigger_source * @throws IOException */ synchronized public static void acquireOscilloscopeData(Session user, int channels, String trigger_mode, int trigger_level, String trigger_slope, int trigger_source) throws IOException { mcphaResetOscilloscope(); // Set number of samples to skip before trigger mcphaSetNumberOfSamplesBeforeTrigger(5000); // Set total number of samples to acquire for this run mcphaSetTotalNumberOfSamplesToAcquire(65536); // Start oscilloscope mcphaStartOscilloscope(); // wait for 200 milliseconds try { Thread.sleep(200); } catch (InterruptedException ex) { Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex); } // Read oscilloscope status for (int i = 0; i < 5; i++) { try { Thread.sleep(100); } catch (InterruptedException ex) { Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("Oscilloscope status:" + mcphaReadOscilloscopeStatus()); } // get oscillsocope data ShortBuffer data = mcphaGetOsilloscopeData(); boolean channel_1_requested = (channels & 0x01) != 0; boolean channel_2_requested = (channels & 0x02) != 0; // push data JSONObject json = createJSONResponseObject(); json.put("command", "get_oscilloscope_data"); json.put("message", ""); json.put("status", 0); JSONArray arr1 = new JSONArray(); JSONArray arr2 = new JSONArray(); data.rewind(); for (int i = 0, n1 = 0, n2 = 0; i < data.capacity(); i += 2) { // channel 1 data JSONArray xy = new JSONArray(); short d = data.get(); if (channel_1_requested) { arr1.put(xy.put(n1++).put(d)); } // channel 2 data xy = new JSONArray(); d = data.get(); if (channel_2_requested) { arr2.put(xy.put(n2++).put(d)); } } json.put("data1", arr1); json.put("label1", channel_1_requested ? "Channel 1" : ""); json.put("data2", arr2); json.put("label2", channel_2_requested ? "Channel 2" : ""); sendJSONObjectMessage(user.getRemote(), json); }
From source file:c.depthchart.ViewerPanel.java
private void updateDepthImage() /* build a new histogram of 8-bit depth values, and convert it to image pixels (as bytes) *//* w w w . jav a 2 s . co m*/ { ShortBuffer depthBuf = depthMD.getData().createShortBuffer(); calcHistogram(depthBuf); depthBuf.rewind(); while (depthBuf.remaining() > 0) { int pos = depthBuf.position(); short depth = depthBuf.get(); imgbytes[pos] = (byte) histogram[depth]; } }
From source file:haven.Utils.java
public static ShortBuffer bufcp(short[] a) { ShortBuffer b = mksbuf(a.length); b.put(a);/*from w w w.ja v a 2 s. c om*/ b.rewind(); return (b); }
From source file:TrackerPanel.java
private void updateUserDepths() { depthMD = depthGen.getMetaData();/*from w ww .ja va 2 s.c om*/ ShortBuffer depthBuf = depthMD.getData().createShortBuffer(); calcHistogram(depthBuf); depthBuf.rewind(); ShortBuffer usersBuf = sceneMD.getData().createShortBuffer(); while (depthBuf.remaining() > 0) { int pos = depthBuf.position(); short depthVal = depthBuf.get(); short userID = usersBuf.get(); imgbytes[3 * pos] = 0; // default colour is black when there's no // depth data imgbytes[3 * pos + 1] = 0; imgbytes[3 * pos + 2] = 0; if (depthVal != 0) { // there is depth data // convert userID to index into USER_COLORS[] int colorIdx = userID % (USER_COLORS.length - 1); // skip last // color if (userID == 0) // not a user; actually the background colorIdx = USER_COLORS.length - 1; // use last index: the position of white in USER_COLORS[] // convert histogram value (0.0-1.0f) to a RGB color float histValue = histogram[depthVal]; imgbytes[3 * pos] = (byte) (histValue * USER_COLORS[colorIdx].getRed()); imgbytes[3 * pos + 1] = (byte) (histValue * USER_COLORS[colorIdx].getGreen()); imgbytes[3 * pos + 2] = (byte) (histValue * USER_COLORS[colorIdx].getBlue()); } } }
From source file:com.google.android.apps.body.LayersLoader.java
private static ShortBuffer decodeVertexBuffer(DrawGroup drawGroup, char[] data, int start, int length) { ByteBuffer byteBuffer = ByteBuffer.allocateDirect(length * 2); byteBuffer.order(ByteOrder.nativeOrder()); ShortBuffer vertexData = byteBuffer.asShortBuffer(); short prev0 = 0, prev1 = 0, prev2 = 0, prev3 = 0; short prev4 = 0, prev5 = 0, prev6 = 0, prev7 = 0; for (int i = 0; i < length;) { int limit = Math.min(length - i, BUFSIZE); int s = start + i; for (int j = 0; j < limit;) { short word = (short) data[s + j]; prev0 += (word >> 1) ^ (-(word & 1)); mBuffer[j++] = (short) (prev0 - 8192); word = (short) data[s + j]; prev1 += (word >> 1) ^ (-(word & 1)); mBuffer[j++] = (short) (prev1 - 4096); word = (short) data[s + j]; prev2 += (word >> 1) ^ (-(word & 1)); mBuffer[j++] = (short) (prev2 - 8192); word = (short) data[s + j]; prev3 += (word >> 1) ^ (-(word & 1)); mBuffer[j++] = (short) ((prev3 - 256) << 7); word = (short) data[s + j]; prev4 += (word >> 1) ^ (-(word & 1)); mBuffer[j++] = (short) ((prev4 - 256) << 7); word = (short) data[s + j]; prev5 += (word >> 1) ^ (-(word & 1)); mBuffer[j++] = (short) ((prev5 - 256) << 7); word = (short) data[s + j]; prev6 += (word >> 1) ^ (-(word & 1)); mBuffer[j++] = (short) prev6; word = (short) data[s + j]; prev7 += (word >> 1) ^ (-(word & 1)); // The web version flips the tex images instead. mBuffer[j++] = (short) (512 - prev7); }/*w w w .j av a 2 s . c om*/ i += limit; vertexData.put(mBuffer, 0, limit); } vertexData.rewind(); return vertexData; }