refactor
This commit is contained in:
parent
c1f83e1706
commit
b56a6af143
|
@ -54,8 +54,9 @@ internal class ExifData(
|
||||||
var compressedThumbnail : ByteArray? = null
|
var compressedThumbnail : ByteArray? = null
|
||||||
|
|
||||||
private val mStripBytes = ArrayList<ByteArray?>()
|
private val mStripBytes = ArrayList<ByteArray?>()
|
||||||
val stripCount : Int
|
|
||||||
get() = mStripBytes.size
|
val stripList : List<ByteArray>?
|
||||||
|
get() = mStripBytes.filterNotNull().notEmpty()
|
||||||
|
|
||||||
// Decodes the user comment tag into string as specified in the EXIF standard.
|
// Decodes the user comment tag into string as specified in the EXIF standard.
|
||||||
// Returns null if decoding failed.
|
// Returns null if decoding failed.
|
||||||
|
@ -101,13 +102,10 @@ internal class ExifData(
|
||||||
val imageSize : IntArray
|
val imageSize : IntArray
|
||||||
get() = intArrayOf(imageWidth, imageLength)
|
get() = intArrayOf(imageWidth, imageLength)
|
||||||
|
|
||||||
val stripList : List<ByteArray>?
|
|
||||||
get() = mStripBytes.filterNotNull().notEmpty()
|
|
||||||
|
|
||||||
val thumbnailBytes : ByteArray?
|
val thumbnailBytes : ByteArray?
|
||||||
get() = when {
|
get() = when {
|
||||||
compressedThumbnail != null -> compressedThumbnail
|
compressedThumbnail != null -> compressedThumbnail
|
||||||
hasUncompressedStrip() -> null // TODO: implement this
|
stripList != null -> null // TODO: implement this
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +129,7 @@ internal class ExifData(
|
||||||
* Adds an uncompressed strip.
|
* Adds an uncompressed strip.
|
||||||
*/
|
*/
|
||||||
fun setStripBytes(index : Int, strip : ByteArray) {
|
fun setStripBytes(index : Int, strip : ByteArray) {
|
||||||
if(index < mStripBytes.size) {
|
if(index in mStripBytes.indices) {
|
||||||
mStripBytes[index] = strip
|
mStripBytes[index] = strip
|
||||||
} else {
|
} else {
|
||||||
for(i in mStripBytes.size until index) {
|
for(i in mStripBytes.size until index) {
|
||||||
|
@ -142,16 +140,17 @@ internal class ExifData(
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the strip at the specified index.
|
* Returns the [IfdData] object corresponding to a given IFD or
|
||||||
*
|
* generates one if none exist.
|
||||||
* @exceptions #IndexOutOfBoundException
|
|
||||||
*/
|
*/
|
||||||
fun getStrip(index : Int) : ByteArray? = mStripBytes[index]
|
private fun prepareIfdData(ifdId : Int) : IfdData {
|
||||||
|
var ifdData = mIfdDatas[ifdId]
|
||||||
/**
|
if(ifdData == null) {
|
||||||
* Returns true if this header contains uncompressed strip.
|
ifdData = IfdData(ifdId)
|
||||||
*/
|
mIfdDatas[ifdId] = ifdData
|
||||||
fun hasUncompressedStrip() : Boolean = mStripBytes.isNotEmpty()
|
}
|
||||||
|
return ifdData
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds IFD data. If IFD data of the same type already exists, it will be
|
* Adds IFD data. If IFD data of the same type already exists, it will be
|
||||||
|
@ -186,20 +185,14 @@ internal class ExifData(
|
||||||
when {
|
when {
|
||||||
tag == null -> null
|
tag == null -> null
|
||||||
! ExifTag.isValidIfd(ifdId) -> null
|
! ExifTag.isValidIfd(ifdId) -> null
|
||||||
else -> getOrCreateIfdData(ifdId).setTag(tag)
|
else -> prepareIfdData(ifdId).setTag(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the [IfdData] object corresponding to a given IFD or
|
* Removes the tag with a given TID and IFD.
|
||||||
* generates one if none exist.
|
|
||||||
*/
|
*/
|
||||||
private fun getOrCreateIfdData(ifdId : Int) : IfdData {
|
fun removeTag(tagId : Short, ifdId : Int) {
|
||||||
var ifdData = mIfdDatas[ifdId]
|
mIfdDatas[ifdId]?.removeTag(tagId)
|
||||||
if(ifdData == null) {
|
|
||||||
ifdData = IfdData(ifdId)
|
|
||||||
mIfdDatas[ifdId] = ifdData
|
|
||||||
}
|
|
||||||
return ifdData
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -215,14 +208,6 @@ internal class ExifData(
|
||||||
mStripBytes.clear()
|
mStripBytes.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes the tag with a given TID and IFD.
|
|
||||||
*/
|
|
||||||
fun removeTag(tagId : Short, ifdId : Int) {
|
|
||||||
val ifdData = mIfdDatas[ifdId] ?: return
|
|
||||||
ifdData.removeTag(tagId)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of all [ExifTag]s in a given IFD or null if there
|
* Returns a list of all [ExifTag]s in a given IFD or null if there
|
||||||
* are none.
|
* are none.
|
||||||
|
@ -232,18 +217,10 @@ internal class ExifData(
|
||||||
|
|
||||||
// Returns a list of all [ExifTag]s with a given TID
|
// Returns a list of all [ExifTag]s with a given TID
|
||||||
// or null if there are none.
|
// or null if there are none.
|
||||||
fun getAllTagsForTagId(tag : Short) : List<ExifTag>? {
|
fun getAllTagsForTagId(tag : Short) : List<ExifTag>? =
|
||||||
val ret = ArrayList<ExifTag>()
|
ArrayList<ExifTag>()
|
||||||
for(d in mIfdDatas) {
|
.apply { mIfdDatas.forEach { it?.getTag(tag)?.let { t -> add(t) } } }
|
||||||
if(d != null) {
|
.notEmpty()
|
||||||
val t = d.getTag(tag)
|
|
||||||
if(t != null) {
|
|
||||||
ret.add(t)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return if(ret.isEmpty()) null else ret
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun equals(other : Any?) : Boolean {
|
override fun equals(other : Any?) : Boolean {
|
||||||
if(this === other) return true
|
if(this === other) return true
|
||||||
|
|
|
@ -83,6 +83,13 @@ open class ExifTag internal constructor(
|
||||||
val dataSize : Int
|
val dataSize : Int
|
||||||
get() = componentCount * getElementSize(dataType)
|
get() = componentCount * getElementSize(dataType)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if this ExifTag contains value; otherwise, this tag will
|
||||||
|
* contain an offset value that is determined when the tag is written.
|
||||||
|
*/
|
||||||
|
val hasValue :Boolean
|
||||||
|
get() = mValue != null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value as a byte array. This method should be used for tags of
|
* Gets the value as a byte array. This method should be used for tags of
|
||||||
* type [.TYPE_UNDEFINED] or [.TYPE_UNSIGNED_BYTE].
|
* type [.TYPE_UNDEFINED] or [.TYPE_UNSIGNED_BYTE].
|
||||||
|
@ -165,13 +172,6 @@ open class ExifTag internal constructor(
|
||||||
componentCount = count
|
componentCount = count
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if this ExifTag contains value; otherwise, this tag will
|
|
||||||
* contain an offset value that is determined when the tag is written.
|
|
||||||
*/
|
|
||||||
val hasValue :Boolean
|
|
||||||
get() = mValue != null
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets integer values into this tag. This method should be used for tags of
|
* Sets integer values into this tag. This method should be used for tags of
|
||||||
* type [.TYPE_UNSIGNED_SHORT]. This method will fail if:
|
* type [.TYPE_UNSIGNED_SHORT]. This method will fail if:
|
||||||
|
|
Loading…
Reference in New Issue