Impact of canvas transform on SkImageFilters::MatrixTransform

41 views
Skip to first unread message

Abhishek Pandey

unread,
May 21, 2021, 1:13:03 PM5/21/21
to skia-discuss
Hi,

I am trying to understand at what resolution does SkImageFilters::MatrixTransform's input get resampled and does it have any effect on canvas tranform.

The documentation says that MatrixTransform's effectively happens before any transform from render target. However, this and this fiddle having equivalent output make things confusing.

If I am not wrong input A is resampled at (1: resolution) and then stretched my matrix transform and then its output is rendered using canvas transform..


Michael Ludwig

unread,
May 24, 2021, 9:47:35 AM5/24/21
to skia-discuss
The effect of the canvas transform is somewhat complex because it is dependent on the capabilities of the specific image filters that need to be evaluated, and on the type of transform the canvas has. All image filters support direct evaluation of input images produced from a canvas that has a scale+translate transform. Not all image filters support general affine or perspective transformations. In these cases, the canvas decomposes its transform into a scale matrix that's used to render the input content at approximately the final resolution, and then a post-filtering transform that composes the filter result on to the device.

All image filters transform their parameters and/or behavior based on this decomposed scale matrix, S.  If the original canvas matrix was already scale+translate, then S = canvas matrix. For the SkImageFilters::Image filter you're using as input, that means drawing the image transformed by S (and is sampled using the ::Image SkSamplingOptions). For an SkImageFilters::MatrixTransform with matrix T, it assumes its input image has drawn subject to S.  It actually applies (S*T*S^-1) to that image to produce it's output. Assuming that the input image was S*original, then the MatrixTransform's output is approximately S*T*S^-1*S*original = S*T*original. So while the transform happens after the canvas transform from a sampling perspective, it's effective transformation behavior is as if it happened before.

So in your fiddle where the canvas has m2 performing the scale by 0.1, so the MatrixTransform using nearest-neighbor sampling is sampling a lower resolution image.

HTH,
Michael

Abhishek Pandey

unread,
May 27, 2021, 5:15:56 AM5/27/21
to skia-discuss
Thanks a lot Michael for the clarification. That helped!!
Reply all
Reply to author
Forward
0 new messages