List of usage examples for java.nio IntBuffer get
public abstract int get(int index);
From source file:edu.iu.daal_pca.Service.java
public static void printAprioriItemsets(HomogenNumericTable largeItemsetsTable, HomogenNumericTable largeItemsetsSupportTable) { /* Get sizes of tables to store large item sets */ int nItemsInLargeItemsets = (int) largeItemsetsTable.getNumberOfRows(); int largeItemsetCount = (int) largeItemsetsSupportTable.getNumberOfRows(); int nItemsetToPrint = 20; /* Get item sets and their support values */ IntBuffer bufLargeItemsets = IntBuffer .allocate(nItemsInLargeItemsets * (int) largeItemsetsTable.getNumberOfColumns()); bufLargeItemsets = largeItemsetsTable.getBlockOfRows(0, nItemsInLargeItemsets, bufLargeItemsets); int[] largeItemsets = new int[bufLargeItemsets.capacity()]; bufLargeItemsets.get(largeItemsets); IntBuffer bufLargeItemsetsSupportData = IntBuffer .allocate(largeItemsetCount * (int) largeItemsetsSupportTable.getNumberOfColumns()); bufLargeItemsetsSupportData = largeItemsetsSupportTable.getBlockOfRows(0, largeItemsetCount, bufLargeItemsetsSupportData); int[] largeItemsetsSupportData = new int[bufLargeItemsetsSupportData.capacity()]; bufLargeItemsetsSupportData.get(largeItemsetsSupportData); ArrayList<ArrayList<Integer>> largeItemsetsVector = new ArrayList<ArrayList<Integer>>(largeItemsetCount); for (int i = 0; i < largeItemsetCount; i++) { largeItemsetsVector.add(new ArrayList<Integer>()); }/*w ww . j av a2 s . c o m*/ for (int i = 0; i < nItemsInLargeItemsets; i++) { largeItemsetsVector.get(largeItemsets[2 * i]).add(largeItemsets[2 * i + 1]); } ArrayList<Integer> supportVector = new ArrayList<Integer>(largeItemsetCount); for (int i = 0; i < largeItemsetCount; i++) { supportVector.add(0); } for (int i = 0; i < largeItemsetCount; i++) { int index = largeItemsetsSupportData[2 * i]; supportVector.set(index, largeItemsetsSupportData[2 * i + 1]); } System.out.println("Apriori example program results"); System.out.println("Last " + nItemsetToPrint + " large itemsets: "); System.out.println("Itemset\t\t\tSupport"); int iMin = ((largeItemsetCount > nItemsetToPrint) ? largeItemsetCount - nItemsetToPrint : 0); for (int i = iMin; i < largeItemsetCount; i++) { System.out.print("{"); for (int l = 0; l < largeItemsetsVector.get(i).size() - 1; l++) { System.out.print(largeItemsetsVector.get(i).get(l) + ", "); } System.out.print(largeItemsetsVector.get(i).get(largeItemsetsVector.get(i).size() - 1) + "}\t\t"); System.out.println(supportVector.get(i)); } }
From source file:org.jtrfp.trcl.gpu.GLShader.java
private void printStatusInfo(GL3 gl, int shaderID) { IntBuffer statBuf = IntBuffer.allocate(1); gl.glGetShaderiv(shaderID, GL4.GL_COMPILE_STATUS, statBuf); if (statBuf.get(0) == GL4.GL_FALSE) { statBuf.clear();//w ww . j a v a 2 s.co m gl.glGetShaderiv(shaderID, GL4.GL_INFO_LOG_LENGTH, statBuf); ByteBuffer log = ByteBuffer.allocate(statBuf.get(0)); gl.glGetShaderInfoLog(shaderID, statBuf.get(0), null, log); System.out.println(Charset.forName("US-ASCII").decode(log).toString()); System.exit(1); } }
From source file:ja.lingo.engine.searchindex.SearchIndex.java
private INode _deserialize(IntBuffer buffer, int deep) throws IOException { if (deep > 0) { memoryNodesLoaded++;//from w w w . j a v a 2s . com //int size = buffer.get( offset ); int childrenCount = buffer.get(offset + 1); char key = (char) buffer.get(offset + 2); int value = buffer.get(offset + 3); offset += 4; IMutableNode node = Node.create(key, value); deep--; for (int i = 0; i < childrenCount; i++) { node.addChild(_deserialize(buffer, deep)); } return node; } else { lazyNodesLoaded++; INode node = new LazyNode(buffer, offset); int size = buffer.get(offset); offset += size >> 2; return node; } }
From source file:edu.csun.ecs.cs.multitouchj.audio.openal.OpenAlAudioPlayer.java
@Override public synchronized void update() { IntBuffer emptyBuffers = unqueueEmptyBuffers(); for (int i = 0; i < emptyBuffers.limit(); i++) { setBufferStatus(emptyBuffers.get(i), false); eventOccurred("bufferEmptied"); }//from w w w . ja v a 2 s. c om if ((!isStoppedEventSent) && (getStatus().equals(Status.STOPPED))) { eventOccurred("audioStopped"); } }
From source file:xbird.util.nio.RemoteMemoryMappedFile.java
private int[] recvResponse(final ReadableByteChannel channel, final ByteBuffer buf, final int dstlen) throws IOException { buf.clear();/*from w w w . ja va2 s .c o m*/ // set endian optimized for this machine final boolean isBufBigEndian = (buf.order() == ByteOrder.BIG_ENDIAN); if (_bigEndian != isBufBigEndian) { buf.order(_bigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN); } NIOUtils.readFully(channel, buf, _pageSize); buf.flip(); IntBuffer ibuf = buf.asIntBuffer(); int[] dst = new int[dstlen]; ibuf.get(dst); return dst; }
From source file:com.clov4r.moboplayer.android.nil.codec.SubtitleJni.java
public Bitmap createBitmapOfSubtitle(ByteBuffer data, int width, int height) { IntBuffer intBuffer = data.asIntBuffer(); int[] dataArray = new int[intBuffer.limit()]; intBuffer.get(dataArray); Bitmap rest = Bitmap.createBitmap(dataArray, width, height, Config.RGB_565); return rest;//from w ww. ja va2 s.co m }
From source file:com.linkedin.pinot.core.startree.StarTreeDataSorter.java
/** * Sort from to given start (inclusive) to end (exclusive) as per the provided sort order. * @param startRecordId inclusive//from ww w .j a v a 2 s . co m * @param endRecordId exclusive * @param sortOrder */ public void sort(int startRecordId, int endRecordId, final int[] sortOrder) { int length = endRecordId - startRecordId; final int startOffset = startRecordId * totalSizeInBytes; List<Integer> idList = new ArrayList<Integer>(); for (int i = startRecordId; i < endRecordId; i++) { idList.add(i - startRecordId); } Comparator<Integer> comparator = new Comparator<Integer>() { byte[] buf1 = new byte[dimensionSizeInBytes]; byte[] buf2 = new byte[dimensionSizeInBytes]; @Override public int compare(Integer o1, Integer o2) { int pos1 = startOffset + (o1) * totalSizeInBytes; int pos2 = startOffset + (o2) * totalSizeInBytes; mappedByteBuffer.copyTo(pos1, buf1, 0, dimensionSizeInBytes); mappedByteBuffer.copyTo(pos2, buf2, 0, dimensionSizeInBytes); IntBuffer bb1 = ByteBuffer.wrap(buf1).asIntBuffer(); IntBuffer bb2 = ByteBuffer.wrap(buf2).asIntBuffer(); for (int dimIndex : sortOrder) { int v1 = bb1.get(dimIndex); int v2 = bb2.get(dimIndex); if (v1 != v2) { return v1 - v2; } } return 0; } }; Collections.sort(idList, comparator); int[] currentPositions = new int[length]; int[] indexToRecordIdMapping = new int[length]; byte[] buf1 = new byte[totalSizeInBytes]; byte[] buf2 = new byte[totalSizeInBytes]; for (int i = 0; i < length; i++) { currentPositions[i] = i; indexToRecordIdMapping[i] = i; } for (int i = 0; i < length; i++) { int thisRecordId = indexToRecordIdMapping[i]; int thisRecordIdPos = currentPositions[thisRecordId]; int thatRecordId = idList.get(i); int thatRecordIdPos = currentPositions[thatRecordId]; // swap the buffers mappedByteBuffer.copyTo(startOffset + thisRecordIdPos * totalSizeInBytes, buf1, 0, totalSizeInBytes); mappedByteBuffer.copyTo(startOffset + thatRecordIdPos * totalSizeInBytes, buf2, 0, totalSizeInBytes); mappedByteBuffer.readFrom(buf2, 0, startOffset + thisRecordIdPos * totalSizeInBytes, totalSizeInBytes); mappedByteBuffer.readFrom(buf1, 0, startOffset + thatRecordIdPos * totalSizeInBytes, totalSizeInBytes); // update the positions indexToRecordIdMapping[i] = thatRecordId; indexToRecordIdMapping[thatRecordIdPos] = thisRecordId; currentPositions[thatRecordId] = i; currentPositions[thisRecordId] = thatRecordIdPos; } }
From source file:itemrender.client.rendering.FBOHelper.java
public void saveToFile(File file) { // Bind framebuffer texture GlStateManager.bindTexture(textureID); GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); int width = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_WIDTH); int height = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_HEIGHT); IntBuffer texture = BufferUtils.createIntBuffer(width * height); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, texture); int[] texture_array = new int[width * height]; texture.get(texture_array); BufferedImage image = new BufferedImage(renderTextureSize, renderTextureSize, BufferedImage.TYPE_INT_ARGB); image.setRGB(0, 0, renderTextureSize, renderTextureSize, texture_array, 0, width); file.mkdirs();/*from w w w . j ava2 s . c o m*/ try { ImageIO.write(image, "png", file); } catch (Exception e) { // Do nothing } }
From source file:itemrender.client.rendering.FBOHelper.java
public String getBase64() { // Bind framebuffer texture GlStateManager.bindTexture(textureID); GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); int width = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_WIDTH); int height = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_HEIGHT); IntBuffer texture = BufferUtils.createIntBuffer(width * height); GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, texture); int[] texture_array = new int[width * height]; texture.get(texture_array); BufferedImage image = new BufferedImage(renderTextureSize, renderTextureSize, BufferedImage.TYPE_INT_ARGB); image.setRGB(0, 0, renderTextureSize, renderTextureSize, texture_array, 0, width); ByteArrayOutputStream out = new ByteArrayOutputStream(); try {/* www . ja v a 2s. c o m*/ ImageIO.write(image, "PNG", out); } catch (IOException e) { // Do nothing } return Base64.encodeBase64String(out.toByteArray()); }
From source file:com.adobe.plugins.FastCanvasRenderer.java
public void onSurfaceCreated(GL10 gl, EGLConfig config) { Log.i("CANVAS", "CanvasRenderer onSurfaceCreated. config:" + config.toString() + " gl:" + gl.toString()); IntBuffer ib = IntBuffer.allocate(100); ib.position(0);/*www . j a va 2s .c o m*/ GLES10.glGetIntegerv(GLES10.GL_RED_BITS, ib); int red = ib.get(0); GLES10.glGetIntegerv(GLES10.GL_GREEN_BITS, ib); int green = ib.get(0); GLES10.glGetIntegerv(GLES10.GL_BLUE_BITS, ib); int blue = ib.get(0); GLES10.glGetIntegerv(GLES10.GL_STENCIL_BITS, ib); int stencil = ib.get(0); GLES10.glGetIntegerv(GLES10.GL_DEPTH_BITS, ib); int depth = ib.get(0); Log.i("CANVAS", "CanvasRenderer R=" + red + " G=" + green + " B=" + blue + " DEPETH=" + depth + " STENCIL=" + stencil); }