Merge pull request #9479 from Stypox/create-scaled-bitmap

Use smoother bitmap downscaling for thumbnails
pull/9498/head
Stypox 2022-11-29 16:09:31 +01:00 zatwierdzone przez GitHub
commit 72a250b610
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 12 dodań i 6 usunięć

Wyświetl plik

@ -8,6 +8,7 @@ import android.widget.ImageView;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.core.graphics.BitmapCompat;
import androidx.core.math.MathUtils;
import androidx.preference.PreferenceManager;
@ -91,8 +92,8 @@ public final class SeekbarPreviewThumbnailHelper {
final float scaleFactor = (float) newWidth / srcWidth;
final int newHeight = (int) (srcBitmap.getHeight() * scaleFactor);
currentSeekbarPreviewThumbnail.setImageBitmap(
Bitmap.createScaledBitmap(srcBitmap, newWidth, newHeight, true));
currentSeekbarPreviewThumbnail.setImageBitmap(BitmapCompat.createScaledBitmap(srcBitmap,
newWidth, newHeight, null, true));
} catch (final Exception ex) {
Log.e(TAG, "Failed to resize and set seekbar preview thumbnail", ex);
currentSeekbarPreviewThumbnail.setVisibility(View.GONE);

Wyświetl plik

@ -42,6 +42,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.appcompat.view.ContextThemeWrapper;
import androidx.appcompat.widget.PopupMenu;
import androidx.core.graphics.BitmapCompat;
import androidx.core.graphics.Insets;
import androidx.core.math.MathUtils;
import androidx.core.view.ViewCompat;
@ -455,10 +456,11 @@ public abstract class VideoPlayerUi extends PlayerUi
}
final float endScreenHeight = calculateMaxEndScreenThumbnailHeight(thumbnail);
final Bitmap endScreenBitmap = Bitmap.createScaledBitmap(
final Bitmap endScreenBitmap = BitmapCompat.createScaledBitmap(
thumbnail,
(int) (thumbnail.getWidth() / (thumbnail.getHeight() / endScreenHeight)),
(int) endScreenHeight,
null,
true);
if (DEBUG) {

Wyświetl plik

@ -9,6 +9,7 @@ import android.graphics.Bitmap;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.core.graphics.BitmapCompat;
import com.squareup.picasso.Cache;
import com.squareup.picasso.LruCache;
@ -139,21 +140,23 @@ public final class PicassoHelper {
.getDimension(R.dimen.player_notification_thumbnail_width),
source.getWidth());
final Bitmap result = Bitmap.createScaledBitmap(
final Bitmap result = BitmapCompat.createScaledBitmap(
source,
(int) notificationThumbnailWidth,
(int) (source.getHeight()
/ (source.getWidth() / notificationThumbnailWidth)),
null,
true);
if (result == source) {
if (result == source || !result.isMutable()) {
// create a new mutable bitmap to prevent strange crashes on some
// devices (see #4638)
final Bitmap copied = Bitmap.createScaledBitmap(
final Bitmap copied = BitmapCompat.createScaledBitmap(
source,
(int) notificationThumbnailWidth - 1,
(int) (source.getHeight() / (source.getWidth()
/ (notificationThumbnailWidth - 1))),
null,
true);
source.recycle();
return copied;