SilkFX: Add example SDR<->HDR animations via gainmap params.

In the gainmap image view, when the image is clicked in an HDR output
mode, animate from HDR to SDR then back again after a short delay on
SDR. The animation is done by animating minDisplayRatioForHdrTransition
between its original value and the value of displayRatioForFullHdr.

Bug: 292241206
Test: manully confirmed new click behavior and output mode switching
Change-Id: I77038330f9cfc03a3071342244923a3861c0fb6a
This commit is contained in:
Nick Deakin
2023-07-21 12:36:59 -04:00
parent 0903f20e25
commit 7d722536fd

View File

@@ -16,6 +16,10 @@
package com.android.test.silkfx.hdr
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.animation.ValueAnimator
import android.animation.ValueAnimator.AnimatorUpdateListener
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
@@ -65,15 +69,9 @@ class GainmapImage(context: Context, attrs: AttributeSet?) : FrameLayout(context
findViewById<RadioGroup>(R.id.output_mode)!!.also {
it.check(outputMode)
it.setOnCheckedChangeListener { _, checkedId ->
val previousMode = outputMode
outputMode = checkedId
if (previousMode == R.id.output_sdr && checkedId == R.id.output_hdr) {
animateToHdr()
} else if (previousMode == R.id.output_hdr && checkedId == R.id.output_sdr) {
animateToSdr()
} else {
updateDisplay()
}
// Intentionally don't do anything fancy so that mode A/B comparisons are easy
updateDisplay()
}
}
@@ -103,10 +101,41 @@ class GainmapImage(context: Context, attrs: AttributeSet?) : FrameLayout(context
imageView.apply {
isClickable = true
// Example of animating between SDR and HDR using gainmap params; animates HDR->SDR->HDR
// with a brief pause on SDR. The key thing here is that the gainmap's
// minDisplayRatioForHdrTransition is animated between its original value (for full HDR)
// and displayRatioForFullHdr (for full SDR). The view must also be invalidated during
// the animation for the updates to take effect.
setOnClickListener {
animate().alpha(.5f).withEndAction {
animate().alpha(1f).start()
}.start()
if (gainmap != null && (outputMode == R.id.output_hdr ||
outputMode == R.id.output_hdr_test)) {
val animationLengthMs: Long = 500
val updateListener = object : AnimatorUpdateListener {
override fun onAnimationUpdate(animation: ValueAnimator) {
imageView.invalidate()
}
}
val hdrToSdr = ObjectAnimator.ofFloat(
gainmap, "minDisplayRatioForHdrTransition",
gainmap!!.minDisplayRatioForHdrTransition,
gainmap!!.displayRatioForFullHdr).apply {
duration = animationLengthMs
addUpdateListener(updateListener)
}
val sdrToHdr = ObjectAnimator.ofFloat(
gainmap, "minDisplayRatioForHdrTransition",
gainmap!!.displayRatioForFullHdr,
gainmap!!.minDisplayRatioForHdrTransition).apply {
duration = animationLengthMs
addUpdateListener(updateListener)
}
AnimatorSet().apply {
play(hdrToSdr)
play(sdrToHdr).after(animationLengthMs)
start()
}
}
}
}
}
@@ -164,20 +193,6 @@ class GainmapImage(context: Context, attrs: AttributeSet?) : FrameLayout(context
updateDisplay()
}
private fun animateToHdr() {
if (bitmap == null || gainmap == null) return
// TODO: Trigger an animation
updateDisplay()
}
private fun animateToSdr() {
if (bitmap == null) return
// TODO: Trigger an animation
updateDisplay()
}
private fun updateDisplay() {
if (bitmap == null) return