Downsampling PNG with SkCodec (or anything else)

464 views
Skip to first unread message

Matthew Leibowitz

unread,
Feb 11, 2017, 2:32:23 PM2/11/17
to skia-discuss
I just wanted to confirm whether or not downsampling a PNG during the decode is supported. I tried a jpg and webp, and those work. I also tested on the native Android, and PNG doesn't downsample.
This most probably is a limitation of the codec, since that is what is loading the bitmap.

If this is not supported, what would be the recommended way to load a huge, but downsampled, PNG into memory? I am thinking of a mobile device that just downloaded a huge image. If I want to generate a thumbnail, what would I do? Sure I can load it into memory and then resize, but there is the problem of limited memory...

Waiting on the experts,
Matthew

Matt Sarett

unread,
Feb 13, 2017, 8:36:33 AM2/13/17
to skia-d...@googlegroups.com
SkCodec supports scaled jpeg and webp decodes because the native decoding libraries (libjpeg-turbo, libwebp) support downscaling.  Ex: the jpeg library can perform a faster decode when downscaling because it will drop some of the DCT coefficients.  There's no similar option for png.

However, SkAndroidCodec (wraps SkCodec) allows for decoding any format with a fSampleSize specified in AndroidOptions.  fSampleSize=N instructs the codec to sample every Nth pixel as it decodes.  This should do what you want.

Best,
Matt

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://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