-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RgbAdjustment class to build RgbaMatrices
* Add RgbaMatrix interface implementation. * Add Builder class for easy adjustments. * Adjust existing RgbaMatrixPixelTests to use new RgbAdjustment class. PiperOrigin-RevId: 465545429
- Loading branch information
1 parent
e63d594
commit 6502fce
Showing
3 changed files
with
142 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
...droid_libs/media/libraries/effect/src/main/java/androidx/media3/effect/RgbAdjustment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package androidx.media3.effect; | ||
|
||
import static com.google.android.exoplayer2.util.Assertions.checkArgument; | ||
|
||
import android.opengl.Matrix; | ||
import com.google.errorprone.annotations.CanIgnoreReturnValue; | ||
|
||
/** Scales the red, green, and blue color channels of a frame. */ | ||
public final class RgbAdjustment implements RgbaMatrix { | ||
|
||
/** A builder for {@link RgbAdjustment} instances. */ | ||
public static final class Builder { | ||
private float redScale; | ||
private float greenScale; | ||
private float blueScale; | ||
|
||
/** Creates a new instance with default values. */ | ||
public Builder() { | ||
redScale = 1; | ||
greenScale = 1; | ||
blueScale = 1; | ||
} | ||
|
||
/** | ||
* Scales the red channel of the frame by {@param redScale}. | ||
* | ||
* @param redScale The scale to apply to the red channel. Needs to be non-negative and the | ||
* default value is {@code 1}. | ||
*/ | ||
@CanIgnoreReturnValue | ||
public Builder setRedScale(float redScale) { | ||
checkArgument(0 <= redScale, "Red scale needs to be non-negative."); | ||
this.redScale = redScale; | ||
return this; | ||
} | ||
|
||
/** | ||
* Scales the green channel of the frame by {@param greenScale}. | ||
* | ||
* @param greenScale The scale to apply to the green channel. Needs to be non-negative and the | ||
* default value is {@code 1}. | ||
*/ | ||
@CanIgnoreReturnValue | ||
public Builder setGreenScale(float greenScale) { | ||
checkArgument(0 <= greenScale, "Green scale needs to be non-negative."); | ||
this.greenScale = greenScale; | ||
return this; | ||
} | ||
|
||
/** | ||
* Scales the blue channel of the frame by {@param blueScale}. | ||
* | ||
* @param blueScale The scale to apply to the blue channel. Needs to be non-negative and the | ||
* default value is {@code 1}. | ||
*/ | ||
@CanIgnoreReturnValue | ||
public Builder setBlueScale(float blueScale) { | ||
checkArgument(0 <= blueScale, "Blue scale needs to be non-negative."); | ||
this.blueScale = blueScale; | ||
return this; | ||
} | ||
|
||
/** Creates a new {@link RgbAdjustment} instance. */ | ||
public RgbAdjustment build() { | ||
float[] rgbaMatrix = new float[16]; | ||
Matrix.setIdentityM(rgbaMatrix, /* smOffset= */ 0); | ||
Matrix.scaleM( | ||
rgbaMatrix, | ||
/* smOffset= */ 0, | ||
/* x= */ redScale, | ||
/* y= */ greenScale, | ||
/* z= */ blueScale); | ||
|
||
return new RgbAdjustment(rgbaMatrix); | ||
} | ||
} | ||
|
||
private final float[] rgbaMatrix; | ||
|
||
private RgbAdjustment(float[] rgbaMatrix) { | ||
this.rgbaMatrix = rgbaMatrix; | ||
} | ||
|
||
@Override | ||
public float[] getMatrix(long presentationTimeUs) { | ||
return rgbaMatrix; | ||
} | ||
} |
Binary file added
BIN
+462 KB
...ta/src/test/assets/media/bitmap/sample_mp4_first_frame/increase_red_channel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.