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
This commit is contained in:
parent
ab7e84fb34
commit
e282c0ad67
@ -19,6 +19,7 @@ package androidx.media3.effect;
|
|||||||
import static androidx.media3.common.util.Assertions.checkArgument;
|
import static androidx.media3.common.util.Assertions.checkArgument;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import androidx.annotation.FloatRange;
|
||||||
import androidx.media3.common.VideoFrameProcessingException;
|
import androidx.media3.common.VideoFrameProcessingException;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
|
|
||||||
@ -35,7 +36,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 androidx.media3.effect;
|
|||||||
import static androidx.media3.common.util.Assertions.checkArgument;
|
import static androidx.media3.common.util.Assertions.checkArgument;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import androidx.annotation.FloatRange;
|
||||||
import androidx.media3.common.VideoFrameProcessingException;
|
import androidx.media3.common.VideoFrameProcessingException;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||||
@ -63,7 +64,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 "
|
||||||
@ -83,7 +84,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;
|
|||||||
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 androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.util.Size;
|
import androidx.media3.common.util.Size;
|
||||||
@ -116,7 +117,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 androidx.media3.effect;
|
|||||||
import static androidx.media3.common.util.Assertions.checkArgument;
|
import static androidx.media3.common.util.Assertions.checkArgument;
|
||||||
|
|
||||||
import android.opengl.Matrix;
|
import android.opengl.Matrix;
|
||||||
|
import androidx.annotation.FloatRange;
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||||
@ -47,7 +48,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;
|
||||||
@ -60,7 +61,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;
|
||||||
@ -73,7 +74,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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user