Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Conversation

@dburckh
Copy link
Contributor

@dburckh dburckh commented Jan 11, 2022

This ImageProcessor uses the new RenderEffect logic available in Android S. Observations from my Pixel 3a are that the blur is considerably faster than the other processes. Unfortunately, the hue rotation is much slower. This is likely due using a 4x5 matrix vs a 3x3 matrix.

Copy link
Contributor

@Kottsone Kottsone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks really good. Thank you for your contribution! Just some cleanup suggestions. Please take a look.


override fun rotateHue(radian: Float, outputIndex: Int): Bitmap {
params?.let {
val colorMatrix = it.matrices[outputIndex]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: I slightly prefer to create a new ColorMatrix every time this function is invoked, and get rid of the matrices field in Params because it looks cleaner. Although the construction of ColorMatrix takes time, I don't think it is even noticeable. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have mixed feelings on this one. Creating new is (Thread) safer, but it does add a little overhead. Since, this method is a doggy already, so I'll roll with you on it. :)

it.hardwareBuffers[outputIndex] = hardwareBuffer
val bitmap = Bitmap.wrapHardwareBuffer(hardwareBuffer, null)
?: throw RuntimeException("Create Bitmap Failed")
image.close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardwareBuffer can be closed at this point because Bitmap.wrapHardwareBuffer already acquires another reference. If the hardwareBuffer is closed here, the hardwareBuffers field in Params can also be removed, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent suggestion!

@Kottsone Kottsone merged commit 08d5130 into android:main Jan 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

2 participants