Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ public HardwareBufferFrame process(HardwareBufferFrame inputFrame) {
if (currentFrame == null) {
HardwareBuffer buffer = null;
try {
if (SDK_INT >= 31) {
if (nextBitmap.getConfig() == Config.RGBA_1010102) {
buffer = copyCpuBitmapToHardwareBuffer(nextBitmap, hardwareBufferJniWrapper);
} else if (SDK_INT >= 31) {
if (nextBitmap.getConfig() == Config.HARDWARE) {
// Input is HARDWARE and API >= 31: Direct access to HardwareBuffer is possible.
buffer = nextBitmap.getHardwareBuffer();
Expand Down Expand Up @@ -199,16 +201,19 @@ public void close() {
* <p>The created buffer will have {@linkplain HardwareBuffer#USAGE_GPU_SAMPLED_IMAGE GPU read},
* {@linkplain HardwareBuffer#USAGE_GPU_COLOR_OUTPUT GPU write}, {@linkplain
* HardwareBuffer#USAGE_CPU_READ_OFTEN CPU read} and {@linkplain
* HardwareBuffer#USAGE_CPU_WRITE_OFTEN CPU write} usage flags set, and pixelFormat of {@link
* HardwareBuffer#RGBA_8888}.
* HardwareBuffer#USAGE_CPU_WRITE_OFTEN CPU write} usage flags set.
*/
private static HardwareBuffer copyCpuBitmapToHardwareBuffer(
Bitmap bitmap, HardwareBufferJniWrapper hardwareBufferJniWrapper) {
int pixelFormat =
bitmap.getConfig() == Config.RGBA_1010102
? HardwareBuffer.RGBA_1010102
: HardwareBuffer.RGBA_8888;
HardwareBuffer buffer =
HardwareBuffer.create(
bitmap.getWidth(),
bitmap.getHeight(),
/* pixelFormat= */ HardwareBuffer.RGBA_8888,
pixelFormat,
/* layers= */ 1,
/* usageFlags= */ HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE
| HardwareBuffer.USAGE_GPU_COLOR_OUTPUT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static com.google.common.base.Preconditions.checkState;

import android.graphics.Bitmap;
import android.graphics.ColorSpace;
import android.hardware.HardwareBuffer;
import android.os.Handler;
import android.os.Looper;
Expand Down Expand Up @@ -228,7 +229,7 @@ void outputBitmap(
.setSampleMimeType(MimeTypes.IMAGE_RAW)
.setWidth(bitmap.getWidth())
.setHeight(bitmap.getHeight())
.setColorInfo(ColorInfo.SRGB_BT709_FULL)
.setColorInfo(resolveColorInfoFromBitmap(bitmap))
.setFrameRate(/* frameRate= */ DEFAULT_FRAME_RATE)
.build();
synchronized (this) {
Expand Down Expand Up @@ -505,6 +506,29 @@ private void maybeWakeupVideoRenderer() {
}
}

private static ColorInfo resolveColorInfoFromBitmap(Bitmap bitmap) {
if (SDK_INT >= 34) {
ColorSpace colorSpace = bitmap.getColorSpace();
if (colorSpace != null) {
int id = colorSpace.getId();
if (id == ColorSpace.get(ColorSpace.Named.BT2020_HLG).getId()) {
return new ColorInfo.Builder()
.setColorSpace(C.COLOR_SPACE_BT2020)
.setColorRange(C.COLOR_RANGE_FULL)
.setColorTransfer(C.COLOR_TRANSFER_HLG)
.build();
} else if (id == ColorSpace.get(ColorSpace.Named.BT2020_PQ).getId()) {
return new ColorInfo.Builder()
.setColorSpace(C.COLOR_SPACE_BT2020)
.setColorRange(C.COLOR_RANGE_FULL)
.setColorTransfer(C.COLOR_TRANSFER_ST2084)
.build();
}
}
}
return ColorInfo.SRGB_BT709_FULL;
}

/**
* A {@link Executor} which executes commands on a {@link Handler} and propagates {@linkplain
* RuntimeException errors} to the {@link Listener}.
Expand Down