Merge "MTP: Add thumbnail generation for JPG" am: 5aac2c84ba am: d68b21d215

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1657579

Change-Id: I9b85e42a66e310666de6d811e2af38d428a86f3d
This commit is contained in:
Treehugger Robot
2021-04-01 07:37:36 +00:00
committed by Automerger Merge Worker
3 changed files with 18 additions and 5 deletions

View File

@@ -772,8 +772,10 @@ public class MtpDatabase implements AutoCloseable {
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteStream); 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; return null;
}
byte[] byteArray = byteStream.toByteArray(); byte[] byteArray = byteStream.toByteArray();
@@ -803,7 +805,15 @@ public class MtpDatabase implements AutoCloseable {
outLongs[0] = thumbOffsetAndSize != null ? thumbOffsetAndSize[1] : 0; outLongs[0] = thumbOffsetAndSize != null ? thumbOffsetAndSize[1] : 0;
outLongs[1] = exif.getAttributeInt(ExifInterface.TAG_PIXEL_X_DIMENSION, 0); outLongs[1] = exif.getAttributeInt(ExifInterface.TAG_PIXEL_X_DIMENSION, 0);
outLongs[2] = exif.getAttributeInt(ExifInterface.TAG_PIXEL_Y_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) { } catch (IOException e) {
// ignore and fall through // ignore and fall through
} }
@@ -836,7 +846,9 @@ public class MtpDatabase implements AutoCloseable {
case MtpConstants.FORMAT_JFIF: case MtpConstants.FORMAT_JFIF:
try { try {
ExifInterface exif = new ExifInterface(path); ExifInterface exif = new ExifInterface(path);
return exif.getThumbnail();
if (exif.getThumbnailRange() != null)
return exif.getThumbnail();
} catch (IOException e) { } catch (IOException e) {
// ignore and fall through // ignore and fall through
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 0 B

After

Width:  |  Height:  |  Size: 8.4 KiB

View File

@@ -271,9 +271,10 @@ public class MtpDatabaseTest {
Log.d(TAG, "testMtpDatabaseThumbnail: Test bad JPG"); Log.d(TAG, "testMtpDatabaseThumbnail: Test bad JPG");
testThumbnail(handleJpgBadThumb, jpgfileBadThumb, false); // Now we support to generate thumbnail if embedded thumbnail is corrupted or not existed
testThumbnail(handleJpgBadThumb, jpgfileBadThumb, true);
testThumbnail(handleJpgNoThumb, jpgFileNoThumb, false); testThumbnail(handleJpgNoThumb, jpgFileNoThumb, true);
testThumbnail(handleJpgBad, jpgfileBad, false); testThumbnail(handleJpgBad, jpgfileBad, false);