Add slider option for contrast in demo app

PiperOrigin-RevId: 464050072
This commit is contained in:
leonwind 2022-07-29 11:30:44 +00:00 committed by tonihei
parent 61e4f92310
commit 3fae9df8a9
4 changed files with 89 additions and 11 deletions

View File

@ -67,6 +67,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
public static final String PERIODIC_VIGNETTE_CENTER_Y = "periodic_vignette_center_y"; public static final String PERIODIC_VIGNETTE_CENTER_Y = "periodic_vignette_center_y";
public static final String PERIODIC_VIGNETTE_INNER_RADIUS = "periodic_vignette_inner_radius"; public static final String PERIODIC_VIGNETTE_INNER_RADIUS = "periodic_vignette_inner_radius";
public static final String PERIODIC_VIGNETTE_OUTER_RADIUS = "periodic_vignette_outer_radius"; public static final String PERIODIC_VIGNETTE_OUTER_RADIUS = "periodic_vignette_outer_radius";
public static final String CONTRAST_VALUE = "contrast_value";
private static final String[] INPUT_URIS = { private static final String[] INPUT_URIS = {
"https://storage.googleapis.com/exoplayer-test-media-1/mp4/android-screens-10s.mp4", "https://storage.googleapis.com/exoplayer-test-media-1/mp4/android-screens-10s.mp4",
"https://storage.googleapis.com/exoplayer-test-media-0/android-block-1080-hevc.mp4", "https://storage.googleapis.com/exoplayer-test-media-0/android-block-1080-hevc.mp4",
@ -100,13 +101,14 @@ public final class ConfigurationActivity extends AppCompatActivity {
private static final String[] DEMO_EFFECTS = { private static final String[] DEMO_EFFECTS = {
"Dizzy crop", "Dizzy crop",
"Edge detector (Media Pipe)", "Edge detector (Media Pipe)",
"Contrast",
"Periodic vignette", "Periodic vignette",
"3D spin", "3D spin",
"Overlay logo & timer", "Overlay logo & timer",
"Zoom in start", "Zoom in start",
"Increase contrast"
}; };
private static final int PERIODIC_VIGNETTE_INDEX = 2; private static final int CONTRAST_INDEX = 2;
private static final int PERIODIC_VIGNETTE_INDEX = 3;
private static final String SAME_AS_INPUT_OPTION = "same as input"; private static final String SAME_AS_INPUT_OPTION = "same as input";
private static final float HALF_DIAGONAL = 1f / (float) Math.sqrt(2); private static final float HALF_DIAGONAL = 1f / (float) Math.sqrt(2);
@ -130,6 +132,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
private int inputUriPosition; private int inputUriPosition;
private long trimStartMs; private long trimStartMs;
private long trimEndMs; private long trimEndMs;
private float contrastValue;
private float periodicVignetteCenterX; private float periodicVignetteCenterX;
private float periodicVignetteCenterY; private float periodicVignetteCenterY;
private float periodicVignetteInnerRadius; private float periodicVignetteInnerRadius;
@ -285,6 +288,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
ENABLE_REQUEST_SDR_TONE_MAPPING, enableRequestSdrToneMappingCheckBox.isChecked()); ENABLE_REQUEST_SDR_TONE_MAPPING, enableRequestSdrToneMappingCheckBox.isChecked());
bundle.putBoolean(ENABLE_HDR_EDITING, enableHdrEditingCheckBox.isChecked()); bundle.putBoolean(ENABLE_HDR_EDITING, enableHdrEditingCheckBox.isChecked());
bundle.putBooleanArray(DEMO_EFFECTS_SELECTIONS, demoEffectsSelections); bundle.putBooleanArray(DEMO_EFFECTS_SELECTIONS, demoEffectsSelections);
bundle.putFloat(CONTRAST_VALUE, contrastValue);
bundle.putFloat(PERIODIC_VIGNETTE_CENTER_X, periodicVignetteCenterX); bundle.putFloat(PERIODIC_VIGNETTE_CENTER_X, periodicVignetteCenterX);
bundle.putFloat(PERIODIC_VIGNETTE_CENTER_Y, periodicVignetteCenterY); bundle.putFloat(PERIODIC_VIGNETTE_CENTER_Y, periodicVignetteCenterY);
bundle.putFloat(PERIODIC_VIGNETTE_INNER_RADIUS, periodicVignetteInnerRadius); bundle.putFloat(PERIODIC_VIGNETTE_INNER_RADIUS, periodicVignetteInnerRadius);
@ -347,10 +351,35 @@ public final class ConfigurationActivity extends AppCompatActivity {
@RequiresNonNull("demoEffectsSelections") @RequiresNonNull("demoEffectsSelections")
private void selectDemoEffect(DialogInterface dialog, int which, boolean isChecked) { private void selectDemoEffect(DialogInterface dialog, int which, boolean isChecked) {
demoEffectsSelections[which] = isChecked; demoEffectsSelections[which] = isChecked;
if (!isChecked || which != PERIODIC_VIGNETTE_INDEX) { if (!isChecked) {
return; return;
} }
switch (which) {
case CONTRAST_INDEX:
controlContrastSettings();
break;
case PERIODIC_VIGNETTE_INDEX:
controlPeriodicVignetteSettings();
break;
}
}
private void controlContrastSettings() {
View dialogView = getLayoutInflater().inflate(R.layout.contrast_options, /* root= */ null);
Slider contrastSlider = checkNotNull(dialogView.findViewById(R.id.contrast_slider));
new AlertDialog.Builder(/* context= */ this)
.setView(dialogView)
.setPositiveButton(
android.R.string.ok,
(DialogInterface dialogInterface, int i) -> {
contrastValue = contrastSlider.getValue();
})
.create()
.show();
}
private void controlPeriodicVignetteSettings() {
View dialogView = View dialogView =
getLayoutInflater().inflate(R.layout.periodic_vignette_options, /* root= */ null); getLayoutInflater().inflate(R.layout.periodic_vignette_options, /* root= */ null);
Slider centerXSlider = Slider centerXSlider =

View File

@ -301,6 +301,9 @@ public final class TransformerActivity extends AppCompatActivity {
} }
} }
if (selectedEffects[2]) { if (selectedEffects[2]) {
effects.add(new Contrast(bundle.getFloat(ConfigurationActivity.CONTRAST_VALUE)));
}
if (selectedEffects[3]) {
effects.add( effects.add(
(GlEffect) (GlEffect)
(Context context, boolean useHdr) -> (Context context, boolean useHdr) ->
@ -315,18 +318,14 @@ public final class TransformerActivity extends AppCompatActivity {
ConfigurationActivity.PERIODIC_VIGNETTE_OUTER_RADIUS), ConfigurationActivity.PERIODIC_VIGNETTE_OUTER_RADIUS),
bundle.getFloat(ConfigurationActivity.PERIODIC_VIGNETTE_OUTER_RADIUS))); bundle.getFloat(ConfigurationActivity.PERIODIC_VIGNETTE_OUTER_RADIUS)));
} }
if (selectedEffects[3]) { if (selectedEffects[4]) {
effects.add(MatrixTransformationFactory.createSpin3dEffect()); effects.add(MatrixTransformationFactory.createSpin3dEffect());
} }
if (selectedEffects[4]) { if (selectedEffects[5]) {
effects.add((GlEffect) BitmapOverlayProcessor::new); effects.add((GlEffect) BitmapOverlayProcessor::new);
} }
if (selectedEffects[5]) {
effects.add(MatrixTransformationFactory.createZoomInTransition());
}
if (selectedEffects[6]) { if (selectedEffects[6]) {
// TODO(b/238630175): Add slider for contrast adjustments. effects.add(MatrixTransformationFactory.createZoomInTransition());
effects.add(new Contrast(0.75f));
} }
transformerBuilder.setVideoEffects(effects.build()); transformerBuilder.setVideoEffects(effects.build());
} }

View File

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2022 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".ConfigurationActivity">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:layout_marginTop="32dp"
android:measureWithLargestChild="true"
android:paddingLeft="24dp"
android:paddingRight="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
<TableRow
android:layout_weight="1"
android:gravity="center_vertical" >
<TextView
android:text="@string/contrast_value" />
<com.google.android.material.slider.Slider
android:id="@+id/contrast_slider"
android:valueFrom="-1.0"
android:value="0.0"
android:valueTo="1.0"
android:layout_gravity="right"/>
</TableRow>
</TableLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -41,8 +41,9 @@
<string name="transformation_timer" translatable="false">Transformation started %d seconds ago.</string> <string name="transformation_timer" translatable="false">Transformation started %d seconds ago.</string>
<string name="transformation_completed" translatable="false">Transformation completed in %d seconds.</string> <string name="transformation_completed" translatable="false">Transformation completed in %d seconds.</string>
<string name="transformation_error" translatable="false">Transformation error</string> <string name="transformation_error" translatable="false">Transformation error</string>
<string name="trim_range">Bounds in seconds</string>
<string name="contrast_value" translatable="false">Contrast value</string>
<string name="center_x">Center X</string> <string name="center_x">Center X</string>
<string name="center_y">Center Y</string> <string name="center_y">Center Y</string>
<string name="radius_range">Radius range</string> <string name="radius_range">Radius range</string>
<string name="trim_range">Bounds in seconds</string>
</resources> </resources>