HomeAndroidAndroid HDR | Migrating from TextureView to SurfaceView (Half #2) — Coping...

Android HDR | Migrating from TextureView to SurfaceView (Half #2) — Coping with coloration washout | by Mozart Louis | Android Builders | Jan, 2023


Half 2 of a technical information on the right way to migrate away from TextureView to the a lot most popular SurfaceView centered on Coloration Washout with HDR tone-mapping

Hiya once more! That is Half 2 of the Android HDR sequence centered on migrating away from TextureView to SurfaceView! This a part of the sequence will concentrate on coping with “coloration washout.” We’ll speak about the right way to appropriately transcode 10-bit HDR video to 8-bit SDR video to make sure help for gadgets that may’t show HDR content material. This additionally ensures that the colours of your content material look appropriate on TextureView.

In Half 1, we have been in a position to show 10-bit HDR movies on a SurfaceView. We strongly suggest shifting to SurfaceView for efficiency and constancy, however you will have different causes to remain on TextureView, with the ability to set the alpha worth to mix with the background. What must you do on this case?

Effectively first, let’s see what occurs whenever you try to show 10-bit HDR content material on a TextureView. In our graphics samples repository, we created an exercise that accommodates one SurfaceView and two TextureViews. One TextureView makes use of our Customized Decoder and the opposite makes use of MediaPlayer. Right here is the ensuing picture evaluating TextureView and SurfaceView on three completely different gadgets working completely different variations of Android.

For Android 13 (API 33) on the Pixel 6 Professional, all of them look similar. It’s because on API 33, conversion from 10-bit HDR to 8-bit SDR occurs implicitly. This implies below the hood, Android converts your content material from 10-bit HDR to 8-bit SDR with out you needing to do something. The standard of the HDR to SDR conversion will depend on the machine’s underlying tone-mapping implementation.

That is nice for Android 13 (API 33), however on Android 12 (API 32), this isn’t the story. You’ll be able to see the entire movies play, however the TextureViews appear to lack plenty of coloration. The picture appears to be like bland in comparison with the SurfaceView. That is particularly obvious within the coloration of the sky. It’s because the 10-bit HDR content material shouldn’t be being transformed appropriately to 8-bit SDR for TextureView.

When sharing 10-bit content material to a tool that’s API 32 or decrease, you have to convert the 10-bit content material to 8-bit content material. This ensures the receiving machine that’s API 32 or beneath performs again the footage with the right colours.

To transcode 10-bit content material to 8-bit, Google recommends utilizing the Transformer API from Media3. The Transformer API can be utilized to transform media streams. It takes an enter media stream, applies adjustments to it as configured by the app, and produces the corresponding output file.

There are a number of use instances for the Transformer API. We shall be specializing in its tone-mapping performance, which does the conversion from HDR 10-bit coloration to SDR 8-bit coloration.

On the time of writing, the conversion relies on the underlying codec tone-mapping functionality, which is just assured on gadgets in a position to seize 10-bit HDR movies on API 33. Media3 APIs will quickly be up to date to incorporate its personal tone-mapping algorithm that can be utilized on different gadgets.

To remodel media, add the next dependency from media3 to your app’s construct.gradle file:

In your class, create a TransformationRequest object and name the setEnableRequestSdrToneMapping() technique, which we set to true.

We now can construct our Transformer object utilizing the TransformationRequest and a listener.

The addListener() perform wants a Transformer.Listener. This class permits you to override and implement two capabilities:

  • onTransformationCompleted(): Referred to as when the transformation is accomplished efficiently.
  • onTransformationError(): Referred to as if an exception happens through the transformation.

In our case, we wish to be sure that the transformed 10-bit file appropriately shows its coloration on a TextureView. If there may be an error, we wish to show what occurs through the transformation try.

To begin the transformation of the media, we have to name on our Transformer object, move it the situation of the video file, and name the startTransformation() perform. We are able to do that as soon as we all know the TextureView’s SurfaceTexture is offered by way of the onSurfaceTextureAvailable() perform.

With this, we now have the flexibility to rework 10-bit content material to 8-bit content material.

The complete pattern code may be present in our graphics samples repository.

With all the pieces above, it’s best to now be capable of rework 10-bit HDR content material to 8-bit SDR content material. This ensures that when sharing content material with different gadgets, colours are represented appropriately and are now not washed out.

In Half #3, we’ll focus on some lifecycle variations between TextureView and SurfaceView and transformations with SurfaceView (this implies shifting a floor throughout the display or how SurfaceView interacts with a scrollable container akin to a RecycleView or ViewPager).

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments