Skip to content

Commit b84c5ee

Browse files
author
nekocode
committed
Initial commit
0 parents  commit b84c5ee

27 files changed

+794
-0
lines changed

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.gradle
2+
.idea
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
*.iml
10+
*.apk
11+
*.jobf

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# CameraFilter
2+
[![Apache 2.0 License](https://img.shields.io/badge/license-Apache%202.0-blue.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0.html)
3+
4+
Realtime camera filters. Process frames by OpenGL shaders.
5+
6+
## Filters
7+
8+
- **[Edge Detection](https://www.shadertoy.com/view/Xtd3W7#)**
9+
![](art/1.png)

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 23
5+
buildToolsVersion "24.0.0"
6+
7+
defaultConfig {
8+
applicationId "cn.nekocode.camerafilter"
9+
minSdkVersion 15
10+
targetSdkVersion 23
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
compile 'com.android.support:appcompat-v7:23.4.0'
25+
}

app/proguard-rules.pro

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /usr/local/opt/android-sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}

app/src/main/AndroidManifest.xml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="cn.nekocode.camerafilter">
4+
5+
<uses-permission android:name="android.permission.CAMERA"/>
6+
7+
<uses-feature
8+
android:name="android.hardware.camera"
9+
android:required="true"/>
10+
11+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
12+
13+
<application
14+
android:allowBackup="true"
15+
android:icon="@mipmap/ic_launcher"
16+
android:label="@string/app_name"
17+
android:supportsRtl="true"
18+
android:theme="@style/AppTheme">
19+
<activity android:name=".MainActivity">
20+
<intent-filter>
21+
<action android:name="android.intent.action.MAIN"/>
22+
23+
<category android:name="android.intent.category.LAUNCHER"/>
24+
</intent-filter>
25+
</activity>
26+
</application>
27+
28+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package cn.nekocode.camerafilter;
2+
3+
import android.app.Activity;
4+
import android.content.res.Resources;
5+
import android.graphics.SurfaceTexture;
6+
import android.hardware.Camera;
7+
import android.opengl.GLES11Ext;
8+
import android.opengl.GLES20;
9+
import android.opengl.GLUtils;
10+
import android.util.Log;
11+
import android.util.Pair;
12+
import android.view.TextureView;
13+
14+
import java.io.ByteArrayOutputStream;
15+
import java.io.IOException;
16+
import java.io.InputStream;
17+
import java.nio.ByteBuffer;
18+
import java.nio.ByteOrder;
19+
import java.nio.FloatBuffer;
20+
21+
import javax.microedition.khronos.egl.EGL10;
22+
import javax.microedition.khronos.egl.EGLConfig;
23+
import javax.microedition.khronos.egl.EGLContext;
24+
import javax.microedition.khronos.egl.EGLDisplay;
25+
import javax.microedition.khronos.egl.EGLSurface;
26+
import javax.microedition.khronos.opengles.GL10;
27+
import javax.microedition.khronos.opengles.GL11;
28+
29+
/**
30+
* Created by nekocode on 16/8/5.
31+
*/
32+
public class CameraSurfaceTexutreListener extends Thread implements TextureView.SurfaceTextureListener {
33+
private Camera camera;
34+
private Activity activity;
35+
private RenderThread renderThread;
36+
37+
public CameraSurfaceTexutreListener(Activity activity) {
38+
this.activity = activity;
39+
}
40+
41+
@Override
42+
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
43+
}
44+
45+
@Override
46+
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
47+
}
48+
49+
@Override
50+
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
51+
camera.stopPreview();
52+
camera.release();
53+
renderThread.release();
54+
55+
return true;
56+
}
57+
58+
@Override
59+
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
60+
// Open camera
61+
Pair<Camera.CameraInfo, Integer> backCamera = getBackCamera();
62+
final int backCameraId = backCamera.second;
63+
camera = Camera.open(backCameraId);
64+
65+
// Start rendering
66+
renderThread = new RenderThread(activity, surface, camera);
67+
renderThread.start();
68+
}
69+
70+
private Pair<Camera.CameraInfo, Integer> getBackCamera() {
71+
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
72+
final int numberOfCameras = Camera.getNumberOfCameras();
73+
74+
for (int i = 0; i < numberOfCameras; ++i) {
75+
Camera.getCameraInfo(i, cameraInfo);
76+
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
77+
return new Pair<>(cameraInfo, i);
78+
}
79+
}
80+
return null;
81+
}
82+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package cn.nekocode.camerafilter;
2+
3+
import android.os.Bundle;
4+
import android.support.v7.app.AppCompatActivity;
5+
import android.view.TextureView;
6+
7+
public class MainActivity extends AppCompatActivity {
8+
private TextureView textureView;
9+
10+
@Override
11+
protected void onCreate(Bundle savedInstanceState) {
12+
super.onCreate(savedInstanceState);
13+
14+
textureView = new TextureView(this);
15+
textureView.setSurfaceTextureListener(new CameraSurfaceTexutreListener(this));
16+
17+
setContentView(textureView);
18+
}
19+
}

0 commit comments

Comments
 (0)