Overlay: Rename alpha to alphaScale.

The actual logic scales the alpha, instead of setting it, so rename
this to what it does.

We would also prefer alpha to be scaled here, to not lose alpha information
(for example for PNGs with transparent regions).

PiperOrigin-RevId: 560121708
This commit is contained in:
huangdarwin 2023-08-25 09:58:03 -07:00 committed by Copybara-Service
parent 1f013afea8
commit 6da70c842e
4 changed files with 20 additions and 19 deletions

View File

@ -617,7 +617,7 @@ public final class TransformerActivity extends AppCompatActivity {
if (selectedEffects[ConfigurationActivity.BITMAP_OVERLAY_INDEX]) { if (selectedEffects[ConfigurationActivity.BITMAP_OVERLAY_INDEX]) {
OverlaySettings overlaySettings = OverlaySettings overlaySettings =
new OverlaySettings.Builder() new OverlaySettings.Builder()
.setAlpha( .setAlphaScale(
bundle.getFloat( bundle.getFloat(
ConfigurationActivity.BITMAP_OVERLAY_ALPHA, /* defaultValue= */ 1)) ConfigurationActivity.BITMAP_OVERLAY_ALPHA, /* defaultValue= */ 1))
.build(); .build();
@ -631,7 +631,7 @@ public final class TransformerActivity extends AppCompatActivity {
if (selectedEffects[ConfigurationActivity.TEXT_OVERLAY_INDEX]) { if (selectedEffects[ConfigurationActivity.TEXT_OVERLAY_INDEX]) {
OverlaySettings overlaySettings = OverlaySettings overlaySettings =
new OverlaySettings.Builder() new OverlaySettings.Builder()
.setAlpha( .setAlphaScale(
bundle.getFloat(ConfigurationActivity.TEXT_OVERLAY_ALPHA, /* defaultValue= */ 1)) bundle.getFloat(ConfigurationActivity.TEXT_OVERLAY_ALPHA, /* defaultValue= */ 1))
.build(); .build();
SpannableString overlayText = SpannableString overlayText =

View File

@ -253,7 +253,7 @@ public class OverlayShaderProgramPixelTest {
@RequiresNonNull("testId") @RequiresNonNull("testId")
public void drawFrame_translucentBitmapOverlay_blendsBitmapIntoFrame() throws Exception { public void drawFrame_translucentBitmapOverlay_blendsBitmapIntoFrame() throws Exception {
Bitmap bitmap = readBitmap(OVERLAY_PNG_ASSET_PATH); Bitmap bitmap = readBitmap(OVERLAY_PNG_ASSET_PATH);
OverlaySettings overlaySettings = new OverlaySettings.Builder().setAlpha(0.5f).build(); OverlaySettings overlaySettings = new OverlaySettings.Builder().setAlphaScale(0.5f).build();
BitmapOverlay translucentBitmapOverlay = BitmapOverlay translucentBitmapOverlay =
BitmapOverlay.createStaticBitmapOverlay(bitmap, overlaySettings); BitmapOverlay.createStaticBitmapOverlay(bitmap, overlaySettings);
overlayShaderProgram = overlayShaderProgram =
@ -277,7 +277,7 @@ public class OverlayShaderProgramPixelTest {
@RequiresNonNull("testId") @RequiresNonNull("testId")
public void drawFrame_transparentTextOverlay_blendsBitmapIntoFrame() throws Exception { public void drawFrame_transparentTextOverlay_blendsBitmapIntoFrame() throws Exception {
SpannableString overlayText = new SpannableString(/* source= */ "Text styling"); SpannableString overlayText = new SpannableString(/* source= */ "Text styling");
OverlaySettings overlaySettings = new OverlaySettings.Builder().setAlpha(0f).build(); OverlaySettings overlaySettings = new OverlaySettings.Builder().setAlphaScale(0f).build();
overlayText.setSpan( overlayText.setSpan(
new ForegroundColorSpan(Color.GRAY), new ForegroundColorSpan(Color.GRAY),
/* start= */ 0, /* start= */ 0,
@ -400,7 +400,7 @@ public class OverlayShaderProgramPixelTest {
new OverlaySettings.Builder().setVideoFrameAnchor(0.5f, 0.5f).build(); new OverlaySettings.Builder().setVideoFrameAnchor(0.5f, 0.5f).build();
TextOverlay textOverlay = TextOverlay.createStaticTextOverlay(overlayText, overlaySettings1); TextOverlay textOverlay = TextOverlay.createStaticTextOverlay(overlayText, overlaySettings1);
Bitmap bitmap = readBitmap(OVERLAY_PNG_ASSET_PATH); Bitmap bitmap = readBitmap(OVERLAY_PNG_ASSET_PATH);
OverlaySettings overlaySettings2 = new OverlaySettings.Builder().setAlpha(0.5f).build(); OverlaySettings overlaySettings2 = new OverlaySettings.Builder().setAlphaScale(0.5f).build();
BitmapOverlay bitmapOverlay = BitmapOverlay.createStaticBitmapOverlay(bitmap, overlaySettings2); BitmapOverlay bitmapOverlay = BitmapOverlay.createStaticBitmapOverlay(bitmap, overlaySettings2);
overlayShaderProgram = overlayShaderProgram =
new OverlayEffect(ImmutableList.of(textOverlay, bitmapOverlay)) new OverlayEffect(ImmutableList.of(textOverlay, bitmapOverlay))

View File

@ -26,7 +26,7 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue;
@UnstableApi @UnstableApi
public final class OverlaySettings { public final class OverlaySettings {
public final boolean useHdr; public final boolean useHdr;
public final float alpha; public final float alphaScale;
public final Pair<Float, Float> videoFrameAnchor; public final Pair<Float, Float> videoFrameAnchor;
public final Pair<Float, Float> overlayAnchor; public final Pair<Float, Float> overlayAnchor;
public final Pair<Float, Float> scale; public final Pair<Float, Float> scale;
@ -34,13 +34,13 @@ public final class OverlaySettings {
private OverlaySettings( private OverlaySettings(
boolean useHdr, boolean useHdr,
float alpha, float alphaScale,
Pair<Float, Float> videoFrameAnchor, Pair<Float, Float> videoFrameAnchor,
Pair<Float, Float> overlayAnchor, Pair<Float, Float> overlayAnchor,
Pair<Float, Float> scale, Pair<Float, Float> scale,
float rotationDegrees) { float rotationDegrees) {
this.useHdr = useHdr; this.useHdr = useHdr;
this.alpha = alpha; this.alphaScale = alphaScale;
this.videoFrameAnchor = videoFrameAnchor; this.videoFrameAnchor = videoFrameAnchor;
this.overlayAnchor = overlayAnchor; this.overlayAnchor = overlayAnchor;
this.scale = scale; this.scale = scale;
@ -50,7 +50,7 @@ public final class OverlaySettings {
/** A builder for {@link OverlaySettings} instances. */ /** A builder for {@link OverlaySettings} instances. */
public static final class Builder { public static final class Builder {
private boolean useHdr; private boolean useHdr;
private float alpha; private float alphaScale;
private Pair<Float, Float> videoFrameAnchor; private Pair<Float, Float> videoFrameAnchor;
private Pair<Float, Float> overlayAnchor; private Pair<Float, Float> overlayAnchor;
private Pair<Float, Float> scale; private Pair<Float, Float> scale;
@ -58,7 +58,7 @@ public final class OverlaySettings {
/** Creates a new {@link Builder}. */ /** Creates a new {@link Builder}. */
public Builder() { public Builder() {
alpha = 1f; alphaScale = 1f;
videoFrameAnchor = Pair.create(0f, 0f); videoFrameAnchor = Pair.create(0f, 0f);
overlayAnchor = Pair.create(0f, 0f); overlayAnchor = Pair.create(0f, 0f);
scale = Pair.create(1f, 1f); scale = Pair.create(1f, 1f);
@ -80,15 +80,15 @@ public final class OverlaySettings {
/** /**
* Sets the alpha scale value of the overlay, altering its translucency. * Sets the alpha scale value of the overlay, altering its translucency.
* *
* <p>An {@code alpha} value of {@code 1} means no change is applied. A value below {@code 1} * <p>An {@code alphaScale} value of {@code 1} means no change is applied. A value below {@code
* increases translucency, and a value above {@code 1} reduces translucency. * 1} increases translucency, and a value above {@code 1} reduces translucency.
* *
* <p>Set to always return {@code 1} by default. * <p>Set to always return {@code 1} by default.
*/ */
@CanIgnoreReturnValue @CanIgnoreReturnValue
public Builder setAlpha(@FloatRange(from = 0) float alpha) { public Builder setAlphaScale(@FloatRange(from = 0) float alphaScale) {
checkArgument(0 <= alpha, "Alpha needs to be more than or equal to zero."); checkArgument(0 <= alphaScale, "alphaScale needs to be greater than or equal to zero.");
this.alpha = alpha; this.alphaScale = alphaScale;
return this; return this;
} }
@ -165,7 +165,7 @@ public final class OverlaySettings {
/** Creates an instance of {@link OverlaySettings}, using defaults if values are unset. */ /** Creates an instance of {@link OverlaySettings}, using defaults if values are unset. */
public OverlaySettings build() { public OverlaySettings build() {
return new OverlaySettings( return new OverlaySettings(
useHdr, alpha, videoFrameAnchor, overlayAnchor, scale, rotationDegrees); useHdr, alphaScale, videoFrameAnchor, overlayAnchor, scale, rotationDegrees);
} }
} }
} }

View File

@ -276,7 +276,8 @@ import com.google.common.collect.ImmutableList;
Util.formatInvariant("uTransformationMatrix%d", texUnitIndex), transformationMatrix); Util.formatInvariant("uTransformationMatrix%d", texUnitIndex), transformationMatrix);
glProgram.setFloatUniform( glProgram.setFloatUniform(
Util.formatInvariant("uOverlayAlpha%d", texUnitIndex), overlaySettings.alpha); Util.formatInvariant("uOverlayAlphaScale%d", texUnitIndex),
overlaySettings.alphaScale);
} }
} }
glProgram.setSamplerTexIdUniform("uVideoTexSampler0", inputTexId, /* texUnitIndex= */ 0); glProgram.setSamplerTexIdUniform("uVideoTexSampler0", inputTexId, /* texUnitIndex= */ 0);
@ -387,7 +388,7 @@ import com.google.common.collect.ImmutableList;
for (int texUnitIndex = 1; texUnitIndex <= numOverlays; texUnitIndex++) { for (int texUnitIndex = 1; texUnitIndex <= numOverlays; texUnitIndex++) {
shader shader
.append(Util.formatInvariant("uniform sampler2D uOverlayTexSampler%d;\n", texUnitIndex)) .append(Util.formatInvariant("uniform sampler2D uOverlayTexSampler%d;\n", texUnitIndex))
.append(Util.formatInvariant("uniform float uOverlayAlpha%d;\n", texUnitIndex)) .append(Util.formatInvariant("uniform float uOverlayAlphaScale%d;\n", texUnitIndex))
.append(Util.formatInvariant("varying vec2 vOverlayTexSamplingCoord%d;\n", texUnitIndex)); .append(Util.formatInvariant("varying vec2 vOverlayTexSamplingCoord%d;\n", texUnitIndex));
} }
@ -405,7 +406,7 @@ import com.google.common.collect.ImmutableList;
texUnitIndex)) texUnitIndex))
.append( .append(
Util.formatInvariant( Util.formatInvariant(
" uOverlayTexSampler%d, vOverlayTexSamplingCoord%d, uOverlayAlpha%d);\n", " uOverlayTexSampler%d, vOverlayTexSamplingCoord%d, uOverlayAlphaScale%d);\n",
texUnitIndex, texUnitIndex, texUnitIndex)) texUnitIndex, texUnitIndex, texUnitIndex))
.append(Util.formatInvariant(" vec4 opticalOverlayColor%d = vec4(\n", texUnitIndex)) .append(Util.formatInvariant(" vec4 opticalOverlayColor%d = vec4(\n", texUnitIndex))
.append( .append(