Skip to content

Commit

Permalink
update .
Browse files Browse the repository at this point in the history
  • Loading branch information
lambiengcode committed May 28, 2024
1 parent 36ac1d8 commit c37f5e9
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.nio.ByteBuffer;

public class GPUPixel {

Expand Down Expand Up @@ -230,6 +231,8 @@ public static void copyAssetsToFiles(Context context, String oldPath, String ne
// SourceRawDataInput
public static native long nativeSourceRawInputNew();
public static native void nativeSourceRawInputUploadBytes(final long classID, final int[] pixel, final int width, final int height, final int stride);

public static native void nativeWaterbusUploadBytes(final long classID, final ByteBuffer pixel, final int width, final int height, final int stride);
public static native void nativeSourceRawInputSetRotation(final long classID, final int rotation);

// Source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ public void onFaceLandmark(float[] landmarks) {
}
}

public void setFrame(final int[] data, final int width, final int height) {
GPUPixel.getInstance().runOnDraw(new Runnable() {
@Override
public void run() {
GPUPixel.nativeSourceCameraSetFrame(mNativeClassID, width, height, data, GPUPixel.NoRotation);
}
});

proceed(true, true);
}

@Override
public void onPreviewFrame(final byte[] data, Camera camera) {
final Camera.Size previewSize = camera.getParameters().getPreviewSize();
Expand Down Expand Up @@ -103,68 +114,68 @@ public void SetSourceRawInput(final GPUPixelSourceRawInput source_input) {
}

private void setUpCamera(final int id) {
mCamera = Camera.open(id);
Camera.Parameters parameters = mCamera.getParameters();
if (parameters.getSupportedFocusModes().contains(
Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
}
parameters.setPreviewSize(1280, 720);
parameters.setPreviewFormat(ImageFormat.NV21);
mCamera.setParameters(parameters);

int deviceRotation = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay()
.getRotation();
android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
android.hardware.Camera.getCameraInfo(mCurrentCameraId, info);

int rotation = 0;
switch (deviceRotation) {
case Surface.ROTATION_0:
rotation = 0;
break;
case Surface.ROTATION_90:
rotation = 90;
break;
case Surface.ROTATION_180:
rotation = 180;
break;
case Surface.ROTATION_270:
rotation = 270;
break;
}
// mCamera = Camera.open(id);
// Camera.Parameters parameters = mCamera.getParameters();
// if (parameters.getSupportedFocusModes().contains(
// Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
// parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
// }
// parameters.setPreviewSize(1280, 720);
// parameters.setPreviewFormat(ImageFormat.NV21);
// mCamera.setParameters(parameters);
//
// int deviceRotation = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay()
// .getRotation();
// android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
// android.hardware.Camera.getCameraInfo(mCurrentCameraId, info);
//
// int rotation = 0;
// switch (deviceRotation) {
// case Surface.ROTATION_0:
// rotation = 0;
// break;
// case Surface.ROTATION_90:
// rotation = 90;
// break;
// case Surface.ROTATION_180:
// rotation = 180;
// break;
// case Surface.ROTATION_270:
// rotation = 270;
// break;
// }

mRotation = GPUPixel.NoRotation;
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
rotation = (info.orientation + rotation) % 360;
switch (rotation) {
case 0:
mRotation = GPUPixel.FlipHorizontal;
break;
case 90:
mRotation = GPUPixel.RotateRightFlipVertical;
break;
case 180:
mRotation = GPUPixel.FlipVertical;
break;
case 270:
mRotation = GPUPixel.RotateRightFlipHorizontal;
break;
}
} else {
rotation = (info.orientation - rotation + 360) % 360;
switch (rotation) {
case 90:
mRotation = GPUPixel.RotateRight;
break;
case 180:
mRotation = GPUPixel.Rotate180;
break;
case 270:
mRotation = GPUPixel.RotateLeft;
break;
}
}
// if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
// rotation = (info.orientation + rotation) % 360;
// switch (rotation) {
// case 0:
// mRotation = GPUPixel.FlipHorizontal;
// break;
// case 90:
// mRotation = GPUPixel.RotateRightFlipVertical;
// break;
// case 180:
// mRotation = GPUPixel.FlipVertical;
// break;
// case 270:
// mRotation = GPUPixel.RotateRightFlipHorizontal;
// break;
// }
// } else {
// rotation = (info.orientation - rotation + 360) % 360;
// switch (rotation) {
// case 90:
// mRotation = GPUPixel.RotateRight;
// break;
// case 180:
// mRotation = GPUPixel.Rotate180;
// break;
// case 270:
// mRotation = GPUPixel.RotateLeft;
// break;
// }
// }

if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
GPUPixel.getInstance().runOnDraw(new Runnable() {
Expand All @@ -175,13 +186,13 @@ public void run() {
int[] textures = new int[1];
GLES20.glGenTextures(1, textures, 0);
mSurfaceTexture = new SurfaceTexture(textures[0]);
try {
mCamera.setPreviewTexture(mSurfaceTexture);
mCamera.setPreviewCallback(GPUPixelSourceCamera.this);
mCamera.startPreview();
} catch (IOException e) {
e.printStackTrace();
}
// try {
// mCamera.setPreviewTexture(mSurfaceTexture);
// mCamera.setPreviewCallback(GPUPixelSourceCamera.this);
// mCamera.startPreview();
// } catch (IOException e) {
// e.printStackTrace();
// }
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@

package com.pixpark.gpupixel;

import android.annotation.TargetApi;
import android.graphics.Bitmap;
import android.graphics.SurfaceTexture;
import android.opengl.GLES20;
import android.os.Build;
import android.util.Log;

import java.io.IOException;
import java.nio.ByteBuffer;

public class GPUPixelSourceRawInput extends GPUPixelSource {
private Object object_this;
private GPUPixel.GPUPixelLandmarkCallback landmarkCallback;

private SurfaceTexture mSurfaceTexture = null;
public GPUPixelSourceRawInput() {
object_this = this;

Expand Down Expand Up @@ -44,6 +53,11 @@ public void uploadBytes(final int[] pixels, int width, int height, int stride) {
proceed(true, false);
}

public void uploadByteBuffer(final ByteBuffer pixels, int width, int height, int stride) {
GPUPixel.nativeWaterbusUploadBytes(mNativeClassID, pixels, width, height, stride);
proceed(true, false);
}

public void setLandmarkCallbck(GPUPixel.GPUPixelLandmarkCallback filter) {
landmarkCallback = filter;

Expand Down
25 changes: 19 additions & 6 deletions src/android/jni/jni_gpupixel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

USING_NS_GPUPIXEL
std::list<std::shared_ptr<Filter>> filter_list_;
bool is_processing = false;
//std::shared_ptr<SourceRawDataInput> source_raw_data_;

extern "C" jlong Java_com_pixpark_gpupixel_GPUPixel_nativeSourceImageNew(
Expand Down Expand Up @@ -112,14 +111,30 @@ Java_com_pixpark_gpupixel_GPUPixel_nativeSourceRawInputUploadBytes(
jint width,
jint height,
jint stride) {
if (is_processing) return;
is_processing = true;

jint* pixel = env->GetIntArrayElements(jPixel, 0);
((SourceRawDataInput*)classId)->uploadBytes((uint8_t*)pixel, width, height, stride, 0);
env->ReleaseIntArrayElements(jPixel, pixel, 0);
};

extern "C" void Java_com_pixpark_gpupixel_GPUPixel_nativeWaterbusUploadBytes(
JNIEnv* env,
jclass,
jlong classId,
jobject buffer,
jint width,
jint height,
jint stride
) {
// Get the pointer to the ByteBuffer data
void* pixels = env->GetDirectBufferAddress(buffer);
if (pixels == nullptr) {
// Handle error: Direct buffer address could not be obtained
return;
}

((SourceRawDataInput*)classId)->uploadBytes((uint8_t*) pixels, width, height, stride, 0);
}

extern "C" void
Java_com_pixpark_gpupixel_GPUPixel_nativeSourceRawInputSetRotation(
JNIEnv* env,
Expand Down Expand Up @@ -190,8 +205,6 @@ extern "C" jlong Java_com_pixpark_gpupixel_GPUPixel_nativeSourceAddTargetOutputC
int b = data[i * 4 + 2]; // Blue
__android_log_print(ANDROID_LOG_INFO, "OpenGL", "value: %d %d %d %d", a, r, g, b);
}

is_processing = false;
});
target = output;

Expand Down

0 comments on commit c37f5e9

Please sign in to comment.