Skip to content

Commit 4391b6a

Browse files
committed
Small improvements
1 parent ec67f6e commit 4391b6a

File tree

4 files changed

+20
-38
lines changed

4 files changed

+20
-38
lines changed

apng_library/src/main/java/oupson/apng/APNGDisassembler.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ import oupson.apng.chunks.fcTL
99
import oupson.apng.exceptions.NotApngException
1010
import java.util.zip.CRC32
1111

12-
class APNGDisassembler() {
12+
class APNGDisassembler {
1313
companion object {
14-
1514
fun disassemble(byteArray: ByteArray) : Apng {
1615
val pngList = ArrayList<Frame>()
1716
var png: ArrayList<Byte>? = null

apng_library/src/main/java/oupson/apng/ImageUtils/PnnQuantizer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class PnnQuantizer {
2727
protected int width, height;
2828
protected int pixels[] = null;
2929
private Integer m_transparentColor;
30-
private Map<Integer, short[]> closestMap = new HashMap();
30+
private HashMap<Integer, short[]> closestMap = new HashMap();
3131

3232
public PnnQuantizer(String fname) throws IOException {
3333
fromBitmap(fname);
@@ -156,7 +156,7 @@ private Integer[] pnnquan(final int[] pixels, int nMaxColors, boolean quan_sqrt)
156156
/* Merge bins which increase error the least */
157157
int extbins = maxbins - nMaxColors;
158158
for (int i = 0; i < extbins; ) {
159-
Pnnbin tb = null;
159+
Pnnbin tb;
160160
/* Use heap to find which bins to merge */
161161
for (;;) {
162162
int b1 = heap[1];
@@ -253,7 +253,7 @@ private short nearestColorIndex(final Integer[] palette, final int[] squares3, f
253253
return k;
254254
}
255255

256-
private short closestColorIndex(final Integer[] palette, final int[] squares3, final int c)
256+
private short closestColorIndex(final Integer[] palette, final int c)
257257
{
258258
short k = 0;
259259
short[] closest = new short[5];
@@ -407,7 +407,7 @@ boolean quantize_image(final int[] pixels, final Integer[] palette, int[] qPixel
407407
}
408408
else {
409409
for (int i = 0; i < qPixels.length; i++)
410-
qPixels[i] = palette[closestColorIndex(palette, squares3, pixels[i])];
410+
qPixels[i] = palette[closestColorIndex(palette, pixels[i])];
411411
}
412412

413413
return true;

apng_library/src/main/java/oupson/apng/Loader.kt

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,28 @@ package oupson.apng
22

33
import android.content.Context
44
import java.io.BufferedInputStream
5-
import java.io.ByteArrayOutputStream
65
import java.io.File
76
import java.io.IOException
87
import java.net.URL
98

109
class Loader {
1110
companion object {
11+
@Throws(IOException::class)
1212
fun load(context: Context, url: URL): ByteArray {
13-
val currenDir = context.filesDir
14-
val fileTXT = File(currenDir, "apngLoader.txt")
15-
var filePNG = File(currenDir, "apngLoader.png")
16-
if (fileTXT.exists() && url.toString() == fileTXT.readText()) {
17-
return filePNG.readBytes()
13+
val currentDir = context.filesDir
14+
val fileTXT = File(currentDir, "apngLoader.txt")
15+
val filePNG = File(currentDir, "apngLoader.png")
16+
return if (fileTXT.exists() && url.toString() == fileTXT.readText()) {
17+
filePNG.readBytes()
1818
} else {
19-
try {
20-
val connection = url.openConnection()
21-
connection.connect()
22-
val input = BufferedInputStream(connection.getInputStream())
23-
val output = ByteArrayOutputStream()
24-
val data = ByteArray(1024)
25-
var count = 0
26-
while ({ count = input.read(data); count }() != -1) {
27-
output.write(data, 0, count)
28-
}
29-
output.flush()
30-
output.close()
31-
input.close()
32-
fileTXT.writeText(url.toString())
33-
filePNG.writeBytes(output.toByteArray())
34-
return output.toByteArray()
35-
} catch (e: IOException) {
36-
throw e
37-
}
19+
val connection = url.openConnection()
20+
connection.connect()
21+
val input = BufferedInputStream(connection.getInputStream())
22+
val bytes = input.readBytes()
23+
input.close()
24+
fileTXT.writeText(url.toString())
25+
filePNG.writeBytes(bytes)
26+
bytes
3827
}
3928
}
4029
}

app-test/src/main/java/oupson/apngcreator/MainActivity.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,25 @@ class MainActivity : AppCompatActivity() {
3434
}
3535
}
3636

37-
3837
doAsync {
3938
Loader.load(applicationContext, URL(imageUrl)).apply {
4039
val a = APNGDisassembler.disassemble(this)
4140
a.reduceSize(100, false, 60)
42-
File(File(Environment.getExternalStorageDirectory(), "Documents"), "apng.png").writeBytes(a.toByteArray())
41+
File(File(Environment.getExternalStorageDirectory(), "Download"), "apng.png").writeBytes(a.toByteArray())
4342
runOnUiThread {
4443
toast("Converted ! ")
4544
}
4645
}
4746
}
4847

4948
this.seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
50-
internal var progress = 0
5149

52-
// When Progress value changed.
5350
override fun onProgressChanged(seekBar: SeekBar, progressValue: Int, fromUser: Boolean) {
54-
progress = progressValue
5551
}
5652

57-
// Notification that the user has started a touch gesture.
5853
override fun onStartTrackingTouch(seekBar: SeekBar) {
5954
}
6055

61-
// Notification that the user has finished a touch gesture
6256
override fun onStopTrackingTouch(seekBar: SeekBar) {
6357
Log.e("TAG" , (seekBar.progress.toFloat() / 100f).toString())
6458
animator.speed = (seekBar.progress.toFloat() / 100f)

0 commit comments

Comments
 (0)