Update dependencies

This commit is contained in:
Oupson 2020-09-16 22:00:06 +02:00
parent 8e45eab274
commit efa874e661
8 changed files with 70 additions and 65 deletions

View File

@ -29,14 +29,14 @@ android {
dependencies {
// https://github.com/Kotlin/kotlinx.coroutines/issues/2049
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.5'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.6'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
repositories {

View File

@ -45,6 +45,7 @@ class ApngDecoder {
companion object {
private const val TAG = "ApngDecoder"
private val zeroLength = arrayOf(0x00, 0x00, 0x00, 0x00).map { it.toByte() }
// Paint used to clear the buffer
private val clearPaint: Paint by lazy {
@ -58,7 +59,7 @@ class ApngDecoder {
/**
* Decode Apng and return a Drawable who can be an [AnimationDrawable] if it end successfully. Can also be an [android.graphics.drawable.AnimatedImageDrawable].
* @param context Context needed for the animation drawable
* @param inStream Input Stream to decode. Will be close at the end.
* @param inStream Input Stream to decode. Will be closed at the end.
* @param speed Optional parameter.
* @param config Configuration applied to the bitmap added to the animation. Please note that the frame is decoded in ARGB_8888 and converted after, for the buffer.
* @return [AnimationDrawable] if successful and an [AnimatedImageDrawable] if the image decoded is not an APNG but a gif. If it is not an animated image, it is a [Drawable].
@ -122,14 +123,12 @@ class ApngDecoder {
name.contentEquals(Utils.fcTL) -> {
if (png == null) {
cover?.let {
it.addAll(Utils.to4Bytes(0).asList())
// Add IEND
val iend = byteArrayOf(0x49, 0x45, 0x4E, 0x44)
it.addAll(zeroLength)
// Generate crc for IEND
val crC32 = CRC32()
crC32.update(iend, 0, iend.size)
it.addAll(iend.asList())
it.addAll(Utils.to4Bytes(crC32.value.toInt()).asList())
crC32.update(Utils.IEND, 0, Utils.IEND.size)
it.addAll(Utils.IEND.asList())
it.addAll(Utils.to4Bytes(crC32.value.toInt()))
/**APNGDisassembler.apng.cover = BitmapFactory.decodeByteArray(
it.toByteArray(),
0,
@ -169,14 +168,13 @@ class ApngDecoder {
}
} else {
// Add IEND body length : 0
png.addAll(Utils.to4Bytes(0).asList())
png.addAll(zeroLength)
// Add IEND
val iend = byteArrayOf(0x49, 0x45, 0x4E, 0x44)
// Generate crc for IEND
val crC32 = CRC32()
crC32.update(iend, 0, iend.size)
png.addAll(iend.asList())
png.addAll(Utils.to4Bytes(crC32.value.toInt()).asList())
crC32.update(Utils.IEND, 0, Utils.IEND.size)
png.addAll(Utils.IEND.asList())
png.addAll(Utils.to4Bytes(crC32.value.toInt()))
val btm = Bitmap.createBitmap(
maxWidth,
@ -280,14 +278,13 @@ class ApngDecoder {
}
name.contentEquals(Utils.IEND) -> {
if (isApng && png != null) {
png.addAll(Utils.to4Bytes(0).asList())
png.addAll(zeroLength)
// Add IEND
val iend = byteArrayOf(0x49, 0x45, 0x4E, 0x44)
// Generate crc for IEND
val crC32 = CRC32()
crC32.update(iend, 0, iend.size)
png.addAll(iend.asList())
png.addAll(Utils.to4Bytes(crC32.value.toInt()).asList())
crC32.update(Utils.IEND, 0, Utils.IEND.size)
png.addAll(Utils.IEND.asList())
png.addAll(Utils.to4Bytes(crC32.value.toInt()))
val btm = Bitmap.createBitmap(
@ -364,14 +361,13 @@ class ApngDecoder {
} else {
// TODO Check before the end
cover?.let {
it.addAll(Utils.to4Bytes(0).asList())
it.addAll(zeroLength)
// Add IEND
val iend = byteArrayOf(0x49, 0x45, 0x4E, 0x44)
// Generate crc for IEND
val crC32 = CRC32()
crC32.update(iend, 0, iend.size)
it.addAll(iend.asList())
it.addAll(Utils.to4Bytes(crC32.value.toInt()).asList())
crC32.update(Utils.IEND, 0, Utils.IEND.size)
it.addAll(Utils.IEND.asList())
it.addAll(Utils.to4Bytes(crC32.value.toInt()))
inputStream.close()
return BitmapDrawable(
context.resources,
@ -402,7 +398,7 @@ class ApngDecoder {
Utils.parseLength(byteArray.copyOfRange(i - 4, i))
cover.addAll(byteArray.copyOfRange(i - 4, i).asList())
val body = ArrayList<Byte>()
body.addAll(byteArrayOf(0x49, 0x44, 0x41, 0x54).asList())
body.addAll(Utils.IDAT.asList())
// Get image bytes
body.addAll(
byteArray.copyOfRange(
@ -413,14 +409,14 @@ class ApngDecoder {
val crC32 = CRC32()
crC32.update(body.toByteArray(), 0, body.size)
cover.addAll(body)
cover.addAll(Utils.to4Bytes(crC32.value.toInt()).asList())
cover.addAll(Utils.to4Bytes(crC32.value.toInt()))
} else {
// Find the chunk length
val bodySize =
Utils.parseLength(byteArray.copyOfRange(i - 4, i))
png.addAll(byteArray.copyOfRange(i - 4, i).asList())
val body = ArrayList<Byte>()
body.addAll(byteArrayOf(0x49, 0x44, 0x41, 0x54).asList())
body.addAll(Utils.IDAT.asList())
// Get image bytes
body.addAll(
byteArray.copyOfRange(
@ -431,7 +427,7 @@ class ApngDecoder {
val crC32 = CRC32()
crC32.update(body.toByteArray(), 0, body.size)
png.addAll(body)
png.addAll(Utils.to4Bytes(crC32.value.toInt()).asList())
png.addAll(Utils.to4Bytes(crC32.value.toInt()))
}
}
name.contentEquals(Utils.fdAT) -> {
@ -439,13 +435,13 @@ class ApngDecoder {
val bodySize = Utils.parseLength(byteArray.copyOfRange(i - 4, i))
png?.addAll(Utils.to4Bytes(bodySize - 4).asList())
val body = ArrayList<Byte>()
body.addAll(byteArrayOf(0x49, 0x44, 0x41, 0x54).asList())
body.addAll(Utils.IDAT.asList())
// Get image bytes
body.addAll(byteArray.copyOfRange(i + 8, i + 4 + bodySize).asList())
val crC32 = CRC32()
crC32.update(body.toByteArray(), 0, body.size)
png?.addAll(body)
png?.addAll(Utils.to4Bytes(crC32.value.toInt()).asList())
png?.addAll(Utils.to4Bytes(crC32.value.toInt()))
}
name.contentEquals(Utils.plte) -> {
plte = byteArray
@ -855,19 +851,19 @@ class ApngDecoder {
// We need a body var to know body length and generate crc
val ihdrBody = ArrayList<Byte>()
// Add chunk body length
ihdr.addAll(Utils.to4Bytes(ihdrOfApng.body.size).asList())
ihdr.addAll(Utils.to4Bytes(ihdrOfApng.body.size))
// Add IHDR
ihdrBody.addAll(
byteArrayOf(
arrayOf(
0x49.toByte(),
0x48.toByte(),
0x44.toByte(),
0x52.toByte()
).asList()
)
)
// Add the max width and height
ihdrBody.addAll(Utils.to4Bytes(width).asList())
ihdrBody.addAll(Utils.to4Bytes(height).asList())
ihdrBody.addAll(Utils.to4Bytes(width))
ihdrBody.addAll(Utils.to4Bytes(height))
// Add complicated stuff like depth color ...
// If you want correct png you need same parameters. Good solution is to create new png.
ihdrBody.addAll(ihdrOfApng.body.copyOfRange(8, 13).asList())
@ -875,7 +871,7 @@ class ApngDecoder {
val crC32 = CRC32()
crC32.update(ihdrBody.toByteArray(), 0, ihdrBody.size)
ihdr.addAll(ihdrBody)
ihdr.addAll(Utils.to4Bytes(crC32.value.toInt()).asList())
ihdr.addAll(Utils.to4Bytes(crC32.value.toInt()))
return ihdr.toByteArray()
}
}

View File

@ -87,13 +87,13 @@ class ApngEncoder(
i.toByteArray()
}
// Add the chunk body length
outputStream.write(Utils.to4Bytes(idatBody.size))
outputStream.write(Utils.to4BytesArray(idatBody.size))
// Generate CRC
val crc1 = CRC32()
crc1.update(idatChunk, 0, idatChunk.size)
outputStream.write(idatChunk)
outputStream.write(Utils.to4Bytes(crc1.value.toInt()))
outputStream.write(Utils.to4BytesArray(crc1.value.toInt()))
} else {
val fdat = ArrayList<Byte>().let { fdat ->
fdat.addAll(byteArrayOf(0x66, 0x64, 0x41, 0x54).asList())
@ -104,13 +104,13 @@ class ApngEncoder(
fdat.toByteArray()
}
// Add the chunk body length
outputStream.write(Utils.to4Bytes(idatBody.size + 4))
outputStream.write(Utils.to4BytesArray(idatBody.size + 4))
// Generate CRC
val crc1 = CRC32()
crc1.update(fdat, 0, fdat.size)
outputStream.write(fdat)
outputStream.write(Utils.to4Bytes(crc1.value.toInt()))
outputStream.write(Utils.to4BytesArray(crc1.value.toInt()))
}
}
frameIndex++
@ -121,14 +121,14 @@ class ApngEncoder(
fun writeEnd() {
// Add IEND body length : 0
outputStream.write(Utils.to4Bytes(0))
outputStream.write(Utils.to4BytesArray(0))
// Add IEND
val iend = byteArrayOf(0x49, 0x45, 0x4E, 0x44)
// Generate crc for IEND
val crC32 = CRC32()
crC32.update(iend, 0, iend.size)
outputStream.write(iend)
outputStream.write(Utils.to4Bytes(crC32.value.toInt()))
outputStream.write(Utils.to4BytesArray(crC32.value.toInt()))
}
/**
@ -230,6 +230,6 @@ class ApngEncoder(
val crc = CRC32()
crc.update(fcTL.toByteArray(), 0, fcTL.size)
outputStream.write(fcTL.toByteArray())
outputStream.write(Utils.to4Bytes(crc.value.toInt()))
outputStream.write(Utils.to4BytesArray(crc.value.toInt()))
}
}

View File

@ -90,13 +90,13 @@ class ExperimentalApngEncoder(
i.toByteArray()
}
// Add the chunk body length
outputStream.write(Utils.to4Bytes(idatBody.size))
outputStream.write(Utils.to4BytesArray(idatBody.size))
// Generate CRC
val crc1 = CRC32()
crc1.update(idatChunk, 0, idatChunk.size)
outputStream.write(idatChunk)
outputStream.write(Utils.to4Bytes(crc1.value.toInt()))
outputStream.write(Utils.to4BytesArray(crc1.value.toInt()))
} else {
val fdat = ArrayList<Byte>().let { fdat ->
fdat.addAll(byteArrayOf(0x66, 0x64, 0x41, 0x54).asList())
@ -107,13 +107,13 @@ class ExperimentalApngEncoder(
fdat.toByteArray()
}
// Add the chunk body length
outputStream.write(Utils.to4Bytes(idatBody.size + 4))
outputStream.write(Utils.to4BytesArray(idatBody.size + 4))
// Generate CRC
val crc1 = CRC32()
crc1.update(fdat, 0, fdat.size)
outputStream.write(fdat)
outputStream.write(Utils.to4Bytes(crc1.value.toInt()))
outputStream.write(Utils.to4BytesArray(crc1.value.toInt()))
}
}
frameIndex++
@ -124,14 +124,14 @@ class ExperimentalApngEncoder(
fun writeEnd() {
// Add IEND body length : 0
outputStream.write(Utils.to4Bytes(0))
outputStream.write(Utils.to4BytesArray(0))
// Add IEND
val iend = byteArrayOf(0x49, 0x45, 0x4E, 0x44)
// Generate crc for IEND
val crC32 = CRC32()
crC32.update(iend, 0, iend.size)
outputStream.write(iend)
outputStream.write(Utils.to4Bytes(crC32.value.toInt()))
outputStream.write(Utils.to4BytesArray(crC32.value.toInt()))
}
/**
@ -263,6 +263,6 @@ class ExperimentalApngEncoder(
val crc = CRC32()
crc.update(fcTL.toByteArray(), 0, fcTL.size)
outputStream.write(fcTL.toByteArray())
outputStream.write(Utils.to4Bytes(crc.value.toInt()))
outputStream.write(Utils.to4BytesArray(crc.value.toInt()))
}
}

View File

@ -121,9 +121,18 @@ class Utils {
/**
* Generate a 4 bytes array from an Int
* @param i The int
* @return [ByteArray] 2 Bytes
* @return [Array] 4 Bytes
*/
fun to4Bytes(i: Int): ByteArray {
fun to4Bytes(i: Int): Array<Byte> {
return arrayOf((i shr 24).toByte(), (i shr 16).toByte(), (i shr 8).toByte(), i.toByte())
}
/**
* Generate a 4 bytes array from an Int
* @param i The int
* @return [ByteArray] 4 Bytes
*/
fun to4BytesArray(i: Int): ByteArray {
return byteArrayOf((i shr 24).toByte(), (i shr 16).toByte(), (i shr 8).toByte(), i.toByte())
}

View File

@ -36,16 +36,16 @@ android {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// https://github.com/Kotlin/kotlinx.coroutines/issues/2049
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.5'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.6'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.3.0-alpha01'
implementation 'com.google.android.material:material:1.3.0-alpha02'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.squareup.picasso:picasso:2.71828'

View File

@ -5,9 +5,9 @@ import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView
class SquareImageView : AppCompatImageView {
constructor(context: Context?) : super(context)
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(
context,
attrs,
defStyle

View File

@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.72'
ext.kotlin_version = '1.4.0'
ext.anko_version = '0.10.8'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
classpath 'com.android.tools.build:gradle:4.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files