Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
Switch to the public NDK API for bitmap
Browse files Browse the repository at this point in the history
Change-Id: I6a100a55b7fffca4c069461de20364c51c4a06e4
  • Loading branch information
jreck committed Mar 3, 2015
1 parent 55f541b commit f566512
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Android.mk
Expand Up @@ -117,7 +117,7 @@ LOCAL_SHARED_LIBRARIES := \
libnativehelper \
libutils \
liblog \
libskia \
libjnigraphics \
libcutils

LOCAL_MODULE:= libFFTEm
Expand Down
21 changes: 7 additions & 14 deletions FaceDetector_jni.cpp
Expand Up @@ -24,7 +24,7 @@
#include <utils/String8.h>
#include <utils/Log.h>

#include <SkBitmap.h>
#include <android/bitmap.h>

#include "jni.h"
#include "JNIHelp.h"
Expand Down Expand Up @@ -66,8 +66,6 @@ struct FaceDetectorOffsets
jfieldID bwbuffer;
} gFaceDetectorOffsets;

jfieldID nativeBitmapID;

// ---------------------------------------------------------------------------

static void getFaceData(btk_HDCR hdcr, FaceData* fdata)
Expand Down Expand Up @@ -111,9 +109,6 @@ nativeClassInit
gFaceOffsets.eulerx = _env->GetFieldID(faceClass, "mPoseEulerX", "F");
gFaceOffsets.eulery = _env->GetFieldID(faceClass, "mPoseEulerY", "F");
gFaceOffsets.eulerz = _env->GetFieldID(faceClass, "mPoseEulerZ", "F");

jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
nativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "J");
}

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -209,21 +204,18 @@ detect(JNIEnv *_env, jobject _this,
jbyteArray bwbufferObject = (jbyteArray)
_env->GetObjectField(_this, gFaceDetectorOffsets.bwbuffer);

// get to the native bitmap
SkBitmap const * nativeBitmap =
(SkBitmap const *)_env->GetLongField(bitmap, nativeBitmapID);

// get to our BW temporary buffer
jbyte* bwbuffer = _env->GetByteArrayElements(bwbufferObject, 0);

// convert the image to B/W
uint8_t* dst = (uint8_t*)bwbuffer;

// manage the life-time of locking our pixels
SkAutoLockPixels alp(*nativeBitmap);
uint16_t const* src;
AndroidBitmapInfo bitmapInfo;
AndroidBitmap_getInfo(_env, bitmap, &bitmapInfo);
AndroidBitmap_lockPixels(_env, bitmap, (void**) &src);

uint16_t const* src = (uint16_t const*)nativeBitmap->getPixels();
int wpr = nativeBitmap->rowBytes() / 2;
int wpr = bitmapInfo.stride / 2;
for (u32 y=0 ; y<height; y++) {
for (u32 x=0 ; x<width ; x++) {
uint16_t rgb = src[x];
Expand All @@ -248,6 +240,7 @@ detect(JNIEnv *_env, jobject _this,
}

// release the arrays we're using
AndroidBitmap_unlockPixels(_env, bitmap);
_env->ReleaseByteArrayElements(bwbufferObject, bwbuffer, 0);
return numberOfFaces;
}
Expand Down

0 comments on commit f566512

Please sign in to comment.