List of usage examples for java.nio IntBuffer rewind
public final Buffer rewind()
From source file:io.druid.segment.IndexMergerV9.java
private void mergeIndexesAndWriteColumns(final List<IndexableAdapter> adapters, final ProgressIndicator progress, final Iterable<Rowboat> theRows, final LongColumnSerializer timeWriter, final ArrayList<GenericColumnSerializer> metWriters, final List<IntBuffer> rowNumConversions, final List<DimensionMerger> mergers) throws IOException { final String section = "walk through and merge rows"; progress.startSection(section);/* w w w . j av a2 s. com*/ long startTime = System.currentTimeMillis(); int rowCount = 0; for (IndexableAdapter adapter : adapters) { int[] arr = new int[adapter.getNumRows()]; Arrays.fill(arr, INVALID_ROW); rowNumConversions.add(IntBuffer.wrap(arr)); } long time = System.currentTimeMillis(); for (Rowboat theRow : theRows) { progress.progress(); timeWriter.serialize(theRow.getTimestamp()); final Object[] metrics = theRow.getMetrics(); for (int i = 0; i < metrics.length; ++i) { metWriters.get(i).serialize(metrics[i]); } Object[] dims = theRow.getDims(); for (int i = 0; i < dims.length; ++i) { DimensionMerger merger = mergers.get(i); if (merger.canSkip()) { continue; } merger.processMergedRow(dims[i]); } for (Map.Entry<Integer, TreeSet<Integer>> comprisedRow : theRow.getComprisedRows().entrySet()) { final IntBuffer conversionBuffer = rowNumConversions.get(comprisedRow.getKey()); for (Integer rowNum : comprisedRow.getValue()) { while (conversionBuffer.position() < rowNum) { conversionBuffer.put(INVALID_ROW); } conversionBuffer.put(rowCount); } } if ((++rowCount % 500000) == 0) { log.info("walked 500,000/%d rows in %,d millis.", rowCount, System.currentTimeMillis() - time); time = System.currentTimeMillis(); } } for (IntBuffer rowNumConversion : rowNumConversions) { rowNumConversion.rewind(); } log.info("completed walk through of %,d rows in %,d millis.", rowCount, System.currentTimeMillis() - startTime); progress.stopSection(section); }
From source file:org.goko.viewer.jogl.utils.render.internal.AbstractVboJoglRenderer.java
/** (inheritDoc) * @see org.goko.viewer.jogl.service.ICoreJoglRenderer#performDestroy(javax.media.opengl.GL3) */// www . ja va 2 s . co m @Override public void performDestroy(GL3 gl) throws GkException { if (!isInitialized()) { return; } List<Integer> lstBuffers = new ArrayList<Integer>(); if (useVerticesBuffer) { lstBuffers.add(verticesBufferObject); } if (useColorsBuffer) { lstBuffers.add(colorsBufferObject); } if (useUvsBuffer) { lstBuffers.add(uvsBufferObject); } IntBuffer buffers = IntBuffer.allocate(lstBuffers.size()); for (Integer integer : lstBuffers) { buffers.put(integer); } buffers.rewind(); gl.glDeleteBuffers(lstBuffers.size(), buffers); IntBuffer intBuffer = IntBuffer.wrap(new int[] { vertexArrayObject }); gl.glDeleteVertexArrays(1, intBuffer); }
From source file:com.creativeongreen.imageeffects.MainActivity.java
public static Bitmap colorDodgeBlend(Bitmap source, Bitmap layer) { Bitmap base = source.copy(Config.ARGB_8888, true); Bitmap blend = layer.copy(Config.ARGB_8888, false); IntBuffer buffBase = IntBuffer.allocate(base.getWidth() * base.getHeight()); base.copyPixelsToBuffer(buffBase);/*from w ww . j ava 2 s .c o m*/ buffBase.rewind(); IntBuffer buffBlend = IntBuffer.allocate(blend.getWidth() * blend.getHeight()); blend.copyPixelsToBuffer(buffBlend); buffBlend.rewind(); IntBuffer buffOut = IntBuffer.allocate(base.getWidth() * base.getHeight()); buffOut.rewind(); while (buffOut.position() < buffOut.limit()) { int filterInt = buffBlend.get(); int srcInt = buffBase.get(); int redValueFilter = Color.red(filterInt); int greenValueFilter = Color.green(filterInt); int blueValueFilter = Color.blue(filterInt); int redValueSrc = Color.red(srcInt); int greenValueSrc = Color.green(srcInt); int blueValueSrc = Color.blue(srcInt); int redValueFinal = colordodge(redValueFilter, redValueSrc); int greenValueFinal = colordodge(greenValueFilter, greenValueSrc); int blueValueFinal = colordodge(blueValueFilter, blueValueSrc); int pixel = Color.argb(255, redValueFinal, greenValueFinal, blueValueFinal); /* * float[] hsv = new float[3]; Color.colorToHSV(pixel, hsv); hsv[1] = 0.0f; float top = * VALUE_TOP; // Setting this as 0.95f gave the best result so far if (hsv[2] <= top) { * hsv[2] = 0.0f; } else { hsv[2] = 1.0f; } pixel = Color.HSVToColor(hsv); */ buffOut.put(pixel); } buffOut.rewind(); base.copyPixelsFromBuffer(buffOut); blend.recycle(); return base; }
From source file:org.apache.druid.segment.IndexMergerV9.java
/** * Returns rowNumConversions, if fillRowNumConversions argument is true *///from ww w . ja v a2s. co m @Nullable private List<IntBuffer> mergeIndexesAndWriteColumns(final List<IndexableAdapter> adapters, final ProgressIndicator progress, final TimeAndDimsIterator timeAndDimsIterator, final GenericColumnSerializer timeWriter, final ArrayList<GenericColumnSerializer> metricWriters, final List<DimensionMergerV9> mergers, final boolean fillRowNumConversions) throws IOException { final String section = "walk through and merge rows"; progress.startSection(section); long startTime = System.currentTimeMillis(); List<IntBuffer> rowNumConversions = null; int rowCount = 0; if (fillRowNumConversions) { rowNumConversions = new ArrayList<>(adapters.size()); for (IndexableAdapter adapter : adapters) { int[] arr = new int[adapter.getNumRows()]; Arrays.fill(arr, INVALID_ROW); rowNumConversions.add(IntBuffer.wrap(arr)); } } long time = System.currentTimeMillis(); while (timeAndDimsIterator.moveToNext()) { progress.progress(); TimeAndDimsPointer timeAndDims = timeAndDimsIterator.getPointer(); timeWriter.serialize(timeAndDims.timestampSelector); for (int metricIndex = 0; metricIndex < timeAndDims.getNumMetrics(); metricIndex++) { metricWriters.get(metricIndex).serialize(timeAndDims.getMetricSelector(metricIndex)); } for (int dimIndex = 0; dimIndex < timeAndDims.getNumDimensions(); dimIndex++) { DimensionMerger merger = mergers.get(dimIndex); if (merger.canSkip()) { continue; } merger.processMergedRow(timeAndDims.getDimensionSelector(dimIndex)); } if (timeAndDimsIterator instanceof RowCombiningTimeAndDimsIterator) { RowCombiningTimeAndDimsIterator comprisedRows = (RowCombiningTimeAndDimsIterator) timeAndDimsIterator; for (int originalIteratorIndex = comprisedRows.nextCurrentlyCombinedOriginalIteratorIndex( 0); originalIteratorIndex >= 0; originalIteratorIndex = comprisedRows .nextCurrentlyCombinedOriginalIteratorIndex(originalIteratorIndex + 1)) { IntBuffer conversionBuffer = rowNumConversions.get(originalIteratorIndex); int minRowNum = comprisedRows .getMinCurrentlyCombinedRowNumByOriginalIteratorIndex(originalIteratorIndex); int maxRowNum = comprisedRows .getMaxCurrentlyCombinedRowNumByOriginalIteratorIndex(originalIteratorIndex); for (int rowNum = minRowNum; rowNum <= maxRowNum; rowNum++) { while (conversionBuffer.position() < rowNum) { conversionBuffer.put(INVALID_ROW); } conversionBuffer.put(rowCount); } } } else if (timeAndDimsIterator instanceof MergingRowIterator) { RowPointer rowPointer = (RowPointer) timeAndDims; IntBuffer conversionBuffer = rowNumConversions.get(rowPointer.getIndexNum()); int rowNum = rowPointer.getRowNum(); while (conversionBuffer.position() < rowNum) { conversionBuffer.put(INVALID_ROW); } conversionBuffer.put(rowCount); } else { if (fillRowNumConversions) { throw new IllegalStateException( "Filling row num conversions is supported only with RowCombining and Merging iterators"); } } if ((++rowCount % 500000) == 0) { log.info("walked 500,000/%d rows in %,d millis.", rowCount, System.currentTimeMillis() - time); time = System.currentTimeMillis(); } } if (rowNumConversions != null) { for (IntBuffer rowNumConversion : rowNumConversions) { rowNumConversion.rewind(); } } log.info("completed walk through of %,d rows in %,d millis.", rowCount, System.currentTimeMillis() - startTime); progress.stopSection(section); return rowNumConversions; }
From source file:com.creativeongreen.imageeffects.MainActivity.java
public static Bitmap getCartoonizedBitmap(Bitmap realBitmap, Bitmap dodgeBlendBitmap, int hueIntervalSize, int saturationIntervalSize, int valueIntervalSize, int saturationPercent, int valuePercent) { // Bitmap bitmap = Bitmap.createBitmap(scaledBitmap); // //fastblur(scaledBitmap, 4); Bitmap base = fastblur(realBitmap, 3).copy(Config.ARGB_8888, true); Bitmap dodge = dodgeBlendBitmap.copy(Config.ARGB_8888, false); try {//from w w w . ja va 2 s . c om int realColor; int color; float top = 0.87f;// VALUE_TOP; // Between 0.0f .. 1.0f I use 0.87f IntBuffer templatePixels = IntBuffer.allocate(dodge.getWidth() * dodge.getHeight()); IntBuffer scaledPixels = IntBuffer.allocate(base.getWidth() * base.getHeight()); IntBuffer buffOut = IntBuffer.allocate(base.getWidth() * base.getHeight()); base.copyPixelsToBuffer(scaledPixels); dodge.copyPixelsToBuffer(templatePixels); templatePixels.rewind(); scaledPixels.rewind(); buffOut.rewind(); while (buffOut.position() < buffOut.limit()) { color = (templatePixels.get()); realColor = scaledPixels.get(); float[] realHSV = new float[3]; Color.colorToHSV(realColor, realHSV); realHSV[0] = getRoundedValue(realHSV[0], hueIntervalSize); realHSV[2] = (getRoundedValue(realHSV[2] * 100, valueIntervalSize) / 100) * (valuePercent / 100); realHSV[2] = realHSV[2] < 1.0 ? realHSV[2] : 1.0f; realHSV[1] = realHSV[1] * (saturationPercent / 100); realHSV[1] = realHSV[1] < 1.0 ? realHSV[1] : 1.0f; float[] HSV = new float[3]; Color.colorToHSV(color, HSV); boolean putBlackPixel = HSV[2] <= top; realColor = Color.HSVToColor(realHSV); if (putBlackPixel) { buffOut.put(color); } else { buffOut.put(realColor); } } // END WHILE dodge.recycle(); buffOut.rewind(); base.copyPixelsFromBuffer(buffOut); } catch (Exception e) { // TODO: handle exception } return base; }
From source file:org.shaman.terrain.polygonal.PolygonalMapGenerator.java
private void updateGraphNode() { if (graphNode == null) { return;//www.j av a 2 s . c o m } //edges Mesh edgeMesh = new Mesh(); FloatBuffer pos = BufferUtils.createVector3Buffer(graph.corners.size()); IntBuffer index = BufferUtils.createIntBuffer(graph.edges.size() * 2); pos.rewind(); for (Graph.Corner c : graph.corners) { pos.put(c.point.x).put(c.point.y).put(0); } pos.rewind(); index.rewind(); for (Graph.Edge e : graph.edges) { index.put(e.v0.index).put(e.v1.index); } index.rewind(); edgeMesh.setBuffer(VertexBuffer.Type.Position, 3, pos); edgeMesh.setBuffer(VertexBuffer.Type.Index, 1, index); edgeMesh.setMode(Mesh.Mode.Lines); edgeMesh.setLineWidth(1); edgeMesh.updateCounts(); edgeMesh.updateBound(); Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); mat.setColor("Color", ColorRGBA.Gray); Geometry edgeGeom = new Geometry("edgeGeom", edgeMesh); edgeGeom.setMaterial(mat); edgeGeom.setCullHint(Spatial.CullHint.Never); edgeNode.detachAllChildren(); edgeNode.attachChild(edgeGeom); LOG.info("edge geometry updated"); }
From source file:org.apache.fop.complexscripts.fonts.ttx.TTXFile.java
public GlyphSequence mapCharsToGlyphs(String s) { Integer[] ca = UTF32.toUTF32(s, 0, true); int ng = ca.length; IntBuffer cb = IntBuffer.allocate(ng); IntBuffer gb = IntBuffer.allocate(ng); for (Integer c : ca) { int g = mapCharToGlyph((int) c); if (g >= 0) { cb.put(c);/*from w w w. java 2 s . c o m*/ gb.put(g); } else { throw new IllegalArgumentException( "character " + CharUtilities.format(c) + " has no corresponding glyph"); } } cb.rewind(); gb.rewind(); return new GlyphSequence(cb, gb, null); }
From source file:org.apache.fop.complexscripts.fonts.ttx.TTXFile.java
public GlyphSequence getGlyphSequence(String[] gids) { assert gids != null; int ng = gids.length; IntBuffer cb = IntBuffer.allocate(ng); IntBuffer gb = IntBuffer.allocate(ng); for (String gid : gids) { int g = mapGlyphId0(gid); if (g >= 0) { int c = mapGlyphIdToChar(gid); if (c < 0) { c = CharUtilities.NOT_A_CHARACTER; }/*from w ww .ja v a 2s .c om*/ cb.put(c); gb.put(g); } else { throw new IllegalArgumentException("unmapped glyph id \"" + gid + "\""); } } cb.rewind(); gb.rewind(); return new GlyphSequence(cb, gb, null); }