From ba1e9c8e1bd29618cee6c7b0e07369aae4ddde1a Mon Sep 17 00:00:00 2001 From: Thompson3142 <115718208+Thompson3142@users.noreply.github.com> Date: Thu, 24 Oct 2024 19:35:39 +0200 Subject: [PATCH 1/2] Update comment Co-authored-by: Tobi --- .../SeekbarPreviewThumbnailHolder.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/seekbarpreview/SeekbarPreviewThumbnailHolder.java b/app/src/main/java/org/schabi/newpipe/player/seekbarpreview/SeekbarPreviewThumbnailHolder.java index 2db6d39b2..38c2d5d38 100644 --- a/app/src/main/java/org/schabi/newpipe/player/seekbarpreview/SeekbarPreviewThumbnailHolder.java +++ b/app/src/main/java/org/schabi/newpipe/player/seekbarpreview/SeekbarPreviewThumbnailHolder.java @@ -133,7 +133,7 @@ public class SeekbarPreviewThumbnailHolder { // Get the bounds where the frame is found final int[] bounds = frameset.getFrameBoundsAt(currentPosMs); generatedDataForUrl.put(currentPosMs, - createBitmapSupplier(srcBitMap, bounds, frameset)); + createBitmapSupplier(srcBitMap, bounds, frameset)); currentPosMs += frameset.getDurationPerFrame(); pos++; @@ -168,6 +168,18 @@ public class SeekbarPreviewThumbnailHolder { return null; } + // Under some rare circumstances the YouTube API returns slightly too small storyboards, + // (or not the matching frame width/height) + // This would lead to createBitmap cutting out a bitmap that is out of bounds, + // so we need to adjust the bounds accordingly + if (srcBitMap.getWidth() < bounds[1] + frameset.getFrameWidth()) { + bounds[1] = srcBitMap.getWidth() - frameset.getFrameWidth(); + } + + if (srcBitMap.getHeight() < bounds[2] + frameset.getFrameHeight()) { + bounds[2] = srcBitMap.getHeight() - frameset.getFrameHeight(); + } + // Cut out the corresponding bitmap form the "srcBitMap" final Bitmap cutOutBitmap = Bitmap.createBitmap(srcBitMap, bounds[1], bounds[2], frameset.getFrameWidth(), frameset.getFrameHeight()); From 23961548c0256a52ed0e0a4e1e9454311d7509e0 Mon Sep 17 00:00:00 2001 From: Thompson3142 <115718208+Thompson3142@users.noreply.github.com> Date: Sun, 27 Oct 2024 14:38:25 +0100 Subject: [PATCH 2/2] Formatting changes (back to original) --- .../player/seekbarpreview/SeekbarPreviewThumbnailHolder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/seekbarpreview/SeekbarPreviewThumbnailHolder.java b/app/src/main/java/org/schabi/newpipe/player/seekbarpreview/SeekbarPreviewThumbnailHolder.java index 38c2d5d38..09c61b8b3 100644 --- a/app/src/main/java/org/schabi/newpipe/player/seekbarpreview/SeekbarPreviewThumbnailHolder.java +++ b/app/src/main/java/org/schabi/newpipe/player/seekbarpreview/SeekbarPreviewThumbnailHolder.java @@ -133,7 +133,7 @@ public class SeekbarPreviewThumbnailHolder { // Get the bounds where the frame is found final int[] bounds = frameset.getFrameBoundsAt(currentPosMs); generatedDataForUrl.put(currentPosMs, - createBitmapSupplier(srcBitMap, bounds, frameset)); + createBitmapSupplier(srcBitMap, bounds, frameset)); currentPosMs += frameset.getDurationPerFrame(); pos++;