Skip to content

Commit

Permalink
Add example CLUT to demo.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 476390089
(cherry picked from commit 29cf093)
  • Loading branch information
leonwind authored and microkatz committed Sep 23, 2022
1 parent 0a1f30a commit 8b80743
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
Expand Up @@ -112,6 +112,7 @@ public final class ConfigurationActivity extends AppCompatActivity {
"Dizzy crop",
"Edge detector (Media Pipe)",
"Color filters",
"Map White to Green Color Lookup Table",
"RGB Adjustments",
"HSL Adjustments",
"Contrast",
Expand All @@ -121,10 +122,10 @@ public final class ConfigurationActivity extends AppCompatActivity {
"Zoom in start",
};
private static final int COLOR_FILTERS_INDEX = 2;
private static final int RGB_ADJUSTMENTS_INDEX = 3;
private static final int HSL_ADJUSTMENT_INDEX = 4;
private static final int CONTRAST_INDEX = 5;
private static final int PERIODIC_VIGNETTE_INDEX = 6;
private static final int RGB_ADJUSTMENTS_INDEX = 4;
private static final int HSL_ADJUSTMENT_INDEX = 5;
private static final int CONTRAST_INDEX = 6;
private static final int PERIODIC_VIGNETTE_INDEX = 7;
private static final String SAME_AS_INPUT_OPTION = "same as input";
private static final float HALF_DIAGONAL = 1f / (float) Math.sqrt(2);

Expand Down
Expand Up @@ -23,6 +23,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
Expand All @@ -44,6 +45,7 @@
import androidx.media3.effect.RgbAdjustment;
import androidx.media3.effect.RgbFilter;
import androidx.media3.effect.RgbMatrix;
import androidx.media3.effect.SingleColorLut;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
Expand Down Expand Up @@ -338,14 +340,29 @@ private Transformer createTransformer(@Nullable Bundle bundle, String filePath)
}
}
if (selectedEffects[3]) {
int length = 3;
int[][][] mapWhiteToGreenLut = new int[length][length][length];
int scale = 255 / (length - 1);
for (int r = 0; r < length; r++) {
for (int g = 0; g < length; g++) {
for (int b = 0; b < length; b++) {
mapWhiteToGreenLut[r][g][b] =
Color.rgb(/* red= */ r * scale, /* green= */ g * scale, /* blue= */ b * scale);
}
}
}
mapWhiteToGreenLut[length - 1][length - 1][length - 1] = Color.GREEN;
effects.add(SingleColorLut.createFromCube(mapWhiteToGreenLut));
}
if (selectedEffects[4]) {
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]) {
if (selectedEffects[5]) {
effects.add(
new HslAdjustment.Builder()
.adjustHue(bundle.getFloat(ConfigurationActivity.HSL_ADJUSTMENTS_HUE))
Expand All @@ -354,10 +371,10 @@ private Transformer createTransformer(@Nullable Bundle bundle, String filePath)
.adjustLightness(bundle.getFloat(ConfigurationActivity.HSL_ADJUSTMENTS_LIGHTNESS))
.build());
}
if (selectedEffects[5]) {
if (selectedEffects[6]) {
effects.add(new Contrast(bundle.getFloat(ConfigurationActivity.CONTRAST_VALUE)));
}
if (selectedEffects[6]) {
if (selectedEffects[7]) {
effects.add(
(GlEffect)
(Context context, boolean useHdr) ->
Expand All @@ -372,13 +389,13 @@ private Transformer createTransformer(@Nullable Bundle bundle, String filePath)
ConfigurationActivity.PERIODIC_VIGNETTE_OUTER_RADIUS),
bundle.getFloat(ConfigurationActivity.PERIODIC_VIGNETTE_OUTER_RADIUS)));
}
if (selectedEffects[6]) {
if (selectedEffects[8]) {
effects.add(MatrixTransformationFactory.createSpin3dEffect());
}
if (selectedEffects[7]) {
if (selectedEffects[9]) {
effects.add((GlEffect) BitmapOverlayProcessor::new);
}
if (selectedEffects[8]) {
if (selectedEffects[10]) {
effects.add(MatrixTransformationFactory.createZoomInTransition());
}
transformerBuilder.setVideoEffects(effects.build());
Expand Down

0 comments on commit 8b80743

Please sign in to comment.