Skip to content

Commit

Permalink
bugfix: tagetview add mirror function
Browse files Browse the repository at this point in the history
  • Loading branch information
jaaronkot committed Dec 25, 2023
1 parent e5d79b8 commit f34e472
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ It is GPU-based and comes with built-in beauty effects filters that can achieve

It supports platforms including iOS, Mac, Android, and it can theoretically be ported to any platform that supports OpenGL/ES.

The face key points detection currently utilizes the [Face++](https://www.faceplusplus.com.cn/) library, but it will be replaced with either ncnn or mnn in the future.

## Effects Preview
**Skin whitening & smoothing**:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected void onCreate(Bundle savedInstanceState) {

// preview
surfaceView = findViewById(R.id.surfaceView);

surfaceView.setMirror(true);
// 美颜滤镜
filter = GPUPixelFilter.create("FaceBeautyFilter");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ public void runOnPostDraw(Runnable runnable) {
public static native void nativeTargetViewFinalize(final long classID);
public static native void nativeTargetViewOnSizeChanged(final long classID, final int width, final int height);
public static native void nativeTargetViewSetFillMode(final long classID, final int fillMode);
public static native void nativeTargetViewSetMirror(final long classID, final boolean mirror);
// context
public static native void nativeContextInit();
public static native void nativeContextDestroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ public void run() {
});
}

public void setMirror(final boolean mirror) {
GPUPixel.getInstance().runOnDraw(new Runnable() {
@Override
public void run() {
if (mNativeClassID != 0)
GPUPixel.nativeTargetViewSetMirror(mNativeClassID, mirror);
}
});
}

public int getSurfaceWidth() {
return mGLSurfaceView.getWidth();
}
Expand Down
10 changes: 9 additions & 1 deletion src/GPUPixelJNI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ extern "C" void Java_com_pixpark_gpupixel_GPUPixel_nativeTargetViewSetFillMode(
((TargetView*)classId)->setFillMode((TargetView::FillMode)fillMode);
};


extern "C"
JNIEXPORT void JNICALL
Java_com_pixpark_gpupixel_GPUPixel_nativeTargetViewSetMirror(JNIEnv *env, jclass clazz,
jlong class_id, jboolean mirror) {
((TargetView*)class_id)->setMirror(mirror);
}

extern "C" jlong Java_com_pixpark_gpupixel_GPUPixel_nativeFilterCreate(
JNIEnv* env,
jobject obj,
Expand Down Expand Up @@ -365,4 +373,4 @@ extern "C" void JNIEXPORT JNICALL JNI_OnUnLoad(JavaVM* jvm, void* reserved) {
// RTC_CHECK(rtc::CleanupSSL()) << "Failed to CleanupSSL()";
}

#endif
#endif
16 changes: 14 additions & 2 deletions src/target/TargetView.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ void TargetView::setFillMode(FillMode fillMode) {
}
}

void TargetView::setMirror(bool mirror) {
if (_mirror != mirror) {
_mirror = mirror;
}
}


void TargetView::onSizeChanged(int width, int height) {
if (_viewWidth != width || _viewHeight != height) {
_viewWidth = width;
Expand Down Expand Up @@ -214,8 +221,13 @@ const GLfloat* TargetView::_getTexureCoordinate(RotationMode rotationMode) {
};

switch (rotationMode) {
case NoRotation:
return noRotationTextureCoordinates;
case NoRotation: {
if(_mirror) {
return horizontalFlipTextureCoordinates;
} else {
return noRotationTextureCoordinates;
}
}
case RotateLeft:
return rotateLeftTextureCoordinates;
case RotateRight:
Expand Down
2 changes: 2 additions & 0 deletions src/target/TargetView.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ class TargetView : public Target {
RotationMode rotationMode = NoRotation,
int texIdx = 0) override;
void setFillMode(FillMode fillMode);
void setMirror(bool mirror);
void onSizeChanged(int width, int height);
virtual void update(int64_t frameTime) override;

private:
int _viewWidth;
int _viewHeight;
FillMode _fillMode;
bool _mirror = false;
GLProgram* _displayProgram;
GLuint _positionAttribLocation;
GLuint _texCoordAttribLocation;
Expand Down

0 comments on commit f34e472

Please sign in to comment.