Skip to content

Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.

Merge PR #277: decode the wallpaper at screen size, refuse one over 4K

Gathin2348ec76356793
diff --cc launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
index afcafef27,97ccf4f44..630707ff7
--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
@@@ -398,10 -382,17 +399,19 @@@ public class MainActivity extends Activ
android.graphics.BitmapFactory.Options opts = new android.graphics.BitmapFactory.Options();
opts.inJustDecodeBounds = true;
android.graphics.BitmapFactory.decodeFile(file.getPath(), opts);
- int sample = 1;
- while (opts.outWidth / (sample * 2) >= dm.widthPixels && opts.outHeight / (sample * 2) >= dm.heightPixels) sample *= 2;
+ int w = opts.outWidth, h = opts.outHeight;
- if (!WallpaperSize.accepted(w, h)) return;
++ if (w <= 0 || h <= 0) return;
+ int sample = WallpaperSize.sampleSize(w, h, dm.widthPixels, dm.heightPixels);
++ // The limit applies to what is decoded, so a 12 MP photo still works once it is sampled down.
++ if (!WallpaperSize.accepted(w / sample, h / sample)) return;
opts.inJustDecodeBounds = false;
opts.inSampleSize = sample;
+ int[] scale = WallpaperSize.coverScale(w / sample, h / sample, dm.widthPixels, dm.heightPixels);
+ if (scale != null) {
+ opts.inScaled = true;
+ opts.inDensity = scale[0];
+ opts.inTargetDensity = scale[1];
+ }
opts.inPreferredConfig = android.graphics.Bitmap.Config.RGB_565; // no alpha needed, half the memory
android.graphics.Bitmap bmp = android.graphics.BitmapFactory.decodeFile(file.getPath(), opts);
if (bmp == null) return;
diff --cc launcher/app/src/test/java/com/gathin/tvhome/WallpaperSizeTest.java
index 000000000,c2a20b12e..ad9caf968
mode 000000,100644..100644
--- a/launcher/app/src/test/java/com/gathin/tvhome/WallpaperSizeTest.java
+++ b/launcher/app/src/test/java/com/gathin/tvhome/WallpaperSizeTest.java
@@@ -1,0 -1,44 +1,52 @@@
+ package com.gathin.tvhome;
+
+ import org.junit.Test;
+ import static org.junit.Assert.assertArrayEquals;
+ import static org.junit.Assert.assertEquals;
+ import static org.junit.Assert.assertFalse;
+ import static org.junit.Assert.assertNull;
+ import static org.junit.Assert.assertTrue;
+
+ public class WallpaperSizeTest {
+ @Test public void veryWidePictureIsRefused() {
+ assertFalse(WallpaperSize.accepted(65535, 2159));
+ }
+
+ @Test public void fourKPictureIsAccepted() {
+ assertTrue(WallpaperSize.accepted(3840, 2160));
+ assertTrue(WallpaperSize.accepted(1920, 1080));
+ }
+
+ @Test public void unreadablePictureIsRefused() {
+ assertFalse(WallpaperSize.accepted(-1, -1));
+ assertFalse(WallpaperSize.accepted(0, 1080));
+ }
+
+ @Test public void fourKOn1080pSamplesByTwo() {
+ assertEquals(2, WallpaperSize.sampleSize(3840, 2160, 1920, 1080));
+ assertNull(WallpaperSize.coverScale(1920, 1080, 1920, 1080));
+ }
+
+ @Test public void photoBetweenSampleSizesIsScaledToTheScreen() {
+ // 3000x2000 keeps sample size 1; the cover is limited by the width, so it decodes 1920 wide.
+ assertEquals(1, WallpaperSize.sampleSize(3000, 2000, 1920, 1080));
+ assertArrayEquals(new int[]{3000, 1920}, WallpaperSize.coverScale(3000, 2000, 1920, 1080));
+ }
+
+ @Test public void widePictureIsScaledByItsHeight() {
+ assertArrayEquals(new int[]{2000, 1080}, WallpaperSize.coverScale(4000, 2000, 1920, 1080));
+ }
+
+ @Test public void smallPictureIsNotScaled() {
+ assertEquals(1, WallpaperSize.sampleSize(1280, 720, 1920, 1080));
+ assertNull(WallpaperSize.coverScale(1280, 720, 1920, 1080));
+ }
++
++ @Test
++ public void aPhoneSizedPhotoIsAcceptedOnceSampledDown() {
++ int s = WallpaperSize.sampleSize(4032, 3024, 1920, 1080);
++ org.junit.Assert.assertTrue(WallpaperSize.accepted(4032 / s, 3024 / s));
++ int t = WallpaperSize.sampleSize(65535, 2159, 1920, 1080);
++ org.junit.Assert.assertFalse(WallpaperSize.accepted(65535 / t, 2159 / t));
++ }
+ }
diff --cc themes/README.md
index ee6c761a9,f10eacdce..152306f29
--- a/themes/README.md
+++ b/themes/README.md
@@@ -52,7 -48,8 +52,8 @@@ is ignored, and a file that doesn't par
`wallpaper.jpg` is drawn full screen behind the launcher, centre-cropped. Keep it dark, 1920×1080 and
under about 300 KB: the text, the hero name and the dock band are designed for black, and a 1 GB TV
- decodes the picture into memory on every Home start. Pictures larger than the screen are downsampled.
+ decodes the picture into memory on every Home start. Pictures larger than the screen are scaled down to
-it; a picture over 4K (about 8.4 million pixels) is not shown at all and the plain colour stays.
++it; a picture that is still over 4K (about 8.4 million pixels) after it is sampled down to the screen is not shown at all, and the plain colour stays.
## Reduced motion