info: show GeoTiff tags in their own section
This commit is contained in:
parent
bc19f12805
commit
cc61e93c74
2 changed files with 28 additions and 4 deletions
|
@ -18,6 +18,7 @@ import com.adobe.internal.xmp.properties.XMPPropertyInfo
|
|||
import com.bumptech.glide.load.resource.bitmap.TransformationUtils
|
||||
import com.drew.imaging.ImageMetadataReader
|
||||
import com.drew.lang.Rational
|
||||
import com.drew.metadata.Tag
|
||||
import com.drew.metadata.exif.*
|
||||
import com.drew.metadata.file.FileTypeDirectory
|
||||
import com.drew.metadata.gif.GifAnimationDirectory
|
||||
|
@ -125,17 +126,29 @@ class MetadataHandler(private val context: Context) : MethodCallHandler {
|
|||
metadataMap[dirName] = dirMap
|
||||
|
||||
// tags
|
||||
val tags = dir.tags
|
||||
if (mimeType == MimeTypes.TIFF && (dir is ExifIFD0Directory || dir is ExifThumbnailDirectory)) {
|
||||
dirMap.putAll(dir.tags.map {
|
||||
fun tagMapper(it: Tag): Pair<String, String> {
|
||||
val name = if (it.hasTagName()) {
|
||||
it.tagName
|
||||
} else {
|
||||
TiffTags.getTagName(it.tagType) ?: it.tagName
|
||||
}
|
||||
Pair(name, it.description)
|
||||
})
|
||||
return Pair(name, it.description)
|
||||
}
|
||||
|
||||
if (dir is ExifIFD0Directory && dir.isGeoTiff()) {
|
||||
// split GeoTIFF tags in their own directory
|
||||
val byGeoTiff = tags.groupBy { TiffTags.isGeoTiffTag(it.tagType) }
|
||||
metadataMap["GeoTIFF"] = HashMap<String, String>().apply {
|
||||
byGeoTiff[true]?.map { tagMapper(it) }?.let { putAll(it) }
|
||||
}
|
||||
byGeoTiff[false]?.map { tagMapper(it) }?.let { dirMap.putAll(it) }
|
||||
} else {
|
||||
dirMap.putAll(dir.tags.map { Pair(it.tagName, it.description) })
|
||||
dirMap.putAll(tags.map { tagMapper(it) })
|
||||
}
|
||||
} else {
|
||||
dirMap.putAll(tags.map { Pair(it.tagName, it.description) })
|
||||
}
|
||||
if (dir is XmpDirectory) {
|
||||
try {
|
||||
|
|
|
@ -110,6 +110,15 @@ object TiffTags {
|
|||
// Count = variable
|
||||
const val TAG_ORIGINAL_RAW_FILE_NAME = 0xc68b
|
||||
|
||||
private val geotiffTags = listOf(
|
||||
TAG_GEO_ASCII_PARAMS,
|
||||
TAG_GEO_DOUBLE_PARAMS,
|
||||
TAG_GEO_KEY_DIRECTORY,
|
||||
TAG_MODEL_PIXEL_SCALE,
|
||||
TAG_MODEL_TIEPOINT,
|
||||
TAG_MODEL_TRANSFORMATION,
|
||||
)
|
||||
|
||||
private val tagNameMap = hashMapOf(
|
||||
TAG_X_POSITION to "X Position",
|
||||
TAG_Y_POSITION to "Y Position",
|
||||
|
@ -132,6 +141,8 @@ object TiffTags {
|
|||
TAG_ORIGINAL_RAW_FILE_NAME to "Original Raw File Name",
|
||||
)
|
||||
|
||||
fun isGeoTiffTag(tag: Int) = geotiffTags.contains(tag)
|
||||
|
||||
fun getTagName(tag: Int): String? {
|
||||
return tagNameMap[tag]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue