metadata extractor update fix
This commit is contained in:
parent
f15d19c080
commit
90d836cf37
5 changed files with 7 additions and 8 deletions
|
@ -388,7 +388,7 @@ enum class DirType {
|
|||
override fun createDirectory() = ExifIFD0Directory()
|
||||
},
|
||||
EXIF_THUMBNAIL {
|
||||
override fun createDirectory() = ExifThumbnailDirectory()
|
||||
override fun createDirectory() = ExifThumbnailDirectory(0)
|
||||
},
|
||||
GPS {
|
||||
override fun createDirectory() = GpsDirectory()
|
||||
|
|
|
@ -18,7 +18,6 @@ object ExifTags {
|
|||
private const val SAMPLE_FORMAT = 0x0153
|
||||
private const val SMIN_SAMPLE_VALUE = 0x0154
|
||||
private const val SMAX_SAMPLE_VALUE = 0x0155
|
||||
private const val RATING_PERCENT = 0x4749
|
||||
private const val SONY_RAW_FILE_TYPE = 0x7000
|
||||
private const val SONY_TONE_CURVE = 0x7010
|
||||
private const val MATTEING = 0x80e3
|
||||
|
@ -40,7 +39,6 @@ object ExifTags {
|
|||
SAMPLE_FORMAT to "Sample Format",
|
||||
SMIN_SAMPLE_VALUE to "S Min Sample Value",
|
||||
SMAX_SAMPLE_VALUE to "S Max Sample Value",
|
||||
RATING_PERCENT to "Rating Percent",
|
||||
SONY_RAW_FILE_TYPE to "Sony Raw File Type",
|
||||
SONY_TONE_CURVE to "Sony Tone Curve",
|
||||
MATTEING to "Matteing",
|
||||
|
|
|
@ -116,7 +116,7 @@ object Helper {
|
|||
fun safeReadTiff(input: InputStream): com.drew.metadata.Metadata {
|
||||
val reader = RandomAccessStreamReader(input, RandomAccessStreamReader.DEFAULT_CHUNK_LENGTH, safeReadStreamLength)
|
||||
val metadata = com.drew.metadata.Metadata()
|
||||
val handler = SafeExifTiffHandler(metadata, null)
|
||||
val handler = SafeExifTiffHandler(metadata, null, 0)
|
||||
TiffReader().processTiff(reader, handler, 0)
|
||||
return metadata
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import com.drew.metadata.exif.ExifSubIFDDirectory
|
|||
import com.drew.metadata.exif.ExifTiffHandler
|
||||
import java.io.IOException
|
||||
|
||||
class SafeExifTiffHandler(metadata: Metadata, parentDirectory: Directory?) : ExifTiffHandler(metadata, parentDirectory) {
|
||||
class SafeExifTiffHandler(metadata: Metadata, parentDirectory: Directory?, exifStartOffset: Int) : ExifTiffHandler(metadata, parentDirectory, exifStartOffset) {
|
||||
@Throws(IOException::class)
|
||||
override fun customProcessTag(
|
||||
tagOffset: Int,
|
||||
|
|
|
@ -45,6 +45,7 @@ object SafePngMetadataReader {
|
|||
private const val chunkSizeDangerThreshold = SafeXmpReader.SEGMENT_TYPE_SIZE_DANGER_THRESHOLD
|
||||
|
||||
private val latin1Encoding = Charsets.ISO_8859_1
|
||||
private val utf8Encoding = Charsets.UTF_8
|
||||
private val desiredChunkTypes: Set<PngChunkType> = hashSetOf(
|
||||
PngChunkType.IHDR,
|
||||
PngChunkType.PLTE,
|
||||
|
@ -234,7 +235,7 @@ object SafePngMetadataReader {
|
|||
val reader: SequentialReader = SequentialByteArrayReader(bytes)
|
||||
|
||||
// Keyword is 1-79 bytes, followed by the 1 byte null character
|
||||
val keywordsv = reader.getNullTerminatedStringValue(79 + 1, latin1Encoding)
|
||||
val keywordsv = reader.getNullTerminatedStringValue(79 + 1, utf8Encoding)
|
||||
val keyword = keywordsv.toString()
|
||||
val compressionFlag = reader.int8
|
||||
val compressionMethod = reader.int8
|
||||
|
@ -273,7 +274,7 @@ object SafePngMetadataReader {
|
|||
XmpReader().extract(textBytes, metadata)
|
||||
} else {
|
||||
val textPairs: MutableList<KeyValuePair> = ArrayList()
|
||||
textPairs.add(KeyValuePair(keyword, StringValue(textBytes, latin1Encoding)))
|
||||
textPairs.add(KeyValuePair(keyword, StringValue(textBytes, utf8Encoding)))
|
||||
val directory = PngDirectory(PngChunkType.iTXt)
|
||||
directory.setObject(PngDirectory.TAG_TEXTUAL_DATA, textPairs)
|
||||
metadata.addDirectory(directory)
|
||||
|
@ -316,7 +317,7 @@ object SafePngMetadataReader {
|
|||
metadata.addDirectory(directory)
|
||||
} else if (chunkType == PngChunkType.eXIf) {
|
||||
try {
|
||||
val handler = ExifTiffHandler(metadata, null)
|
||||
val handler = ExifTiffHandler(metadata, null, 0)
|
||||
TiffReader().processTiff(ByteArrayReader(bytes), handler, 0)
|
||||
} catch (ex: TiffProcessingException) {
|
||||
val directory = PngDirectory(PngChunkType.eXIf)
|
||||
|
|
Loading…
Reference in a new issue