Effect: Implement brightness convenience class.

It can be confusing how to use RgbMatrix for app devs not comfortable with image
manipulation, so add a helper class that simply translates rgb values the same
constant brightness value, to update the brightness values.

PiperOrigin-RevId: 509287229
This commit is contained in:
huangdarwin 2023-02-13 19:34:34 +00:00 committed by christosts
parent 38dd1489ba
commit 3e2c6797bb
3 changed files with 57 additions and 6 deletions

View File

@ -373,13 +373,8 @@ public final class GlEffectsFrameProcessorPixelTest {
@Test @Test
public void increaseBrightness_matchesGoldenFile() throws Exception { public void increaseBrightness_matchesGoldenFile() throws Exception {
String testId = "increaseBrightness_matchesGoldenFile"; String testId = "increaseBrightness_matchesGoldenFile";
ImmutableList<Effect> increaseBrightness =
ImmutableList.of(
new RgbAdjustment.Builder().setRedScale(5).build(),
new RgbAdjustment.Builder().setGreenScale(5).build(),
new RgbAdjustment.Builder().setBlueScale(5).build());
frameProcessorTestRunner = frameProcessorTestRunner =
getDefaultFrameProcessorTestRunnerBuilder(testId).setEffects(increaseBrightness).build(); getDefaultFrameProcessorTestRunnerBuilder(testId).setEffects(new Brightness(0.5f)).build();
Bitmap expectedBitmap = readBitmap(INCREASE_BRIGHTNESS_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(INCREASE_BRIGHTNESS_PNG_ASSET_PATH);
Bitmap actualBitmap = frameProcessorTestRunner.processFirstFrameAndEnd(); Bitmap actualBitmap = frameProcessorTestRunner.processFirstFrameAndEnd();

View File

@ -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;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 344 KiB

After

Width:  |  Height:  |  Size: 370 KiB