More TODO
This commit is contained in:
parent
36ac99d97f
commit
b4bd0dd17e
|
@ -2,6 +2,7 @@ package oupson.apng.chunks
|
||||||
|
|
||||||
import oupson.apng.utils.Utils
|
import oupson.apng.utils.Utils
|
||||||
|
|
||||||
|
// TODO REMOVE
|
||||||
class IHDR : Chunk {
|
class IHDR : Chunk {
|
||||||
override var body = byteArrayOf()
|
override var body = byteArrayOf()
|
||||||
var pngWidth = -1
|
var pngWidth = -1
|
||||||
|
|
|
@ -5,6 +5,7 @@ import oupson.apng.utils.Utils.Companion.decodeBlendOp
|
||||||
import oupson.apng.utils.Utils.Companion.decodeDisposeOp
|
import oupson.apng.utils.Utils.Companion.decodeDisposeOp
|
||||||
|
|
||||||
@Suppress("ClassName")
|
@Suppress("ClassName")
|
||||||
|
// TODO REMOVE
|
||||||
class fcTL : Chunk {
|
class fcTL : Chunk {
|
||||||
override var body : ByteArray = byteArrayOf()
|
override var body : ByteArray = byteArrayOf()
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,7 @@ class ApngDecoder {
|
||||||
var blendOp: Utils.Companion.BlendOp = Utils.Companion.BlendOp.APNG_BLEND_OP_SOURCE
|
var blendOp: Utils.Companion.BlendOp = Utils.Companion.BlendOp.APNG_BLEND_OP_SOURCE
|
||||||
var disposeOp: Utils.Companion.DisposeOp =
|
var disposeOp: Utils.Companion.DisposeOp =
|
||||||
Utils.Companion.DisposeOp.APNG_DISPOSE_OP_NONE
|
Utils.Companion.DisposeOp.APNG_DISPOSE_OP_NONE
|
||||||
|
// TODO REMOVE
|
||||||
val ihdr = IHDR()
|
val ihdr = IHDR()
|
||||||
var isApng = false
|
var isApng = false
|
||||||
|
|
||||||
|
@ -142,6 +143,8 @@ class ApngDecoder {
|
||||||
}
|
}
|
||||||
png = ArrayList()
|
png = ArrayList()
|
||||||
val fcTL = fcTL()
|
val fcTL = fcTL()
|
||||||
|
|
||||||
|
// TODO REMOVE FCTL CLASS
|
||||||
fcTL.parse(byteArray)
|
fcTL.parse(byteArray)
|
||||||
delay = fcTL.delay
|
delay = fcTL.delay
|
||||||
yOffset = fcTL.yOffset
|
yOffset = fcTL.yOffset
|
||||||
|
@ -851,6 +854,7 @@ class ApngDecoder {
|
||||||
* @param height The height of the frame.
|
* @param height The height of the frame.
|
||||||
* @return [ByteArray] The generated IHDR.
|
* @return [ByteArray] The generated IHDR.
|
||||||
*/
|
*/
|
||||||
|
// TODO REMOVE IHDR
|
||||||
private fun generateIhdr(ihdrOfApng: IHDR, width: Int, height: Int): ByteArray {
|
private fun generateIhdr(ihdrOfApng: IHDR, width: Int, height: Int): ByteArray {
|
||||||
val ihdr = ArrayList<Byte>()
|
val ihdr = ArrayList<Byte>()
|
||||||
// We need a body var to know body length and generate crc
|
// We need a body var to know body length and generate crc
|
||||||
|
|
|
@ -217,7 +217,12 @@ class Utils {
|
||||||
* @property offsetY the y offset
|
* @property offsetY the y offset
|
||||||
* @property blendOp a [BlendOp]
|
* @property blendOp a [BlendOp]
|
||||||
*/
|
*/
|
||||||
data class DiffResult(val bitmap: Bitmap, val offsetX : Int, val offsetY : Int, val blendOp: BlendOp)
|
data class DiffResult(
|
||||||
|
val bitmap: Bitmap,
|
||||||
|
val offsetX: Int,
|
||||||
|
val offsetY: Int,
|
||||||
|
val blendOp: BlendOp
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the difference between two bitmaps
|
* Get the difference between two bitmaps
|
||||||
|
@ -226,12 +231,21 @@ class Utils {
|
||||||
* @return [DiffResult], the difference between the second and the first bitmap
|
* @return [DiffResult], the difference between the second and the first bitmap
|
||||||
*/
|
*/
|
||||||
@Throws(BadBitmapsDiffSize::class)
|
@Throws(BadBitmapsDiffSize::class)
|
||||||
fun getDiffBitmap(firstBitmap : Bitmap, secondBitmap : Bitmap) : DiffResult {
|
fun getDiffBitmap(firstBitmap: Bitmap, secondBitmap: Bitmap): DiffResult {
|
||||||
if (firstBitmap.width < secondBitmap.width || firstBitmap.height < secondBitmap.height) {
|
if (firstBitmap.width < secondBitmap.width || firstBitmap.height < secondBitmap.height) {
|
||||||
throw BadBitmapsDiffSize(firstBitmap.width, firstBitmap.height, firstBitmap.width, firstBitmap.height)
|
throw BadBitmapsDiffSize(
|
||||||
|
firstBitmap.width,
|
||||||
|
firstBitmap.height,
|
||||||
|
firstBitmap.width,
|
||||||
|
firstBitmap.height
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val resultBtm = Bitmap.createBitmap(secondBitmap.width, secondBitmap.height, Bitmap.Config.ARGB_8888)
|
val resultBtm = Bitmap.createBitmap(
|
||||||
|
secondBitmap.width,
|
||||||
|
secondBitmap.height,
|
||||||
|
Bitmap.Config.ARGB_8888
|
||||||
|
)
|
||||||
|
|
||||||
var offsetX = resultBtm.width + 1
|
var offsetX = resultBtm.width + 1
|
||||||
var offsetY = resultBtm.height + 1
|
var offsetY = resultBtm.height + 1
|
||||||
|
@ -240,12 +254,17 @@ class Utils {
|
||||||
var lastY = 0
|
var lastY = 0
|
||||||
|
|
||||||
// Find if the image contain transparent pixels, if true, then transparent pixels must replace the pixels in the buffer
|
// Find if the image contain transparent pixels, if true, then transparent pixels must replace the pixels in the buffer
|
||||||
val blendOp = if(containTransparency(secondBitmap)) APNG_BLEND_OP_SOURCE else APNG_BLEND_OP_OVER
|
val blendOp =
|
||||||
|
if (containTransparency(secondBitmap)) APNG_BLEND_OP_SOURCE else APNG_BLEND_OP_OVER
|
||||||
|
|
||||||
for (y in 0 until secondBitmap.height) {
|
for (y in 0 until secondBitmap.height) {
|
||||||
for (x in 0 until secondBitmap.width) {
|
for (x in 0 until secondBitmap.width) {
|
||||||
val btmPixel = secondBitmap.getPixel(x, y)
|
val btmPixel = secondBitmap.getPixel(x, y)
|
||||||
if (firstBitmap.getPixel(x, y) == btmPixel) { // Similar pixels could be forgotten
|
if (firstBitmap.getPixel(
|
||||||
|
x,
|
||||||
|
y
|
||||||
|
) == btmPixel
|
||||||
|
) { // Similar pixels could be forgotten
|
||||||
if (blendOp == APNG_BLEND_OP_OVER)
|
if (blendOp == APNG_BLEND_OP_OVER)
|
||||||
resultBtm.setPixel(x, y, Color.TRANSPARENT)
|
resultBtm.setPixel(x, y, Color.TRANSPARENT)
|
||||||
else
|
else
|
||||||
|
@ -271,7 +290,8 @@ class Utils {
|
||||||
val newHeight = lastY - offsetY
|
val newHeight = lastY - offsetY
|
||||||
|
|
||||||
// Resize bitmap
|
// Resize bitmap
|
||||||
val resizedResultBtm = Bitmap.createBitmap(resultBtm, offsetX, offsetY, newWidth, newHeight)
|
val resizedResultBtm =
|
||||||
|
Bitmap.createBitmap(resultBtm, offsetX, offsetY, newWidth, newHeight)
|
||||||
|
|
||||||
return DiffResult(resizedResultBtm, offsetX, offsetY, blendOp)
|
return DiffResult(resizedResultBtm, offsetX, offsetY, blendOp)
|
||||||
}
|
}
|
||||||
|
@ -281,12 +301,12 @@ class Utils {
|
||||||
* @param btm A [Bitmap]
|
* @param btm A [Bitmap]
|
||||||
* @return [Boolean] true if if the bitmap contain transparent pixels
|
* @return [Boolean] true if if the bitmap contain transparent pixels
|
||||||
*/
|
*/
|
||||||
fun containTransparency(btm : Bitmap) : Boolean {
|
fun containTransparency(btm: Bitmap): Boolean {
|
||||||
var result = false
|
var result = false
|
||||||
var y = 0
|
var y = 0
|
||||||
var x = 0
|
var x = 0
|
||||||
while (y < btm.height && !result) {
|
while (y < btm.height && !result) {
|
||||||
if (btm.getPixel(x, y) == Color.TRANSPARENT) {
|
if (btm.getPixel(x, y) == Color.TRANSPARENT) {
|
||||||
result = true
|
result = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue