forked from uu-code007/PixelFreeEffects
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request uu-code007#7 from MJLblabla/master
add uikit
- Loading branch information
Showing
72 changed files
with
1,322 additions
and
223 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
SMBeautyEngine_andriod/pixelfree_android_demo/.idea/jarRepositories.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 57 additions & 80 deletions
137
...driod/pixelfree_android_demo/app/src/main/java/com/hapi/pixelfree_android/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,127 +1,104 @@ | ||
package com.hapi.pixelfree_android | ||
|
||
import android.graphics.Bitmap | ||
import android.opengl.* | ||
import android.os.Bundle | ||
import android.util.Log | ||
import android.widget.Button | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.byteflow.pixelfree.* | ||
import com.hapi.avcapture.FrameCall | ||
import com.hapi.avcapture.HapiTrackFactory | ||
import com.hapi.avparam.VideoFrame | ||
import com.hapi.avrender.HapiCapturePreView | ||
import com.hapi.pixelfreeuikit.PixeBeautyDialog | ||
import java.nio.ByteBuffer | ||
import java.util.concurrent.CountDownLatch | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
private val mPixelFree by lazy { | ||
PixelFree() | ||
} | ||
private val mPixeBeautyDialog by lazy { | ||
PixeBeautyDialog(mPixelFree) | ||
} | ||
val hapiCapturePreView by lazy { findViewById<HapiCapturePreView>(R.id.preview) } | ||
|
||
//摄像头轨道 | ||
private val cameTrack by lazy { | ||
HapiTrackFactory.createCameraXTrack(this, this, 720, 1280).apply { | ||
frameCall = object : FrameCall<VideoFrame> { | ||
//帧回调 | ||
override fun onFrame(frame: VideoFrame) {} | ||
override fun onFrame(frame: VideoFrame) { | ||
} | ||
|
||
//数据处理回调 | ||
override fun onProcessFrame(frame: VideoFrame): VideoFrame { | ||
OpenGLTools.switchContext() | ||
if(!mPixelFree.isCreate()){ | ||
// OpenGLTools.switchContext() | ||
mPixelFree.create() | ||
val face_fiter = mPixelFree.readBundleFile(this@MainActivity, "face_fiter.bundle") | ||
mPixelFree.createBeautyItemFormBundle( | ||
face_fiter, | ||
face_fiter.size, | ||
PFSrcType.PFSrcTypeFilter | ||
) | ||
|
||
val face_detect = mPixelFree.readBundleFile(this@MainActivity, "face_detect.bundle") | ||
mPixelFree.createBeautyItemFormBundle( | ||
face_detect, | ||
face_detect.size, | ||
PFSrcType.PFSrcTypeDetect | ||
) | ||
// 滤镜依赖gl 上下文创建素材,必须放在 gl 环境 | ||
mPixelFree.pixelFreeSetFiterParam( | ||
"heibai1", | ||
1f | ||
) | ||
|
||
|
||
}else{ | ||
val iamgeInput = frame.toPFIamgeInput(); | ||
mPixelFree.processWithBuffer(iamgeInput) | ||
GLES30.glFinish() | ||
// frame.textureID = iamgeInput.textureID; | ||
// val code =GLES30.glGetError() | ||
// Log.d("mjl","GLES30.glGetError()" + code) | ||
// val byteBuffer = ByteBuffer.wrap(ByteArray(frame.data.size)) | ||
// GLES30.glReadPixels(0, 0, frame.width, frame.height, | ||
// GLES30.GL_RGBA, GLES30.GL_UNSIGNED_BYTE, byteBuffer); | ||
// val stitchBmp = Bitmap.createBitmap(frame.width, frame.height, Bitmap.Config.ARGB_8888) | ||
// stitchBmp.copyPixelsFromBuffer(byteBuffer) | ||
if (mPixelFree.isCreate()) { | ||
val countDownLatch = CountDownLatch(1) | ||
mPixelFree.glThread.runOnGLThread { | ||
val texture: Int = mPixelFree.glThread.getTexture( | ||
frame.width, | ||
frame.height, | ||
ByteBuffer.wrap(frame.data, 0, frame.data.size) | ||
) | ||
frame.textureID = texture | ||
val pxInput = PFIamgeInput().apply { | ||
textureID = texture | ||
wigth = frame.width | ||
height = frame.height | ||
p_data0 = frame.data | ||
p_data1 = frame.data | ||
p_data2 = frame.data | ||
stride_0 = frame.rowStride | ||
stride_1 = frame.rowStride | ||
stride_2 = frame.rowStride | ||
format = PFDetectFormat.PFFORMAT_IMAGE_RGBA | ||
rotationMode = PFRotationMode.PFRotationMode90 | ||
} | ||
mPixelFree.processWithBuffer(pxInput) | ||
countDownLatch.countDown() | ||
} | ||
countDownLatch.await() | ||
} | ||
|
||
return super.onProcessFrame(frame) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun VideoFrame.toPFIamgeInput(): PFIamgeInput { | ||
val vf = this | ||
var texture:Int = OpenGLTools.createTexture( | ||
this.width, | ||
this.height, | ||
ByteBuffer.wrap(this.data, 0, this.data.size) | ||
) | ||
|
||
|
||
vf.textureID = texture | ||
return PFIamgeInput().apply { | ||
textureID = texture | ||
wigth = vf.width | ||
height = vf.height | ||
p_data0 = vf.data | ||
p_data1 = vf.data | ||
p_data2 = vf.data | ||
stride_0 = vf.rowStride | ||
stride_1 = vf.rowStride | ||
stride_2 = vf.rowStride | ||
format = PFDetectFormat.PFFORMAT_IMAGE_RGBA | ||
rotationMode = PFRotationMode.PFRotationMode90 | ||
} | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
val hapiCapturePreView = findViewById<HapiCapturePreView>(R.id.preview) | ||
//如果需要预览视频轨道 | ||
cameTrack.playerView = hapiCapturePreView | ||
cameTrack.start() | ||
|
||
hapiCapturePreView.mHapiGLSurfacePreview.mOpenGLRender.glCreateCall = { | ||
OpenGLTools.load() | ||
cameTrack.start() | ||
} | ||
|
||
findViewById<Button>(R.id.btSouLian).setOnClickListener { | ||
mPixelFree.pixelFreeSetBeautyFiterParam( | ||
PFBeautyFiterType.PFBeautyFiterTypeFace_thinning, | ||
1f | ||
) | ||
//在当前项目gl环境创建后 | ||
mPixelFree.glThread.attachGLContext { | ||
//在绑定上下文后初始化 | ||
mPixelFree.create() | ||
val face_fiter = | ||
mPixelFree.readBundleFile(this@MainActivity, "face_fiter.bundle") | ||
mPixelFree.createBeautyItemFormBundle( | ||
face_fiter, | ||
face_fiter.size, | ||
PFSrcType.PFSrcTypeFilter | ||
) | ||
val face_detect = | ||
mPixelFree.readBundleFile(this@MainActivity, "face_detect.bundle") | ||
mPixelFree.createBeautyItemFormBundle( | ||
face_detect, | ||
face_detect.size, | ||
PFSrcType.PFSrcTypeDetect | ||
) | ||
} | ||
} | ||
findViewById<Button>(R.id.btWhite).setOnClickListener { | ||
|
||
findViewById<Button>(R.id.showBeauty).setOnClickListener { | ||
mPixeBeautyDialog.show(supportFragmentManager, "") | ||
} | ||
} | ||
|
||
override fun onDestroy() { | ||
mPixelFree.release() | ||
super.onDestroy() | ||
OpenGLTools.release() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.