diff --git a/libraries/effect/src/androidTest/java/androidx/media3/effect/GlEffectsFrameProcessorPixelTest.java b/libraries/effect/src/androidTest/java/androidx/media3/effect/GlEffectsFrameProcessorPixelTest.java index d4ec6b6df1..04edbd4967 100644 --- a/libraries/effect/src/androidTest/java/androidx/media3/effect/GlEffectsFrameProcessorPixelTest.java +++ b/libraries/effect/src/androidTest/java/androidx/media3/effect/GlEffectsFrameProcessorPixelTest.java @@ -373,13 +373,8 @@ public final class GlEffectsFrameProcessorPixelTest { @Test public void increaseBrightness_matchesGoldenFile() throws Exception { String testId = "increaseBrightness_matchesGoldenFile"; - ImmutableList increaseBrightness = - ImmutableList.of( - new RgbAdjustment.Builder().setRedScale(5).build(), - new RgbAdjustment.Builder().setGreenScale(5).build(), - new RgbAdjustment.Builder().setBlueScale(5).build()); frameProcessorTestRunner = - getDefaultFrameProcessorTestRunnerBuilder(testId).setEffects(increaseBrightness).build(); + getDefaultFrameProcessorTestRunnerBuilder(testId).setEffects(new Brightness(0.5f)).build(); Bitmap expectedBitmap = readBitmap(INCREASE_BRIGHTNESS_PNG_ASSET_PATH); Bitmap actualBitmap = frameProcessorTestRunner.processFirstFrameAndEnd(); diff --git a/libraries/effect/src/main/java/androidx/media3/effect/Brightness.java b/libraries/effect/src/main/java/androidx/media3/effect/Brightness.java new file mode 100644 index 0000000000..80c161e24c --- /dev/null +++ b/libraries/effect/src/main/java/androidx/media3/effect/Brightness.java @@ -0,0 +1,56 @@ +/* + * Copyright 2023 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. + */ + +package androidx.media3.effect; + +import static androidx.media3.common.util.Assertions.checkArgument; + +import android.opengl.Matrix; +import androidx.annotation.FloatRange; +import androidx.media3.common.util.GlUtil; +import androidx.media3.common.util.UnstableApi; + +/** Modifies brightness of an input frame. */ +@UnstableApi +public class Brightness implements RgbMatrix { + + private final float[] rgbMatrix; + + /** + * Modifies brightness by adding a constant value to red, green, and blue values. + * + * @param brightness The constant value to add to red, green, and blue values. Should be greater + * than or equal to -1f, and less than or equal to 1f. + */ + public Brightness(@FloatRange(from = -1, to = 1) float brightness) { + checkArgument( + brightness >= -1f && brightness <= 1f, + "brightness value outside of range from -1f to 1f, inclusive"); + rgbMatrix = GlUtil.create4x4IdentityMatrix(); + Matrix.translateM( + rgbMatrix, + /* smOffset= */ 0, + /* x= */ brightness, + /* y= */ brightness, + /* z= */ brightness); + } + + @Override + public float[] getMatrix(long presentationTimeUs, boolean useHdr) { + checkArgument(!useHdr, "HDR is not supported."); + return rgbMatrix; + } +} diff --git a/libraries/test_data/src/test/assets/media/bitmap/sample_mp4_first_frame/electrical_colors/increase_brightness.png b/libraries/test_data/src/test/assets/media/bitmap/sample_mp4_first_frame/electrical_colors/increase_brightness.png index 51abe66541..3493731adb 100644 Binary files a/libraries/test_data/src/test/assets/media/bitmap/sample_mp4_first_frame/electrical_colors/increase_brightness.png and b/libraries/test_data/src/test/assets/media/bitmap/sample_mp4_first_frame/electrical_colors/increase_brightness.png differ