lincollincol / compose-audiowaveform

Audio waveform library for Jetpack Compose
Apache License 2.0
199 stars 12 forks source link

Wrong behavior when using an alpha color #18

Open Jhiertz opened 1 year ago

Jhiertz commented 1 year ago

Hi, thank you for this compose library

I've got an issue when using a colour with an alpha in waveformBrush, the alpha is also carried over to the progressBrush.

A small example to reproduce:

var waveformProgress by remember { mutableStateOf(0F) }

AudioWaveform(
    amplitudes = amplitude,
    waveformBrush = SolidColor(Color.White.copy(alpha = .5f)),
    progressBrush = SolidColor(Color.Red),
    amplitudeType = AmplitudeType.Max,
    progress = waveformProgress,
    onProgressChange = { waveformProgress = it }
)

And here is the actual rendering, the red does not match, it also has the alpha channel

image

IbrahimEzzatSaad commented 6 months ago

is there any updates on those bugs?

antweb commented 1 month ago

If you are just using the alpha value to get a specific color and don't actually need the transparency, you can work around this by creating a solid color with compositeOver:

// The color behind the waveform
val background = MaterialTheme.colorScheme.background

AudioWaveform(
    amplitudes = amplitude,
    waveformBrush = SolidColor(Color.White.copy(alpha = .5f).compositeOver(background)),
    progressBrush = SolidColor(Color.Red),
    amplitudeType = AmplitudeType.Max,
    progress = waveformProgress,
    onProgressChange = { waveformProgress = it }
)