Skip to content

Commit

Permalink
Merge pull request uu-code007#7 from MJLblabla/master
Browse files Browse the repository at this point in the history
 add uikit
  • Loading branch information
uu-code007 authored Sep 6, 2022
2 parents 3c4ba11 + dbc2d0d commit 157f42d
Show file tree
Hide file tree
Showing 72 changed files with 1,322 additions and 223 deletions.
1 change: 0 additions & 1 deletion SMBeautyEngine_andriod/pixelfree_android_demo/.idea/.name

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions SMBeautyEngine_andriod/pixelfree_android_demo/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions SMBeautyEngine_andriod/pixelfree_android_demo/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies {
implementation project(':hapiAVCapture')
implementation project(':hapiAVRender')
implementation project(':lib_pixelFree')
// implementation project(':nativelib')
implementation project(':lib_pixelFree_uikit')

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.0'
Expand Down
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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,13 @@
android:layout_gravity="center" />

<Button
android:id="@+id/btSouLian"
android:id="@+id/showBeauty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="瘦脸"
android:text="美颜"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/btWhite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="美白"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/btSouLian" />


</androidx.constraintlayout.widget.ConstraintLayout>
Loading

0 comments on commit 157f42d

Please sign in to comment.