Java Code Examples for com.sun.jna.ptr.PointerByReference#setValue()

The following examples show how to use com.sun.jna.ptr.PointerByReference#setValue() . 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: MockMxnetLibrary.java    From djl with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public int MXNDArrayCreateEx(
        int[] shape,
        int ndim,
        int dev_type,
        int dev_id,
        int delay_alloc,
        int dtype,
        PointerByReference out) {
    if (functions.containsKey("MXNDArrayCreateEx")) {
        return functions
                .get("MXNDArrayCreateEx")
                .apply(new Object[] {shape, ndim, dev_type, dev_id, delay_alloc, dtype, out});
    }

    out.setValue(new PointerArray());
    return 0;
}
 
Example 2
Source File: LeptUtilsTest.java    From lept4j with Apache License 2.0 6 votes vote down vote up
/**
 * Test of convertPixToImage method, of class LeptUtils.
 *
 * @throws java.lang.Exception
 */
@Test
public void testConvertPixToImage() throws Exception {
    System.out.println("convertPixToImage");
    File input = new File(testResourcesPath, "eurotext.png");
    Leptonica leptInstance = Leptonica.INSTANCE;
    Pix pix = leptInstance.pixRead(input.getPath());
    BufferedImage result = LeptUtils.convertPixToImage(pix);
    assertEquals(pix.w, result.getWidth());
    assertEquals(pix.h, result.getHeight());
    assertEquals(pix.d, result.getColorModel().getPixelSize());
    System.out.println(String.format("Image properties: width=%d, height=%d, depth=%d", result.getWidth(), result.getHeight(), result.getColorModel().getPixelSize()));
    PointerByReference pRef = new PointerByReference();
    pRef.setValue(pix.getPointer());
    leptInstance.pixDestroy(pRef);
}
 
Example 3
Source File: TessAPITest.java    From tess4j with Apache License 2.0 6 votes vote down vote up
/**
 * Test of TessBaseAPIGetUTF8Text method, of class TessAPI.
 *
 * @throws java.lang.Exception
 */
@Test
public void testTessBaseAPIGetUTF8Text_Pix() throws Exception {
    logger.info("TessBaseAPIGetUTF8Text_Pix");
    String expResult = expOCRResult;
    File tiff = new File(this.testResourcesDataPath, "eurotext.tif");
    Leptonica leptInstance = Leptonica.INSTANCE;
    Pix pix = leptInstance.pixRead(tiff.getPath());
    api.TessBaseAPIInit3(handle, datapath, language);
    api.TessBaseAPISetImage2(handle, pix);
    Pointer utf8Text = api.TessBaseAPIGetUTF8Text(handle);
    String result = utf8Text.getString(0);
    api.TessDeleteText(utf8Text);
    logger.info(result);

    //release Pix resource
    PointerByReference pRef = new PointerByReference();
    pRef.setValue(pix.getPointer());
    leptInstance.pixDestroy(pRef);

    assertTrue(result.startsWith(expResult));
}
 
Example 4
Source File: MockMxnetLibrary.java    From djl with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public int NNSymbolListInputNames(
        Pointer symbol, int option, IntBuffer out_size, PointerByReference out_str_array) {
    if (functions.containsKey("NNSymbolListInputNames")) {
        return functions
                .get("NNSymbolListInputNames")
                .apply(new Object[] {symbol, option, out_size, out_str_array});
    }

    out_size.put(0, 5);
    PointerArray ndarrays =
            new PointerArray(
                    TestHelper.toPointer("a"),
                    TestHelper.toPointer("b"),
                    TestHelper.toPointer("c"),
                    TestHelper.toPointer("d"),
                    TestHelper.toPointer("e"));
    out_str_array.setValue(ndarrays);
    return 0;
}
 
Example 5
Source File: MockMxnetLibrary.java    From djl with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public int MXInvokeCachedOp(
        Pointer handle,
        int num_inputs,
        Pointer inputs,
        IntBuffer num_outputs,
        PointerByReference outputs) {
    if (functions.containsKey("MXInvokeCachedOp")) {
        return functions
                .get("MXInvokeCachedOp")
                .apply(new Object[] {handle, num_inputs, inputs, num_outputs, outputs});
    }

    num_outputs.put(0, 3);
    PointerArray arr =
            new PointerArray(
                    TestHelper.toPointer("a"),
                    TestHelper.toPointer("b"),
                    TestHelper.toPointer("c"));
    outputs.setValue(arr);
    return 0;
}
 
Example 6
Source File: MockMxnetLibrary.java    From djl with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public int MXListAllOpNames(IntBuffer out_size, PointerByReference out_array) {
    if (functions.containsKey("MXListAllOpNames")) {
        return functions.get("MXListAllOpNames").apply(new Object[] {out_size, out_array});
    }

    PointerArray pa =
            new PointerArray(
                    TestHelper.toPointer("softmax"),
                    TestHelper.toPointer("_npi_copyto"),
                    TestHelper.toPointer("_np_zeros_like"));
    out_size.put(0, 3);
    out_array.setValue(pa);
    return 0;
}
 
Example 7
Source File: LeptUtilsTest.java    From lept4j with Apache License 2.0 5 votes vote down vote up
/**
 * Test of convertImageToPix method, of class LeptUtils.
 *
 * @throws java.lang.Exception
 */
@Test
public void testConvertImageToPix() throws Exception {
    System.out.println("convertImageToPix");
    File input = new File(testResourcesPath, "eurotext.png");
    BufferedImage image = ImageIO.read(new FileInputStream(input));
    Pix result = LeptUtils.convertImageToPix(image);
    assertEquals(image.getWidth(), result.w);
    assertEquals(image.getHeight(), result.h);
    assertEquals(image.getColorModel().getPixelSize(), result.d);
    System.out.println(String.format("Image properties: width=%d, height=%d, depth=%d", result.w, result.h, result.d));
    PointerByReference pRef = new PointerByReference();
    pRef.setValue(result.getPointer());
    Leptonica1.pixDestroy(pRef);
}
 
Example 8
Source File: TessAPITest.java    From tess4j with Apache License 2.0 5 votes vote down vote up
/**
 * Test of TessBaseAPIAnalyseLayout method, of class TessAPI.
 *
 * @throws java.lang.Exception
 */
@Test
public void testTessBaseAPIAnalyseLayout() throws Exception {
    logger.info("TessBaseAPIAnalyseLayout");
    File image = new File(testResourcesDataPath, "eurotext.png");
    int expResult = 12; // number of lines in the test image
    Leptonica leptInstance = Leptonica.INSTANCE;
    Pix pix = leptInstance.pixRead(image.getPath());
    api.TessBaseAPIInit3(handle, datapath, language);
    api.TessBaseAPISetImage2(handle, pix);
    int pageIteratorLevel = TessPageIteratorLevel.RIL_TEXTLINE;
    logger.info("PageIteratorLevel: " + Utils.getConstantName(pageIteratorLevel, TessPageIteratorLevel.class));
    int i = 0;
    TessPageIterator pi = api.TessBaseAPIAnalyseLayout(handle);

    do {
        IntBuffer leftB = IntBuffer.allocate(1);
        IntBuffer topB = IntBuffer.allocate(1);
        IntBuffer rightB = IntBuffer.allocate(1);
        IntBuffer bottomB = IntBuffer.allocate(1);
        api.TessPageIteratorBoundingBox(pi, pageIteratorLevel, leftB, topB, rightB, bottomB);
        int left = leftB.get();
        int top = topB.get();
        int right = rightB.get();
        int bottom = bottomB.get();
        logger.info(String.format("Box[%d]: x=%d, y=%d, w=%d, h=%d", i++, left, top, right - left, bottom - top));
    } while (api.TessPageIteratorNext(pi, pageIteratorLevel) == TRUE);
    api.TessPageIteratorDelete(pi);
    PointerByReference pRef = new PointerByReference();
    pRef.setValue(pix.getPointer());
    leptInstance.pixDestroy(pRef);
    assertEquals(expResult, i);
}
 
Example 9
Source File: SecureStorageManagerTest.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
@Override
public boolean CredReadW(String targetName, int type, int flags, PointerByReference pcred)
{
  Pointer target = MockWindowsCredentialManager.getCredential(targetName);
  pcred.setValue(target);
  return target == null ? false : true;
}
 
Example 10
Source File: TessAPITest.java    From tess4j with Apache License 2.0 5 votes vote down vote up
/**
 * Test of TessBaseAPIDetectOrientationScript method, of class TessAPI.
 *
 * @throws java.lang.Exception
 */
@Test
public void testTessBaseAPIDetectOrientationScript() throws Exception {
    logger.info("TessBaseAPIDetectOrientationScript");
    File image = new File(testResourcesDataPath, "eurotext90.png");
    int expResult = TRUE;
    Leptonica leptInstance = Leptonica.INSTANCE;
    Pix pix = leptInstance.pixRead(image.getPath());
    api.TessBaseAPIInit3(handle, datapath, "osd");
    api.TessBaseAPISetImage2(handle, pix);

    IntBuffer orient_degB = IntBuffer.allocate(1);
    FloatBuffer orient_confB = FloatBuffer.allocate(1);
    PointerByReference script_nameB = new PointerByReference();
    FloatBuffer script_confB = FloatBuffer.allocate(1);

    int result = api.TessBaseAPIDetectOrientationScript(handle, orient_degB, orient_confB, script_nameB, script_confB);
    if (result == TRUE) {
        int orient_deg = orient_degB.get();
        float orient_conf = orient_confB.get();
        String script_name = script_nameB.getValue().getString(0);
        float script_conf = script_confB.get();
        logger.info(String.format("OrientationScript: orient_deg=%d, orient_conf=%f, script_name=%s, script_conf=%f", orient_deg, orient_conf, script_name, script_conf));
    }

    PointerByReference pRef = new PointerByReference();
    pRef.setValue(pix.getPointer());
    leptInstance.pixDestroy(pRef);
    assertEquals(expResult, result);
}
 
Example 11
Source File: MockMxnetLibrary.java    From djl with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public int MXSymbolCreateFromFile(String fname, PointerByReference out) {
    if (functions.containsKey("MXSymbolCreateFromFile")) {
        return functions.get("MXSymbolCreateFromFile").apply(new Object[] {fname, out});
    }

    out.setValue(new PointerArray());
    return 0;
}
 
Example 12
Source File: MockMxnetLibrary.java    From djl with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public int MXInvokeCachedOpEx(
        Pointer handle,
        int num_inputs,
        Pointer inputs,
        IntBuffer num_outputs,
        PointerByReference outputs,
        PointerByReference out_stypes) {
    if (functions.containsKey("MXInvokeCachedOpEx")) {
        return functions
                .get("MXInvokeCachedOpEx")
                .apply(
                        new Object[] {
                            handle, num_inputs, inputs, num_outputs, outputs, out_stypes
                        });
    }

    num_outputs.put(0, 3);
    PointerArray arr =
            new PointerArray(
                    TestHelper.toPointer("a"),
                    TestHelper.toPointer("b"),
                    TestHelper.toPointer("c"));
    outputs.setValue(arr);
    Pointer sTypes = TestHelper.toPointer(new int[] {0, 0, 1});
    out_stypes.setValue(sTypes);
    return 0;
}
 
Example 13
Source File: TessAPI1Test.java    From tess4j with Apache License 2.0 5 votes vote down vote up
/**
 * Test of TessBaseAPIAnalyseLayout method, of class TessAPI1.
 *
 * @throws java.lang.Exception
 */
@Test
public void testTessBaseAPIAnalyseLayout() throws Exception {
    logger.info("TessBaseAPIAnalyseLayout");
    File image = new File(testResourcesDataPath, "eurotext.png");
    int expResult = 12; // number of lines in the test image
    Pix pix = Leptonica1.pixRead(image.getPath());
    TessAPI1.TessBaseAPIInit3(handle, datapath, language);
    TessAPI1.TessBaseAPISetImage2(handle, pix);
    int pageIteratorLevel = TessPageIteratorLevel.RIL_TEXTLINE;
    logger.info("PageIteratorLevel: " + Utils.getConstantName(pageIteratorLevel, TessPageIteratorLevel.class));
    int i = 0;
    TessPageIterator pi = TessAPI1.TessBaseAPIAnalyseLayout(handle);

    do {
        IntBuffer leftB = IntBuffer.allocate(1);
        IntBuffer topB = IntBuffer.allocate(1);
        IntBuffer rightB = IntBuffer.allocate(1);
        IntBuffer bottomB = IntBuffer.allocate(1);
        TessAPI1.TessPageIteratorBoundingBox(pi, pageIteratorLevel, leftB, topB, rightB, bottomB);
        int left = leftB.get();
        int top = topB.get();
        int right = rightB.get();
        int bottom = bottomB.get();
        logger.info(String.format("Box[%d]: x=%d, y=%d, w=%d, h=%d", i++, left, top, right - left, bottom - top));
    } while (TessAPI1.TessPageIteratorNext(pi, pageIteratorLevel) == TRUE);
    TessAPI1.TessPageIteratorDelete(pi);
    PointerByReference pRef = new PointerByReference();
    pRef.setValue(pix.getPointer());
    Leptonica1.pixDestroy(pRef);
    assertEquals(expResult, i);
}
 
Example 14
Source File: MockMxnetLibrary.java    From djl with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public int MXCreateCachedOpEx(
        Pointer handle, int num_flags, String[] keys, String[] vals, PointerByReference out) {
    if (functions.containsKey("MXCreateCachedOpEx")) {
        return functions
                .get("MXCreateCachedOpEx")
                .apply(new Object[] {handle, num_flags, keys, vals, out});
    }

    out.setValue(TestHelper.toPointer("This is a cachedOp"));
    return 0;
}
 
Example 15
Source File: MockMxnetLibrary.java    From djl with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public int MXImperativeInvokeEx(
        Pointer creator,
        int num_inputs,
        PointerArray inputs,
        IntBuffer num_outputs,
        PointerByReference outputs,
        int num_params,
        String[] param_keys,
        String[] param_vals,
        PointerByReference out_stypes) {
    if (functions.containsKey("MXImperativeInvokeEx")) {
        return functions
                .get("MXImperativeInvokeEx")
                .apply(
                        new Object[] {
                            creator,
                            num_inputs,
                            inputs,
                            num_outputs,
                            outputs,
                            num_params,
                            param_keys,
                            param_vals,
                            out_stypes
                        });
    }
    num_outputs.put(1);
    outputs.setValue(new PointerArray(TestHelper.toPointer("test")));
    out_stypes.setValue(TestHelper.toPointer(new int[] {1}));
    return 0;
}
 
Example 16
Source File: MockMxnetLibrary.java    From djl with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public int MXNDArrayGetShapeEx64(
        Pointer handle, IntBuffer out_dim, PointerByReference out_pdata) {
    if (functions.containsKey("MXNDArrayGetShapeEx64")) {
        return functions
                .get("MXNDArrayGetShapeEx64")
                .apply(new Object[] {handle, out_dim, out_pdata});
    }

    out_dim.put(0, 3);
    Pointer ptr = TestHelper.toPointer(new int[] {1, 2, 3});
    out_pdata.setValue(ptr);
    return 0;
}
 
Example 17
Source File: MockMxnetLibrary.java    From djl with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public int MXNDArrayGetShapeEx(
        Pointer handle, IntBuffer out_dim, PointerByReference out_pdata) {
    if (functions.containsKey("MXNDArrayGetShapeEx")) {
        return functions
                .get("MXNDArrayGetShapeEx")
                .apply(new Object[] {handle, out_dim, out_pdata});
    }

    out_dim.put(0, 3);
    Pointer ptr = TestHelper.toPointer(new int[] {1, 2, 3});
    out_pdata.setValue(ptr);
    return 0;
}
 
Example 18
Source File: TessAPI1Test.java    From tess4j with Apache License 2.0 5 votes vote down vote up
/**
 * Test of TessBaseAPIDetectOrientationScript method, of class TessAPI1.
 *
 * @throws java.lang.Exception
 */
@Test
public void testTessBaseAPIDetectOrientationScript() throws Exception {
    logger.info("TessBaseAPIDetectOrientationScript");
    File image = new File(testResourcesDataPath, "eurotext90.png");
    int expResult = TRUE;
    Pix pix = Leptonica1.pixRead(image.getPath());
    TessAPI1.TessBaseAPIInit3(handle, datapath, "osd");
    TessAPI1.TessBaseAPISetImage2(handle, pix);

    IntBuffer orient_degB = IntBuffer.allocate(1);
    FloatBuffer orient_confB = FloatBuffer.allocate(1);
    PointerByReference script_nameB = new PointerByReference();
    FloatBuffer script_confB = FloatBuffer.allocate(1);

    int result = TessAPI1.TessBaseAPIDetectOrientationScript(handle, orient_degB, orient_confB, script_nameB, script_confB);
    if (result == TRUE) {
        int orient_deg = orient_degB.get();
        float orient_conf = orient_confB.get();
        String script_name = script_nameB.getValue().getString(0);
        float script_conf = script_confB.get();
        logger.info(String.format("OrientationScript: orient_deg=%d, orient_conf=%f, script_name=%s, script_conf=%f", orient_deg, orient_conf, script_name, script_conf));
    }

    PointerByReference pRef = new PointerByReference();
    pRef.setValue(pix.getPointer());
    Leptonica1.pixDestroy(pRef);
    assertEquals(expResult, result);
}
 
Example 19
Source File: MockMxnetLibrary.java    From djl with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public int MXNDArrayLoad(
        String fname,
        IntBuffer out_size,
        PointerByReference out_arr,
        IntBuffer out_name_size,
        PointerByReference out_names) {
    if (functions.containsKey("MXNDArrayLoad")) {
        return functions
                .get("MXNDArrayLoad")
                .apply(new Object[] {fname, out_size, out_arr, out_name_size, out_names});
    }

    out_size.put(0, 3);
    out_name_size.put(0, 3);

    PointerArray ndarrays =
            new PointerArray(
                    TestHelper.toPointer("A:" + fname),
                    TestHelper.toPointer("B:b"),
                    TestHelper.toPointer("C:c"));
    PointerArray names =
            new PointerArray(
                    TestHelper.toPointer("A:" + fname),
                    TestHelper.toPointer("B:b"),
                    TestHelper.toPointer("C:c"));

    out_arr.setValue(ndarrays);
    out_names.setValue(names);
    return 0;
}
 
Example 20
Source File: LeptUtils.java    From lept4j with Apache License 2.0 4 votes vote down vote up
/**
 * Disposes of Leptonica native resource.
 *
 * @param resource A Leptonica object, such as <code>Pix</code>,
 * <code>Pixa</code>, <code>Box</code>, <code>Boxa</code>,
 * <code>PixColormap</code>, etc.
 */
public static void dispose(Structure resource) {
    if (resource == null) {
        return;
    }
    PointerByReference pRef = new PointerByReference();
    pRef.setValue(resource.getPointer());

    if (resource instanceof Pix) {
        Leptonica1.pixDestroy(pRef);
    } else if (resource instanceof Pixa) {
        Leptonica1.pixaDestroy(pRef);
    } else if (resource instanceof Box) {
        Leptonica1.boxDestroy(pRef);
    } else if (resource instanceof Boxa) {
        Leptonica1.boxaDestroy(pRef);
    } else if (resource instanceof L_Bmf) {
        Leptonica1.bmfDestroy(pRef);
    } else if (resource instanceof L_ByteBuffer) {
        Leptonica1.bbufferDestroy(pRef);
    } else if (resource instanceof Boxaa) {
        Leptonica1.boxaaDestroy(pRef);
    } else if (resource instanceof L_Bytea) {
        Leptonica1.l_byteaDestroy(pRef);
    } else if (resource instanceof CCBorda) {
        Leptonica1.ccbaDestroy(pRef);
    } else if (resource instanceof CCBord) {
        Leptonica1.ccbDestroy(pRef);
    } else if (resource instanceof PixColormap) {
        Leptonica1.pixcmapDestroy(pRef);
    } else if (resource instanceof L_Dewarp) {
        Leptonica1.dewarpDestroy(pRef);
    } else if (resource instanceof L_Dewarpa) {
        Leptonica1.dewarpaDestroy(pRef);
    } else if (resource instanceof L_Dna) {
        Leptonica1.l_dnaDestroy(pRef);
    } else if (resource instanceof L_Dnaa) {
        Leptonica1.l_dnaaDestroy(pRef);
    } else if (resource instanceof L_DnaHash) {
        Leptonica1.l_dnaHashDestroy(pRef);
    } else if (resource instanceof FPix) {
        Leptonica1.fpixDestroy(pRef);
    } else if (resource instanceof FPixa) {
        Leptonica1.fpixaDestroy(pRef);
    } else if (resource instanceof DPix) {
        Leptonica1.dpixDestroy(pRef);
    } else if (resource instanceof GPlot) {
        Leptonica1.gplotDestroy(pRef);
    } else if (resource instanceof JbClasser) {
        Leptonica1.jbClasserDestroy(pRef);
    } else if (resource instanceof JbData) {
        Leptonica1.jbDataDestroy(pRef);
    } else if (resource instanceof L_Kernel) {
        Leptonica1.kernelDestroy(pRef);
    } else if (resource instanceof Numa) {
        Leptonica1.numaDestroy(pRef);
    } else if (resource instanceof Numaa) {
        Leptonica1.numaaDestroy(pRef);
    } else if (resource instanceof Pixaa) {
        Leptonica1.pixaaDestroy(pRef);
    } else if (resource instanceof Pixacc) {
        Leptonica1.pixaccDestroy(pRef);
    } else if (resource instanceof PixComp) {
        Leptonica1.pixcompDestroy(pRef);
    } else if (resource instanceof PixaComp) {
        Leptonica1.pixacompDestroy(pRef);
    } else if (resource instanceof PixTiling) {
        Leptonica1.pixTilingDestroy(pRef);
    } else if (resource instanceof Pta) {
        Leptonica1.ptaDestroy(pRef);
    } else if (resource instanceof Ptaa) {
        Leptonica1.ptaaDestroy(pRef);
    } else if (resource instanceof L_Recog) {
        Leptonica1.recogDestroy(pRef);
    } else if (resource instanceof Sarray) {
        Leptonica1.sarrayDestroy(pRef);
    } else if (resource instanceof Sel) {
        Leptonica1.selDestroy(pRef);
    } else if (resource instanceof Sela) {
        Leptonica1.selaDestroy(pRef);
    } else if (resource instanceof L_Sudoku) {
        Leptonica1.sudokuDestroy(pRef);
    } else if (resource instanceof L_WShed) {
        Leptonica1.wshedDestroy(pRef);
    } else if (resource instanceof DoubleLinkedList) {
        Leptonica1.listDestroy(pRef);
    } else if (resource instanceof L_Rbtree) {
        Leptonica1.l_rbtreeDestroy(pRef);
    } else {
        throw new RuntimeException("Not supported.");
    }
}