示例#1
0
  void traverse(String tab, HIDP_LINK_COLLECTION_NODE[] nodes, int n, HIDP_PREPARSED_DATA ppd) {
    do {
      visit(tab, nodes, n, ppd);

      short[] plen = {0};
      boolean res = HidP_GetSpecificValueCaps(0, (short) 0, (short) n, (short) 0, null, plen, ppd);
      System.out.println(res + " " + plen[0]);
      int len = plen[0];
      if (len > 0) {
        HIDP_VALUE_CAPS[] valueCaps = new HIDP_VALUE_CAPS[len];
        // for (int i=0; i<len; i++)
        // valueCaps[i]=new HIDP_VALUE_CAPS();
        System.out.println();
        res = HidP_GetSpecificValueCaps(0, (short) 0, (short) n, (short) 0, valueCaps, plen, ppd);
        Pointer p = valueCaps[0].getPointer();
        for (int j = 0; j < valueCaps[0].size(); j++)
          System.out.printf("%02X %d\n", p.getByte(j), p.getByte(j));
        for (int j = 0; j < len; j++)
          System.out.println(
              " usage page "
                  + valueCaps[j].UsagePage
                  + " usage "
                  + valueCaps[j].u.NotRange.Usage
                  + " min "
                  + valueCaps[j].LogicalMin.intValue()
                  + " max "
                  + valueCaps[j].LogicalMax.intValue());
      }

      if (nodes[n].FirstChild != 0) traverse(tab + "   ", nodes, nodes[n].FirstChild, ppd);
    } while (0 != (n = nodes[n].NextSibling));
  }
 /**
  * Gets recognized text.
  *
  * @return the recognized text
  */
 private String getOCRText() {
   Pointer utf8Text =
       hocr ? api.TessBaseAPIGetHOCRText(handle, pageNum - 1) : api.TessBaseAPIGetUTF8Text(handle);
   String str = utf8Text.getString(0);
   api.TessDeleteText(utf8Text);
   return str;
 }
示例#3
0
 @Test
 public void testSizes() {
   MXArray a = createDoubleMatrix(123, 456);
   assertEquals(8L, MXLibrary.INSTANCE.mxGetElementSize(a).longValue());
   assertEquals(123L, MXLibrary.INSTANCE.mxGetM(a).longValue());
   assertEquals(456L, MXLibrary.INSTANCE.mxGetN(a).longValue());
   assertEquals(2L, MXLibrary.INSTANCE.mxGetNumberOfDimensions(a).longValue());
   assertEquals(123L * 456L, MXLibrary.INSTANCE.mxGetNumberOfElements(a).longValue());
   Pointer dims = MXLibrary.INSTANCE.mxGetDimensions(a);
   assertEquals(123L, dims.getNativeLong(0).longValue());
   assertEquals(456L, dims.getNativeLong(NativeLong.SIZE).longValue());
   NativeLong[] subs = null;
   NativeLong singleSub = null;
   // check single subscript of first element
   subs = toNativeLongs(0, 0);
   singleSub = MXLibrary.INSTANCE.mxCalcSingleSubscript(a, new NativeLong(subs.length), subs);
   assertEquals(0L, singleSub.longValue());
   // check single subscript of second element (MATLAB always uses
   // column-major order)
   subs = toNativeLongs(1, 0);
   singleSub = MXLibrary.INSTANCE.mxCalcSingleSubscript(a, new NativeLong(subs.length), subs);
   assertEquals(1L, singleSub.longValue());
   // check single subscript of first element in second row
   subs = toNativeLongs(0, 1);
   singleSub = MXLibrary.INSTANCE.mxCalcSingleSubscript(a, new NativeLong(subs.length), subs);
   assertEquals(123L, singleSub.longValue());
   // check single subscript of last element
   subs = toNativeLongs(122, 455);
   singleSub = MXLibrary.INSTANCE.mxCalcSingleSubscript(a, new NativeLong(subs.length), subs);
   assertEquals(123L * 456L - 1, singleSub.longValue());
   destroy(a);
 }
 public void invoke(
     Pointer streamRef,
     Pointer clientCallBackInfo,
     NativeLong numEvents,
     Pointer eventPaths,
     Pointer eventFlags,
     Pointer eventIds) {
   final long st = System.currentTimeMillis();
   final int length = numEvents.intValue();
   final Pointer[] pointers = eventPaths.getPointerArray(0, length);
   final int[] flags = eventFlags.getIntArray(0, length);
   for (int i = 0; i < length; i++) {
     final Pointer p = pointers[i];
     final int flag = flags[i];
     boolean found = false;
     final String path = p.getString(0);
     final Key key = listensOn.get(path);
     if (key != null) {
       if ((flag & kFSEventStreamEventFlagMustScanSubDirs)
               == kFSEventStreamEventFlagMustScanSubDirs
           || (flag & kFSEventStreamEventFlagMount) == kFSEventStreamEventFlagMount
           || (flag & kFSEventStreamEventFlagUnmount) == kFSEventStreamEventFlagUnmount) {
         events.add(createEvent(key, EventKind.OVERFLOW, path));
       } else {
         events.add(createEvent(key, EventKind.MODIFY, path));
       }
       found = true;
     }
     LOG.log(DEBUG_LOG_LEVEL, "Event on {0} interesting: {1}", new Object[] {path, found});
   }
   LOG.log(PERF_LOG_LEVEL, "Callback time: {0}", (System.currentTimeMillis() - st));
 }
  private static void initialize() {
    if (ApplicationManager.getApplication().isUnitTestMode()) {
      return;
    }

    Ole32 ole32 = Ole32.INSTANCE;
    ole32.CoInitializeEx(Pointer.NULL, 0);

    Guid.GUID CLSID_TaskbarList =
        Ole32Util.getGUIDFromString("{56FDF344-FD6D-11d0-958A-006097C9A090}");
    Guid.GUID IID_ITaskbarList3 =
        Ole32Util.getGUIDFromString("{EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF}");
    PointerByReference p = new PointerByReference();
    ole32.CoCreateInstance(
        CLSID_TaskbarList, Pointer.NULL, ObjBase.CLSCTX_ALL, IID_ITaskbarList3, p);

    myInterfacePointer = p.getValue();
    Pointer vTablePointer = myInterfacePointer.getPointer(0);
    Pointer[] vTable = new Pointer[TaskBarList_Methods];
    vTablePointer.read(0, vTable, 0, vTable.length);

    mySetProgressValue =
        Function.getFunction(vTable[TaskBarList_SetProgressValue], Function.ALT_CONVENTION);
    mySetProgressState =
        Function.getFunction(vTable[TaskBarList_SetProgressState], Function.ALT_CONVENTION);
    mySetOverlayIcon =
        Function.getFunction(vTable[TaskBarList_SetOverlayIcon], Function.ALT_CONVENTION);
  }
示例#6
0
 public static Pointer nativeString(String sql) { // TODO Check encoding?
   byte[] data = sql.getBytes();
   final Pointer pointer = new Memory(data.length + 1);
   pointer.write(0, data, 0, data.length);
   pointer.setByte(data.length, (byte) 0);
   return pointer;
 }
示例#7
0
 public final void putAddress(long offset, long value) {
   checkBounds(offset, ADDRESS_SIZE >> 3);
   if (ADDRESS_SIZE == 32) {
     ptr.setInt(offset, (int) value);
   } else {
     ptr.setLong(offset, value);
   }
 }
示例#8
0
 /**
  * String representation of the buffer.
  *
  * @return Unicode string.
  */
 public String getString() {
   byte[] data = Buffer.getByteArray(0, Length);
   if (data.length < 2 || data[data.length - 1] != 0) {
     Memory newdata = new Memory(data.length + 2);
     newdata.write(0, data, 0, data.length);
     return newdata.getString(0, true);
   }
   return Buffer.getString(0, true);
 }
示例#9
0
文件: Pcaps.java 项目: Mehrkat/pcap4j
  /**
   * @return a name of a network interface.
   * @throws PcapNativeException
   */
  public static String lookupDev() throws PcapNativeException {
    PcapErrbuf errbuf = new PcapErrbuf();
    Pointer result = NativeMappings.pcap_lookupdev(errbuf);

    if (result == null || errbuf.length() != 0) {
      throw new PcapNativeException(errbuf.toString());
    }

    return result.getWideString(0);
  }
示例#10
0
  public String getParameter(String key) {
    logger.trace("Get parameter " + deviceId + ", " + key);
    Pointer pointer = library.tdGetDeviceParameter(deviceId, key, "");
    String value = pointer.getString(0);

    logger.trace("Release parameter " + deviceId);
    library.tdReleaseString(pointer);

    return value;
  }
示例#11
0
 @Test
 public void testArrayToString() {
   String expectedValue = "hello1234";
   MXArray strArray = MXLibrary.INSTANCE.mxCreateString(expectedValue);
   assertTrue(MXLibrary.INSTANCE.mxIsChar(strArray));
   Pointer strPointer = MXLibrary.INSTANCE.mxArrayToString(strArray);
   String actualValue = strPointer.getString(0);
   MXLibrary.INSTANCE.mxFree(strPointer);
   destroy(strArray);
   assertEquals(actualValue, expectedValue);
 }
示例#12
0
 /** {@inheritDoc} */
 @Override
 public boolean isCpu64bit() {
   if (this.cpu64 == null) {
     IntByReference size = new IntByReference(SystemB.INT_SIZE);
     Pointer p = new Memory(size.getValue());
     if (0 != SystemB.INSTANCE.sysctlbyname("hw.cpu64bit_capable", p, size, null, 0)) {
       LOG.error("Failed to get 64Bit_capable. Error code: " + Native.getLastError());
       return false;
     }
     this.cpu64 = p.getInt(0) != 0;
   }
   return this.cpu64.booleanValue();
 }
示例#13
0
 /** {@inheritDoc} */
 @Override
 public String getFamily() {
   if (this.cpuFamily == null) {
     IntByReference size = new IntByReference(SystemB.INT_SIZE);
     Pointer p = new Memory(size.getValue());
     if (0 != SystemB.INSTANCE.sysctlbyname("machdep.cpu.family", p, size, null, 0)) {
       LOG.error("Failed to get Family. Error code: " + Native.getLastError());
       return "";
     }
     this.cpuFamily = Integer.toString(p.getInt(0));
   }
   return this.cpuFamily;
 }
示例#14
0
  /**
   * Test of ChoiceIterator.
   *
   * @throws Exception
   */
  @Test
  public void testChoiceIterator() throws Exception {
    logger.info("TessResultIteratorGetChoiceIterator");
    String filename = String.format("%s/%s", this.testResourcesDataPath, "eurotext.tif");
    File tiff = new File(filename);
    BufferedImage image =
        ImageIO.read(new FileInputStream(tiff)); // require jai-imageio lib to read TIFF
    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.TessBaseAPISetImage(
        handle, buf, image.getWidth(), image.getHeight(), bytespp, bytespl);
    TessAPI1.TessBaseAPISetVariable(handle, "save_blob_choices", "T");
    TessAPI1.TessBaseAPISetRectangle(handle, 37, 228, 548, 31);
    ETEXT_DESC monitor = new ETEXT_DESC();
    ProgressMonitor pmo = new ProgressMonitor(monitor);
    pmo.start();
    TessAPI1.TessBaseAPIRecognize(handle, monitor);
    logger.info("Message: " + pmo.getMessage());
    TessResultIterator ri = TessAPI1.TessBaseAPIGetIterator(handle);
    int level = TessPageIteratorLevel.RIL_SYMBOL;

    if (ri != null) {
      do {
        Pointer symbol = TessAPI1.TessResultIteratorGetUTF8Text(ri, level);
        float conf = TessAPI1.TessResultIteratorConfidence(ri, level);
        if (symbol != null) {
          logger.info(String.format("symbol %s, conf: %f", symbol.getString(0), conf));
          boolean indent = false;
          TessChoiceIterator ci = TessAPI1.TessResultIteratorGetChoiceIterator(ri);
          do {
            if (indent) {
              System.out.print("\t");
            }
            System.out.print("\t- ");
            String choice = TessAPI1.TessChoiceIteratorGetUTF8Text(ci);
            logger.info(
                String.format("%s conf: %f", choice, TessAPI1.TessChoiceIteratorConfidence(ci)));
            indent = true;
          } while (TessAPI1.TessChoiceIteratorNext(ci) == TessAPI1.TRUE);
          TessAPI1.TessChoiceIteratorDelete(ci);
        }
        logger.info("---------------------------------------------");
        TessAPI1.TessDeleteText(symbol);
      } while (TessAPI1.TessResultIteratorNext(ri, level) == TessAPI1.TRUE);
    }

    assertTrue(true);
  }
示例#15
0
  /** Updates logical and physical processor counts from sysctl calls */
  private void calculateProcessorCounts() {
    IntByReference size = new IntByReference(SystemB.INT_SIZE);
    Pointer p = new Memory(size.getValue());

    // Get number of logical processors
    if (0 != SystemB.INSTANCE.sysctlbyname("hw.logicalcpu", p, size, null, 0)) {
      LOG.error("Failed to get number of logical CPUs. Error code: " + Native.getLastError());
      this.logicalProcessorCount = 1;
    } else this.logicalProcessorCount = p.getInt(0);

    // Get number of physical processors
    if (0 != SystemB.INSTANCE.sysctlbyname("hw.physicalcpu", p, size, null, 0)) {
      LOG.error("Failed to get number of physical CPUs. Error code: " + Native.getLastError());
      this.physicalProcessorCount = 1;
    } else this.physicalProcessorCount = p.getInt(0);
  }
  @Test
  public void setArray() {
    float value = 0.5f;
    float[] array = {value, value, value, value};
    String name = "test";

    ssclib.ssc_data_set_array(data, name, array, array.length);
    IntByReference length = new IntByReference();
    Pointer result = ssclib.ssc_data_get_array(data, name, length);

    assertThat(length.getValue()).isEqualTo(array.length);
    for (int i = 0; i < length.getValue(); i++) {
      // Offset is by byte (float = 4 bytes)
      assertThat(result.getFloat(i * 4)).isWithin(EPSILON).of(value);
    }
  }
  /** @see EtherstubHelper#getEtherstubNames() */
  @Override
  public String[] getEtherstubNames() throws EtherstubException {

    logger.debug("Trying to read names of existing etherstubs");

    Pointer pointer = handle.get_etherstub_names();

    if (pointer != null) {

      String[] array = pointer.getStringArray(0);
      handle.free_char_array(pointer);
      return (array != null) ? array : new String[] {};
    } else {
      return new String[] {};
    }
  }
示例#18
0
 public final void putMemoryIO(long offset, MemoryIO value) {
   checkBounds(offset, ADDRESS_SIZE >> 3);
   if (value instanceof BoundedNativeMemoryIO) {
     ptr.setPointer(offset, ((BoundedNativeMemoryIO) value).ptr);
   } else {
     putAddress(offset, ((DirectMemoryIO) value).getAddress());
   }
 }
示例#19
0
 /** {@inheritDoc} */
 @Override
 public String getName() {
   if (this.cpuName == null) {
     IntByReference size = new IntByReference();
     if (0 != SystemB.INSTANCE.sysctlbyname("machdep.cpu.brand_string", null, size, null, 0)) {
       LOG.error("Failed to get Name. Error code: " + Native.getLastError());
       return "";
     }
     Pointer p = new Memory(size.getValue() + 1);
     if (0 != SystemB.INSTANCE.sysctlbyname("machdep.cpu.brand_string", p, size, null, 0)) {
       LOG.error("Failed to get Name. Error code: " + Native.getLastError());
       return "";
     }
     this.cpuName = p.getString(0);
   }
   return this.cpuName;
 }
示例#20
0
 /**
  * Test of TessBaseAPIRect method, of class TessDllAPI1.
  *
  * @throws Exception while processing the image
  */
 @Test
 public void testTessBaseAPIRect() throws Exception {
   logger.info("TessBaseAPIRect");
   String expResult = expOCRResult;
   File tiff = new File(this.testResourcesDataPath, "eurotext.tif");
   BufferedImage image = ImageIO.read(tiff); // require jai-imageio lib to read TIFF
   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, TessPageSegMode.PSM_AUTO);
   Pointer utf8Text = TessAPI1.TessBaseAPIRect(handle, buf, bytespp, bytespl, 0, 0, 1024, 800);
   String result = utf8Text.getString(0);
   TessAPI1.TessDeleteText(utf8Text);
   logger.info(result);
   assertEquals(expResult, result.substring(0, expResult.length()));
 }
示例#21
0
 public static int getProcessID(Process process) {
   long id = getProcessHandle(process);
   if (id != 0) {
     HANDLE handle = new HANDLE();
     handle.setPointer(Pointer.createConstant(id));
     return Kernel32.INSTANCE.GetProcessId(handle);
   }
   return 0;
 }
示例#22
0
 /** {@inheritDoc} */
 @Override
 public long getSystemUptime() {
   IntByReference size = new IntByReference();
   if (0 != SystemB.INSTANCE.sysctlbyname("kern.boottime", null, size, null, 0)) {
     LOG.error("Failed to get Boot Time. Error code: " + Native.getLastError());
     return 0L;
   }
   // This should point to a 16-byte structure. If not, this code is valid
   if (size.getValue() != 16)
     throw new UnsupportedOperationException("sysctl kern.boottime should be 16 bytes but isn't.");
   Pointer p = new Memory(size.getValue() + 1);
   if (0 != SystemB.INSTANCE.sysctlbyname("kern.boottime", p, size, null, 0)) {
     LOG.error("Failed to get Boot Time. Error code: " + Native.getLastError());
     return 0L;
   }
   // p now points to a 16-bit timeval structure for boot time.
   // First 8 bytes are seconds, second 8 bytes are microseconds (ignore)
   return System.currentTimeMillis() / 1000 - p.getLong(0);
 }
示例#23
0
 /**
  * Test of TessBaseAPIGetHOCRText method, of class TessAPI1.
  *
  * @throws Exception while getting ocr text from image.
  */
 @Test
 public void testTessBaseAPIGetHOCRText() throws Exception {
   logger.info("TessBaseAPIGetHOCRText");
   File tiff = new File(this.testResourcesDataPath, "eurotext.tif");
   BufferedImage image =
       ImageIO.read(new FileInputStream(tiff)); // require jai-imageio lib to read TIFF
   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.TessBaseAPISetPageSegMode(handle, TessPageSegMode.PSM_AUTO);
   TessAPI1.TessBaseAPIInit3(handle, datapath, language);
   TessAPI1.TessBaseAPISetImage(
       handle, buf, image.getWidth(), image.getHeight(), bytespp, bytespl);
   int page_number = 0;
   Pointer utf8Text = TessAPI1.TessBaseAPIGetHOCRText(handle, page_number);
   String result = utf8Text.getString(0);
   TessAPI1.TessDeleteText(utf8Text);
   assertTrue(result.contains("<div class='ocr_page'"));
 }
示例#24
0
  @Override
  public void execute() {
    long x = this.params.get(0);

    int nIndex = (int) x;
    HBRUSH ret = User32DLL.INSTANCE.GetSysColorBrush(nIndex);

    long value = (ret == null) ? 0 : Pointer.nativeValue(ret.getPointer());
    register.mov("eax", new LongValue(value));
    System.out.println("Return Value: " + value);
  }
示例#25
0
  public Pointer getHIcon(Pointer hWnd) {
    FuFlags fuFlags = new FuFlags();
    fuFlags.setSMTO_NORMAL();

    try {
      Pointer icon =
          SendMessageTimeoutA(
              hWnd, Messages.WM_GETICON, FType.ICON_SMALL, 0, fuFlags.getFlags(), 20);
      if (icon != null) return u32.CopyIcon(icon);
    } catch (Exception e) {
    }

    try {
      Pointer icon =
          SendMessageTimeoutA(hWnd, Messages.WM_GETICON, FType.ICON_BIG, 0, fuFlags.getFlags(), 20);
      if (icon != null) return u32.CopyIcon(icon);
    } catch (Exception e) {
    }

    try {
      Pointer icon =
          SendMessageTimeoutA(
              hWnd, Messages.WM_GETICON, FType.ICON_SMALL2, 0, fuFlags.getFlags(), 20);
      if (icon != null) return u32.CopyIcon(icon);
    } catch (Exception e) {
    }

    try {
      int hiconSM = GetClassLong(hWnd, GCFlags.GCL_HICONSM);
      if (hiconSM != 0) return u32.CopyIcon(Pointer.createConstant(hiconSM));
    } catch (Exception e) {
    }

    try {
      int hicon = GetClassLong(hWnd, GCFlags.GCL_HICON);
      if (hicon != 0) return u32.CopyIcon(Pointer.createConstant(hicon));
    } catch (Exception e) {
    }

    return null;
  }
示例#26
0
    public List<Word> getTextElements(File file, int pageIteratorLevel) {
      this.init();
      this.setTessVariables();

      List<Word> words = new ArrayList<Word>();
      try {
        BufferedImage bi = ImageIO.read(file);
        setImage(bi, null);

        TessAPI api = this.getAPI();
        api.TessBaseAPIRecognize(this.getHandle(), null);
        TessResultIterator ri = api.TessBaseAPIGetIterator(this.getHandle());
        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 {
        this.dispose();
      }
    }
示例#27
0
  /** try to install our custom rule profile into sandbox_init() to block execution */
  private static void macImpl(Path tmpFile) throws IOException {
    // first be defensive: we can give nice errors this way, at the very least.
    boolean supported = Constants.MAC_OS_X;
    if (supported == false) {
      throw new IllegalStateException(
          "bug: should not be trying to initialize seatbelt for an unsupported OS");
    }

    // we couldn't link methods, could be some really ancient OS X (< Leopard) or some bug
    if (libc_mac == null) {
      throw new UnsupportedOperationException(
          "seatbelt unavailable: could not link methods. requires Leopard or above.");
    }

    // write rules to a temporary file, which will be passed to sandbox_init()
    Path rules = Files.createTempFile(tmpFile, "es", "sb");
    Files.write(rules, Collections.singleton(SANDBOX_RULES));

    boolean success = false;
    try {
      PointerByReference errorRef = new PointerByReference();
      int ret = libc_mac.sandbox_init(rules.toAbsolutePath().toString(), SANDBOX_NAMED, errorRef);
      // if sandbox_init() fails, add the message from the OS (e.g. syntax error) and free the
      // buffer
      if (ret != 0) {
        Pointer errorBuf = errorRef.getValue();
        RuntimeException e =
            new UnsupportedOperationException("sandbox_init(): " + errorBuf.getString(0));
        libc_mac.sandbox_free_error(errorBuf);
        throw e;
      }
      logger.debug("OS X seatbelt initialization successful");
      success = true;
    } finally {
      if (success) {
        Files.delete(rules);
      } else {
        IOUtils.deleteFilesIgnoringExceptions(rules);
      }
    }
  }
示例#28
0
  @Override
  public void execute() {

    // Call the real windows API
    HANDLE handle = Kernel32.INSTANCE.GetCurrentProcess();
    long value = Pointer.nativeValue(handle.getPointer());

    System.out.println("Return Value: " + value);

    // Store
    register.mov("eax", new LongValue(value));
  }
示例#29
0
  /**
   * Test of TessBaseAPIGetUTF8Text method, of class TessAPI1.
   *
   * @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());
    TessAPI1.TessBaseAPIInit3(handle, datapath, language);
    TessAPI1.TessBaseAPISetImage2(handle, pix);
    Pointer utf8Text = TessAPI1.TessBaseAPIGetUTF8Text(handle);
    String result = utf8Text.getString(0);
    TessAPI1.TessDeleteText(utf8Text);
    logger.info(result);

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

    assertEquals(expResult, result.substring(0, expResult.length()));
  }
  @Test
  public void setMatrix() {
    float value = 0.5f;
    int n = 2;
    float[] array = {value, value, value, value};
    String name = "test";

    ssclib.ssc_data_set_matrix(data, name, array, n, n);
    IntByReference rows = new IntByReference();
    IntByReference cols = new IntByReference();
    Pointer result = ssclib.ssc_data_get_matrix(data, name, rows, cols);

    assertThat(rows.getValue()).isEqualTo(n);
    assertThat(cols.getValue()).isEqualTo(n);
    for (int i = 0; i < rows.getValue(); i++) {
      for (int j = 0; j < cols.getValue(); j++) {
        // Offset is by byte (float = 4 bytes)
        assertThat(result.getFloat((i * j + j) * 4)).isWithin(EPSILON).of(value);
      }
    }
  }