Commit c670e177 authored by Geoffrey Métais's avatar Geoffrey Métais

Generate thumbnails from dimension values

- No need to calculate from display density, frameworks gives use right values already
- Generate thumbs or downscale cover at the right size
- avoid useless Bitamp decode
parent 0a92e7bb
......@@ -56,13 +56,11 @@ public class Thumbnailer implements Runnable {
protected Thread mThread;
private LibVLC mLibVlc;
private int totalCount;
private final float mDensity;
private final String mPrefix;
public Thumbnailer(Context context, Display display) {
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
mDensity = metrics.density;
mPrefix = context.getResources().getString(R.string.thumbnail);
}
......@@ -172,8 +170,8 @@ public class Thumbnailer implements Runnable {
if (item.getArtworkURL() != null)
continue; //no need for thumbnail, we have a cover
int width = (int) (120 * mDensity);
int height = (int) (75 * mDensity);
int width = (VLCApplication.getAppResources().getDimensionPixelSize(R.dimen.grid_card_thumb_width));
int height = (VLCApplication.getAppResources().getDimensionPixelSize(R.dimen.grid_card_thumb_height));
//Get bitmap
byte[] b = mLibVlc.getThumbnail(item.getLocation(), width, height);
......
......@@ -22,9 +22,11 @@ package org.videolan.vlc.util;
import org.videolan.vlc.MediaWrapper;
import org.videolan.vlc.MediaDatabase;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
......@@ -108,25 +110,28 @@ public class BitmapUtil {
private static Bitmap readCoverBitmap(String path) {
if (path == null)
return null;
Resources res = VLCApplication.getAppResources();
String uri = Uri.decode(path);
if (uri.startsWith("file://"))
uri = uri.substring(7);
Bitmap cover = null;
BitmapFactory.Options options = new BitmapFactory.Options();
int height = res.getDimensionPixelSize(R.dimen.grid_card_thumb_height);
int width = res.getDimensionPixelSize(R.dimen.grid_card_thumb_width);
/* Get the resolution of the bitmap without allocating the memory */
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(uri, options);
if (options.outWidth > 0 && options.outHeight > 0) {
if (options.outWidth > width){
options.outWidth = width;
options.outHeight = height;
}
options.inJustDecodeBounds = false;
// Decode the file (with memory allocation this time)
cover = BitmapFactory.decodeFile(uri, options);
if (cover != null) {
cover = Bitmap.createScaledBitmap(cover, options.outWidth, options.outHeight, false);
}
}
return cover;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment