Feature: add filter of blur

pull/221/head
xufuji456 2 years ago
parent 9d0cb83334
commit e112ecdeb9
  1. 3
      CameraFilter/src/main/java/com/frank/camerafilter/factory/BeautyFilterFactory.java
  2. 1
      CameraFilter/src/main/java/com/frank/camerafilter/factory/BeautyFilterType.java
  3. 33
      CameraFilter/src/main/java/com/frank/camerafilter/filter/advance/BeautyBlurFilter.java
  4. 24
      CameraFilter/src/main/res/raw/zoomblur.glsl
  5. 1
      app/src/main/java/com/frank/ffmpeg/activity/CameraFilterActivity.kt
  6. 1
      app/src/main/java/com/frank/ffmpeg/util/FilterTypeUtil.kt
  7. 1
      app/src/main/res/values-en/strings.xml
  8. 1
      app/src/main/res/values/strings.xml

@ -2,6 +2,7 @@ package com.frank.camerafilter.factory;
import android.content.Context; import android.content.Context;
import com.frank.camerafilter.filter.advance.BeautyBlurFilter;
import com.frank.camerafilter.filter.advance.BeautyHueFilter; import com.frank.camerafilter.filter.advance.BeautyHueFilter;
import com.frank.camerafilter.filter.advance.BeautySketchFilter; import com.frank.camerafilter.filter.advance.BeautySketchFilter;
import com.frank.camerafilter.filter.BaseFilter; import com.frank.camerafilter.filter.BaseFilter;
@ -16,6 +17,8 @@ public class BeautyFilterFactory {
switch (type) { switch (type) {
case SKETCH: case SKETCH:
return new BeautySketchFilter(context); return new BeautySketchFilter(context);
case BLUR:
return new BeautyBlurFilter(context);
case HUE: case HUE:
return new BeautyHueFilter(context); return new BeautyHueFilter(context);
case WHITE_BALANCE: case WHITE_BALANCE:

@ -2,6 +2,7 @@ package com.frank.camerafilter.factory;
public enum BeautyFilterType { public enum BeautyFilterType {
NONE, NONE,
BLUR,
HUE, HUE,
WHITE_BALANCE, WHITE_BALANCE,
SKETCH SKETCH

@ -0,0 +1,33 @@
package com.frank.camerafilter.filter.advance;
import android.content.Context;
import android.opengl.GLES30;
import com.frank.camerafilter.R;
import com.frank.camerafilter.filter.BaseFilter;
import com.frank.camerafilter.util.OpenGLUtil;
public class BeautyBlurFilter extends BaseFilter {
private int blurSize;
public BeautyBlurFilter(Context context) {
super(NORMAL_VERTEX_SHADER, OpenGLUtil.readShaderFromSource(context, R.raw.zoomblur));
}
protected void onInit() {
super.onInit();
blurSize = GLES30.glGetUniformLocation(getProgramId(), "blurSize");
}
protected void onInitialized() {
super.onInitialized();
setFloat(blurSize, 0.3f);
}
@Override
public void onInputSizeChanged(int width, int height) {
super.onInputSizeChanged(width, height);
}
}

@ -0,0 +1,24 @@
varying highp vec2 textureCoordinate;
uniform sampler2D inputImageTexture;
uniform highp vec2 blurCenter;
uniform highp float blurSize;
void main()
{
// TODO: Do a more intelligent scaling based on resolution here
highp vec2 samplingOffset = 1.0/100.0 * (blurCenter - textureCoordinate) * blurSize;
lowp vec4 fragmentColor = texture2D(inputImageTexture, textureCoordinate) * 0.18;
fragmentColor += texture2D(inputImageTexture, textureCoordinate + samplingOffset) * 0.15;
fragmentColor += texture2D(inputImageTexture, textureCoordinate + (2.0 * samplingOffset)) * 0.12;
fragmentColor += texture2D(inputImageTexture, textureCoordinate + (3.0 * samplingOffset)) * 0.09;
fragmentColor += texture2D(inputImageTexture, textureCoordinate + (4.0 * samplingOffset)) * 0.05;
fragmentColor += texture2D(inputImageTexture, textureCoordinate - samplingOffset) * 0.15;
fragmentColor += texture2D(inputImageTexture, textureCoordinate - (2.0 * samplingOffset)) * 0.12;
fragmentColor += texture2D(inputImageTexture, textureCoordinate - (3.0 * samplingOffset)) * 0.09;
fragmentColor += texture2D(inputImageTexture, textureCoordinate - (4.0 * samplingOffset)) * 0.05;
gl_FragColor = fragmentColor;
}

@ -15,6 +15,7 @@ class CameraFilterActivity : BaseActivity() {
private val filterType: Array<BeautyFilterType> = arrayOf( private val filterType: Array<BeautyFilterType> = arrayOf(
BeautyFilterType.NONE, BeautyFilterType.NONE,
BeautyFilterType.BLUR,
BeautyFilterType.HUE, BeautyFilterType.HUE,
BeautyFilterType.WHITE_BALANCE, BeautyFilterType.WHITE_BALANCE,
BeautyFilterType.SKETCH BeautyFilterType.SKETCH

@ -13,6 +13,7 @@ object FilterTypeUtil {
fun filterTypeToNameId(type: BeautyFilterType): Int { fun filterTypeToNameId(type: BeautyFilterType): Int {
return when (type) { return when (type) {
BeautyFilterType.NONE -> R.string.camera_filter_none BeautyFilterType.NONE -> R.string.camera_filter_none
BeautyFilterType.BLUR -> R.string.camera_filter_blur
BeautyFilterType.HUE -> R.string.camera_filter_hue BeautyFilterType.HUE -> R.string.camera_filter_hue
BeautyFilterType.WHITE_BALANCE -> R.string.camera_filter_balance BeautyFilterType.WHITE_BALANCE -> R.string.camera_filter_balance
BeautyFilterType.SKETCH -> R.string.camera_filter_sketch BeautyFilterType.SKETCH -> R.string.camera_filter_sketch

@ -116,5 +116,6 @@
<string name="camera_filter_hue">Hue</string> <string name="camera_filter_hue">Hue</string>
<string name="camera_filter_balance">White balance</string> <string name="camera_filter_balance">White balance</string>
<string name="camera_filter_sketch">Sketch</string> <string name="camera_filter_sketch">Sketch</string>
<string name="camera_filter_blur">Blur</string>
</resources> </resources>

@ -116,5 +116,6 @@
<string name="camera_filter_hue">Hue</string> <string name="camera_filter_hue">Hue</string>
<string name="camera_filter_balance">白平衡</string> <string name="camera_filter_balance">白平衡</string>
<string name="camera_filter_sketch">素描</string> <string name="camera_filter_sketch">素描</string>
<string name="camera_filter_blur">模糊</string>
</resources> </resources>

Loading…
Cancel
Save