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();
}
}
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);
}
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();
}
}
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;
}
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();
}
}
Aggregations