JNIEXPORT void JNICALL Java_com_lge_ccdevs_tracker_CameraPreview_native_1cv_1facex
(JNIEnv *env, jobject thiz, jobject srcimg) {
	AndroidBitmapInfo bInfo;
//    uint32_t* bPixs;
    char *bPixs;
	int bRet;
	LOGE("**IN JNI bitmap converter IN!");
	//1. retrieve information about the bitmap
	if ((bRet = AndroidBitmap_getInfo(env, srcimg, &bInfo)) < 0) {
		LOGE("AndroidBitmap_getInfo failed! error = %d", bRet);
		return;
	}
	if (bInfo.format != ANDROID_BITMAP_FORMAT_RGBA_8888) {
		LOGE("Bitmap format is not RGBA_8888!");
		return;
	}

	//2. lock the pixel buffer and retrieve a pointer to it
	if ((bRet = AndroidBitmap_lockPixels(env, srcimg, (void**)&bPixs)) < 0) {
		LOGE("AndroidBitmap_lockPixels() failed! error = %d", bRet);
		return;
	}

	//3. convert bitmap to IplImage
	LOGE("#### Start JNI bitmap processing");
	IplImage* img = cvCreateImage(cvSize(bInfo.width,bInfo.height), IPL_DEPTH_8U, 4);
	memcpy(img->imageData, bPixs, img->imageSize);
	AndroidBitmap_unlockPixels(env, srcimg);

	//4. apply processing
	IplImage* dst = cvCreateImage(cvSize(bInfo.width,bInfo.height), IPL_DEPTH_8U, 4);
	cvCopy(img, dst);

	FaceDetector *detector = new FaceDetector();
	detector->detect_faces(dst);
//	detector->display_faces(dst);

	if(detector->mfaces) {
		FaceAligner *aligner = new FaceAligner();
		CvRect rt_ref = cvRect(0,0,bInfo.width,bInfo.height);
		aligner->align_faces(dst, *(CvRect*)cvGetSeqElem(detector->mfaces,0), rt_ref);
	}

/*
	SkBitmap* bitmap = new SkBitmap;
	bitmap->setConfig(SkBitmap::kARGB_8888_Config, bInfo.width, bInfo.height);
	if( !bitmap->allocPixels() ) {
		android_printLog(ANDROID_LOG_DEBUG, "CheckPoint", "Fail: allocPixels");
		delete bitmap;
		return NULL;
	}

	char *p = (char *)bitmap->getPixels();
	memcpy( p, dst->imageData, dst->imageSize );
*/
	memcpy( bPixs, dst->imageData, dst->imageSize );
	AndroidBitmap_unlockPixels(env, srcimg);

	cvReleaseImage(&img);
	cvReleaseImage(&dst);
	LOGE("#### End processing");

//	return env->NewObject(fields.bitmapClazz, fields.bitmapConstructor, (int)bitmap, p, true, NULL, -1);
	return;
}