Last active
January 13, 2021 21:35
-
-
Save TemMax/f768a97e00f380929a104c9da41413ee to your computer and use it in GitHub Desktop.
Postprocessor for Facebook's Fresco library that combines few postprocessors
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
import android.graphics.Bitmap | |
import com.facebook.common.references.CloseableReference | |
import com.facebook.imagepipeline.bitmaps.PlatformBitmapFactory | |
import com.facebook.imagepipeline.request.BasePostprocessor | |
class CombinePostProcessors( | |
private val processors: List<BasePostprocessor> | |
) : BasePostprocessor() { | |
override fun process( | |
sourceBitmap: Bitmap, | |
bitmapFactory: PlatformBitmapFactory | |
): CloseableReference<Bitmap> { | |
var result: CloseableReference<Bitmap>? = null | |
for (processor in processors) { | |
val src = result?.get() ?: sourceBitmap | |
result = processor.process(src, bitmapFactory) | |
} | |
return result ?: with(bitmapFactory.createBitmap(sourceBitmap)) { | |
try { | |
CloseableReference.cloneOrNull(this)!! | |
} finally { | |
CloseableReference.closeSafely(this) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment