diff --git a/demos/transformer/src/main/java/androidx/media3/demo/transformer/ConfigurationActivity.java b/demos/transformer/src/main/java/androidx/media3/demo/transformer/ConfigurationActivity.java index 6c822a38f32..d68050b9661 100644 --- a/demos/transformer/src/main/java/androidx/media3/demo/transformer/ConfigurationActivity.java +++ b/demos/transformer/src/main/java/androidx/media3/demo/transformer/ConfigurationActivity.java @@ -69,6 +69,9 @@ public final class ConfigurationActivity extends AppCompatActivity { public static final String PERIODIC_VIGNETTE_OUTER_RADIUS = "periodic_vignette_outer_radius"; public static final String COLOR_FILTER_SELECTION = "color_filter_selection"; public static final String CONTRAST_VALUE = "contrast_value"; + public static final String RGB_ADJUSTMENT_RED_SCALE = "rgb_adjustment_red_scale"; + public static final String RGB_ADJUSTMENT_GREEN_SCALE = "rgb_adjustment_green_scale"; + public static final String RGB_ADJUSTMENT_BLUE_SCALE = "rgb_adjustment_blue_scale"; public static final int COLOR_FILTER_GRAYSCALE = 0; public static final int COLOR_FILTER_INVERTED = 1; public static final int COLOR_FILTER_SEPIA = 2; @@ -106,6 +109,7 @@ public final class ConfigurationActivity extends AppCompatActivity { "Dizzy crop", "Edge detector (Media Pipe)", "Color filters", + "RGB Adjustments", "Contrast", "Periodic vignette", "3D spin", @@ -113,8 +117,9 @@ public final class ConfigurationActivity extends AppCompatActivity { "Zoom in start", }; private static final int COLOR_FILTERS_INDEX = 2; - private static final int CONTRAST_INDEX = 3; - private static final int PERIODIC_VIGNETTE_INDEX = 4; + private static final int RGB_ADJUSTMENTS_INDEX = 3; + private static final int CONTRAST_INDEX = 4; + private static final int PERIODIC_VIGNETTE_INDEX = 5; private static final String SAME_AS_INPUT_OPTION = "same as input"; private static final float HALF_DIAGONAL = 1f / (float) Math.sqrt(2); @@ -139,6 +144,9 @@ public final class ConfigurationActivity extends AppCompatActivity { private long trimStartMs; private long trimEndMs; private int colorFilterSelection; + private float rgbAdjustmentRedScale; + private float rgbAdjustmentGreenScale; + private float rgbAdjustmentBlueScale; private float contrastValue; private float periodicVignetteCenterX; private float periodicVignetteCenterY; @@ -297,6 +305,9 @@ private void startTransformation(View view) { bundle.putBooleanArray(DEMO_EFFECTS_SELECTIONS, demoEffectsSelections); bundle.putInt(COLOR_FILTER_SELECTION, colorFilterSelection); bundle.putFloat(CONTRAST_VALUE, contrastValue); + bundle.putFloat(RGB_ADJUSTMENT_RED_SCALE, rgbAdjustmentRedScale); + bundle.putFloat(RGB_ADJUSTMENT_GREEN_SCALE, rgbAdjustmentGreenScale); + bundle.putFloat(RGB_ADJUSTMENT_BLUE_SCALE, rgbAdjustmentBlueScale); bundle.putFloat(PERIODIC_VIGNETTE_CENTER_X, periodicVignetteCenterX); bundle.putFloat(PERIODIC_VIGNETTE_CENTER_Y, periodicVignetteCenterY); bundle.putFloat(PERIODIC_VIGNETTE_INNER_RADIUS, periodicVignetteInnerRadius); @@ -367,6 +378,9 @@ private void selectDemoEffect(DialogInterface dialog, int which, boolean isCheck case COLOR_FILTERS_INDEX: controlColorFiltersSettings(); break; + case RGB_ADJUSTMENTS_INDEX: + controlRgbAdjustmentsScale(); + break; case CONTRAST_INDEX: controlContrastSettings(); break; @@ -394,6 +408,27 @@ private void controlColorFiltersSettings() { .show(); } + private void controlRgbAdjustmentsScale() { + View dialogView = + getLayoutInflater().inflate(R.layout.rgb_adjustment_options, /* root= */ null); + Slider redScaleSlider = checkNotNull(dialogView.findViewById(R.id.rgb_adjustment_red_scale)); + Slider greenScaleSlider = + checkNotNull(dialogView.findViewById(R.id.rgb_adjustment_green_scale)); + Slider blueScaleSlider = checkNotNull(dialogView.findViewById(R.id.rgb_adjustment_blue_scale)); + new AlertDialog.Builder(/* context= */ this) + .setTitle(R.string.rgb_adjustment_options) + .setView(dialogView) + .setPositiveButton( + android.R.string.ok, + (DialogInterface dialogInterface, int i) -> { + rgbAdjustmentRedScale = redScaleSlider.getValue(); + rgbAdjustmentGreenScale = greenScaleSlider.getValue(); + rgbAdjustmentBlueScale = blueScaleSlider.getValue(); + }) + .create() + .show(); + } + private void controlContrastSettings() { View dialogView = getLayoutInflater().inflate(R.layout.contrast_options, /* root= */ null); Slider contrastSlider = checkNotNull(dialogView.findViewById(R.id.contrast_slider)); diff --git a/demos/transformer/src/main/java/androidx/media3/demo/transformer/TransformerActivity.java b/demos/transformer/src/main/java/androidx/media3/demo/transformer/TransformerActivity.java index 9f1bb20ad46..eb0dde452f4 100644 --- a/demos/transformer/src/main/java/androidx/media3/demo/transformer/TransformerActivity.java +++ b/demos/transformer/src/main/java/androidx/media3/demo/transformer/TransformerActivity.java @@ -44,6 +44,7 @@ import androidx.media3.effect.Contrast; import androidx.media3.effect.GlEffect; import androidx.media3.effect.GlTextureProcessor; +import androidx.media3.effect.RgbAdjustment; import androidx.media3.effect.RgbFilter; import androidx.media3.effect.RgbMatrix; import androidx.media3.exoplayer.ExoPlayer; @@ -335,9 +336,17 @@ private Transformer createTransformer(@Nullable Bundle bundle, String filePath) } } if (selectedEffects[3]) { - effects.add(new Contrast(bundle.getFloat(ConfigurationActivity.CONTRAST_VALUE))); + effects.add( + new RgbAdjustment.Builder() + .setRedScale(bundle.getFloat(ConfigurationActivity.RGB_ADJUSTMENT_RED_SCALE)) + .setGreenScale(bundle.getFloat(ConfigurationActivity.RGB_ADJUSTMENT_GREEN_SCALE)) + .setBlueScale(bundle.getFloat(ConfigurationActivity.RGB_ADJUSTMENT_BLUE_SCALE)) + .build()); } if (selectedEffects[4]) { + effects.add(new Contrast(bundle.getFloat(ConfigurationActivity.CONTRAST_VALUE))); + } + if (selectedEffects[5]) { effects.add( (GlEffect) (Context context, boolean useHdr) -> @@ -352,13 +361,13 @@ private Transformer createTransformer(@Nullable Bundle bundle, String filePath) ConfigurationActivity.PERIODIC_VIGNETTE_OUTER_RADIUS), bundle.getFloat(ConfigurationActivity.PERIODIC_VIGNETTE_OUTER_RADIUS))); } - if (selectedEffects[5]) { + if (selectedEffects[6]) { effects.add(MatrixTransformationFactory.createSpin3dEffect()); } - if (selectedEffects[6]) { + if (selectedEffects[7]) { effects.add((GlEffect) BitmapOverlayProcessor::new); } - if (selectedEffects[7]) { + if (selectedEffects[8]) { effects.add(MatrixTransformationFactory.createZoomInTransition()); } transformerBuilder.setVideoEffects(effects.build()); diff --git a/demos/transformer/src/main/res/layout/rgb_adjustment_options.xml b/demos/transformer/src/main/res/layout/rgb_adjustment_options.xml new file mode 100644 index 00000000000..c87e8fad179 --- /dev/null +++ b/demos/transformer/src/main/res/layout/rgb_adjustment_options.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + diff --git a/demos/transformer/src/main/res/values/strings.xml b/demos/transformer/src/main/res/values/strings.xml index 32eba87a737..db04cb58852 100644 --- a/demos/transformer/src/main/res/values/strings.xml +++ b/demos/transformer/src/main/res/values/strings.xml @@ -48,6 +48,10 @@ Sepia Contrast value + Scale RGB Channels individually + Scale Red + Scale Green + Scale Blue Center X Center Y Radius range