Fwd: Skia pixel snapping

244 views
Skip to first unread message

Tom Hudson

unread,
Apr 8, 2015, 10:34:34 AM4/8/15
to skia-d...@googlegroups.com, hugi2...@gmail.com
Forwarding this to the public discussion list.

---------- Forwarded message ----------
From: Stefan Hug <hugi2...@gmail.com>
Date: Tue, Apr 7, 2015 at 5:52 PM
Subject: Skia pixel snapping
To: tomh...@chromium.org

Hi Tom

I just stumbled across the skia library when i did some experiments with Cairo. After a little evaluation i decided to go further with skia. I'm currently searching an approach to align my strokes and fills to the pixel grid to implement some kind of pixel snapping to geht sharp lines. Is there any special function or trick to do so?

I would be very happy if you could help me to get further with this question.

Thanks a lot in advance
Stefan


Cary Clark

unread,
Apr 8, 2015, 11:14:40 AM4/8/15
to skia-d...@googlegroups.com
Hi Stefan

There's no built-in function for what you want to do, but there are enough helpers to allow you to implement this yourself.

For strokes, you'll want to snap the points to the closest pixel center. For fills, you'll want to snap the points to the closest pixel corner. In the most general case, you'll need to compute the snap for each point separately.

First, map your points to pixel space:

  const SkMatrix& totalMatrix =  canvas->getTotalMatrix();
  totalMatrix.mapPoints(originalPts, pixelPts, pointCount);

Next, after snapping the points to the desired location, map them back to source space:

  SkMatrix inverseMatrix;
  totalMatrix.invert(&inverseMatrix);
  inverseMatrix.mapPoints(snappedPixelPts, snappedPts, pointCount);

Cary

 



--
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 post to this group, send email to skia-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages