java.nio.IntBuffer Java Examples

The following examples show how to use java.nio.IntBuffer. 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: Gl_320_draw_range_arrays.java    From jogl-samples with MIT License 6 votes vote down vote up
private boolean initBuffer(GL3 gl3) {

        FloatBuffer positionBuffer = GLBuffers.newDirectFloatBuffer(positionData);
        IntBuffer uniformBufferOffset = GLBuffers.newDirectIntBuffer(1);

        gl3.glGenBuffers(Buffer.MAX, bufferName);

        gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
        gl3.glBufferData(GL_ARRAY_BUFFER, positionSize, positionBuffer, GL_STATIC_DRAW);
        gl3.glBindBuffer(GL_ARRAY_BUFFER, 0);

        gl3.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset);
        int uniformTransformBlockSize = Math.max(2 * Mat4.SIZE, uniformBufferOffset.get(0));

        gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        gl3.glBufferData(GL_UNIFORM_BUFFER, uniformTransformBlockSize, null, GL_DYNAMIC_DRAW);
        gl3.glBindBuffer(GL_UNIFORM_BUFFER, 0);

        BufferUtils.destroyDirectBuffer(positionBuffer);
        BufferUtils.destroyDirectBuffer(uniformBufferOffset);

        return checkError(gl3, "initBuffer");
    }
 
Example #2
Source File: OpenGlUtils.java    From SimpleVideoEditor with Apache License 2.0 6 votes vote down vote up
public static int loadTexture(final IntBuffer data, final Size size, final int usedTexId) {
    int textures[] = new int[1];
    if (usedTexId == NO_TEXTURE) {
        GLES20.glGenTextures(1, textures, 0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, size.width, size.height,
                0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
    } else {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
        GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, size.width,
                size.height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
        textures[0] = usedTexId;
    }
    return textures[0];
}
 
Example #3
Source File: BufferDirectSequentialNumberCellIndex.java    From yosegi with Apache License 2.0 6 votes vote down vote up
@Override
public Set<Integer> getLe(
    final IDicManager dicManager ,
    final IntBuffer dicIndexIntBuffer ,
    final NumberFilter numberFilter ) throws IOException {
  Float target;
  try {
    target = Float.valueOf( numberFilter.getNumberObject().getFloat() );
  } catch ( NumberFormatException ex ) {
    return null;
  }
  Set<Integer> matchDicList = new HashSet<Integer>();
  for ( int i = 0 ; i < dicManager.getDicSize() ; i++ ) {
    PrimitiveObject numObj = dicManager.get( i );
    if ( numObj == null ) {
      continue;
    }
    if ( 0 <= target.compareTo( numObj.getFloat() ) ) {
      matchDicList.add( Integer.valueOf( i ) );
    }
  }

  return matchDicList;
}
 
Example #4
Source File: GLRenderer.java    From HoloKilo with GNU General Public License v3.0 6 votes vote down vote up
static public int loadShader(int type, String shaderCode)
{
    int shader = GLES20.glCreateShader(type);

    GLES20.glShaderSource(shader, shaderCode);
    GLES20.glCompileShader(shader);
    IntBuffer compile = IntBuffer.allocate(1);
    GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compile);
    if (compile.get(0) == GLES20.GL_FALSE) {
        Log.e(Config.TAG, "Error:");
        Log.e(Config.TAG, shaderCode);
        Log.e(Config.TAG, "Fault:");
        printLog(shader);
        return 0;
    }

    return shader;
}
 
Example #5
Source File: Gl_410_program_separate.java    From jogl-samples with MIT License 6 votes vote down vote up
private boolean initVertexBuffer(GL4 gl4) {

        FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData);
        IntBuffer elementBuffer = GLBuffers.newDirectIntBuffer(elementData);

        gl4.glGenBuffers(Buffer.MAX, bufferName);

        gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
        gl4.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW);
        gl4.glBindBuffer(GL_ARRAY_BUFFER, 0);

        gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));
        gl4.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW);
        gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

        BufferUtils.destroyDirectBuffer(vertexBuffer);
        BufferUtils.destroyDirectBuffer(elementBuffer);

        return checkError(gl4, "initArrayBuffer");
    }
 
Example #6
Source File: DumpArrayColumnBinaryMaker.java    From multiple-dimension-spread with Apache License 2.0 6 votes vote down vote up
private void create() throws IOException{
  ICompressor compressor = FindCompressor.get( columnBinary.compressorClassName );
  byte[] decompressBuffer = compressor.decompress( columnBinary.binary , columnBinary.binaryStart , columnBinary.binaryLength );

  IntBuffer wrapBuffer = ByteBuffer.wrap( decompressBuffer ).asIntBuffer() ;

  arrayColumn = new ArrayColumn( columnBinary.columnName );
  Spread spread = new Spread( arrayColumn );
  for( ColumnBinary childColumnBinary : columnBinary.columnBinaryList ){
    IColumnBinaryMaker maker = FindColumnBinaryMaker.get( childColumnBinary.makerClassName );
    IColumn column = maker.toColumn( childColumnBinary );
    column.setParentsColumn( arrayColumn );
    spread.addColumn( column );
  }
  spread.setRowCount( columnBinary.rowCount );

  arrayColumn.setSpread( spread );
  arrayColumn.setCellManager( new ArrayCellManager( spread , wrapBuffer ) );

  isCreate = true;
}
 
Example #7
Source File: BufferDirectSequentialNumberCellIndex.java    From yosegi with Apache License 2.0 6 votes vote down vote up
@Override
public Set<Integer> getLt(
    final IDicManager dicManager ,
    final IntBuffer dicIndexIntBuffer ,
    final NumberFilter numberFilter ) throws IOException {
  byte target;
  try {
    target = numberFilter.getNumberObject().getByte();
  } catch ( NumberFormatException ex ) {
    return null;
  }
  Set<Integer> matchDicList = new HashSet<Integer>();
  for ( int i = 0 ; i < dicManager.getDicSize() ; i++ ) {
    PrimitiveObject numObj = dicManager.get( i );
    if ( numObj == null ) {
      continue;
    }
    if ( numObj.getByte() < target ) {
      matchDicList.add( Integer.valueOf( i ) );
    }
  }

  return matchDicList;
}
 
Example #8
Source File: DesktopComputeJobManager.java    From graphicsfuzz with Apache License 2.0 6 votes vote down vote up
@Override
public void prepareEnvironment(JsonObject environmentJson) {
  final JsonObject bufferJson = environmentJson.get("buffer").getAsJsonObject();
  final int bufferBinding = bufferJson.get("binding").getAsInt();
  final int[] bufferInput = UniformSetter.getIntArray(bufferJson.get("input").getAsJsonArray());
  final IntBuffer intBufferData = BufferUtils.createIntBuffer(bufferInput.length);
  intBufferData.put(bufferInput);
  intBufferData.flip();
  shaderStorageBufferObject = GL15.glGenBuffers();
  checkError();
  GL15.glBindBuffer(GL43.GL_SHADER_STORAGE_BUFFER, shaderStorageBufferObject);
  checkError();
  GL15.glBufferData(GL43.GL_SHADER_STORAGE_BUFFER, intBufferData, GL15.GL_STATIC_DRAW);
  checkError();
  GL30.glBindBufferBase(GL43.GL_SHADER_STORAGE_BUFFER, bufferBinding, shaderStorageBufferObject);
  checkError();
  numGroups = UniformSetter.getIntArray(environmentJson.get("num_groups").getAsJsonArray());
}
 
Example #9
Source File: TestBufferDirectSequentialStringCellIndex.java    From multiple-dimension-spread with Apache License 2.0 6 votes vote down vote up
@Test
public void T_filter_2() throws IOException{
  List<PrimitiveObject> dic = new ArrayList<PrimitiveObject>();
  dic.add( new StringObj( "abc" ) );
  dic.add( new StringObj( "bcd" ) );
  dic.add( new StringObj( "cde" ) );
  dic.add( new StringObj( "def" ) );
  dic.add( new StringObj( "efg" ) );
  IntBuffer buffer = IntBuffer.allocate( 100 );
  for( int i = 0 ; i < 100 ; i++ ){
    buffer.put( i % 5 );
  }
  ICellIndex index = new BufferDirectSequentialStringCellIndex( new TestDicManager( dic ) , buffer );
  IFilter filter = new PartialMatchStringFilter( "b" );

  FilterdExpressionIndex result = new FilterdExpressionIndex( index.filter( filter , new boolean[100] ) );
  assertEquals( result.size() , 40 );
  for( int i = 0,n=0 ; n < 100 ; i+=2,n+=5 ){
    assertEquals( result.get(i) , n );
    assertEquals( result.get(i+1) , n+1 );
  }
}
 
Example #10
Source File: TestBufferDirectSequentialNumberCellIndexInteger.java    From yosegi with Apache License 2.0 6 votes vote down vote up
@Test
public void T_int_filter_8() throws IOException{
  List<PrimitiveObject> dic = new ArrayList<PrimitiveObject>();
  dic.add( new IntegerObj( 1000 ) );
  dic.add( new IntegerObj( 2000 ) );
  dic.add( new IntegerObj( 3000 ) );
  dic.add( new IntegerObj( 4000 ) );
  dic.add( new IntegerObj( 5000 ) );
  IntBuffer buffer = IntBuffer.allocate( 100 );
  for( int i = 0 ; i < 100 ; i++ ){
    buffer.put( i % 5 );
  }
  ICellIndex index = new BufferDirectSequentialNumberCellIndex( ColumnType.INTEGER , new TestDicManager( dic ) , buffer );
  IFilter filter = new NumberFilter( NumberFilterType.GE , new LongObj( Long.valueOf( Integer.MIN_VALUE ) - (long)1 ) );

  assertEquals( null , index.filter( filter , new boolean[100] ) );
}
 
Example #11
Source File: TestBufferDirectSequentialNumberCellIndexLong.java    From yosegi with Apache License 2.0 6 votes vote down vote up
@Test
public void T_long_filter_3() throws IOException{
  List<PrimitiveObject> dic = new ArrayList<PrimitiveObject>();
  dic.add( new LongObj( 1000 ) );
  dic.add( new LongObj( 2000 ) );
  dic.add( new LongObj( 3000 ) );
  dic.add( new LongObj( 4000 ) );
  dic.add( new LongObj( 5000 ) );
  IntBuffer buffer = IntBuffer.allocate( 100 );
  for( int i = 0 ; i < 100 ; i++ ){
    buffer.put( i % 5 );
  }
  ICellIndex index = new BufferDirectSequentialNumberCellIndex( ColumnType.LONG , new TestDicManager( dic ) , buffer );
  IFilter filter = new NumberFilter( NumberFilterType.LT , new LongObj( 2000 ) );

  FilterdExpressionIndex result = new FilterdExpressionIndex( index.filter( filter , new boolean[100] ) );
  assertEquals( result.size() , 20 );
  for( int i = 0,n=0 ; n < 100 ; i++,n+=5 ){
    assertEquals( result.get(i) , n );
  }
}
 
Example #12
Source File: GlContextJogl.java    From JglTF with MIT License 6 votes vote down vote up
/**
 * For debugging: Print program log info
 * 
 * @param id program ID
 */
private void printProgramLogInfo(int id) 
{
    IntBuffer infoLogLength = ByteBuffer
        .allocateDirect(4)
        .order(ByteOrder.nativeOrder())
        .asIntBuffer();
    gl.glGetProgramiv(id, GL_INFO_LOG_LENGTH, infoLogLength);
    if (infoLogLength.get(0) > 0) 
    {
        infoLogLength.put(0, infoLogLength.get(0) - 1);
    }

    ByteBuffer infoLog = ByteBuffer
        .allocateDirect(infoLogLength.get(0))
        .order(ByteOrder.nativeOrder());
    gl.glGetProgramInfoLog(id, infoLogLength.get(0), null, infoLog);

    String infoLogString = 
        Charset.forName("US-ASCII").decode(infoLog).toString();
    if (infoLogString.trim().length() > 0)
    {
        logger.warning("program log:\n"+infoLogString);
    }
}
 
Example #13
Source File: SwingFXUtils.java    From ShootOFF with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Determine the appropriate {@link WritablePixelFormat} type that can be
 * used to transfer data into the indicated BufferedImage.
 * 
 * @param bimg
 *            the BufferedImage that will be used as a destination for a
 *            {@code PixelReader<IntBuffer>#getPixels()} operation.
 * @return
 */
private static WritablePixelFormat<IntBuffer> getAssociatedPixelFormat(BufferedImage bimg) {
	switch (bimg.getType()) {
	// We lie here for xRGB, but we vetted that the src data was opaque
	// so we can ignore the alpha. We use ArgbPre instead of Argb
	// just to get a loop that does not have divides in it if the
	// PixelReader happens to not know the data is opaque.
	case BufferedImage.TYPE_INT_RGB:
	case BufferedImage.TYPE_INT_ARGB_PRE:
		return PixelFormat.getIntArgbPreInstance();

	case BufferedImage.TYPE_INT_ARGB:
		return PixelFormat.getIntArgbInstance();

	default:
		// Should not happen...
		throw new InternalError("Failed to validate BufferedImage type");
	}
}
 
Example #14
Source File: Texture.java    From lwjglbook with Apache License 2.0 6 votes vote down vote up
public Texture(String fileName) throws Exception {
    ByteBuffer buf;
    // Load Texture file
    try (MemoryStack stack = MemoryStack.stackPush()) {
        IntBuffer w = stack.mallocInt(1);
        IntBuffer h = stack.mallocInt(1);
        IntBuffer channels = stack.mallocInt(1);

        buf = stbi_load(fileName, w, h, channels, 4);
        if (buf == null) {
            throw new Exception("Image file [" + fileName  + "] not loaded: " + stbi_failure_reason());
        }

        width = w.get();
        height = h.get();
    }

    this.id = createTexture(buf);

    stbi_image_free(buf);
}
 
Example #15
Source File: IntBitPacking.java    From metrics with Apache License 2.0 6 votes vote down vote up
public void compressChunk(
        IntBuffer src,
        IntOutputStream dst,
        IntFilter filter)
{
    src.mark();
    filter.saveContext();
    int head = 0;
    for (int i = 0; i < this.blockNum; ++i) {
        int n = this.maxBits[i] = countMaxBits(src, this.blockLen, filter);
        head = (head << 8) | n;
    }
    filter.restoreContext();
    src.reset();

    dst.write(head);
    for (int i = 0; i < this.blockNum; ++i) {
        pack(src, dst, this.maxBits[i], this.blockLen, filter);
    }
}
 
Example #16
Source File: SoundManager.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
 
Example #17
Source File: UnitHelp.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
public static boolean socketPresent(final SocketUDT socket,
        final IntBuffer buffer) {
    for (int index = 0; index < buffer.capacity(); index++) {
        if (buffer.get(index) == socket.id()) {
            return true;
        }
    }
    return false;
}
 
Example #18
Source File: FBOGraphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Initialise the FBO that will be used to render to
 * 
 * @throws SlickException
 */
private void init() throws SlickException {
	IntBuffer buffer = BufferUtils.createIntBuffer(1);
	EXTFramebufferObject.glGenFramebuffersEXT(buffer); 
	FBO = buffer.get();

	// for some reason FBOs won't work on textures unless you've absolutely just
	// created them.
	try {
		Texture tex = InternalTextureLoader.get().createTexture(image.getWidth(), image.getHeight(), image.getFilter());
		
		EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, FBO);
		EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 
													   EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT,
													   GL11.GL_TEXTURE_2D, tex.getTextureID(), 0);
		
		completeCheck();
		unbind();
		
		// Clear our destination area before using it
		clear();
		flush();
		
		// keep hold of the original content
		drawImage(image, 0, 0);
		image.setTexture(tex);
		
	} catch (Exception e) {
		throw new SlickException("Failed to create new texture for FBO");
	}
}
 
Example #19
Source File: BufferDirectSequentialNumberCellIndex.java    From yosegi with Apache License 2.0 5 votes vote down vote up
@Override
public Set<Integer> getEqual(
    final IDicManager dicManager ,
    final IntBuffer dicIndexIntBuffer ,
    final NumberFilter numberFilter ) throws IOException {
  return null;
}
 
Example #20
Source File: Gl_320_query_conditional.java    From jogl-samples with MIT License 5 votes vote down vote up
@Override
protected boolean begin(GL gl) {

    GL3 gl3 = (GL3) gl;

    boolean validated = true;

    IntBuffer queryCounter = GLBuffers.newDirectIntBuffer(1);
    gl3.glGetQueryiv(GL_SAMPLES_PASSED, GL_QUERY_COUNTER_BITS, queryCounter);

    if (validated) {
        validated = initProgram(gl3);
    }
    if (validated) {
        validated = initBuffer(gl3);
    }
    if (validated) {
        validated = initVertexArray(gl3);
    }
    if (validated) {
        validated = initQuery(gl3);
    }

    BufferUtils.destroyDirectBuffer(queryCounter);

    return validated && checkError(gl3, "begin");
}
 
Example #21
Source File: SoundManager.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
 
Example #22
Source File: DumpArrayColumnBinaryMaker.java    From yosegi with Apache License 2.0 5 votes vote down vote up
/**
 * Manage it as an Array cell.
 */
public ArrayCellManager( final Spread spread , final IntBuffer buffer ) {
  int length = buffer.capacity();
  cellArray = new ICell[length];
  int currentIndex = 0;
  for ( int i = 0 ; i < length ; i++ ) {
    int arrayLength = buffer.get();
    if ( arrayLength != 0 ) {
      int start = currentIndex;
      int end = start + arrayLength;
      cellArray[i] = new ArrayCell( new SpreadArrayLink( spread , i , start , end ) );
      currentIndex += arrayLength;
    }
  }
}
 
Example #23
Source File: OptimizeStringColumnBinaryMaker.java    From multiple-dimension-spread with Apache License 2.0 5 votes vote down vote up
@Override
public IntBuffer getIndexIntBuffer( final int size , final ByteBuffer wrapBuffer ) throws IOException{
  IntBuffer result = IntBuffer.allocate( size );
  for( int i = 0 ; i < size ; i++ ){
    result.put( wrapBuffer.getInt() );
  }
  result.position( 0 );
  return result;
}
 
Example #24
Source File: CodecUtils.java    From metrics with Apache License 2.0 5 votes vote down vote up
public static void decodeBlockPack(
        IntBuffer src,
        IntFilterFactory filterFactory,
        IntBitPacking packer,
        IntOutputStream dst)
{
    // Fetch length of original array.
    if (!src.hasRemaining()) {
        return;
    }
    final int outLen = (int)src.get() - 1;

    // Fetch and output first int, and set it as delta's initial context.
    final int first = src.get();
    dst.write(first);
    IntFilter filter = filterFactory.newFilter(first);

    // Decompress intermediate blocks.
    final int chunkSize = packer.getBlockSize();
    final int chunkNum = outLen / chunkSize;
    if (chunkNum > 0) {
        packer.decompress(src, dst, filter, chunkNum);
    }

    // Decompress last block.
    final int chunkRemain = outLen % chunkSize;
    if (chunkRemain > 0) {
        int[] last = new int[chunkSize];
        IntBuffer buf = IntBuffer.wrap(last);
        packer.decompress(src, new IntBufferOutputStream(buf),
                filter, 1);
        dst.write(last, 0, chunkRemain);
    }
}
 
Example #25
Source File: MappedIO.java    From java-core-learning-example with Apache License 2.0 5 votes vote down vote up
@Override
public void test() throws IOException {
    FileChannel fc = new RandomAccessFile(
            new File("data.txt"),"rw").getChannel();
    IntBuffer ib = fc.map(FileChannel.MapMode.READ_WRITE,
            0,fc.size()).asIntBuffer();
    ib.put(0);
    for (int i = 1; i < numOfUbuffInts; i++)
        ib.put(ib.get(i-1));
    fc.close();
}
 
Example #26
Source File: BufferIndexingLinkerExporter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static GuardedInvocation linkSetElement(final Object self) {
    MethodHandle method = null;
    MethodHandle guard = null;
    if (self instanceof ByteBuffer) {
        method = BYTEBUFFER_PUT;
        guard = IS_BYTEBUFFER;
    } else if (self instanceof CharBuffer) {
        method = CHARBUFFER_PUT;
        guard = IS_CHARBUFFER;
    } else if (self instanceof ShortBuffer) {
        method = SHORTBUFFER_PUT;
        guard = IS_SHORTBUFFER;
    } else if (self instanceof IntBuffer) {
        method = INTBUFFER_PUT;
        guard = IS_INTBUFFER;
    } else if (self instanceof LongBuffer) {
        method = LONGBUFFER_PUT;
        guard = IS_LONGBUFFER;
    } else if (self instanceof FloatBuffer) {
        method = FLOATBUFFER_PUT;
        guard = IS_FLOATBUFFER;
    } else if (self instanceof DoubleBuffer) {
        method = DOUBLEBUFFER_PUT;
        guard = IS_DOUBLEBUFFER;
    }

    return method != null? new GuardedInvocation(method, guard) : null;
}
 
Example #27
Source File: TessAPI1Test.java    From tess4j with Apache License 2.0 5 votes vote down vote up
/**
 * Test of Orientation and script detection (OSD).
 *
 * @throws Exception while processing the image.
 */
@Test
public void testOSD() throws Exception {
    logger.info("OSD");
    int expResult = TessPageSegMode.PSM_AUTO_OSD;
    IntBuffer orientation = IntBuffer.allocate(1);
    IntBuffer direction = IntBuffer.allocate(1);
    IntBuffer order = IntBuffer.allocate(1);
    FloatBuffer deskew_angle = FloatBuffer.allocate(1);
    File imageFile = new File(this.testResourcesDataPath, "eurotext90.png");
    BufferedImage image = ImageIO.read(new FileInputStream(imageFile));
    ByteBuffer buf = ImageIOHelper.convertImageData(image);
    int bpp = image.getColorModel().getPixelSize();
    int bytespp = bpp / 8;
    int bytespl = (int) Math.ceil(image.getWidth() * bpp / 8.0);
    TessAPI1.TessBaseAPIInit3(handle, datapath, language);
    TessAPI1.TessBaseAPISetPageSegMode(handle, expResult);
    int actualResult = TessAPI1.TessBaseAPIGetPageSegMode(handle);
    logger.info("PSM: " + Utils.getConstantName(actualResult, TessPageSegMode.class));
    TessAPI1.TessBaseAPISetImage(handle, buf, image.getWidth(), image.getHeight(), bytespp, bytespl);
    int success = TessAPI1.TessBaseAPIRecognize(handle, null);
    if (success == 0) {
        TessAPI1.TessPageIterator pi = TessAPI1.TessBaseAPIAnalyseLayout(handle);
        TessAPI1.TessPageIteratorOrientation(pi, orientation, direction, order, deskew_angle);
        logger.info(String.format(
                "Orientation: %s\nWritingDirection: %s\nTextlineOrder: %s\nDeskew angle: %.4f\n",
                Utils.getConstantName(orientation.get(), TessOrientation.class),
                Utils.getConstantName(direction.get(), TessWritingDirection.class),
                Utils.getConstantName(order.get(), TessTextlineOrder.class),
                deskew_angle.get()));
    }
    assertEquals(expResult, actualResult);
}
 
Example #28
Source File: SyncBulkTransfer.java    From usb4java-examples with The Unlicense 5 votes vote down vote up
/**
 * Writes some data to the device.
 * 
 * @param handle
 *            The device handle.
 * @param data
 *            The data to send to the device.
 */
public static void write(DeviceHandle handle, byte[] data)
{
    ByteBuffer buffer = BufferUtils.allocateByteBuffer(data.length);
    buffer.put(data);
    IntBuffer transferred = BufferUtils.allocateIntBuffer();
    int result = LibUsb.bulkTransfer(handle, OUT_ENDPOINT, buffer,
        transferred, TIMEOUT);
    if (result != LibUsb.SUCCESS)
    {
        throw new LibUsbException("Unable to send data", result);
    }
    System.out.println(transferred.get() + " bytes sent to device");
}
 
Example #29
Source File: IntCodec.java    From metrics with Apache License 2.0 5 votes vote down vote up
public int[] decompress(byte[] src) {
    IntBuffer srcBuf = ByteBuffer.wrap(src).asIntBuffer();
    int len = decompressLength(srcBuf);
    IntArrayOutputStream dst = (len < 0)
        ? new IntArrayOutputStream() : new IntArrayOutputStream(len);
    decompress(srcBuf, dst);
    return dst.toIntArray();
}
 
Example #30
Source File: JnaUtils.java    From djl with Apache License 2.0 5 votes vote down vote up
public static Device getDevice(Pointer ndArray) {
    IntBuffer deviceType = IntBuffer.allocate(1);
    IntBuffer deviceId = IntBuffer.allocate(1);
    checkNDArray(ndArray, "get the device of");
    checkCall(LIB.MXNDArrayGetContext(ndArray, deviceType, deviceId));
    String deviceTypeStr = MxDeviceType.fromDeviceType(deviceType.get(0));
    // CPU is special case which don't have device id
    return Device.of(deviceTypeStr, deviceId.get(0));
}