Search in sources :

Example 41 with Pointer

use of com.sun.jna.Pointer in project sldeditor by robward-scisys.

the class ImportMXD method convert.

/**
 * Read mxd and write out the json file.
 *
 * @param fileData the file data
 */
public void convert(FileData fileData) {
    if (fileData == null) {
        return;
    }
    // Get all the known conversion classes
    RegisterClasses.initialise(data);
    System.out.println("Reading MXD : " + fileData.getInputFile().getAbsolutePath());
    SystemWin sWin = new SystemWin();
    Pointer obj = sWin.getDesktopWindow();
    int hWnd = obj.getInt(0);
    try {
        System.out.println("Opening mxd...");
        IMapDocument mapDocument = new MapDocument();
        String password = null;
        mapDocument.open(fileData.getInputFile().getAbsolutePath(), password);
        IPageLayout iPageLayout = mapDocument.getPageLayout();
        IActiveView activeView = (IActiveView) iPageLayout;
        IMap iMap = activeView.getFocusMap();
        activeView.activate(hWnd);
        JsonArray jsonLayerlist = new JsonArray();
        int count = 1;
        int total = 0;
        // Find total number of layers
        IEnumLayer layerEnum = iMap.getLayers(null, true);
        ILayer layer = layerEnum.next();
        while (layer != null) {
            layer = layerEnum.next();
            total++;
        }
        // Now work through all the layers
        layerEnum = iMap.getLayers(null, true);
        layer = layerEnum.next();
        ParseLayer parseLayer = new ParseLayer(data);
        while (layer != null) {
            parseLayer.convertLayer(count, total, jsonLayerlist, layer, (Map) iMap);
            layer = layerEnum.next();
            count++;
        }
        JsonObject jsonMXDObject = new JsonObject();
        jsonMXDObject.addProperty("mxd", mapDocument.getDocumentFilename());
        jsonMXDObject.add("layers", jsonLayerlist);
        outputJSON(jsonMXDObject, fileData.getOutputFile());
        System.out.println("Written JSON file : " + fileData.getOutputFile().getAbsolutePath());
    } catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : IMapDocument(com.esri.arcgis.carto.IMapDocument) IPageLayout(com.esri.arcgis.carto.IPageLayout) UnknownHostException(java.net.UnknownHostException) ILayer(com.esri.arcgis.carto.ILayer) JsonObject(com.google.gson.JsonObject) Pointer(com.sun.jna.Pointer) IActiveView(com.esri.arcgis.carto.IActiveView) IOException(java.io.IOException) JsonArray(com.google.gson.JsonArray) IMap(com.esri.arcgis.carto.IMap) IMapDocument(com.esri.arcgis.carto.IMapDocument) MapDocument(com.esri.arcgis.carto.MapDocument) IEnumLayer(com.esri.arcgis.carto.IEnumLayer)

Example 42 with Pointer

use of com.sun.jna.Pointer in project rocketmq by apache.

the class MappedFile method munlock.

public void munlock() {
    final long beginTime = System.currentTimeMillis();
    final long address = ((DirectBuffer) (this.mappedByteBuffer)).address();
    Pointer pointer = new Pointer(address);
    int ret = LibC.INSTANCE.munlock(pointer, new NativeLong(this.fileSize));
    log.info("munlock {} {} {} ret = {} time consuming = {}", address, this.fileName, this.fileSize, ret, System.currentTimeMillis() - beginTime);
}
Also used : DirectBuffer(sun.nio.ch.DirectBuffer) NativeLong(com.sun.jna.NativeLong) Pointer(com.sun.jna.Pointer)

Example 43 with Pointer

use of com.sun.jna.Pointer in project tess4j by nguyenq.

the class Tesseract method getWords.

/**
 * Gets recognized words at specified page iterator level.
 *
 * @param bi input image
 * @param pageIteratorLevel TessPageIteratorLevel enum
 * @return list of <code>Word</code>
 */
@Override
public List<Word> getWords(BufferedImage bi, int pageIteratorLevel) {
    this.init();
    this.setTessVariables();
    List<Word> words = new ArrayList<Word>();
    try {
        setImage(bi, null);
        api.TessBaseAPIRecognize(handle, null);
        TessResultIterator ri = api.TessBaseAPIGetIterator(handle);
        TessPageIterator pi = api.TessResultIteratorGetPageIterator(ri);
        api.TessPageIteratorBegin(pi);
        do {
            Pointer ptr = api.TessResultIteratorGetUTF8Text(ri, pageIteratorLevel);
            String text = ptr.getString(0);
            api.TessDeleteText(ptr);
            float confidence = api.TessResultIteratorConfidence(ri, pageIteratorLevel);
            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();
            Word word = new Word(text, confidence, new Rectangle(left, top, right - left, bottom - top));
            words.add(word);
        } while (api.TessPageIteratorNext(pi, pageIteratorLevel) == TRUE);
        return words;
    } catch (Exception e) {
        return words;
    } finally {
        dispose();
    }
}
Also used : TessResultIterator(net.sourceforge.tess4j.ITessAPI.TessResultIterator) TessPageIterator(net.sourceforge.tess4j.ITessAPI.TessPageIterator) IntBuffer(java.nio.IntBuffer) Rectangle(java.awt.Rectangle) Pointer(com.sun.jna.Pointer)

Example 44 with Pointer

use of com.sun.jna.Pointer in project tess4j by nguyenq.

the class Tesseract method getOCRText.

/**
 * Gets recognized text.
 *
 * @param filename input file name. Needed only for reading a UNLV zone
 * file.
 * @param pageNum page number; needed for hocr paging.
 * @return the recognized text
 */
protected String getOCRText(String filename, int pageNum) {
    if (filename != null && !filename.isEmpty()) {
        api.TessBaseAPISetInputName(handle, filename);
    }
    Pointer utf8Text = renderedFormat == RenderedFormat.HOCR ? api.TessBaseAPIGetHOCRText(handle, pageNum - 1) : api.TessBaseAPIGetUTF8Text(handle);
    String str = utf8Text.getString(0);
    api.TessDeleteText(utf8Text);
    return str;
}
Also used : Pointer(com.sun.jna.Pointer)

Example 45 with Pointer

use of com.sun.jna.Pointer in project tess4j by nguyenq.

the class Tesseract1 method getWords.

/**
 * Gets recognized words at specified page iterator level.
 *
 * @param bi input image
 * @param pageIteratorLevel TessPageIteratorLevel enum
 * @return list of <code>Word</code>
 */
@Override
public List<Word> getWords(BufferedImage bi, int pageIteratorLevel) {
    this.init();
    this.setTessVariables();
    List<Word> words = new ArrayList<Word>();
    try {
        setImage(bi, null);
        TessBaseAPIRecognize(handle, null);
        TessResultIterator ri = TessBaseAPIGetIterator(handle);
        TessPageIterator pi = TessResultIteratorGetPageIterator(ri);
        TessPageIteratorBegin(pi);
        do {
            Pointer ptr = TessResultIteratorGetUTF8Text(ri, pageIteratorLevel);
            String text = ptr.getString(0);
            TessAPI1.TessDeleteText(ptr);
            float confidence = TessResultIteratorConfidence(ri, pageIteratorLevel);
            IntBuffer leftB = IntBuffer.allocate(1);
            IntBuffer topB = IntBuffer.allocate(1);
            IntBuffer rightB = IntBuffer.allocate(1);
            IntBuffer bottomB = IntBuffer.allocate(1);
            TessPageIteratorBoundingBox(pi, pageIteratorLevel, leftB, topB, rightB, bottomB);
            int left = leftB.get();
            int top = topB.get();
            int right = rightB.get();
            int bottom = bottomB.get();
            Word word = new Word(text, confidence, new Rectangle(left, top, right - left, bottom - top));
            words.add(word);
        } while (TessPageIteratorNext(pi, pageIteratorLevel) == TRUE);
        return words;
    } catch (Exception e) {
        return words;
    } finally {
        dispose();
    }
}
Also used : IntBuffer(java.nio.IntBuffer) Rectangle(java.awt.Rectangle) Pointer(com.sun.jna.Pointer)

Aggregations

Pointer (com.sun.jna.Pointer)152 PointerByReference (com.sun.jna.ptr.PointerByReference)31 Test (org.junit.Test)31 Memory (com.sun.jna.Memory)23 File (java.io.File)21 ByteBuffer (java.nio.ByteBuffer)18 NativeLong (com.sun.jna.NativeLong)17 IntByReference (com.sun.jna.ptr.IntByReference)17 BufferedImage (java.awt.image.BufferedImage)15 FileInputStream (java.io.FileInputStream)11 HDDEDATA (com.sun.jna.platform.win32.Ddeml.HDDEDATA)8 HSZ (com.sun.jna.platform.win32.Ddeml.HSZ)8 DirectBuffer (sun.nio.ch.DirectBuffer)8 HCONV (com.sun.jna.platform.win32.Ddeml.HCONV)7 ConnectHandler (com.sun.jna.platform.win32.DdemlUtil.ConnectHandler)7 IDdeConnection (com.sun.jna.platform.win32.DdemlUtil.IDdeConnection)7 StandaloneDdeClient (com.sun.jna.platform.win32.DdemlUtil.StandaloneDdeClient)7 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)7 IOException (java.io.IOException)7 CountDownLatch (java.util.concurrent.CountDownLatch)7