diff options
author | James Wei <jameswei@google.com> | 2021-03-22 13:17:01 +0800 |
---|---|---|
committer | James Wei <jameswei@google.com> | 2021-03-30 13:49:27 +0800 |
commit | 1f1f81e0d15dd2130dd2a806e6943b0063a5e9ea (patch) | |
tree | 405a9d53602c5dddf9ff669e1559b13be5000b32 /media/java/android/mtp/MtpDatabase.java | |
parent | a819b9fcf5b1ad00fdb8604a31b5938bb58f6aa9 (diff) |
MTP: Add thumbnail generation for JPG
Add thumbnail generation support for JPG image format
Instead of retrieving thumbnail from EXIF header
Bug: 178726106
Test: atest MtpTests
Test: manual test on Windows 10 file explorer
Test: manual test on Linux nautilus file browser
Change-Id: I29ad89835a8a27204a2e6dbd97b994209a813424
Diffstat (limited to 'media/java/android/mtp/MtpDatabase.java')
-rwxr-xr-x | media/java/android/mtp/MtpDatabase.java | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/media/java/android/mtp/MtpDatabase.java b/media/java/android/mtp/MtpDatabase.java index ed56b4398c22..9fe700a41ab2 100755 --- a/media/java/android/mtp/MtpDatabase.java +++ b/media/java/android/mtp/MtpDatabase.java @@ -821,8 +821,10 @@ public class MtpDatabase implements AutoCloseable { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteStream); - if (byteStream.size() > MAX_THUMB_SIZE) + if (byteStream.size() > MAX_THUMB_SIZE) { + Log.w(TAG, "getThumbnailProcess: size=" + byteStream.size()); return null; + } byte[] byteArray = byteStream.toByteArray(); @@ -852,7 +854,15 @@ public class MtpDatabase implements AutoCloseable { outLongs[0] = thumbOffsetAndSize != null ? thumbOffsetAndSize[1] : 0; outLongs[1] = exif.getAttributeInt(ExifInterface.TAG_PIXEL_X_DIMENSION, 0); outLongs[2] = exif.getAttributeInt(ExifInterface.TAG_PIXEL_Y_DIMENSION, 0); - return true; + if (exif.getThumbnailRange() != null) { + if ((outLongs[0] == 0) || (outLongs[1] == 0) || (outLongs[2] == 0)) { + Log.d(TAG, "getThumbnailInfo: check thumb info:" + + thumbOffsetAndSize[0] + "," + thumbOffsetAndSize[1] + + "," + outLongs[1] + "," + outLongs[2]); + } + + return true; + } } catch (IOException e) { // ignore and fall through } @@ -885,7 +895,9 @@ public class MtpDatabase implements AutoCloseable { case MtpConstants.FORMAT_JFIF: try { ExifInterface exif = new ExifInterface(path); - return exif.getThumbnail(); + + if (exif.getThumbnailRange() != null) + return exif.getThumbnail(); } catch (IOException e) { // ignore and fall through } |