diff --git a/.gitignore b/.gitignore
index 26a464e..2cafd91 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
# Built application files
*.apk
*.ap_
+.idea
# Files for the Dalvik VM
*.dex
diff --git a/Project-AndroidStudio/app/build.gradle b/Project-AndroidStudio/app/build.gradle
index bb3c8b4..5cd57f9 100644
--- a/Project-AndroidStudio/app/build.gradle
+++ b/Project-AndroidStudio/app/build.gradle
@@ -1,24 +1,22 @@
-apply plugin: 'com.android.model.application'
+apply plugin: 'com.android.application'
-model {
- android {
- compileSdkVersion = 23
- buildToolsVersion = "23.0.3"
+android {
+ compileSdkVersion = 23
+ buildToolsVersion = "23.0.3"
- defaultConfig.with {
- applicationId = "com.seu.magiccamera"
- minSdkVersion.apiLevel = 18
- targetSdkVersion.apiLevel = 23
- versionCode = 1
- versionName = "1.0"
- }
+ defaultConfig {
+ applicationId "com.seu.magiccamera"
+ minSdkVersion 18
+ targetSdkVersion 23
+ versionCode 1
+ versionName "1.0"
}
+}
- android.buildTypes {
- release {
- minifyEnabled = false
- proguardFiles.add(file('proguard-rules.txt'))
- }
+android.buildTypes {
+ release {
+ minifyEnabled = false
+ proguardFiles.add(file('proguard-rules.txt'))
}
}
@@ -28,4 +26,5 @@ dependencies {
compile project(':magicfilter')
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
+ compile "com.jakewharton.timber:timber:4.1.2"
}
diff --git a/Project-AndroidStudio/app/src/main/java/com/seu/magiccamera/activity/CameraActivity.java b/Project-AndroidStudio/app/src/main/java/com/seu/magiccamera/activity/CameraActivity.java
index ff738bc..1f966eb 100644
--- a/Project-AndroidStudio/app/src/main/java/com/seu/magiccamera/activity/CameraActivity.java
+++ b/Project-AndroidStudio/app/src/main/java/com/seu/magiccamera/activity/CameraActivity.java
@@ -1,6 +1,5 @@
package com.seu.magiccamera.activity;
-import android.Manifest;
import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
@@ -11,11 +10,10 @@
import android.graphics.Point;
import android.os.Bundle;
import android.os.Environment;
-import android.support.v4.app.ActivityCompat;
-import android.support.v4.content.PermissionChecker;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
+import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
@@ -32,10 +30,12 @@
import java.util.Date;
import java.util.Locale;
+import timber.log.Timber;
+
/**
* Created by why8222 on 2016/3/17.
*/
-public class CameraActivity extends Activity{
+public class CameraActivity extends Activity {
private LinearLayout mFilterLayout;
private RecyclerView mFilterListView;
private FilterAdapter mAdapter;
@@ -95,22 +95,30 @@ public class CameraActivity extends Activity{
MagicFilterType.XPROII
};
+ static boolean timberPlanted = false;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+
+ if (!timberPlanted) {
+ Timber.plant(new Timber.DebugTree());
+ timberPlanted = true;
+ }
+
setContentView(R.layout.activity_camera);
MagicEngine.Builder builder = new MagicEngine.Builder();
magicEngine = builder
- .build((MagicCameraView)findViewById(R.id.glsurfaceview_camera));
+ .build((MagicCameraView) findViewById(R.id.glsurfaceview_camera));
initView();
}
- private void initView(){
- mFilterLayout = (LinearLayout)findViewById(R.id.layout_filter);
+ private void initView() {
+ mFilterLayout = (LinearLayout) findViewById(R.id.layout_filter);
mFilterListView = (RecyclerView) findViewById(R.id.filter_listView);
- btn_shutter = (ImageView)findViewById(R.id.btn_camera_shutter);
- btn_mode = (ImageView)findViewById(R.id.btn_camera_mode);
+ btn_shutter = (ImageView) findViewById(R.id.btn_camera_shutter);
+ btn_mode = (ImageView) findViewById(R.id.btn_camera_mode);
findViewById(R.id.btn_camera_filter).setOnClickListener(btn_listener);
findViewById(R.id.btn_camera_closefilter).setOnClickListener(btn_listener);
@@ -127,19 +135,19 @@ private void initView(){
mFilterListView.setAdapter(mAdapter);
mAdapter.setOnFilterChangeListener(onFilterChangeListener);
- animator = ObjectAnimator.ofFloat(btn_shutter,"rotation",0,360);
+ animator = ObjectAnimator.ofFloat(btn_shutter, "rotation", 0, 360);
animator.setDuration(500);
animator.setRepeatCount(ValueAnimator.INFINITE);
Point screenSize = new Point();
getWindowManager().getDefaultDisplay().getSize(screenSize);
- MagicCameraView cameraView = (MagicCameraView)findViewById(R.id.glsurfaceview_camera);
+ MagicCameraView cameraView = (MagicCameraView) findViewById(R.id.glsurfaceview_camera);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) cameraView.getLayoutParams();
params.width = screenSize.x;
params.height = screenSize.x * 4 / 3;
cameraView.setLayoutParams(params);
}
- private FilterAdapter.onFilterChangeListener onFilterChangeListener = new FilterAdapter.onFilterChangeListener(){
+ private FilterAdapter.onFilterChangeListener onFilterChangeListener = new FilterAdapter.onFilterChangeListener() {
@Override
public void onFilterChanged(MagicFilterType filterType) {
@@ -151,7 +159,7 @@ public void onFilterChanged(MagicFilterType filterType) {
public void onRequestPermissionsResult(int requestCode, String[] permissions,
int[] grantResults) {
if (grantResults.length != 1 || grantResults[0] == PackageManager.PERMISSION_GRANTED) {
- if(mode == MODE_PIC)
+ if (mode == MODE_PIC)
takePhoto();
else
takeVideo();
@@ -160,41 +168,57 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions,
}
}
+ private void zoomOut() {
+ ViewGroup.LayoutParams layoutParams = MagicParams.magicBaseView.getLayoutParams();
+ layoutParams.width /= 2;
+ layoutParams.height /= 2;
+ MagicParams.magicBaseView.setLayoutParams(layoutParams);
+ }
+
+ private void zoomIn() {
+ ViewGroup.LayoutParams layoutParams = MagicParams.magicBaseView.getLayoutParams();
+ layoutParams.width *= 2;
+ layoutParams.height *= 2;
+ MagicParams.magicBaseView.setLayoutParams(layoutParams);
+ }
+
private View.OnClickListener btn_listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
- switch (v.getId()){
+ switch (v.getId()) {
case R.id.btn_camera_mode:
switchMode();
break;
case R.id.btn_camera_shutter:
- if (PermissionChecker.checkSelfPermission(CameraActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
- == PackageManager.PERMISSION_DENIED) {
- ActivityCompat.requestPermissions(CameraActivity.this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
- v.getId());
- } else {
- if(mode == MODE_PIC)
- takePhoto();
- else
- takeVideo();
- }
+// if (PermissionChecker.checkSelfPermission(CameraActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
+// == PackageManager.PERMISSION_DENIED) {
+// ActivityCompat.requestPermissions(CameraActivity.this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
+// v.getId());
+// } else {
+// if(mode == MODE_PIC)
+// takePhoto();
+// else
+// takeVideo();
+// }
+ zoomOut();
break;
case R.id.btn_camera_filter:
- showFilters();
+// showFilters();
+ zoomIn();
break;
case R.id.btn_camera_switch:
magicEngine.switchCamera();
break;
case R.id.btn_camera_beauty:
new AlertDialog.Builder(CameraActivity.this)
- .setSingleChoiceItems(new String[] { "关闭", "1", "2", "3", "4", "5"}, MagicParams.beautyLevel,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- magicEngine.setBeautyLevel(which);
- dialog.dismiss();
- }
- })
+ .setSingleChoiceItems(new String[]{"关闭", "1", "2", "3", "4", "5"}, MagicParams.beautyLevel,
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ magicEngine.setBeautyLevel(which);
+ dialog.dismiss();
+ }
+ })
.setNegativeButton("取消", null)
.show();
break;
@@ -205,32 +229,32 @@ public void onClick(DialogInterface dialog, int which) {
}
};
- private void switchMode(){
- if(mode == MODE_PIC){
+ private void switchMode() {
+ if (mode == MODE_PIC) {
mode = MODE_VIDEO;
btn_mode.setImageResource(R.drawable.icon_camera);
- }else{
+ } else {
mode = MODE_PIC;
btn_mode.setImageResource(R.drawable.icon_video);
}
}
- private void takePhoto(){
- magicEngine.savePicture(getOutputMediaFile(),null);
+ private void takePhoto() {
+ magicEngine.savePicture(getOutputMediaFile(), null);
}
- private void takeVideo(){
- if(isRecording) {
+ private void takeVideo() {
+ if (isRecording) {
animator.end();
magicEngine.stopRecord();
- }else {
+ } else {
animator.start();
magicEngine.startRecord();
}
isRecording = !isRecording;
}
- private void showFilters(){
+ private void showFilters() {
ObjectAnimator animator = ObjectAnimator.ofFloat(mFilterLayout, "translationY", mFilterLayout.getHeight(), 0);
animator.setDuration(200);
animator.addListener(new Animator.AnimatorListener() {
@@ -259,8 +283,8 @@ public void onAnimationCancel(Animator animation) {
animator.start();
}
- private void hideFilters(){
- ObjectAnimator animator = ObjectAnimator.ofFloat(mFilterLayout, "translationY", 0 , mFilterLayout.getHeight());
+ private void hideFilters() {
+ ObjectAnimator animator = ObjectAnimator.ofFloat(mFilterLayout, "translationY", 0, mFilterLayout.getHeight());
animator.setDuration(200);
animator.addListener(new Animator.AnimatorListener() {
diff --git a/Project-AndroidStudio/app/src/main/res/layout/activity_camera.xml b/Project-AndroidStudio/app/src/main/res/layout/activity_camera.xml
index 275aaaf..fd0fbde 100644
--- a/Project-AndroidStudio/app/src/main/res/layout/activity_camera.xml
+++ b/Project-AndroidStudio/app/src/main/res/layout/activity_camera.xml
@@ -3,76 +3,84 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
- tools:context="com.seu.magiccamera.activity.CameraActivity" >
+ tools:context="com.seu.magiccamera.activity.CameraActivity">
+
+
+
+ android:padding="5dp">
+
+ android:src="@drawable/icon_video" />
+
+ android:layout_marginLeft="10dp"
+ android:src="@drawable/selector_rewardcamera" />
+
+
+ android:layout_gravity="bottom"
+ android:background="@android:color/white"
+ android:paddingBottom="5dip"
+ android:paddingTop="5dip">
+
-
+ android:scaleType="center"
+ android:src="@drawable/btn_camera_beauty">
+
-
+ android:src="@drawable/btn_camera_shutter">
+
-
+ android:src="@drawable/btn_camera_filter">
+
+ android:layout_gravity="bottom"
+ android:visibility="invisible" />
diff --git a/Project-AndroidStudio/build.gradle b/Project-AndroidStudio/build.gradle
index c5316b3..9632370 100644
--- a/Project-AndroidStudio/build.gradle
+++ b/Project-AndroidStudio/build.gradle
@@ -5,8 +5,7 @@ buildscript {
jcenter()
}
dependencies {
- classpath "com.android.tools.build:gradle-experimental:0.7.0-beta1"
-
+ classpath 'com.android.tools.build:gradle:2.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
diff --git a/Project-AndroidStudio/gradle/wrapper/gradle-wrapper.properties b/Project-AndroidStudio/gradle/wrapper/gradle-wrapper.properties
index 2f348cb..2fe1f70 100644
--- a/Project-AndroidStudio/gradle/wrapper/gradle-wrapper.properties
+++ b/Project-AndroidStudio/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Wed Apr 10 15:27:10 PDT 2013
+#Thu Nov 10 15:51:40 CST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
\ No newline at end of file
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
diff --git a/Project-AndroidStudio/magicfilter/CMakeLists.txt b/Project-AndroidStudio/magicfilter/CMakeLists.txt
new file mode 100644
index 0000000..744d172
--- /dev/null
+++ b/Project-AndroidStudio/magicfilter/CMakeLists.txt
@@ -0,0 +1,21 @@
+# Sets the minimum version of CMake required to build your native library.
+# This ensures that a certain set of CMake features is available to
+# your build.
+cmake_minimum_required(VERSION 3.4.1)
+
+# Specifies a library name, specifies whether the library is STATIC or
+# SHARED, and provides relative paths to the source code. You can
+# define multiple libraries by adding multiple add.library() commands,
+# and CMake builds them for you. When you build your app, Gradle
+# automatically packages shared libraries with your APK.
+
+
+cmake_minimum_required(VERSION 3.4.1)
+
+set(CMAKE_VERBOSE_MAKEFILE on)
+
+set(lib_build_DIR $ENV{HOME}/tmp)
+file(MAKE_DIRECTORY ${lib_build_DIR})
+
+set(lib_jni_DIR ${CMAKE_SOURCE_DIR}/src/main/jni)
+add_subdirectory(${lib_jni_DIR} ${lib_build_DIR}/lib_jni_DIR)
diff --git a/Project-AndroidStudio/magicfilter/build.gradle b/Project-AndroidStudio/magicfilter/build.gradle
index bf4adc9..ef69a0f 100644
--- a/Project-AndroidStudio/magicfilter/build.gradle
+++ b/Project-AndroidStudio/magicfilter/build.gradle
@@ -1,36 +1,66 @@
-apply plugin: 'com.android.model.library'
-
-model {
- android {
- compileSdkVersion = 23
- buildToolsVersion = "23.0.3"
-
- defaultConfig.with {
- minSdkVersion.apiLevel = 18
- targetSdkVersion.apiLevel = 21
- versionCode = 1
- versionName = "1.0"
+apply plugin: 'com.android.library'
+
+android {
+ compileSdkVersion = 23
+ buildToolsVersion = "23.0.3"
+
+ defaultConfig {
+ minSdkVersion 18
+ targetSdkVersion 23
+ versionCode 1
+ versionName "1.0"
+
+ externalNativeBuild {
+ cmake {
+// targets "YoloLive"
+ // Passes optional arguments to CMake.
+ arguments "-DANDROID_TOOLCHAIN=clang",
+ "-DANDROID_STL=stlport_static",
+ "-DANDROID_ARM_MODE=arm"
+
+ // Sets optional flags for the C compiler.
+// cFlags
+
+ // Sets a flag to enable format macro constants for the C++ compiler.
+ cppFlags "-std=c++11", "-fexceptions", "-fpermissive"
+ }
+ ndk {
+ // Specifies the ABI configurations of your native
+ // libraries Gradle should build and package with your APK.
+ abiFilters 'armeabi'
+ }
}
}
- android.ndk {
- moduleName = "MagicBeautify"
- cppFlags.add("-DANDROID_NDK")
- cppFlags.add("-D_DEBUG")
- ldLibs.add("log")
- ldLibs.add("jnigraphics")
- stl = "stlport_static"
+ externalNativeBuild {
+ cmake {
+ path "CMakeLists.txt"
+ }
}
- android.buildTypes {
+ buildTypes {
release {
- minifyEnabled = false
- proguardFiles.add(file('proguard-rules.txt'))
+ minifyEnabled false
+ externalNativeBuild {
+ debuggable true
+ }
}
}
-}
-dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- testCompile 'junit:junit:4.12'
+ dependencies {
+ compile fileTree(dir: 'libs', include: ['*.jar'])
+ testCompile 'junit:junit:4.12'
+ compile "com.jakewharton.timber:timber:4.1.2"
+ }
}
+
+//android.ndk {
+// moduleName = "MagicBeautify"
+// cppFlags.add("-DANDROID_NDK")
+// cppFlags.add("-D_DEBUG")
+// ldLibs.add("log")
+// ldLibs.add("jnigraphics")
+// stl = "stlport_static"
+//}
+
+
diff --git a/Project-AndroidStudio/magicfilter/src/main/java/com/seu/magicfilter/camera/CameraEngine.java b/Project-AndroidStudio/magicfilter/src/main/java/com/seu/magicfilter/camera/CameraEngine.java
index 7df10cf..b71e8a0 100644
--- a/Project-AndroidStudio/magicfilter/src/main/java/com/seu/magicfilter/camera/CameraEngine.java
+++ b/Project-AndroidStudio/magicfilter/src/main/java/com/seu/magicfilter/camera/CameraEngine.java
@@ -85,7 +85,8 @@ private static void setDefaultParameters(){
parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
}
Size previewSize = CameraUtils.getLargePreviewSize(camera);
- parameters.setPreviewSize(previewSize.width, previewSize.height);
+// parameters.setPreviewSize(previewSize.width, previewSize.height);
+ parameters.setPreviewSize(640, 480);
Size pictureSize = CameraUtils.getLargePictureSize(camera);
parameters.setPictureSize(pictureSize.width, pictureSize.height);
parameters.setRotation(90);
diff --git a/Project-AndroidStudio/magicfilter/src/main/java/com/seu/magicfilter/widget/MagicCameraView.java b/Project-AndroidStudio/magicfilter/src/main/java/com/seu/magicfilter/widget/MagicCameraView.java
index 79c61f4..5870653 100644
--- a/Project-AndroidStudio/magicfilter/src/main/java/com/seu/magicfilter/widget/MagicCameraView.java
+++ b/Project-AndroidStudio/magicfilter/src/main/java/com/seu/magicfilter/widget/MagicCameraView.java
@@ -32,6 +32,8 @@
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
+import timber.log.Timber;
+
/**
* Created by why8222 on 2016/2/25.
*/
@@ -46,12 +48,7 @@ public MagicCameraView(Context context) {
this(context, null);
}
- private boolean recordingEnabled;
- private int recordingStatus;
- private static final int RECORDING_OFF = 0;
- private static final int RECORDING_ON = 1;
- private static final int RECORDING_RESUMED = 2;
private static TextureMovieEncoder videoEncoder = new TextureMovieEncoder();
private File outputFile;
@@ -59,21 +56,14 @@ public MagicCameraView(Context context) {
public MagicCameraView(Context context, AttributeSet attrs) {
super(context, attrs);
this.getHolder().addCallback(this);
- outputFile = new File(MagicParams.videoPath,MagicParams.videoName);
- recordingStatus = -1;
- recordingEnabled = false;
+ outputFile = new File(MagicParams.videoPath, MagicParams.videoName);
scaleType = ScaleType.CENTER_CROP;
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
super.onSurfaceCreated(gl, config);
- recordingEnabled = videoEncoder.isRecording();
- if (recordingEnabled)
- recordingStatus = RECORDING_RESUMED;
- else
- recordingStatus = RECORDING_OFF;
- if(cameraInputFilter == null)
+ if (cameraInputFilter == null)
cameraInputFilter = new MagicCameraInputFilter();
cameraInputFilter.init();
if (textureId == OpenGlUtils.NO_TEXTURE) {
@@ -89,63 +79,52 @@ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
public void onSurfaceChanged(GL10 gl, int width, int height) {
super.onSurfaceChanged(gl, width, height);
openCamera();
+ Timber.d("onSurfaceChanged(GL10 gl, int width:%d, int height:%d)", width, height);
}
@Override
public void onDrawFrame(GL10 gl) {
super.onDrawFrame(gl);
- if(surfaceTexture == null)
+ if (surfaceTexture == null)
return;
surfaceTexture.updateTexImage();
- if (recordingEnabled) {
- switch (recordingStatus) {
- case RECORDING_OFF:
- CameraInfo info = CameraEngine.getCameraInfo();
- videoEncoder.setPreviewSize(info.previewWidth, info.pictureHeight);
- videoEncoder.setTextureBuffer(gLTextureBuffer);
- videoEncoder.setCubeBuffer(gLCubeBuffer);
- videoEncoder.startRecording(new TextureMovieEncoder.EncoderConfig(
- outputFile, info.previewWidth, info.pictureHeight,
- 1000000, EGL14.eglGetCurrentContext(),
- info));
- recordingStatus = RECORDING_ON;
- break;
- case RECORDING_RESUMED:
- videoEncoder.updateSharedContext(EGL14.eglGetCurrentContext());
- recordingStatus = RECORDING_ON;
- break;
- case RECORDING_ON:
- break;
- default:
- throw new RuntimeException("unknown status " + recordingStatus);
- }
- } else {
- switch (recordingStatus) {
- case RECORDING_ON:
- case RECORDING_RESUMED:
- videoEncoder.stopRecording();
- recordingStatus = RECORDING_OFF;
- break;
- case RECORDING_OFF:
- break;
- default:
- throw new RuntimeException("unknown status " + recordingStatus);
- }
- }
+
float[] mtx = new float[16];
surfaceTexture.getTransformMatrix(mtx);
cameraInputFilter.setTextureTransformMatrix(mtx);
int id = textureId;
- if(filter == null){
+ if (filter == null) {
cameraInputFilter.onDrawFrame(textureId, gLCubeBuffer, gLTextureBuffer);
- }else{
+ } else {
id = cameraInputFilter.onDrawToTexture(textureId);
filter.onDrawFrame(id, gLCubeBuffer, gLTextureBuffer);
}
+
+ Timber.d("onDrawFrame");
+ dumpImage(imageWidth, imageHeight);
videoEncoder.setTextureId(id);
videoEncoder.frameAvailable(surfaceTexture);
}
+
+ private ByteBuffer mRgbaBuf;
+
+ // for test
+ private void dumpImage(int width, int height) {
+ if (mRgbaBuf == null) {
+ mRgbaBuf = ByteBuffer.allocateDirect(width * height * 4);
+ }
+ mRgbaBuf.position(0);
+ long start = System.nanoTime();
+ GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, mRgbaBuf);
+ Timber.d("dumpImage, glReadPixels, consume: %d, width:%d, height:%d", (System.nanoTime()-start)/1000_000, width, height);
+
+// IntBuffer ib = IntBuffer.allocate(width * height);
+// GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ib);
+// Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+// result.copyPixelsFromBuffer(ib);
+ }
+
private SurfaceTexture.OnFrameAvailableListener onFrameAvailableListener = new SurfaceTexture.OnFrameAvailableListener() {
@Override
@@ -160,20 +139,20 @@ public void setFilter(MagicFilterType type) {
videoEncoder.setFilter(type);
}
- private void openCamera(){
- if(CameraEngine.getCamera() == null)
+ private void openCamera() {
+ if (CameraEngine.getCamera() == null)
CameraEngine.openCamera();
CameraInfo info = CameraEngine.getCameraInfo();
- if(info.orientation == 90 || info.orientation == 270){
+ if (info.orientation == 90 || info.orientation == 270) {
imageWidth = info.previewHeight;
imageHeight = info.previewWidth;
- }else{
+ } else {
imageWidth = info.previewWidth;
imageHeight = info.previewHeight;
}
cameraInputFilter.onInputSizeChanged(imageWidth, imageHeight);
adjustSize(info.orientation, info.isFront, true);
- if(surfaceTexture != null)
+ if (surfaceTexture != null)
CameraEngine.startPreview(surfaceTexture);
}
@@ -184,13 +163,12 @@ public void surfaceDestroyed(SurfaceHolder holder) {
}
public void changeRecordingState(boolean isRecording) {
- recordingEnabled = isRecording;
}
- protected void onFilterChanged(){
+ protected void onFilterChanged() {
super.onFilterChanged();
cameraInputFilter.onDisplaySizeChanged(surfaceWidth, surfaceHeight);
- if(filter != null)
+ if (filter != null)
cameraInputFilter.initCameraFrameBuffer(imageWidth, imageHeight);
else
cameraInputFilter.destroyFramebuffers();
@@ -206,7 +184,7 @@ public void onPictureTaken(byte[] data, Camera camera) {
queueEvent(new Runnable() {
@Override
public void run() {
- final Bitmap photo = drawPhoto(bitmap,CameraEngine.getCameraInfo().isFront);
+ final Bitmap photo = drawPhoto(bitmap, CameraEngine.getCameraInfo().isFront);
GLES20.glViewport(0, 0, surfaceWidth, surfaceHeight);
if (photo != null)
savePictureTask.execute(photo);
@@ -217,18 +195,18 @@ public void run() {
});
}
- private Bitmap drawPhoto(Bitmap bitmap,boolean isRotated){
+ private Bitmap drawPhoto(Bitmap bitmap, boolean isRotated) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int[] mFrameBuffers = new int[1];
int[] mFrameBufferTextures = new int[1];
- if(beautyFilter == null)
+ if (beautyFilter == null)
beautyFilter = new MagicBeautyFilter();
beautyFilter.init();
beautyFilter.onDisplaySizeChanged(width, height);
beautyFilter.onInputSizeChanged(width, height);
- if(filter != null) {
+ if (filter != null) {
filter.onInputSizeChanged(width, height);
filter.onDisplaySizeChanged(width, height);
}
@@ -259,15 +237,15 @@ private Bitmap drawPhoto(Bitmap bitmap,boolean isRotated){
.order(ByteOrder.nativeOrder())
.asFloatBuffer();
gLCubeBuffer.put(TextureRotationUtil.CUBE).position(0);
- if(isRotated)
+ if (isRotated)
gLTextureBuffer.put(TextureRotationUtil.getRotation(Rotation.NORMAL, false, false)).position(0);
else
gLTextureBuffer.put(TextureRotationUtil.getRotation(Rotation.NORMAL, false, true)).position(0);
- if(filter == null){
+ if (filter == null) {
beautyFilter.onDrawFrame(textureId, gLCubeBuffer, gLTextureBuffer);
- }else{
+ } else {
beautyFilter.onDrawFrame(textureId);
filter.onDrawFrame(mFrameBufferTextures[0], gLCubeBuffer, gLTextureBuffer);
}
@@ -283,7 +261,7 @@ private Bitmap drawPhoto(Bitmap bitmap,boolean isRotated){
beautyFilter.destroy();
beautyFilter = null;
- if(filter != null) {
+ if (filter != null) {
filter.onDisplaySizeChanged(surfaceWidth, surfaceHeight);
filter.onInputSizeChanged(imageWidth, imageHeight);
}
diff --git a/Project-AndroidStudio/magicfilter/src/main/java/com/seu/magicfilter/widget/base/MagicBaseView.java b/Project-AndroidStudio/magicfilter/src/main/java/com/seu/magicfilter/widget/base/MagicBaseView.java
index d588bae..8b64f9e 100644
--- a/Project-AndroidStudio/magicfilter/src/main/java/com/seu/magicfilter/widget/base/MagicBaseView.java
+++ b/Project-AndroidStudio/magicfilter/src/main/java/com/seu/magicfilter/widget/base/MagicBaseView.java
@@ -26,7 +26,7 @@
public abstract class MagicBaseView extends GLSurfaceView implements GLSurfaceView.Renderer{
/**
* 所选择的滤镜,类型为MagicBaseGroupFilter
- * 1.mCameraInputFilter将SurfaceTexture中YUV数据绘制到FrameBuffer
+ * 1.mCameraInputFilter(cameraInputFilter?)将SurfaceTexture中YUV数据绘制到FrameBuffer
* 2.filter将FrameBuffer中的纹理绘制到屏幕中
*/
protected GPUImageFilter filter;
diff --git a/Project-AndroidStudio/magicfilter/src/main/jni/CMakeLists.txt b/Project-AndroidStudio/magicfilter/src/main/jni/CMakeLists.txt
new file mode 100644
index 0000000..72b7cc6
--- /dev/null
+++ b/Project-AndroidStudio/magicfilter/src/main/jni/CMakeLists.txt
@@ -0,0 +1,50 @@
+# Sets the minimum version of CMake required to build your native library.
+# This ensures that a certain set of CMake features is available to
+# your build.
+cmake_minimum_required(VERSION 3.4.1)
+
+# Specifies a library name, specifies whether the library is STATIC or
+# SHARED, and provides relative paths to the source code. You can
+# define multiple libraries by adding multiple add.library() commands,
+# and CMake builds them for you. When you build your app, Gradle
+# automatically packages shared libraries with your APK.
+
+set(src_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+message("src_DIR: " ${src_DIR})
+
+# Specifies a path to native header files.
+include_directories(${src_DIR}/beautify/
+ ${src_DIR}/bitmap/)
+
+aux_source_directory(${src_DIR} DIR_SRC)
+aux_source_directory(${src_DIR}/beautify DIR_BEAUTIFY)
+aux_source_directory(${src_DIR}/bitmap DIR_BITMAP)
+
+add_library( # Specifies the name of the library.
+ MagicBeautify
+
+ # Sets the library as a shared library.
+ SHARED
+
+ # Provides a relative path to your source file(s).
+ ${DIR_SRC}
+ ${DIR_BEAUTIFY}
+ ${DIR_BITMAP}
+ )
+
+
+# copy out the lib binary and remove generated files
+#set(distribution_DIR ${CMAKE_CURRENT_SOURCE_DIR}/distribution)
+#set_target_properties(MagicBeautify
+# PROPERTIES
+# LIBRARY_OUTPUT_DIRECTORY
+# "${distribution_DIR}/MagicBeautify/lib/${ANDROID_ABI}")
+
+# Links your native library against one or more other native libraries.
+target_link_libraries( # Specifies the target library.
+ MagicBeautify
+ # Links the log library to the target library.
+ log
+ android
+ jnigraphics
+ )
\ No newline at end of file