look at only subset of pixels to check for alpha

This commit is contained in:
Daniel Gultsch 2021-01-30 01:50:03 +01:00
parent 53a038d90e
commit ca496fd39f

View file

@ -18,6 +18,7 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Environment; import android.os.Environment;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.os.SystemClock;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.provider.OpenableColumns; import android.provider.OpenableColumns;
import android.system.Os; import android.system.Os;
@ -223,8 +224,12 @@ public class FileBackend {
} }
private static boolean hasAlpha(final Bitmap bitmap) { private static boolean hasAlpha(final Bitmap bitmap) {
for (int x = 0; x < bitmap.getWidth(); ++x) { final int w = bitmap.getWidth();
for (int y = 0; y < bitmap.getWidth(); ++y) { final int h = bitmap.getHeight();
final int yStep = Math.max(1, w / 100);
final int xStep = Math.max(1, h / 100);
for (int x = 0; x < w; x += xStep) {
for (int y = 0; y < h; y += yStep) {
if (Color.alpha(bitmap.getPixel(x, y)) < 255) { if (Color.alpha(bitmap.getPixel(x, y)) < 255) {
return true; return true;
} }
@ -707,7 +712,7 @@ public class FileBackend {
private void copyImageToPrivateStorage(File file, Uri image, int sampleSize) throws FileCopyException, ImageCompressionException { private void copyImageToPrivateStorage(File file, Uri image, int sampleSize) throws FileCopyException, ImageCompressionException {
final File parent = file.getParentFile(); final File parent = file.getParentFile();
if (parent.mkdirs()) { if (parent.mkdirs()) {
Log.d(Config.LOGTAG,"created parent directory"); Log.d(Config.LOGTAG, "created parent directory");
} }
InputStream is = null; InputStream is = null;
OutputStream os = null; OutputStream os = null;
@ -1180,7 +1185,7 @@ public class FileBackend {
} }
} }
if (file.delete()) { if (file.delete()) {
Log.d(Config.LOGTAG,"deleted "+file.getAbsolutePath()); Log.d(Config.LOGTAG, "deleted " + file.getAbsolutePath());
} }
} }