Small improvements

This commit is contained in:
oupson 2018-11-16 20:18:01 +01:00
parent ec67f6e09f
commit 4391b6a3ed
4 changed files with 20 additions and 38 deletions

View File

@ -9,9 +9,8 @@ import oupson.apng.chunks.fcTL
import oupson.apng.exceptions.NotApngException
import java.util.zip.CRC32
class APNGDisassembler() {
class APNGDisassembler {
companion object {
fun disassemble(byteArray: ByteArray) : Apng {
val pngList = ArrayList<Frame>()
var png: ArrayList<Byte>? = null

View File

@ -27,7 +27,7 @@ public class PnnQuantizer {
protected int width, height;
protected int pixels[] = null;
private Integer m_transparentColor;
private Map<Integer, short[]> closestMap = new HashMap();
private HashMap<Integer, short[]> closestMap = new HashMap();
public PnnQuantizer(String fname) throws IOException {
fromBitmap(fname);
@ -156,7 +156,7 @@ public class PnnQuantizer {
/* Merge bins which increase error the least */
int extbins = maxbins - nMaxColors;
for (int i = 0; i < extbins; ) {
Pnnbin tb = null;
Pnnbin tb;
/* Use heap to find which bins to merge */
for (;;) {
int b1 = heap[1];
@ -253,7 +253,7 @@ public class PnnQuantizer {
return k;
}
private short closestColorIndex(final Integer[] palette, final int[] squares3, final int c)
private short closestColorIndex(final Integer[] palette, final int c)
{
short k = 0;
short[] closest = new short[5];
@ -407,7 +407,7 @@ public class PnnQuantizer {
}
else {
for (int i = 0; i < qPixels.length; i++)
qPixels[i] = palette[closestColorIndex(palette, squares3, pixels[i])];
qPixels[i] = palette[closestColorIndex(palette, pixels[i])];
}
return true;

View File

@ -2,39 +2,28 @@ package oupson.apng
import android.content.Context
import java.io.BufferedInputStream
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.IOException
import java.net.URL
class Loader {
companion object {
@Throws(IOException::class)
fun load(context: Context, url: URL): ByteArray {
val currenDir = context.filesDir
val fileTXT = File(currenDir, "apngLoader.txt")
var filePNG = File(currenDir, "apngLoader.png")
if (fileTXT.exists() && url.toString() == fileTXT.readText()) {
return filePNG.readBytes()
val currentDir = context.filesDir
val fileTXT = File(currentDir, "apngLoader.txt")
val filePNG = File(currentDir, "apngLoader.png")
return if (fileTXT.exists() && url.toString() == fileTXT.readText()) {
filePNG.readBytes()
} else {
try {
val connection = url.openConnection()
connection.connect()
val input = BufferedInputStream(connection.getInputStream())
val output = ByteArrayOutputStream()
val data = ByteArray(1024)
var count = 0
while ({ count = input.read(data); count }() != -1) {
output.write(data, 0, count)
}
output.flush()
output.close()
input.close()
fileTXT.writeText(url.toString())
filePNG.writeBytes(output.toByteArray())
return output.toByteArray()
} catch (e: IOException) {
throw e
}
val connection = url.openConnection()
connection.connect()
val input = BufferedInputStream(connection.getInputStream())
val bytes = input.readBytes()
input.close()
fileTXT.writeText(url.toString())
filePNG.writeBytes(bytes)
bytes
}
}
}

View File

@ -34,12 +34,11 @@ class MainActivity : AppCompatActivity() {
}
}
doAsync {
Loader.load(applicationContext, URL(imageUrl)).apply {
val a = APNGDisassembler.disassemble(this)
a.reduceSize(100, false, 60)
File(File(Environment.getExternalStorageDirectory(), "Documents"), "apng.png").writeBytes(a.toByteArray())
File(File(Environment.getExternalStorageDirectory(), "Download"), "apng.png").writeBytes(a.toByteArray())
runOnUiThread {
toast("Converted ! ")
}
@ -47,18 +46,13 @@ class MainActivity : AppCompatActivity() {
}
this.seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
internal var progress = 0
// When Progress value changed.
override fun onProgressChanged(seekBar: SeekBar, progressValue: Int, fromUser: Boolean) {
progress = progressValue
}
// Notification that the user has started a touch gesture.
override fun onStartTrackingTouch(seekBar: SeekBar) {
}
// Notification that the user has finished a touch gesture
override fun onStopTrackingTouch(seekBar: SeekBar) {
Log.e("TAG" , (seekBar.progress.toFloat() / 100f).toString())
animator.speed = (seekBar.progress.toFloat() / 100f)