DEPRECATING OLD CLASSES RELATED TO Apng.kt

Documentation
This commit is contained in:
Oupson 2020-09-20 12:57:07 +02:00
parent 8dfe6cca47
commit 39fdc31aaa
9 changed files with 29 additions and 27 deletions

View File

@ -8,7 +8,7 @@ Contain things related to chunk parsing.
# Package oupson.apng.decoder
Contain class for decode APNG.
a
# Package oupson.apng.encoder
Contain class for encoding APNG.

View File

@ -3,8 +3,8 @@ package oupson.apng
import android.graphics.BitmapFactory
import oupson.apng.chunks.IHDR
import oupson.apng.chunks.fcTL
import oupson.apng.exceptions.BadApng
import oupson.apng.exceptions.BadCRC
import oupson.apng.exceptions.BadApngException
import oupson.apng.exceptions.BadCRCException
import oupson.apng.exceptions.NotApngException
import oupson.apng.exceptions.NotPngException
import oupson.apng.utils.Utils
@ -18,6 +18,7 @@ import java.util.*
import java.util.zip.CRC32
// TODO REWRITE
@Deprecated("Deprecated, Use ApngEncoder and ApngDecoder instead", level = DeprecationLevel.WARNING)
class APNGDisassembler {
private var png: ArrayList<Byte>? = null
private var cover: ArrayList<Byte>? = null
@ -163,9 +164,9 @@ class APNGDisassembler {
val height = fcTL.pngHeight
if (xOffset + width > maxWidth) {
throw BadApng("`yOffset` + `height` must be <= `IHDR` height")
throw BadApngException("`yOffset` + `height` must be <= `IHDR` height")
} else if (yOffset + height > maxHeight) {
throw BadApng("`yOffset` + `height` must be <= `IHDR` height")
throw BadApngException("`yOffset` + `height` must be <= `IHDR` height")
}
png?.addAll(pngSignature.asList())
@ -315,7 +316,7 @@ class APNGDisassembler {
isApng = true
}
}
} else throw BadCRC()
} else throw BadCRCException()
}
/**

View File

@ -24,6 +24,7 @@ import java.util.zip.CRC32
* If you want to create an APNG, use ApngEncoder instead
*/
@Suppress("unused")
@Deprecated("Deprecated, Use ApngEncoder and ApngDecoder instead", level = DeprecationLevel.WARNING)
class Apng {
@Suppress("MemberVisibilityCanBePrivate")
var maxWidth : Int? = null

View File

@ -26,6 +26,7 @@ import java.net.URL
* Class to play APNG
* For better performance but lesser features using [oupson.apng.decoder.ApngDecoder] is strongly recommended.
*/
@Deprecated("Deprecated, Use ApngEncoder and ApngDecoder instead", level = DeprecationLevel.WARNING)
class ApngAnimator(private val context: Context?) {
companion object {
/**

View File

@ -20,8 +20,8 @@ import oupson.apng.Loader
import oupson.apng.chunks.IHDR
import oupson.apng.chunks.fcTL
import oupson.apng.decoder.ApngDecoder.Companion.decodeApng
import oupson.apng.exceptions.BadApng
import oupson.apng.exceptions.BadCRC
import oupson.apng.exceptions.BadApngException
import oupson.apng.exceptions.BadCRCException
import oupson.apng.utils.Utils
import oupson.apng.utils.Utils.Companion.isPng
import java.io.*
@ -152,9 +152,9 @@ class ApngDecoder {
val height = fcTL.pngHeight
if (xOffset + width > maxWidth) {
throw BadApng("`xOffset` + `width` must be <= `IHDR` width")
throw BadApngException("`xOffset` + `width` must be <= `IHDR` width")
} else if (yOffset + height > maxHeight) {
throw BadApng("`yOffset` + `height` must be <= `IHDR` height")
throw BadApngException("`yOffset` + `height` must be <= `IHDR` height")
}
png.addAll(Utils.pngSignature.asList())
@ -468,7 +468,7 @@ class ApngDecoder {
isApng = true
}
}
} else throw BadCRC()
} else throw BadCRCException()
} while (byteRead != -1)
inputStream.close()
return drawable

View File

@ -33,6 +33,7 @@ class ApngEncoder(
// TODO ADD SUPPORT FOR FIRST FRAME NOT IN ANIM
// TODO OPTIMISE APNG
@Suppress("unused")
@JvmOverloads
fun writeFrame(
inputStream: InputStream,
@ -119,6 +120,7 @@ class ApngEncoder(
}*/
}
@Suppress("unused")
fun writeEnd() {
// Add IEND body length : 0
outputStream.write(Utils.to4BytesArray(0))

View File

@ -3,7 +3,7 @@ package oupson.apng.encoder
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.util.Log
import oupson.apng.exceptions.InvalidFrameSize
import oupson.apng.exceptions.InvalidFrameSizeException
import oupson.apng.utils.Utils
import java.io.ByteArrayOutputStream
import java.io.IOException
@ -165,14 +165,13 @@ class ExperimentalApngEncoder(
* @param blendOp See [Utils.BlendOp].
* @param disposeOp See [Utils.DisposeOp].
* @throws NullPointerException If the bitmap failed to be decoded
* @throws InvalidFrameSize If the frame size is bigger than the animation size, or the first frame size is not equal to the animation size.
* @throws InvalidFrameSizeException If the frame size is bigger than the animation size, or the first frame size is not equal to the animation size.
* @throws IOException If something failed when writing into the output stream.
*/
@JvmOverloads
@Throws(
NullPointerException::class,
InvalidFrameSize::class,
InvalidFrameSize::class,
InvalidFrameSizeException::class,
IOException::class
)
fun writeFrame(
@ -197,11 +196,11 @@ class ExperimentalApngEncoder(
* @param yOffsets The offset of the top bound of the frame in the animation.
* @param blendOp See [Utils.BlendOp].
* @param disposeOp See [Utils.DisposeOp].
* @throws InvalidFrameSize If the frame size is bigger than the animation size, or the first frame size is not equal to the animation size.
* @throws InvalidFrameSizeException If the frame size is bigger than the animation size, or the first frame size is not equal to the animation size.
* @throws IOException If something failed when writing into the output stream.
*/
@JvmOverloads
@Throws(InvalidFrameSize::class, IOException::class)
@Throws(InvalidFrameSizeException::class, IOException::class)
fun writeFrame(
btm: Bitmap,
delay: Float = 1000f,
@ -212,15 +211,15 @@ class ExperimentalApngEncoder(
) {
if (currentFrame == 0) {
if (btm.width != width)
throw InvalidFrameSize("Width of first frame must be equal to width of APNG. (${btm.width} != $width)")
throw InvalidFrameSizeException("Width of first frame must be equal to width of APNG. (${btm.width} != $width)")
if (btm.height != height)
throw InvalidFrameSize("Height of first frame must be equal to height of APNG. (${btm.height} != $height)")
throw InvalidFrameSizeException("Height of first frame must be equal to height of APNG. (${btm.height} != $height)")
}
if (btm.width > width)
throw InvalidFrameSize("Frame width must be inferior or equal at the animation width")
throw InvalidFrameSizeException("Frame width must be inferior or equal at the animation width")
else if (btm.height > height)
throw InvalidFrameSize("Frame height must be inferior or equal at the animation height")
throw InvalidFrameSizeException("Frame height must be inferior or equal at the animation height")
writeFCTL(btm, delay, disposeOp, blendOp, xOffsets, yOffsets)
writeImageData(btm)

View File

@ -1,12 +1,9 @@
@file:Suppress("unused")
package oupson.apng.exceptions
class NoFrameException : Exception()
class NotPngException : Exception()
class NotApngException : Exception()
class NoFcTL : Exception()
class BadCRC : Exception()
class BadApng(override val message: String? = null) : Exception()
class BadCRCException : Exception()
class BadApngException(override val message: String? = null) : Exception()
class InvalidFrameSize(override val message: String?) : Exception()
class InvalidFrameSizeException(override val message: String?) : Exception()

View File

@ -137,6 +137,7 @@ class PngEncoder {
return newArray
}
@Suppress("unused")
fun release() {
image?.recycle()
image = null