Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3744bcd2 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Load video thumbnails using ARGB_8888 for quality.

Based on feedback from a partner, it sounds like getFrameAtTime()
and getScaledFrameAtTime() may end up returning low-quality bitmaps.

To make it clear that we want to create high-quality thumbnails,
this change explicitly requests ARGB_8888.

Bug: 157448043
Test: atest --test-mapping packages/providers/MediaProvider
Change-Id: I39c7c552e8fa715ec13efa75c1c3a30d58492bfb
parent 7d4bad92
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.graphics.ImageDecoder.ImageInfo;
import android.graphics.ImageDecoder.Source;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.media.MediaMetadataRetriever.BitmapParams;
import android.net.Uri;
import android.os.Build;
import android.os.CancellationSignal;
@@ -365,6 +366,9 @@ public class ThumbnailUtils {
                return ImageDecoder.decodeBitmap(ImageDecoder.createSource(raw), resizer);
            }

            final BitmapParams params = new BitmapParams();
            params.setPreferredConfig(Bitmap.Config.ARGB_8888);

            final int width = Integer.parseInt(mmr.extractMetadata(METADATA_KEY_VIDEO_WIDTH));
            final int height = Integer.parseInt(mmr.extractMetadata(METADATA_KEY_VIDEO_HEIGHT));
            // Fall back to middle of video
@@ -376,11 +380,11 @@ public class ThumbnailUtils {
            // return a frame without up-scaling it
            if (size.getWidth() > width && size.getHeight() > height) {
                return Objects.requireNonNull(
                        mmr.getFrameAtTime(thumbnailTimeUs, OPTION_CLOSEST_SYNC));
                        mmr.getFrameAtTime(thumbnailTimeUs, OPTION_CLOSEST_SYNC, params));
            } else {
                return Objects.requireNonNull(
                        mmr.getScaledFrameAtTime(thumbnailTimeUs, OPTION_CLOSEST_SYNC,
                        size.getWidth(), size.getHeight()));
                        size.getWidth(), size.getHeight(), params));
            }
        } catch (RuntimeException e) {
            throw new IOException("Failed to create thumbnail", e);