Please help: Issue with SkSamplingOptions

244 views
Skip to first unread message

dot-borg

unread,
Dec 20, 2021, 2:39:53 PM12/20/21
to skia-discuss
I'm rotating and scaling some glyph bitmaps (alpha only, color is applied via SkPaint) with this code using m75:

SkPaint paint;
paint.setAntiAlias(true);
paint.setColor(color);
paint.setFilterQuality(kHigh_SkFilterQuality);

SkMatrix matrix;
matrix.setSinCos(sin, cos, rect.left(), rect.top());

canvas.setMatrix(matrix);
canvas.drawBitmapRect(bitmap, rect, &paint);

The matrix is rotating the glyphs and they are being scaled based on the destination rect.
Here's what it looks like (shown at 3x):

Here is the code I'm trying for m98:

SkPaint paint;
paint.setAntiAlias(true);
paint.setColor(color);

SkMatrix matrix;
matrix.setSinCos(sin, cos, rect.left(), rect.top());

canvas.setMatrix(matrix);
canvas.drawImageRect(bitmap.asImage(), rect, SkSamplingOptions(SkCubicResampler::Mitchell()), &paint);

And here's what it looks like (again at 3x):

The comment in SkSamplingOptions.h says that Mitchel is the "Historic default for kHigh_SkFilterQuality" but it looks to me like it's using nearest neighbor sampling.

How can I achieve the same results as kHigh_SkFilterQuality?

Brian Osman

unread,
Dec 20, 2021, 6:20:12 PM12/20/21
to skia-d...@googlegroups.com
Historically, kHigh implied cubic filtering, but only when upsampling. If you specified kHigh, and were down-sampling, Skia would switch back to kMedium (bilinear filtering plus mipmaps). If you are down-sampling, the new SkSamplingOptions constructors that take a cubic sampler don't set the filter mode to linear. So - if you're not actually up-scaling, you can just use the constructor that takes a filter mode (and specify Linear, possibly with mipmaps).

--
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/f78cafc0-116e-4804-9ce3-b2baadc8177an%40googlegroups.com.

dot-borg

unread,
Dec 20, 2021, 7:05:28 PM12/20/21
to skia-discuss
Thanks for the reply. Based on your information, I found that SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kNearest) is producing the same results that I was getting before.
Reply all
Reply to author
Forward
0 new messages