/ocr/ocrservice/jni/imageutils/blur-jni.cpp

http://eyes-free.googlecode.com/ · C++ · 57 lines · 30 code · 11 blank · 16 comment · 0 complexity · 1b8d67ba11c90e4308a62b5364c11fdb MD5 · raw file

  1. /*
  2. * Copyright 2011, Google Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. // Author: Xiaotao Duan
  17. #include <jni.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include "types.h"
  21. #include "time_log.h"
  22. #include "blur.h"
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. JNIEXPORT jboolean JNICALL
  27. Java_com_googlecode_eyesfree_opticflow_ImageBlur_isBlurred(
  28. JNIEnv* env, jclass clazz, jbyteArray input, jint width, jint height);
  29. #ifdef __cplusplus
  30. }
  31. #endif
  32. JNIEXPORT jboolean JNICALL
  33. Java_com_googlecode_eyesfree_opticflow_ImageBlur_isBlurred(
  34. JNIEnv* env, jclass clazz, jbyteArray input, jint width, jint height) {
  35. jboolean inputCopy = JNI_FALSE;
  36. jbyte* const i = env->GetByteArrayElements(input, &inputCopy);
  37. float blur = 0;
  38. float extent = 0;
  39. resetTimeLog();
  40. int blurred = IsBlurred(reinterpret_cast<uint8*>(i),
  41. width, height, &blur, &extent);
  42. timeLog("Finished image blur detection");
  43. printTimeLog();
  44. env->ReleaseByteArrayElements(input, i, JNI_ABORT);
  45. return blurred ? JNI_TRUE : JNI_FALSE;
  46. }