parent
8dfe6cca47
commit
39fdc31aaa
|
@ -8,7 +8,7 @@ Contain things related to chunk parsing.
|
||||||
|
|
||||||
# Package oupson.apng.decoder
|
# Package oupson.apng.decoder
|
||||||
Contain class for decode APNG.
|
Contain class for decode APNG.
|
||||||
a
|
|
||||||
# Package oupson.apng.encoder
|
# Package oupson.apng.encoder
|
||||||
Contain class for encoding APNG.
|
Contain class for encoding APNG.
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,8 @@ package oupson.apng
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import oupson.apng.chunks.IHDR
|
import oupson.apng.chunks.IHDR
|
||||||
import oupson.apng.chunks.fcTL
|
import oupson.apng.chunks.fcTL
|
||||||
import oupson.apng.exceptions.BadApng
|
import oupson.apng.exceptions.BadApngException
|
||||||
import oupson.apng.exceptions.BadCRC
|
import oupson.apng.exceptions.BadCRCException
|
||||||
import oupson.apng.exceptions.NotApngException
|
import oupson.apng.exceptions.NotApngException
|
||||||
import oupson.apng.exceptions.NotPngException
|
import oupson.apng.exceptions.NotPngException
|
||||||
import oupson.apng.utils.Utils
|
import oupson.apng.utils.Utils
|
||||||
|
@ -18,6 +18,7 @@ import java.util.*
|
||||||
import java.util.zip.CRC32
|
import java.util.zip.CRC32
|
||||||
|
|
||||||
// TODO REWRITE
|
// TODO REWRITE
|
||||||
|
@Deprecated("Deprecated, Use ApngEncoder and ApngDecoder instead", level = DeprecationLevel.WARNING)
|
||||||
class APNGDisassembler {
|
class APNGDisassembler {
|
||||||
private var png: ArrayList<Byte>? = null
|
private var png: ArrayList<Byte>? = null
|
||||||
private var cover: ArrayList<Byte>? = null
|
private var cover: ArrayList<Byte>? = null
|
||||||
|
@ -163,9 +164,9 @@ class APNGDisassembler {
|
||||||
val height = fcTL.pngHeight
|
val height = fcTL.pngHeight
|
||||||
|
|
||||||
if (xOffset + width > maxWidth) {
|
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) {
|
} 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())
|
png?.addAll(pngSignature.asList())
|
||||||
|
@ -315,7 +316,7 @@ class APNGDisassembler {
|
||||||
isApng = true
|
isApng = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else throw BadCRC()
|
} else throw BadCRCException()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.zip.CRC32
|
||||||
* If you want to create an APNG, use ApngEncoder instead
|
* If you want to create an APNG, use ApngEncoder instead
|
||||||
*/
|
*/
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
|
@Deprecated("Deprecated, Use ApngEncoder and ApngDecoder instead", level = DeprecationLevel.WARNING)
|
||||||
class Apng {
|
class Apng {
|
||||||
@Suppress("MemberVisibilityCanBePrivate")
|
@Suppress("MemberVisibilityCanBePrivate")
|
||||||
var maxWidth : Int? = null
|
var maxWidth : Int? = null
|
||||||
|
|
|
@ -26,6 +26,7 @@ import java.net.URL
|
||||||
* Class to play APNG
|
* Class to play APNG
|
||||||
* For better performance but lesser features using [oupson.apng.decoder.ApngDecoder] is strongly recommended.
|
* 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?) {
|
class ApngAnimator(private val context: Context?) {
|
||||||
companion object {
|
companion object {
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -20,8 +20,8 @@ import oupson.apng.Loader
|
||||||
import oupson.apng.chunks.IHDR
|
import oupson.apng.chunks.IHDR
|
||||||
import oupson.apng.chunks.fcTL
|
import oupson.apng.chunks.fcTL
|
||||||
import oupson.apng.decoder.ApngDecoder.Companion.decodeApng
|
import oupson.apng.decoder.ApngDecoder.Companion.decodeApng
|
||||||
import oupson.apng.exceptions.BadApng
|
import oupson.apng.exceptions.BadApngException
|
||||||
import oupson.apng.exceptions.BadCRC
|
import oupson.apng.exceptions.BadCRCException
|
||||||
import oupson.apng.utils.Utils
|
import oupson.apng.utils.Utils
|
||||||
import oupson.apng.utils.Utils.Companion.isPng
|
import oupson.apng.utils.Utils.Companion.isPng
|
||||||
import java.io.*
|
import java.io.*
|
||||||
|
@ -152,9 +152,9 @@ class ApngDecoder {
|
||||||
val height = fcTL.pngHeight
|
val height = fcTL.pngHeight
|
||||||
|
|
||||||
if (xOffset + width > maxWidth) {
|
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) {
|
} 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())
|
png.addAll(Utils.pngSignature.asList())
|
||||||
|
@ -468,7 +468,7 @@ class ApngDecoder {
|
||||||
isApng = true
|
isApng = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else throw BadCRC()
|
} else throw BadCRCException()
|
||||||
} while (byteRead != -1)
|
} while (byteRead != -1)
|
||||||
inputStream.close()
|
inputStream.close()
|
||||||
return drawable
|
return drawable
|
||||||
|
|
|
@ -33,6 +33,7 @@ class ApngEncoder(
|
||||||
|
|
||||||
// TODO ADD SUPPORT FOR FIRST FRAME NOT IN ANIM
|
// TODO ADD SUPPORT FOR FIRST FRAME NOT IN ANIM
|
||||||
// TODO OPTIMISE APNG
|
// TODO OPTIMISE APNG
|
||||||
|
@Suppress("unused")
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun writeFrame(
|
fun writeFrame(
|
||||||
inputStream: InputStream,
|
inputStream: InputStream,
|
||||||
|
@ -119,6 +120,7 @@ class ApngEncoder(
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
fun writeEnd() {
|
fun writeEnd() {
|
||||||
// Add IEND body length : 0
|
// Add IEND body length : 0
|
||||||
outputStream.write(Utils.to4BytesArray(0))
|
outputStream.write(Utils.to4BytesArray(0))
|
||||||
|
|
|
@ -3,7 +3,7 @@ package oupson.apng.encoder
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import oupson.apng.exceptions.InvalidFrameSize
|
import oupson.apng.exceptions.InvalidFrameSizeException
|
||||||
import oupson.apng.utils.Utils
|
import oupson.apng.utils.Utils
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
@ -165,14 +165,13 @@ class ExperimentalApngEncoder(
|
||||||
* @param blendOp See [Utils.BlendOp].
|
* @param blendOp See [Utils.BlendOp].
|
||||||
* @param disposeOp See [Utils.DisposeOp].
|
* @param disposeOp See [Utils.DisposeOp].
|
||||||
* @throws NullPointerException If the bitmap failed to be decoded
|
* @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.
|
* @throws IOException If something failed when writing into the output stream.
|
||||||
*/
|
*/
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
@Throws(
|
@Throws(
|
||||||
NullPointerException::class,
|
NullPointerException::class,
|
||||||
InvalidFrameSize::class,
|
InvalidFrameSizeException::class,
|
||||||
InvalidFrameSize::class,
|
|
||||||
IOException::class
|
IOException::class
|
||||||
)
|
)
|
||||||
fun writeFrame(
|
fun writeFrame(
|
||||||
|
@ -197,11 +196,11 @@ class ExperimentalApngEncoder(
|
||||||
* @param yOffsets The offset of the top bound of the frame in the animation.
|
* @param yOffsets The offset of the top bound of the frame in the animation.
|
||||||
* @param blendOp See [Utils.BlendOp].
|
* @param blendOp See [Utils.BlendOp].
|
||||||
* @param disposeOp See [Utils.DisposeOp].
|
* @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.
|
* @throws IOException If something failed when writing into the output stream.
|
||||||
*/
|
*/
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
@Throws(InvalidFrameSize::class, IOException::class)
|
@Throws(InvalidFrameSizeException::class, IOException::class)
|
||||||
fun writeFrame(
|
fun writeFrame(
|
||||||
btm: Bitmap,
|
btm: Bitmap,
|
||||||
delay: Float = 1000f,
|
delay: Float = 1000f,
|
||||||
|
@ -212,15 +211,15 @@ class ExperimentalApngEncoder(
|
||||||
) {
|
) {
|
||||||
if (currentFrame == 0) {
|
if (currentFrame == 0) {
|
||||||
if (btm.width != width)
|
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)
|
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)
|
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)
|
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)
|
writeFCTL(btm, delay, disposeOp, blendOp, xOffsets, yOffsets)
|
||||||
writeImageData(btm)
|
writeImageData(btm)
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
@file:Suppress("unused")
|
|
||||||
|
|
||||||
package oupson.apng.exceptions
|
package oupson.apng.exceptions
|
||||||
|
|
||||||
class NoFrameException : Exception()
|
class NoFrameException : Exception()
|
||||||
class NotPngException : Exception()
|
class NotPngException : Exception()
|
||||||
class NotApngException : Exception()
|
class NotApngException : Exception()
|
||||||
class NoFcTL : Exception()
|
class BadCRCException : Exception()
|
||||||
class BadCRC : Exception()
|
class BadApngException(override val message: String? = null) : Exception()
|
||||||
class BadApng(override val message: String? = null) : Exception()
|
|
||||||
|
|
||||||
class InvalidFrameSize(override val message: String?) : Exception()
|
class InvalidFrameSizeException(override val message: String?) : Exception()
|
|
@ -137,6 +137,7 @@ class PngEncoder {
|
||||||
return newArray
|
return newArray
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
fun release() {
|
fun release() {
|
||||||
image?.recycle()
|
image?.recycle()
|
||||||
image = null
|
image = null
|
||||||
|
|
Loading…
Reference in New Issue