box.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #include "common.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif /* __cplusplus */
  20. jlong Java_com_googlecode_leptonica_android_Box_nativeCreate(JNIEnv *env, jclass clazz, jint x,
  21. jint y, jint w, jint h) {
  22. BOX *box = boxCreate((l_int32) x, (l_int32) y, (l_int32) w, (l_int32) h);
  23. return (jlong) box;
  24. }
  25. void Java_com_googlecode_leptonica_android_Box_nativeDestroy(JNIEnv *env, jclass clazz,
  26. jlong nativeBox) {
  27. BOX *box = (BOX *) nativeBox;
  28. boxDestroy(&box);
  29. }
  30. jint Java_com_googlecode_leptonica_android_Box_nativeGetX(JNIEnv *env, jclass clazz, jlong nativeBox) {
  31. BOX *box = (BOX *) nativeBox;
  32. return (jint) box->x;
  33. }
  34. jint Java_com_googlecode_leptonica_android_Box_nativeGetY(JNIEnv *env, jclass clazz, jlong nativeBox) {
  35. BOX *box = (BOX *) nativeBox;
  36. return (jint) box->y;
  37. }
  38. jint Java_com_googlecode_leptonica_android_Box_nativeGetWidth(JNIEnv *env, jclass clazz,
  39. jlong nativeBox) {
  40. BOX *box = (BOX *) nativeBox;
  41. return (jint) box->w;
  42. }
  43. jint Java_com_googlecode_leptonica_android_Box_nativeGetHeight(JNIEnv *env, jclass clazz,
  44. jlong nativeBox) {
  45. BOX *box = (BOX *) nativeBox;
  46. return (jint) box->h;
  47. }
  48. jboolean Java_com_googlecode_leptonica_android_Box_nativeGetGeometry(JNIEnv *env, jclass clazz,
  49. jlong nativeBox,
  50. jintArray dimensions) {
  51. BOX *box = (BOX *) nativeBox;
  52. jint *dimensionArray = env->GetIntArrayElements(dimensions, NULL);
  53. l_int32 x, y, w, h;
  54. if (boxGetGeometry(box, &x, &y, &w, &h)) {
  55. return JNI_FALSE;
  56. }
  57. dimensionArray[0] = x;
  58. dimensionArray[1] = y;
  59. dimensionArray[2] = w;
  60. dimensionArray[3] = h;
  61. env->ReleaseIntArrayElements(dimensions, dimensionArray, 0);
  62. return JNI_TRUE;
  63. }
  64. #ifdef __cplusplus
  65. }
  66. #endif /* __cplusplus */