Improve TintFilter and DuotoneFilter

pull/537/head
Mattia Iavarone 6 years ago
parent a9ff98a88c
commit 06760efd1c
  1. 14
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/DuotoneFilter.java
  2. 7
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/TintFilter.java

@ -55,7 +55,8 @@ public class DuotoneFilter extends BaseFilter implements TwoParameterFilter {
*/
@SuppressWarnings("WeakerAccess")
public void setFirstColor(@ColorInt int color) {
mFirstColor = color;
// Remove any alpha.
mFirstColor = Color.rgb(Color.red(color), Color.green(color), Color.blue(color));
}
/**
@ -66,7 +67,8 @@ public class DuotoneFilter extends BaseFilter implements TwoParameterFilter {
*/
@SuppressWarnings("WeakerAccess")
public void setSecondColor(@ColorInt int color) {
mSecondColor = color;
// Remove any alpha.
mSecondColor = Color.rgb(Color.red(color), Color.green(color), Color.blue(color));
}
/**
@ -96,23 +98,23 @@ public class DuotoneFilter extends BaseFilter implements TwoParameterFilter {
@Override
public void setParameter1(float value) {
// no easy way to transform 0...1 into a color.
setFirstColor((int) (value * Integer.MAX_VALUE));
setFirstColor((int) (value * 0xFFFFFF));
}
@Override
public float getParameter1() {
return (float) getFirstColor() / Integer.MAX_VALUE;
return (float) getFirstColor() / 0xFFFFFF;
}
@Override
public void setParameter2(float value) {
// no easy way to transform 0...1 into a color.
setSecondColor((int) (value * Integer.MAX_VALUE));
setSecondColor((int) (value * 0xFFFFFF));
}
@Override
public float getParameter2() {
return (float) getSecondColor() / Integer.MAX_VALUE;
return (float) getSecondColor() / 0xFFFFFF;
}
@NonNull

@ -42,7 +42,8 @@ public class TintFilter extends BaseFilter implements OneParameterFilter {
*/
@SuppressWarnings("WeakerAccess")
public void setTint(@ColorInt int color) {
this.tint = color;
// Remove any alpha.
this.tint = Color.rgb(Color.red(color), Color.green(color), Color.blue(color));
}
/**
@ -60,12 +61,12 @@ public class TintFilter extends BaseFilter implements OneParameterFilter {
@Override
public void setParameter1(float value) {
// no easy way to transform 0...1 into a color.
setTint((int) (value * Integer.MAX_VALUE));
setTint((int) (value * 0xFFFFFF));
}
@Override
public float getParameter1() {
return (float) getTint() / Integer.MAX_VALUE;
return (float) getTint() / 0xFFFFFF;
}
@NonNull

Loading…
Cancel
Save