How to draw translated Image without pixel snapping?

41 views
Skip to first unread message

Julijan Nikolic

unread,
Apr 23, 2020, 5:21:39 PM4/23/20
to skia-discuss
Hi, I am trying to draw the image with translation, but it seems that image is pixel snapping.

In this example text is an image that I am trying to draw and translate.
I found that if I do small rotation, it seems that translation won't be pixel snapped. This looks like a hack, so I guess it must be a better way to do that?

Mike Klein

unread,
Apr 23, 2020, 5:22:25 PM4/23/20
to skia-discuss
Can you reproduce your problem on fiddle.skia.org?

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/7fb6c0d1-02a7-4da5-acf0-88ccabc4f655%40googlegroups.com.

Brian Osman

unread,
Apr 23, 2020, 5:29:22 PM4/23/20
to skia-d...@googlegroups.com
This is a "feature" of the raster backend. I consider it a bug. I had to work around it in GMs that I've created before.

Brian Osman

unread,
Apr 23, 2020, 5:35:19 PM4/23/20
to skia-d...@googlegroups.com
... sorry, I'm trying to find the code that does this, but without luck. Might be related to the SkTreatAsSprite stuff in SkDraw? I specifically hit this when making a filtering GM that drew a black/white checkerboard at half-pixel offset. I had to include a scale (-1) and translation to trick it into not snapping to pixel centers.

Julijan Nikolic

unread,
Apr 23, 2020, 5:41:40 PM4/23/20
to skia-discuss
Here is the fiddle example:

This one is pixel snapping:

This one is with "hack" in order to disable pixel snapping. (It works better in C++ than in fiddle though)

Julijan Nikolic

unread,
Apr 23, 2020, 5:43:28 PM4/23/20
to skia-discuss
Thanks. I will check SkTreatAsSprite. I am coming from Cairo graphics, so this is new to me. 


On Thursday, April 23, 2020 at 11:35:19 PM UTC+2, Brian Osman wrote:
... sorry, I'm trying to find the code that does this, but without luck. Might be related to the SkTreatAsSprite stuff in SkDraw? I specifically hit this when making a filtering GM that drew a black/white checkerboard at half-pixel offset. I had to include a scale (-1) and translation to trick it into not snapping to pixel centers.

On Thu, Apr 23, 2020 at 5:27 PM Brian Osman <brian...@google.com> wrote:
This is a "feature" of the raster backend. I consider it a bug. I had to work around it in GMs that I've created before.

On Thu, Apr 23, 2020 at 5:22 PM 'Mike Klein' via skia-discuss <skia-d...@googlegroups.com> wrote:
Can you reproduce your problem on fiddle.skia.org?

On Thu, Apr 23, 2020 at 4:21 PM Julijan Nikolic <julijannik...@gmail.com> wrote:
Hi, I am trying to draw the image with translation, but it seems that image is pixel snapping.

In this example text is an image that I am trying to draw and translate.
I found that if I do small rotation, it seems that translation won't be pixel snapped. This looks like a hack, so I guess it must be a better way to do that?

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-d...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-d...@googlegroups.com.

Julijan Nikolic

unread,
Apr 23, 2020, 5:43:54 PM4/23/20
to skia-discuss
Sure:

Here is the fiddle example:

This one is pixel snapping:

This one is with "hack" in order to disable pixel snapping. (It works better in C++ than in fiddle though)

On Thursday, April 23, 2020 at 11:22:25 PM UTC+2, Mike Klein wrote:
Can you reproduce your problem on fiddle.skia.org?

On Thu, Apr 23, 2020 at 4:21 PM Julijan Nikolic <julijannik...@gmail.com> wrote:
Hi, I am trying to draw the image with translation, but it seems that image is pixel snapping.

In this example text is an image that I am trying to draw and translate.
I found that if I do small rotation, it seems that translation won't be pixel snapped. This looks like a hack, so I guess it must be a better way to do that?

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-d...@googlegroups.com.

Julijan Nikolic

unread,
Apr 23, 2020, 6:22:37 PM4/23/20
to skia-discuss
It seems that simply adding paint.setAntiAlias(true); fixed the issue.
Thanks for pointing me to SkTreatAsSprite! Using that function I was able to find the solution.


On Thursday, April 23, 2020 at 11:21:39 PM UTC+2, Julijan Nikolic wrote:

Julijan Nikolic

unread,
Apr 23, 2020, 6:31:05 PM4/23/20
to skia-discuss


On Thursday, April 23, 2020 at 11:21:39 PM UTC+2, Julijan Nikolic wrote:
Reply all
Reply to author
Forward
0 new messages