Commit c79eb746 by huangdarwin Committed by Andrew Lewis

Effect: Add FloatRange to public GlEffect impl interfaces.

Using these annotations/checkers should hopefully make it marginally harder to use the wrong input values in the API.

PiperOrigin-RevId: 510966941
parent cbb6878f
...@@ -19,6 +19,7 @@ package com.google.android.exoplayer2.effect; ...@@ -19,6 +19,7 @@ package com.google.android.exoplayer2.effect;
import static com.google.android.exoplayer2.util.Assertions.checkArgument; import static com.google.android.exoplayer2.util.Assertions.checkArgument;
import android.content.Context; import android.content.Context;
import androidx.annotation.FloatRange;
import com.google.android.exoplayer2.util.VideoFrameProcessingException; import com.google.android.exoplayer2.util.VideoFrameProcessingException;
/** A {@link GlEffect} to control the contrast of video frames. */ /** A {@link GlEffect} to control the contrast of video frames. */
...@@ -33,7 +34,7 @@ public class Contrast implements GlEffect { ...@@ -33,7 +34,7 @@ public class Contrast implements GlEffect {
* <p>Contrast values range from -1 (all gray pixels) to 1 (maximum difference of colors). 0 means * <p>Contrast values range from -1 (all gray pixels) to 1 (maximum difference of colors). 0 means
* to add no contrast and leaves the frames unchanged. * to add no contrast and leaves the frames unchanged.
*/ */
public Contrast(float contrast) { public Contrast(@FloatRange(from = -1, to = 1) float contrast) {
checkArgument(-1 <= contrast && contrast <= 1, "Contrast needs to be in the interval [-1, 1]."); checkArgument(-1 <= contrast && contrast <= 1, "Contrast needs to be in the interval [-1, 1].");
this.contrast = contrast; this.contrast = contrast;
} }
......
...@@ -19,6 +19,7 @@ package com.google.android.exoplayer2.effect; ...@@ -19,6 +19,7 @@ package com.google.android.exoplayer2.effect;
import static com.google.android.exoplayer2.util.Assertions.checkArgument; import static com.google.android.exoplayer2.util.Assertions.checkArgument;
import android.content.Context; import android.content.Context;
import androidx.annotation.FloatRange;
import com.google.android.exoplayer2.util.VideoFrameProcessingException; import com.google.android.exoplayer2.util.VideoFrameProcessingException;
import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.CanIgnoreReturnValue;
...@@ -61,7 +62,7 @@ public class HslAdjustment implements GlEffect { ...@@ -61,7 +62,7 @@ public class HslAdjustment implements GlEffect {
* {@code 0}, which means no change is applied. * {@code 0}, which means no change is applied.
*/ */
@CanIgnoreReturnValue @CanIgnoreReturnValue
public Builder adjustSaturation(float saturationAdjustment) { public Builder adjustSaturation(@FloatRange(from = -100, to = 100) float saturationAdjustment) {
checkArgument( checkArgument(
-100 <= saturationAdjustment && saturationAdjustment <= 100, -100 <= saturationAdjustment && saturationAdjustment <= 100,
"Can adjust the saturation by only 100 in either direction, but provided " "Can adjust the saturation by only 100 in either direction, but provided "
...@@ -81,7 +82,7 @@ public class HslAdjustment implements GlEffect { ...@@ -81,7 +82,7 @@ public class HslAdjustment implements GlEffect {
* {@code 0}, which means no change is applied. * {@code 0}, which means no change is applied.
*/ */
@CanIgnoreReturnValue @CanIgnoreReturnValue
public Builder adjustLightness(float lightnessAdjustment) { public Builder adjustLightness(@FloatRange(from = -100, to = 100) float lightnessAdjustment) {
checkArgument( checkArgument(
-100 <= lightnessAdjustment && lightnessAdjustment <= 100, -100 <= lightnessAdjustment && lightnessAdjustment <= 100,
"Can adjust the lightness by only 100 in either direction, but provided " "Can adjust the lightness by only 100 in either direction, but provided "
......
...@@ -21,6 +21,7 @@ import static java.lang.annotation.ElementType.TYPE_USE; ...@@ -21,6 +21,7 @@ import static java.lang.annotation.ElementType.TYPE_USE;
import static java.lang.annotation.RetentionPolicy.SOURCE; import static java.lang.annotation.RetentionPolicy.SOURCE;
import android.graphics.Matrix; import android.graphics.Matrix;
import androidx.annotation.FloatRange;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.util.Size; import com.google.android.exoplayer2.util.Size;
...@@ -114,7 +115,8 @@ public final class Presentation implements MatrixTransformation { ...@@ -114,7 +115,8 @@ public final class Presentation implements MatrixTransformation {
* @param aspectRatio The aspect ratio (width/height ratio) of the output frame. Must be positive. * @param aspectRatio The aspect ratio (width/height ratio) of the output frame. Must be positive.
* @param layout The layout of the output frame. * @param layout The layout of the output frame.
*/ */
public static Presentation createForAspectRatio(float aspectRatio, @Layout int layout) { public static Presentation createForAspectRatio(
@FloatRange(from = 0, fromInclusive = false) float aspectRatio, @Layout int layout) {
checkArgument( checkArgument(
aspectRatio == C.LENGTH_UNSET || aspectRatio > 0, aspectRatio == C.LENGTH_UNSET || aspectRatio > 0,
"aspect ratio " + aspectRatio + " must be positive or unset"); "aspect ratio " + aspectRatio + " must be positive or unset");
......
...@@ -19,6 +19,7 @@ package com.google.android.exoplayer2.effect; ...@@ -19,6 +19,7 @@ package com.google.android.exoplayer2.effect;
import static com.google.android.exoplayer2.util.Assertions.checkArgument; import static com.google.android.exoplayer2.util.Assertions.checkArgument;
import android.opengl.Matrix; import android.opengl.Matrix;
import androidx.annotation.FloatRange;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.CanIgnoreReturnValue;
...@@ -45,7 +46,7 @@ public final class RgbAdjustment implements RgbMatrix { ...@@ -45,7 +46,7 @@ public final class RgbAdjustment implements RgbMatrix {
* default value is {@code 1}. * default value is {@code 1}.
*/ */
@CanIgnoreReturnValue @CanIgnoreReturnValue
public Builder setRedScale(float redScale) { public Builder setRedScale(@FloatRange(from = 0) float redScale) {
checkArgument(0 <= redScale, "Red scale needs to be non-negative."); checkArgument(0 <= redScale, "Red scale needs to be non-negative.");
this.redScale = redScale; this.redScale = redScale;
return this; return this;
...@@ -58,7 +59,7 @@ public final class RgbAdjustment implements RgbMatrix { ...@@ -58,7 +59,7 @@ public final class RgbAdjustment implements RgbMatrix {
* default value is {@code 1}. * default value is {@code 1}.
*/ */
@CanIgnoreReturnValue @CanIgnoreReturnValue
public Builder setGreenScale(float greenScale) { public Builder setGreenScale(@FloatRange(from = 0) float greenScale) {
checkArgument(0 <= greenScale, "Green scale needs to be non-negative."); checkArgument(0 <= greenScale, "Green scale needs to be non-negative.");
this.greenScale = greenScale; this.greenScale = greenScale;
return this; return this;
...@@ -71,7 +72,7 @@ public final class RgbAdjustment implements RgbMatrix { ...@@ -71,7 +72,7 @@ public final class RgbAdjustment implements RgbMatrix {
* default value is {@code 1}. * default value is {@code 1}.
*/ */
@CanIgnoreReturnValue @CanIgnoreReturnValue
public Builder setBlueScale(float blueScale) { public Builder setBlueScale(@FloatRange(from = 0) float blueScale) {
checkArgument(0 <= blueScale, "Blue scale needs to be non-negative."); checkArgument(0 <= blueScale, "Blue scale needs to be non-negative.");
this.blueScale = blueScale; this.blueScale = blueScale;
return this; return this;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment