mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 08:30:44 +00:00
Merge pull request #9479 from Stypox/create-scaled-bitmap
Use smoother bitmap downscaling for thumbnails
This commit is contained in:
commit
72a250b610
@ -8,6 +8,7 @@ import android.widget.ImageView;
|
|||||||
|
|
||||||
import androidx.annotation.IntDef;
|
import androidx.annotation.IntDef;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.graphics.BitmapCompat;
|
||||||
import androidx.core.math.MathUtils;
|
import androidx.core.math.MathUtils;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
@ -91,8 +92,8 @@ public final class SeekbarPreviewThumbnailHelper {
|
|||||||
final float scaleFactor = (float) newWidth / srcWidth;
|
final float scaleFactor = (float) newWidth / srcWidth;
|
||||||
final int newHeight = (int) (srcBitmap.getHeight() * scaleFactor);
|
final int newHeight = (int) (srcBitmap.getHeight() * scaleFactor);
|
||||||
|
|
||||||
currentSeekbarPreviewThumbnail.setImageBitmap(
|
currentSeekbarPreviewThumbnail.setImageBitmap(BitmapCompat.createScaledBitmap(srcBitmap,
|
||||||
Bitmap.createScaledBitmap(srcBitmap, newWidth, newHeight, true));
|
newWidth, newHeight, null, true));
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
Log.e(TAG, "Failed to resize and set seekbar preview thumbnail", ex);
|
Log.e(TAG, "Failed to resize and set seekbar preview thumbnail", ex);
|
||||||
currentSeekbarPreviewThumbnail.setVisibility(View.GONE);
|
currentSeekbarPreviewThumbnail.setVisibility(View.GONE);
|
||||||
|
@ -42,6 +42,7 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.appcompat.content.res.AppCompatResources;
|
import androidx.appcompat.content.res.AppCompatResources;
|
||||||
import androidx.appcompat.view.ContextThemeWrapper;
|
import androidx.appcompat.view.ContextThemeWrapper;
|
||||||
import androidx.appcompat.widget.PopupMenu;
|
import androidx.appcompat.widget.PopupMenu;
|
||||||
|
import androidx.core.graphics.BitmapCompat;
|
||||||
import androidx.core.graphics.Insets;
|
import androidx.core.graphics.Insets;
|
||||||
import androidx.core.math.MathUtils;
|
import androidx.core.math.MathUtils;
|
||||||
import androidx.core.view.ViewCompat;
|
import androidx.core.view.ViewCompat;
|
||||||
@ -455,10 +456,11 @@ public abstract class VideoPlayerUi extends PlayerUi
|
|||||||
}
|
}
|
||||||
|
|
||||||
final float endScreenHeight = calculateMaxEndScreenThumbnailHeight(thumbnail);
|
final float endScreenHeight = calculateMaxEndScreenThumbnailHeight(thumbnail);
|
||||||
final Bitmap endScreenBitmap = Bitmap.createScaledBitmap(
|
final Bitmap endScreenBitmap = BitmapCompat.createScaledBitmap(
|
||||||
thumbnail,
|
thumbnail,
|
||||||
(int) (thumbnail.getWidth() / (thumbnail.getHeight() / endScreenHeight)),
|
(int) (thumbnail.getWidth() / (thumbnail.getHeight() / endScreenHeight)),
|
||||||
(int) endScreenHeight,
|
(int) endScreenHeight,
|
||||||
|
null,
|
||||||
true);
|
true);
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
|
@ -9,6 +9,7 @@ import android.graphics.Bitmap;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.core.graphics.BitmapCompat;
|
||||||
|
|
||||||
import com.squareup.picasso.Cache;
|
import com.squareup.picasso.Cache;
|
||||||
import com.squareup.picasso.LruCache;
|
import com.squareup.picasso.LruCache;
|
||||||
@ -139,21 +140,23 @@ public final class PicassoHelper {
|
|||||||
.getDimension(R.dimen.player_notification_thumbnail_width),
|
.getDimension(R.dimen.player_notification_thumbnail_width),
|
||||||
source.getWidth());
|
source.getWidth());
|
||||||
|
|
||||||
final Bitmap result = Bitmap.createScaledBitmap(
|
final Bitmap result = BitmapCompat.createScaledBitmap(
|
||||||
source,
|
source,
|
||||||
(int) notificationThumbnailWidth,
|
(int) notificationThumbnailWidth,
|
||||||
(int) (source.getHeight()
|
(int) (source.getHeight()
|
||||||
/ (source.getWidth() / notificationThumbnailWidth)),
|
/ (source.getWidth() / notificationThumbnailWidth)),
|
||||||
|
null,
|
||||||
true);
|
true);
|
||||||
|
|
||||||
if (result == source) {
|
if (result == source || !result.isMutable()) {
|
||||||
// create a new mutable bitmap to prevent strange crashes on some
|
// create a new mutable bitmap to prevent strange crashes on some
|
||||||
// devices (see #4638)
|
// devices (see #4638)
|
||||||
final Bitmap copied = Bitmap.createScaledBitmap(
|
final Bitmap copied = BitmapCompat.createScaledBitmap(
|
||||||
source,
|
source,
|
||||||
(int) notificationThumbnailWidth - 1,
|
(int) notificationThumbnailWidth - 1,
|
||||||
(int) (source.getHeight() / (source.getWidth()
|
(int) (source.getHeight() / (source.getWidth()
|
||||||
/ (notificationThumbnailWidth - 1))),
|
/ (notificationThumbnailWidth - 1))),
|
||||||
|
null,
|
||||||
true);
|
true);
|
||||||
source.recycle();
|
source.recycle();
|
||||||
return copied;
|
return copied;
|
||||||
|
Loading…
Reference in New Issue
Block a user