fixed size for videos unsupported by MediaMetadataRetriever but supported by metadata-extractor

This commit is contained in:
Thibault Deckers 2020-11-18 15:51:53 +09:00
parent d28ea44ff2
commit be2c9ed914
2 changed files with 19 additions and 17 deletions

View file

@ -122,17 +122,15 @@ class SourceImageEntry {
if (isVideo) {
fillVideoByMediaMetadataRetriever(context)
if (isSized && hasDuration) return this
}
// skip metadata-extractor for raw images because it reports the decoded dimensions instead of the raw dimensions
if (!MimeTypes.isRaw(sourceMimeType) && MimeTypes.isSupportedByMetadataExtractor(sourceMimeType)) {
fillByMetadataExtractor(context)
} else {
fillByMetadataExtractor(context)
if (isSized && foundExif) return this
}
if (ExifInterface.isSupportedMimeType(sourceMimeType)) {
fillByExifInterface(context)
if (isSized) return this
}
fillByBitmapDecode(context)
if (!isSized) {
fillByBitmapDecode(context)
}
return this
}
@ -156,6 +154,9 @@ class SourceImageEntry {
// finds: width, height, orientation, date, duration
private fun fillByMetadataExtractor(context: Context) {
// skip raw images because `metadata-extractor` reports the decoded dimensions instead of the raw dimensions
if (!MimeTypes.isSupportedByMetadataExtractor(sourceMimeType) || MimeTypes.isRaw(sourceMimeType)) return
try {
StorageUtils.openInputStream(context, uri)?.use { input ->
val metadata = ImageMetadataReader.readMetadata(input)
@ -206,6 +207,8 @@ class SourceImageEntry {
// finds: width, height, orientation, date
private fun fillByExifInterface(context: Context) {
if (!ExifInterface.isSupportedMimeType(sourceMimeType)) return;
try {
StorageUtils.openInputStream(context, uri)?.use { input ->
val exif = ExifInterface(input)

View file

@ -98,16 +98,13 @@ class _ThumbnailRasterImageState extends State<ThumbnailRasterImage> {
@override
Widget build(BuildContext context) {
if (!entry.canDecode) {
return ErrorThumbnail(
entry: entry,
extent: extent,
tooltip: '${entry.mimeType} not supported',
);
return _buildError(context, '${entry.mimeType} not supported', null);
}
final fastImage = Image(
key: ValueKey('LQ'),
image: _fastThumbnailProvider,
errorBuilder: _buildError,
width: extent,
height: extent,
fit: BoxFit.cover,
@ -137,11 +134,7 @@ class _ThumbnailRasterImageState extends State<ThumbnailRasterImage> {
child: frame == null ? fastImage : child,
);
},
errorBuilder: (context, error, stackTrace) => ErrorThumbnail(
entry: entry,
extent: extent,
tooltip: error.toString(),
),
errorBuilder: _buildError,
width: extent,
height: extent,
fit: BoxFit.cover,
@ -173,6 +166,12 @@ class _ThumbnailRasterImageState extends State<ThumbnailRasterImage> {
);
}
Widget _buildError(BuildContext context, Object error, StackTrace stackTrace) => ErrorThumbnail(
entry: entry,
extent: extent,
tooltip: error.toString(),
);
// when the entry image itself changed (e.g. after rotation)
void _onImageChanged() async {
// rebuild to refresh the thumbnails