Impact of canvas transform on SkImageFilters::MatrixTransform

Skip to first unread message

Abhishek Pandey

May 21, 2021, 1:13:03 PMMay 21
to skia-discuss

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

May 24, 2021, 9:47:35 AMMay 24
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.


Abhishek Pandey

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