示例#1
0
jboolean Java_com_googlecode_leptonica_android_ReadFile_nativeReplaceBytes8(JNIEnv *env,
                                                                            jclass clazz,
                                                                            jlong nativePix,
                                                                            jbyteArray data,
                                                                            jint srcw, jint srch) {
    PIX *pix = (PIX *) nativePix;
    l_int32 w, h, d;

    pixGetDimensions(pix, &w, &h, &d);

    if (d != 8 || (l_int32) srcw != w || (l_int32) srch != h) {
        LOGE("Failed to replace bytes at w=%d, h=%d, d=%d with w=%d, h=%d", w, h, d, srcw, srch);

        return JNI_FALSE;
    }

    l_uint8 **lineptrs = pixSetupByteProcessing(pix, NULL, NULL);
    jbyte *data_buffer = env->GetByteArrayElements(data, NULL);
    l_uint8 *byte_buffer = (l_uint8 *) data_buffer;

    for (int i = 0; i < h; i++) {
        memcpy(lineptrs[i], (byte_buffer + (i * w)), w);
    }

    env->ReleaseByteArrayElements(data, data_buffer, JNI_ABORT);
    pixCleanupByteProcessing(pix, lineptrs);

    return JNI_TRUE;
}
示例#2
0
jint Java_com_googlecode_leptonica_android_ReadFile_nativeReadBytes8(JNIEnv *env, jclass clazz,
                                                                     jbyteArray data, jint w,
                                                                     jint h) {
  LOGV(__FUNCTION__);

  PIX *pix = pixCreateNoInit((l_int32) w, (l_int32) h, 8);
  l_uint8 **lineptrs = pixSetupByteProcessing(pix, NULL, NULL);
  jbyte *data_buffer = env->GetByteArrayElements(data, NULL);
  l_uint8 *byte_buffer = (l_uint8 *) data_buffer;

  for (int i = 0; i < h; i++) {
    memcpy(lineptrs[i], (byte_buffer + (i * w)), w);
  }

  env->ReleaseByteArrayElements(data, data_buffer, JNI_ABORT);
  pixCleanupByteProcessing(pix, lineptrs);

  l_int32 d;

  pixGetDimensions(pix, &w, &h, &d);

  LOGE("Created image width w=%d, h=%d, d=%d", w, h, d);

  return (jint) pix;
}
示例#3
0
jint Java_com_googlecode_leptonica_android_WriteFile_nativeWriteBytes8(JNIEnv *env, jclass clazz,
                                                                       jlong nativePix,
                                                                       jbyteArray data) {
  l_int32 w, h, d;
  PIX *pix = (PIX *) nativePix;
  pixGetDimensions(pix, &w, &h, &d);

  l_uint8 **lineptrs = pixSetupByteProcessing(pix, NULL, NULL);
  jbyte *data_buffer = env->GetByteArrayElements(data, NULL);
  l_uint8 *byte_buffer = (l_uint8 *) data_buffer;

  for (int i = 0; i < h; i++) {
    memcpy((byte_buffer + (i * w)), lineptrs[i], w);
  }

  env->ReleaseByteArrayElements(data, data_buffer, 0);
  pixCleanupByteProcessing(pix, lineptrs);

  return (jint)(w * h);
}