Document all filters, implement onCopy, suppress warnings

pull/535/head
Mattia Iavarone 6 years ago
parent eff8018704
commit dccd542c7c
  1. 7
      cameraview/src/main/java/com/otaliastudios/cameraview/filter/BaseFilter.java
  2. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/filter/Filter.java
  3. 35
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/AutoFixFilter.java
  4. 1
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/BlackAndWhiteFilter.java
  5. 49
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/BrightnessFilter.java
  6. 32
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/ContrastFilter.java
  7. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/CrossProcessFilter.java
  8. 10
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/DocumentaryFilter.java
  9. 64
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/DuotoneFilter.java
  10. 32
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/FillLightFilter.java
  11. 49
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/GammaFilter.java
  12. 38
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/GrainFilter.java
  13. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/GrayscaleFilter.java
  14. 27
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/HueFilter.java
  15. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/InvertColorsFilter.java
  16. 9
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/LomoishFilter.java
  17. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/PosterizeFilter.java
  18. 44
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/SaturationFilter.java
  19. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/SepiaFilter.java
  20. 40
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/SharpnessFilter.java
  21. 39
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/TemperatureFilter.java
  22. 28
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/TintFilter.java
  23. 59
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/VignetteFilter.java
  24. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/preview/FilterCameraPreview.java
  25. 4
      cameraview/src/main/java/com/otaliastudios/cameraview/preview/GlCameraPreview.java

@ -149,7 +149,7 @@ public abstract class BaseFilter implements Filter {
} }
@Override @Override
public void setOutputSize(int width, int height) { public void setSize(int width, int height) {
outputSize = new Size(width, height); outputSize = new Size(width, height);
} }
@ -198,13 +198,12 @@ public abstract class BaseFilter implements Filter {
} }
@Override @Override
public BaseFilter copy() { public final BaseFilter copy() {
BaseFilter copy = onCopy(); BaseFilter copy = onCopy();
copy.setOutputSize(outputSize.getWidth(), outputSize.getHeight()); copy.setSize(outputSize.getWidth(), outputSize.getHeight());
return copy; return copy;
} }
@SuppressWarnings("WeakerAccess")
protected BaseFilter onCopy() { protected BaseFilter onCopy() {
try { try {
return getClass().newInstance(); return getClass().newInstance();

@ -70,7 +70,7 @@ public interface Filter {
* @param width width * @param width width
* @param height height * @param height height
*/ */
void setOutputSize(int width, int height); void setSize(int width, int height);
/** /**
* Clones this filter creating a new instance of it. * Clones this filter creating a new instance of it.

@ -5,29 +5,42 @@ import androidx.annotation.NonNull;
import com.otaliastudios.cameraview.filter.BaseFilter; import com.otaliastudios.cameraview.filter.BaseFilter;
/** /**
* Attempts to auto-fix the preview based on histogram equalization. * Attempts to auto-fix the frames based on histogram equalization.
*/ */
public class AutoFixFilter extends BaseFilter { public class AutoFixFilter extends BaseFilter {
private float scale = 1.0f; private float scale = 1.0f;
@SuppressWarnings("WeakerAccess")
public AutoFixFilter() { } public AutoFixFilter() { }
public float getScale() { /**
return scale; * A parameter between 0 and 1. Zero means no adjustment, while 1 indicates
* the maximum amount of adjustment.
*
* @param scale scale
*/
public void setScale(float scale) {
if (scale < 0.0f) scale = 0.0f;
if (scale > 1.0f) scale = 1.0f;
this.scale = scale;
} }
/** /**
* @param scale Float, between 0 and 1. Zero means no adjustment, while 1 * Returns the current scale.
* indicates the maximum amount of adjustment. *
* @see #setScale(float)
* @return current scale
*/ */
public void setScale(float scale) { public float getScale() {
if (scale < 0.0f) return scale;
scale = 0.0f; }
else if (scale > 1.0f)
scale = 1.0f;
this.scale = scale; @Override
protected BaseFilter onCopy() {
AutoFixFilter filter = new AutoFixFilter();
filter.setScale(getScale());
return filter;
} }
@NonNull @NonNull

@ -9,7 +9,6 @@ import com.otaliastudios.cameraview.filter.BaseFilter;
*/ */
public class BlackAndWhiteFilter extends BaseFilter { public class BlackAndWhiteFilter extends BaseFilter {
public BlackAndWhiteFilter() { } public BlackAndWhiteFilter() { }
@NonNull @NonNull

@ -5,37 +5,50 @@ import androidx.annotation.NonNull;
import com.otaliastudios.cameraview.filter.BaseFilter; import com.otaliastudios.cameraview.filter.BaseFilter;
/** /**
* Adjusts the brightness of the preview. * Adjusts the brightness of the frames.
*/ */
public class BrightnessFilter extends BaseFilter { public class BrightnessFilter extends BaseFilter {
private float brightnessValue = 2.0f;
/** private float brightness = 2.0f;
* Initialize Effect
*/ @SuppressWarnings("WeakerAccess")
public BrightnessFilter() { public BrightnessFilter() { }
}
/** /**
* setBrightnessValue * Sets the brightness adjustment.
* 0.0: normal brightness.
* 1.0: high brightness.
* *
* @param brightnessvalue Range should be between 0.0- 1.0 with 0.0 being normal. * @param brightness brightness.
*/ */
public void setBrightnessValue(float brightnessvalue) { @SuppressWarnings("WeakerAccess")
if (brightnessvalue < 0.0f) public void setBrightness(float brightness) {
brightnessvalue = 0.0f; if (brightness < 0.0f) brightness = 0.0f;
else if (brightnessvalue > 1.0f) if (brightness > 1.0f) brightness = 1.0f;
brightnessvalue = 1.0f;
//since the shader excepts a range of 1.0 - 2.0 //since the shader excepts a range of 1.0 - 2.0
// will add the 1.0 to every value // will add the 1.0 to every value
this.brightnessValue = 1.0f + brightnessvalue; this.brightness = 1.0f + brightness;
} }
public float getBrightnessValue() { /**
* Returns the current brightness.
*
* @see #setBrightness(float)
* @return brightness
*/
@SuppressWarnings({"unused", "WeakerAccess"})
public float getBrightness() {
//since the shader excepts a range of 1.0 - 2.0 //since the shader excepts a range of 1.0 - 2.0
//to keep it between 0.0f - 1.0f range, will subtract the 1.0 to every value //to keep it between 0.0f - 1.0f range, will subtract the 1.0 to every value
return brightnessValue - 1.0f; return brightness - 1.0f;
}
@Override
protected BaseFilter onCopy() {
BrightnessFilter filter = new BrightnessFilter();
filter.setBrightness(getBrightness());
return filter;
} }
@NonNull @NonNull
@ -47,7 +60,7 @@ public class BrightnessFilter extends BaseFilter {
+ "float brightness ;\n" + "float brightness ;\n"
+ "varying vec2 vTextureCoord;\n" + "varying vec2 vTextureCoord;\n"
+ "void main() {\n" + "void main() {\n"
+ " brightness =" + brightnessValue + ";\n" + " brightness =" + brightness + ";\n"
+ " vec4 color = texture2D(sTexture, vTextureCoord);\n" + " vec4 color = texture2D(sTexture, vTextureCoord);\n"
+ " gl_FragColor = brightness * color;\n" + " gl_FragColor = brightness * color;\n"
+ "}\n"; + "}\n";

@ -5,35 +5,51 @@ import androidx.annotation.NonNull;
import com.otaliastudios.cameraview.filter.BaseFilter; import com.otaliastudios.cameraview.filter.BaseFilter;
/** /**
* Adjusts the contrast of the preview. * Adjusts the contrast.
*/ */
public class ContrastFilter extends BaseFilter { public class ContrastFilter extends BaseFilter {
private float contrast = 2.0f; private float contrast = 2.0f;
@SuppressWarnings("WeakerAccess")
public ContrastFilter() { } public ContrastFilter() { }
/** /**
* setContrast * Sets the current contrast adjustment.
* 0.0: no adjustment
* 1.0: maximum adjustment
* *
* @param contrast Range should be between 0.0- 1.0 with 0.0 being normal. * @param contrast contrast
*/ */
@SuppressWarnings("WeakerAccess")
public void setContrast(float contrast) { public void setContrast(float contrast) {
if (contrast < 0.0f) if (contrast < 0.0f) contrast = 0.0f;
contrast = 0.0f; if (contrast > 1.0f) contrast = 1.0f;
else if (contrast > 1.0f)
contrast = 1.0f;
//since the shader excepts a range of 1.0 - 2.0 //since the shader excepts a range of 1.0 - 2.0
//will add the 1.0 to every value //will add the 1.0 to every value
this.contrast = contrast + 1.0f; this.contrast = contrast + 1.0f;
} }
/**
* Returns the current contrast.
*
* @see #setContrast(float)
* @return contrast
*/
@SuppressWarnings({"unused", "WeakerAccess"})
public float getContrast() { public float getContrast() {
//since the shader excepts a range of 1.0 - 2.0 //since the shader excepts a range of 1.0 - 2.0
//to keep it between 0.0f - 1.0f range, will subtract the 1.0 to every value //to keep it between 0.0f - 1.0f range, will subtract the 1.0 to every value
return contrast - 1.0f; return contrast - 1.0f;
} }
@Override
protected BaseFilter onCopy() {
ContrastFilter filter = new ContrastFilter();
filter.setContrast(getContrast());
return filter;
}
@NonNull @NonNull
@Override @Override
public String getFragmentShader() { public String getFragmentShader() {

@ -5,7 +5,7 @@ import androidx.annotation.NonNull;
import com.otaliastudios.cameraview.filter.BaseFilter; import com.otaliastudios.cameraview.filter.BaseFilter;
/** /**
* Applies a cross process effect on preview, in which the red and green channels * Applies a cross process effect, in which the red and green channels
* are enhanced while the blue channel is restricted. * are enhanced while the blue channel is restricted.
*/ */
public class CrossProcessFilter extends BaseFilter { public class CrossProcessFilter extends BaseFilter {

@ -8,19 +8,19 @@ import java.util.Date;
import java.util.Random; import java.util.Random;
/** /**
* Applies black and white documentary style effect on preview. * Applies black and white documentary style effect.
*/ */
public class DocumentaryFilter extends BaseFilter { public class DocumentaryFilter extends BaseFilter {
private final Random mRandom = new Random(new Date().getTime()); private final Random mRandom = new Random(new Date().getTime());
private int mOutputWidth = 1; private int mOutputWidth = 1;
private int mOutputHeight = 1; private int mOutputHeight = 1;
public DocumentaryFilter() { public DocumentaryFilter() { }
}
@Override @Override
public void setOutputSize(int width, int height) { public void setSize(int width, int height) {
super.setOutputSize(width, height); super.setSize(width, height);
mOutputWidth = width; mOutputWidth = width;
mOutputHeight = height; mOutputHeight = height;
} }

@ -2,43 +2,87 @@ package com.otaliastudios.cameraview.filters;
import android.graphics.Color; import android.graphics.Color;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.otaliastudios.cameraview.filter.BaseFilter; import com.otaliastudios.cameraview.filter.BaseFilter;
/** /**
* Representation of preview using only two color tones. * Representation of input frames using only two color tones.
*/ */
public class DuotoneFilter extends BaseFilter { public class DuotoneFilter extends BaseFilter {
// Default values // Default values
private int mFirstColor = Color.MAGENTA; private int mFirstColor = Color.MAGENTA;
private int mSecondColor = Color.YELLOW; private int mSecondColor = Color.YELLOW;
@SuppressWarnings("WeakerAccess")
public DuotoneFilter() { }
public DuotoneFilter() { /**
* Sets the two duotone ARGB colors.
* @param firstColor first
* @param secondColor second
*/
@SuppressWarnings({"unused", "WeakerAccess"})
public void setColors(@ColorInt int firstColor, @ColorInt int secondColor) {
setFirstColor(firstColor);
setSecondColor(secondColor);
} }
/** /**
* setDuotoneColors * Sets the first of the duotone ARGB colors.
* Defaults to {@link Color#MAGENTA}.
* *
* @param firstColor Integer, representing an ARGB color with 8 bits per channel. * @param color first color
* May be created using Color class.
* @param secondColor Integer, representing an ARGB color with 8 bits per channel.
* May be created using Color class.
*/ */
public void setDuotoneColors(int firstColor, int secondColor) { @SuppressWarnings("WeakerAccess")
this.mFirstColor = firstColor; public void setFirstColor(@ColorInt int color) {
this.mSecondColor = secondColor; mFirstColor = color;
} }
/**
* Sets the second of the duotone ARGB colors.
* Defaults to {@link Color#YELLOW}.
*
* @param color second color
*/
@SuppressWarnings("WeakerAccess")
public void setSecondColor(@ColorInt int color) {
mSecondColor = color;
}
/**
* Returns the first color.
*
* @see #setFirstColor(int)
* @return first
*/
@SuppressWarnings("unused")
@ColorInt
public int getFirstColor() { public int getFirstColor() {
return mFirstColor; return mFirstColor;
} }
/**
* Returns the second color.
*
* @see #setSecondColor(int)
* @return second
*/
@SuppressWarnings("unused")
@ColorInt
public int getSecondColor() { public int getSecondColor() {
return mSecondColor; return mSecondColor;
} }
@Override
protected BaseFilter onCopy() {
DuotoneFilter filter = new DuotoneFilter();
filter.setColors(mFirstColor, mSecondColor);
return filter;
}
@NonNull @NonNull
@Override @Override
public String getFragmentShader() { public String getFragmentShader() {

@ -5,31 +5,47 @@ import androidx.annotation.NonNull;
import com.otaliastudios.cameraview.filter.BaseFilter; import com.otaliastudios.cameraview.filter.BaseFilter;
/** /**
* Applies back-light filling to the preview. * Applies back-light filling to the frames.
*/ */
public class FillLightFilter extends BaseFilter { public class FillLightFilter extends BaseFilter {
private float strength = 0.5f; private float strength = 0.5f;
@SuppressWarnings("WeakerAccess")
public FillLightFilter() { } public FillLightFilter() { }
/** /**
* setStrength * Sets the current strength.
* 0.0: no change.
* 1.0: max strength.
* *
* @param strength Float, between 0.0 and 1.0 where 0.0 means no change. * @param strength strength
*/ */
@SuppressWarnings("WeakerAccess")
public void setStrength(float strength) { public void setStrength(float strength) {
if (strength < 0.0f) if (strength < 0.0f) strength = 0f;
strength = 0f; if (strength > 1.0f) strength = 1f;
else if (strength > 1.0f)
strength = 1f;
this.strength = strength; this.strength = strength;
} }
/**
* Returns the current strength.
*
* @see #setStrength(float)
* @return strength
*/
@SuppressWarnings({"unused", "WeakerAccess"})
public float getStrength() { public float getStrength() {
return strength; return strength;
} }
@Override
protected BaseFilter onCopy() {
FillLightFilter filter = new FillLightFilter();
filter.setStrength(getStrength());
return filter;
}
@NonNull @NonNull
@Override @Override
public String getFragmentShader() { public String getFragmentShader() {

@ -5,37 +5,48 @@ import androidx.annotation.NonNull;
import com.otaliastudios.cameraview.filter.BaseFilter; import com.otaliastudios.cameraview.filter.BaseFilter;
/** /**
* Apply Gamma Effect on preview being played * Applies gamma correction to the frames.
*/ */
public class GammaFilter extends BaseFilter { public class GammaFilter extends BaseFilter {
private float gammaValue = 2.0f;
/** private float gamma = 2.0f;
* Initialize Effect
*/ @SuppressWarnings("WeakerAccess")
public GammaFilter() { public GammaFilter() { }
}
/** /**
* setGammaValue * Sets the new gamma value in the 0.0 - 1.0 range.
* The 0.5 value means no correction will be applied.
* *
* @param gammaValue Range should be between 0.0 - 1.0 with 0.5 being normal. * @param gamma gamma value
*/ */
public void setGammaValue(float gammaValue) { @SuppressWarnings("WeakerAccess")
if (gammaValue < 0.0f) public void setGamma(float gamma) {
gammaValue = 0.0f; if (gamma < 0.0f) gamma = 0.0f;
else if (gammaValue > 1.0f) if (gamma > 1.0f) gamma = 1.0f;
gammaValue = 1.0f;
//since the shader excepts a range of 0.0 - 2.0 //since the shader excepts a range of 0.0 - 2.0
//will multiply the 2.0 to every value //will multiply the 2.0 to every value
this.gammaValue = gammaValue * 2.0f; this.gamma = gamma * 2.0f;
} }
public float getGammaValue() { /**
* Returns the current gamma.
*
* @see #setGamma(float)
* @return gamma
*/
@SuppressWarnings({"unused", "WeakerAccess"})
public float getGamma() {
//since the shader excepts a range of 0.0 - 2.0 //since the shader excepts a range of 0.0 - 2.0
//to keep it between 0.0f - 1.0f range, will divide it with 2.0 //to keep it between 0.0f - 1.0f range, will divide it with 2.0
return gammaValue / 2.0f; return gamma / 2.0f;
}
@Override
protected BaseFilter onCopy() {
GammaFilter filter = new GammaFilter();
filter.setGamma(getGamma());
return filter;
} }
@NonNull @NonNull
@ -45,7 +56,7 @@ public class GammaFilter extends BaseFilter {
+ "precision mediump float;\n" + "precision mediump float;\n"
+ "varying vec2 vTextureCoord;\n" + "varying vec2 vTextureCoord;\n"
+ "uniform samplerExternalOES sTexture;\n" + "uniform samplerExternalOES sTexture;\n"
+ "float gamma=" + gammaValue + ";\n" + "float gamma=" + gamma + ";\n"
+ "void main() {\n" + "void main() {\n"
+ " vec4 textureColor = texture2D(sTexture, vTextureCoord);\n" + " vec4 textureColor = texture2D(sTexture, vTextureCoord);\n"
+ " gl_FragColor = vec4(pow(textureColor.rgb, vec3(gamma)), textureColor.w);\n" + " gl_FragColor = vec4(pow(textureColor.rgb, vec3(gamma)), textureColor.w);\n"

@ -8,7 +8,7 @@ import java.util.Date;
import java.util.Random; import java.util.Random;
/** /**
* Applies film grain effect to preview. * Applies film grain effect to the frames.
*/ */
public class GrainFilter extends BaseFilter { public class GrainFilter extends BaseFilter {
@ -17,34 +17,48 @@ public class GrainFilter extends BaseFilter {
private int mOutputWidth = 1; private int mOutputWidth = 1;
private int mOutputHeight = 1; private int mOutputHeight = 1;
@SuppressWarnings("WeakerAccess")
public GrainFilter() { } public GrainFilter() { }
@Override @Override
public void setOutputSize(int width, int height) { public void setSize(int width, int height) {
super.setOutputSize(width, height); super.setSize(width, height);
mOutputWidth = width; mOutputWidth = width;
mOutputHeight = height; mOutputHeight = height;
} }
/** /**
* setDistortionStrength * Sets the current distortion strength.
* 0.0: no distortion.
* 1.0: maximum distortion.
* *
* @param strength Float, between 0.0f and 1.0. Zero means no distortion, while 1 * @param strength strength
* indicates the maximum amount of adjustment.
*/ */
public void setDistortionStrength(float strength) { @SuppressWarnings("WeakerAccess")
if (strength < 0.0f) public void setStrength(float strength) {
strength = 0.0f; if (strength < 0.0f) strength = 0.0f;
else if (strength > 1.0f) if (strength > 1.0f) strength = 1.0f;
strength = 1.0f;
this.strength = strength; this.strength = strength;
} }
/**
* Returns the current strength.
*
* @see #setStrength(float)
* @return strength
*/
@SuppressWarnings({"unused", "WeakerAccess"})
public float getStrength() { public float getStrength() {
return strength; return strength;
} }
@Override
protected BaseFilter onCopy() {
GrainFilter filter = new GrainFilter();
filter.setStrength(getStrength());
return filter;
}
@NonNull @NonNull
@Override @Override
public String getFragmentShader() { public String getFragmentShader() {

@ -5,7 +5,7 @@ import androidx.annotation.NonNull;
import com.otaliastudios.cameraview.filter.BaseFilter; import com.otaliastudios.cameraview.filter.BaseFilter;
/** /**
* Converts preview to GreyScale. * Converts frames to gray scale.
*/ */
public class GrayscaleFilter extends BaseFilter { public class GrayscaleFilter extends BaseFilter {

@ -5,25 +5,30 @@ import androidx.annotation.NonNull;
import com.otaliastudios.cameraview.filter.BaseFilter; import com.otaliastudios.cameraview.filter.BaseFilter;
/** /**
* Apply Hue effect on the preview * Applies a hue effect on the input frames.
*/ */
public class HueFilter extends BaseFilter { public class HueFilter extends BaseFilter {
private float hueValue = 0.0f; private float hueValue = 0.0f;
/** @SuppressWarnings("WeakerAccess")
* Initialize Effect public HueFilter() { }
*/
public HueFilter() {
}
/** /**
* Hue value chart - https://cloud.githubusercontent.com/assets/2201511/21810115/b99ac22a-d74a-11e6-9f6c-ef74d15c88c7.jpg" * Sets the hue value in degrees. See the values chart:
* * https://cloud.githubusercontent.com/assets/2201511/21810115/b99ac22a-d74a-11e6-9f6c-ef74d15c88c7.jpg
* @param hueDegrees Range of value should be between 0 to 360 degrees as described in the image above
*/ */
public void setHueDegreeValue(float hueDegrees) { @SuppressWarnings("unused")
public void setHue(float degrees) {
// manipulating input value so that we can map it on 360 degree circle // manipulating input value so that we can map it on 360 degree circle
hueValue = ((hueDegrees - 45) / 45f + 0.5f) * -1; hueValue = ((degrees - 45) / 45f + 0.5f) * -1;
}
@Override
protected BaseFilter onCopy() {
HueFilter filter = new HueFilter();
filter.hueValue = hueValue;
return filter;
} }
@NonNull @NonNull

@ -5,7 +5,7 @@ import androidx.annotation.NonNull;
import com.otaliastudios.cameraview.filter.BaseFilter; import com.otaliastudios.cameraview.filter.BaseFilter;
/** /**
* Inverts the preview colors. This can also be known as negative Effect. * Inverts the input colors. This is also known as negative effect.
*/ */
public class InvertColorsFilter extends BaseFilter { public class InvertColorsFilter extends BaseFilter {

@ -8,7 +8,7 @@ import java.util.Date;
import java.util.Random; import java.util.Random;
/** /**
* Applies lomo-camera style effect to preview. * Applies a lomo-camera style effect to the input frames.
*/ */
public class LomoishFilter extends BaseFilter { public class LomoishFilter extends BaseFilter {
@ -16,12 +16,11 @@ public class LomoishFilter extends BaseFilter {
private int mOutputWidth = 1; private int mOutputWidth = 1;
private int mOutputHeight = 1; private int mOutputHeight = 1;
public LomoishFilter() { public LomoishFilter() { }
}
@Override @Override
public void setOutputSize(int width, int height) { public void setSize(int width, int height) {
super.setOutputSize(width, height); super.setSize(width, height);
mOutputWidth = width; mOutputWidth = width;
mOutputHeight = height; mOutputHeight = height;
} }

@ -5,7 +5,7 @@ import androidx.annotation.NonNull;
import com.otaliastudios.cameraview.filter.BaseFilter; import com.otaliastudios.cameraview.filter.BaseFilter;
/** /**
* Applies Posterization effect to Preview. * Applies a posterization effect to the input frames.
*/ */
public class PosterizeFilter extends BaseFilter { public class PosterizeFilter extends BaseFilter {

@ -5,39 +5,53 @@ import androidx.annotation.NonNull;
import com.otaliastudios.cameraview.filter.BaseFilter; import com.otaliastudios.cameraview.filter.BaseFilter;
/** /**
* Adjusts color saturation of preview. * Adjusts color saturation.
*/ */
public class SaturationFilter extends BaseFilter { public class SaturationFilter extends BaseFilter {
private float scale = 1.0f; private float scale = 1.0f;
/** @SuppressWarnings("WeakerAccess")
* Initialize Effect public SaturationFilter() { }
*/
public SaturationFilter() {
}
/** /**
* @param value Float, between 0.0 and 1. 0 means no change, while 0.0 indicates * Sets the saturation correction value:
* full desaturated, i.e. grayscale. * 0.0: fully desaturated, grayscale.
* and 1.0 indicates full saturation * 0.5: no change.
* 1.0: fully saturated.
*
* @param value new value
*/ */
public void setSaturationValue(float value) { @SuppressWarnings("WeakerAccess")
if (value < 0.0f) public void setSaturation(float value) {
value = 0.0f; if (value < 0.0f) value = 0.0f;
else if (value > 1.0f) if (value > 1.0f) value = 1.0f;
value = 1.0f;
//since the shader excepts a range of -1.0 to 1.0 //since the shader excepts a range of -1.0 to 1.0
//will multiply it by 2.0f and subtract 1.0 to every value //will multiply it by 2.0f and subtract 1.0 to every value
this.scale = (2.0f * value) - 1.0f; this.scale = (2.0f * value) - 1.0f;
} }
public float getSaturationValue() { /**
* Returns the current saturation.
*
* @see #setSaturation(float)
* @return saturation
*/
@SuppressWarnings("WeakerAccess")
public float getSaturation() {
//since the shader excepts a range of -1.0 to 1.0 //since the shader excepts a range of -1.0 to 1.0
//will add 1.0 to every value and divide it by 2.0f //will add 1.0 to every value and divide it by 2.0f
return (scale + 1.0f) / 2.0f; return (scale + 1.0f) / 2.0f;
} }
@Override
protected BaseFilter onCopy() {
SaturationFilter filter = new SaturationFilter();
filter.setSaturation(getSaturation());
return filter;
}
@NonNull @NonNull
@Override @Override
public String getFragmentShader() { public String getFragmentShader() {

@ -5,7 +5,7 @@ import androidx.annotation.NonNull;
import com.otaliastudios.cameraview.filter.BaseFilter; import com.otaliastudios.cameraview.filter.BaseFilter;
/** /**
* Converts preview to Sepia tone. * Converts frames to sepia tone.
*/ */
public class SepiaFilter extends BaseFilter { public class SepiaFilter extends BaseFilter {

@ -5,38 +5,56 @@ import androidx.annotation.NonNull;
import com.otaliastudios.cameraview.filter.BaseFilter; import com.otaliastudios.cameraview.filter.BaseFilter;
/** /**
* Sharpens the preview. * Sharpens the input frames.
*/ */
public class SharpnessFilter extends BaseFilter { public class SharpnessFilter extends BaseFilter {
private float scale = 0.5f; private float scale = 0.5f;
private int mOutputWidth = 1; private int mOutputWidth = 1;
private int mOutputHeight = 1; private int mOutputHeight = 1;
@SuppressWarnings("WeakerAccess")
public SharpnessFilter() { } public SharpnessFilter() { }
@Override @Override
public void setOutputSize(int width, int height) { public void setSize(int width, int height) {
super.setOutputSize(width, height); super.setSize(width, height);
mOutputWidth = width; mOutputWidth = width;
mOutputHeight = height; mOutputHeight = height;
} }
/** /**
* @param value Float, between 0 and 1. 0 means no change. * Sets the current sharpness value:
* 0.0: no change.
* 1.0: maximum sharpness.
*
* @param value new sharpness
*/ */
public void setSharpnessValue(float value) { @SuppressWarnings("WeakerAccess")
if (value < 0.0f) public void setSharpness(float value) {
value = 0.0f; if (value < 0.0f) value = 0.0f;
else if (value > 1.0f) if (value > 1.0f) value = 1.0f;
value = 1.0f;
this.scale = value; this.scale = value;
} }
public float getSharpnessValue() { /**
* Returns the current sharpness.
*
* @see #setSharpness(float)
* @return sharpness
*/
@SuppressWarnings("WeakerAccess")
public float getSharpness() {
return scale; return scale;
} }
@Override
protected BaseFilter onCopy() {
SharpnessFilter filter = new SharpnessFilter();
filter.setSharpness(getSharpness());
return filter;
}
@NonNull @NonNull
@Override @Override
public String getFragmentShader() { public String getFragmentShader() {

@ -5,29 +5,48 @@ import androidx.annotation.NonNull;
import com.otaliastudios.cameraview.filter.BaseFilter; import com.otaliastudios.cameraview.filter.BaseFilter;
/** /**
* Adjusts color temperature of the preview. * Adjusts color temperature.
*/ */
public class TemperatureFilter extends BaseFilter { public class TemperatureFilter extends BaseFilter {
private float scale = 0f; private float scale = 0f;
@SuppressWarnings("WeakerAccess")
public TemperatureFilter() { } public TemperatureFilter() { }
/** /**
* @param scale Float, between 0 and 1, with 0 indicating cool, and 1 * Sets the new temperature value:
* indicating warm. A value of of 0.5 indicates no change. * 0.0: cool colors
* 0.5: no change
* 1.0: warm colors
*
* @param value new value
*/ */
public void setTemperatureScale(float scale) { @SuppressWarnings("WeakerAccess")
if (scale < 0.0f) public void setTemperature(float value) {
scale = 0.0f; if (value < 0.0f) value = 0.0f;
else if (scale > 1.0f) if (value > 1.0f) value = 1.0f;
scale = 1.0f; this.scale = value;
this.scale = scale;
} }
public float getTemperatureScale() { /**
* Returns the current temperature.
*
* @see #setTemperature(float)
* @return temperature
*/
@SuppressWarnings("WeakerAccess")
public float getTemperature() {
return scale; return scale;
} }
@Override
protected BaseFilter onCopy() {
TemperatureFilter filter = new TemperatureFilter();
filter.setTemperature(getTemperature());
return filter;
}
@NonNull @NonNull
@Override @Override
public String getFragmentShader() { public String getFragmentShader() {

@ -2,27 +2,49 @@ package com.otaliastudios.cameraview.filters;
import android.graphics.Color; import android.graphics.Color;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.otaliastudios.cameraview.filter.BaseFilter; import com.otaliastudios.cameraview.filter.BaseFilter;
/** /**
* Tints the preview with specified color.. * Tints the frames with specified color.
*/ */
public class TintFilter extends BaseFilter { public class TintFilter extends BaseFilter {
private int mTint = 0xFFFF0000; private int mTint = 0xFFFF0000;
@SuppressWarnings("WeakerAccess")
public TintFilter() { } public TintFilter() { }
public void setTintColor(int color) { /**
* Sets the current tint.
* @param color current tint
*/
@SuppressWarnings("WeakerAccess")
public void setTint(@ColorInt int color) {
this.mTint = color; this.mTint = color;
} }
public int getTintColor() { /**
* Returns the current tint.
*
* @see #setTint(int)
* @return tint
*/
@SuppressWarnings("WeakerAccess")
@ColorInt
public int getTint() {
return mTint; return mTint;
} }
@Override
protected BaseFilter onCopy() {
TintFilter filter = new TintFilter();
filter.setTint(getTint());
return filter;
}
@NonNull @NonNull
@Override @Override
public String getFragmentShader() { public String getFragmentShader() {

@ -6,7 +6,7 @@ import com.otaliastudios.cameraview.filter.BaseFilter;
/** /**
* Applies lomo-camera style effect to your preview. * Applies a vignette effect to input frames.
*/ */
public class VignetteFilter extends BaseFilter { public class VignetteFilter extends BaseFilter {
@ -15,21 +15,22 @@ public class VignetteFilter extends BaseFilter {
private int mOutputWidth = 1; private int mOutputWidth = 1;
private int mOutputHeight = 1; private int mOutputHeight = 1;
@SuppressWarnings("WeakerAccess")
public VignetteFilter() { } public VignetteFilter() { }
@Override @Override
public void setOutputSize(int width, int height) { public void setSize(int width, int height) {
super.setOutputSize(width, height); super.setSize(width, height);
mOutputWidth = width; mOutputWidth = width;
mOutputHeight = height; mOutputHeight = height;
} }
/** /**
* setVignetteEffectScale * Sets the vignette effect scale (0.0 - 1.0).
* * @param scale new scale
* @param scale Float, between 0.0 and 1. 0
*/ */
public void setVignetteEffectScale(float scale) { @SuppressWarnings("WeakerAccess")
public void setVignetteScale(float scale) {
if (scale < 0.0f) if (scale < 0.0f)
scale = 0.0f; scale = 0.0f;
else if (scale > 1.0f) else if (scale > 1.0f)
@ -38,18 +39,46 @@ public class VignetteFilter extends BaseFilter {
} }
/** /**
* setVignetteEffectShade * Sets the vignette effect shade (0.0 - 1.0).
* * @param shade new shade
* @param shade Float, between 0.0 and 1. 0
*/ */
public void setVignetteEffectShade(float shade) { @SuppressWarnings("WeakerAccess")
if (shade < 0.0f) public void setVignetteShade(float shade) {
shade = 0.0f; if (shade < 0.0f) shade = 0.0f;
else if (shade > 1.0f) if (shade > 1.0f) shade = 1.0f;
shade = 1.0f;
this.mShade = shade; this.mShade = shade;
} }
/**
* Gets the current vignette scale.
*
* @see #setVignetteScale(float)
* @return scale
*/
@SuppressWarnings("WeakerAccess")
public float getVignetteScale() {
return mScale;
}
/**
* Gets the current vignette shade.
*
* @see #setVignetteShade(float)
* @return shade
*/
@SuppressWarnings("WeakerAccess")
public float getVignetteShade() {
return mShade;
}
@Override
protected BaseFilter onCopy() {
VignetteFilter filter = new VignetteFilter();
filter.setVignetteScale(getVignetteScale());
filter.setVignetteShade(getVignetteShade());
return filter;
}
@NonNull @NonNull
@Override @Override
public String getFragmentShader() { public String getFragmentShader() {

@ -13,7 +13,7 @@ import com.otaliastudios.cameraview.filter.Filter;
/** /**
* A preview that support GL filters defined through the {@link Filter} interface. * A preview that support GL filters defined through the {@link Filter} interface.
* *
* The preview has the responsibility of calling {@link Filter#setOutputSize(int, int)} * The preview has the responsibility of calling {@link Filter#setSize(int, int)}
* whenever the preview size changes and as soon as the filter is applied. * whenever the preview size changes and as soon as the filter is applied.
*/ */
public abstract class FilterCameraPreview<T extends View, Output> extends CameraPreview<T, Output> { public abstract class FilterCameraPreview<T extends View, Output> extends CameraPreview<T, Output> {

@ -171,7 +171,7 @@ public class GlCameraPreview extends FilterCameraPreview<GLSurfaceView, SurfaceT
@Override @Override
public void onSurfaceChanged(GL10 gl, final int width, final int height) { public void onSurfaceChanged(GL10 gl, final int width, final int height) {
gl.glViewport(0, 0, width, height); gl.glViewport(0, 0, width, height);
mCurrentFilter.setOutputSize(width, height); mCurrentFilter.setSize(width, height);
if (!mDispatched) { if (!mDispatched) {
dispatchOnSurfaceAvailable(width, height); dispatchOnSurfaceAvailable(width, height);
mDispatched = true; mDispatched = true;
@ -327,7 +327,7 @@ public class GlCameraPreview extends FilterCameraPreview<GLSurfaceView, SurfaceT
@Override @Override
public void setFilter(@NonNull Filter filter) { public void setFilter(@NonNull Filter filter) {
if (hasSurface()) { if (hasSurface()) {
filter.setOutputSize(mOutputSurfaceWidth, mOutputSurfaceHeight); filter.setSize(mOutputSurfaceWidth, mOutputSurfaceHeight);
} }
mCurrentFilter = filter; mCurrentFilter = filter;
if (mOutputViewport != null) { if (mOutputViewport != null) {

Loading…
Cancel
Save