parent
34c1eede2a
commit
4e807e8b06
|
@ -222,16 +222,12 @@ class ApngEncoder(
|
|||
disposeOp: Utils.Companion.DisposeOp = Utils.Companion.DisposeOp.APNG_DISPOSE_OP_NONE
|
||||
) {
|
||||
if (currentFrame == 0) {
|
||||
if (btm.width != width)
|
||||
throw InvalidFrameSizeException("Width of first frame must be equal to width of APNG. (${btm.width} != $width)")
|
||||
if (btm.height != height)
|
||||
throw InvalidFrameSizeException("Height of first frame must be equal to height of APNG. (${btm.height} != $height)")
|
||||
if (btm.width != width || btm.height != height)
|
||||
throw InvalidFrameSizeException(btm.width, btm.height, width, height, currentFrame == 0)
|
||||
}
|
||||
|
||||
if (btm.width > width)
|
||||
throw InvalidFrameSizeException("Frame width must be inferior or equal at the animation width")
|
||||
else if (btm.height > height)
|
||||
throw InvalidFrameSizeException("Frame height must be inferior or equal at the animation height")
|
||||
if (btm.width > width || btm.height > height)
|
||||
throw InvalidFrameSizeException(btm.width, btm.height, width, height, currentFrame == 0)
|
||||
|
||||
if (firstFrameInAnim || currentFrame != 0)
|
||||
writeFCTL(btm, delay, disposeOp, blendOp, xOffsets, yOffsets)
|
||||
|
@ -373,8 +369,9 @@ class ApngEncoder(
|
|||
* to conserve memory, this method grabs as many rows as will
|
||||
* fit into 32K bytes, or the whole image; whichever is less.
|
||||
*
|
||||
* @param image The frame to encode
|
||||
*
|
||||
* @return true if no errors; false if error grabbing pixels
|
||||
* @return [Boolean] true if no errors; false if error grabbing pixels
|
||||
*/
|
||||
private fun writeImageData(image: Bitmap): Boolean {
|
||||
var rowsLeft = height // number of rows remaining to write
|
||||
|
|
|
@ -4,6 +4,27 @@ class NoFrameException : Exception()
|
|||
class NotPngException : Exception()
|
||||
class NotApngException : Exception()
|
||||
class BadCRCException : Exception()
|
||||
|
||||
// TODO BETTER MESSAGES
|
||||
class BadApngException(override val message: String? = null) : Exception()
|
||||
|
||||
class InvalidFrameSizeException(override val message: String?) : Exception()
|
||||
class InvalidFrameSizeException(animationWidth : Int, animationHeight : Int, frameWidth : Int, frameHeight : Int, isFirstFrame : Boolean) : Exception() {
|
||||
override val message: String = when {
|
||||
animationWidth != frameWidth && isFirstFrame -> {
|
||||
"Width of first frame must be equal to width of APNG ($animationWidth != $frameWidth)."
|
||||
}
|
||||
frameHeight != frameHeight && isFirstFrame -> {
|
||||
"Height of first frame must be equal to height of APNG ($animationHeight != $frameHeight)."
|
||||
}
|
||||
frameWidth > animationWidth -> {
|
||||
"Frame width must be inferior or equal at the animation width ($animationWidth < $frameWidth)."
|
||||
}
|
||||
frameHeight > animationHeight -> {
|
||||
"Frame height must be inferior or equal at the animation height ($animationHeight < $frameHeight)."
|
||||
}
|
||||
else -> {
|
||||
"Unknown problem"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -9,7 +9,6 @@ import java.util.zip.DeflaterOutputStream
|
|||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
// TODO FIND A BETTER SOLUTION
|
||||
/**
|
||||
* Taken from http://catcode.com/pngencoder/com/keypoint/PngEncoder.java
|
||||
*/
|
||||
|
|
|
@ -24,11 +24,10 @@ class Utils {
|
|||
* @param byteArray APNG
|
||||
* @return True if is an APNG
|
||||
*/
|
||||
// TODO OPTIMISE
|
||||
@Deprecated("Will be removed with ApngAnimator and APNGDisassembler")
|
||||
fun isApng(byteArray: ByteArray): Boolean {
|
||||
if (!isPng(byteArray)) return false
|
||||
try {
|
||||
val acTL = byteArrayOf(0x61, 0x63, 0x54, 0x4c)
|
||||
for (i in 8 until byteArray.size) {
|
||||
val it = byteArray.copyOfRange(i, i + 4)
|
||||
// if byteArray contain acTL
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
app:tint="#fff"
|
||||
android:contentDescription="@string/add_frame"
|
||||
app:backgroundTint="@color/secondary"
|
||||
app:layout_anchor="@id/creatorBottomAppBar"
|
||||
app:layout_anchorGravity="bottom|right|end"
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_create_white_24dp"
|
||||
android:text="@string/create"
|
||||
android:contentDescription="@string/create_animation"
|
||||
app:tint="@android:color/white"
|
||||
app:backgroundTint="@color/secondary"
|
||||
app:layout_anchor="@id/bottomAppBar"
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources></resources>
|
|
@ -17,6 +17,8 @@
|
|||
<string name="done">Done</string>
|
||||
<string name="clear">Clear</string>
|
||||
<string name="menu_first_frame_in_anim">First frame in animation</string>
|
||||
<string name="add_frame">Add a frame to the animation</string>
|
||||
<string name="create_animation">Create an animation</string>
|
||||
|
||||
<string name="open">open</string>
|
||||
<string name="close">close</string>
|
||||
|
|
Loading…
Reference in New Issue