Skip to content

Commit ae82c8a

Browse files
committed
Add launcher in build.gradle + + prepare for exposing as library
1 parent 6aeea8a commit ae82c8a

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ And it includes code to process convulational 3x3 kernels on a float matrix.
99

1010
![](/docs/kaifu2x.side2side.png)
1111

12-
### How to use?
12+
### How to use CLI?
1313

1414
You can grab a precompiled jar from [github's the Releases page](https://github.com/soywiz/kaifu2x/releases/)
1515

@@ -19,6 +19,29 @@ cd build/libs
1919
java -jar kaifu2x-all.jar -n0 -s2 input.png output.png
2020
```
2121

22+
Install kaifu2x binary in /usr/local/bin:
23+
24+
```
25+
./gradlew installCli
26+
```
27+
28+
### How to use as library?
29+
30+
It is published to maven central. In your `build.gradle` (or maven equivalent):
31+
```
32+
compile "com.soywiz:kaifu2x:0.1.0"
33+
```
34+
35+
Exposed API:
36+
```
37+
package com.soywiz.kaifu2x
38+
39+
object Kaifu2x {
40+
suspend fun noiseReductionRgba(image: Bitmap32, noise: Int, components: List<ColorComponent> = listOf(ColorComponent.Y, ColorComponent.A), parallel: Boolean = true): Bitmap32
41+
suspend fun scaleRgba(image: Bitmap32, scale: Int, components: List<ColorComponent> = listOf(ColorComponent.Y, ColorComponent.A), parallel: Boolean = true): Bitmap32
42+
}
43+
```
44+
2245
### Help
2346

2447
```

build.gradle

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import java.nio.file.CopyOption
12
import java.nio.file.Files
3+
import java.nio.file.StandardCopyOption
24
import java.nio.file.attribute.PosixFilePermission
35

46
buildscript {
5-
ext.version = '0.1.0'
67
ext.kotlin_version = '1.2.10'
78
ext.korio_version = '0.18.0'
89

@@ -17,7 +18,7 @@ buildscript {
1718
}
1819

1920
group 'com.soywiz'
20-
version version
21+
version '0.1.0'
2122

2223
apply plugin: 'kotlin'
2324
apply plugin: 'maven'
@@ -51,7 +52,6 @@ kotlin {
5152
task fatJarCore(type: Jar) {
5253
manifest {
5354
attributes 'Implementation-Title': 'Kaifu2x',
54-
'Implementation-Version': "$version",
5555
'Main-Class': 'com.soywiz.kaifu2x.Kaifu2xCli'
5656
}
5757
baseName = project.name + '-all'
@@ -63,15 +63,20 @@ task fatJarLauncher() {
6363
doLast {
6464
File launcherFile = new File(rootProject.buildDir, "libs/kaifu2x")
6565
launcherFile.write('java -jar $0-all.jar $*')
66-
67-
6866
Files.setPosixFilePermissions(launcherFile.toPath(), Files.getPosixFilePermissions(launcherFile.toPath()) + [PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_EXECUTE, PosixFilePermission.OTHERS_EXECUTE].toSet())
6967
}
7068
}
7169

7270
task fatJar(dependsOn: [fatJarCore, fatJarLauncher]) {
7371
}
7472

73+
task installCli(dependsOn: fatJar) {
74+
doLast {
75+
Files.copy(new File(rootProject.buildDir, "libs/kaifu2x").toPath(), new File("/usr/local/bin/kaifu2x").toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES)
76+
Files.copy(new File(rootProject.buildDir, "libs/kaifu2x-all.jar").toPath(), new File("/usr/local/bin/kaifu2x-all.jar").toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES)
77+
}
78+
}
79+
7580
task javadoc2(type: Javadoc) {
7681
failOnError = false
7782
}
@@ -150,3 +155,6 @@ publishing {
150155
}
151156
}
152157
}
158+
159+
task deploy(dependsOn: ['install', 'uploadArchives']) {
160+
}

src/main/kotlin/com/soywiz/kaifu2x/Kaifu2x.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ object Kaifu2xCli {
4646
if (args.size < 2) helpAndExit()
4747

4848
var parallel = true
49-
var components = listOf(ColorComponent.RED, ColorComponent.ALPHA)
49+
var components = listOf(ColorComponent.Y, ColorComponent.A)
5050
var inputName: String? = null
5151
var outputName: String? = null
5252
var noiseReduction: Int = 0
@@ -65,8 +65,8 @@ object Kaifu2xCli {
6565
"-n3" -> noiseReduction = 3
6666
"-s1" -> scale = 1
6767
"-s2" -> scale = 2
68-
"-cl" -> components = listOf(ColorComponent.RED)
69-
"-cla" -> components = listOf(ColorComponent.RED, ColorComponent.ALPHA)
68+
"-cl" -> components = listOf(ColorComponent.Y)
69+
"-cla" -> components = listOf(ColorComponent.Y, ColorComponent.A)
7070
"-clca" -> components = ColorComponent.ALL.toList()
7171
else -> {
7272
if (c.startsWith("-")) invalidOp("Unknown switch $c")
@@ -107,11 +107,11 @@ object Kaifu2xCli {
107107

108108
// Exposed functions
109109
object Kaifu2x {
110-
suspend fun noiseReductionRgba(image: Bitmap32, noise: Int, components: List<ColorComponent>, parallel: Boolean): Bitmap32 {
110+
suspend fun noiseReductionRgba(image: Bitmap32, noise: Int, components: List<ColorComponent> = listOf(ColorComponent.Y, ColorComponent.A), parallel: Boolean = true): Bitmap32 {
111111
return getNoiseModel(noise)?.waifu2xCoreRgba("noise$noise", image, components, parallel) ?: image
112112
}
113113

114-
suspend fun scaleRgba(image: Bitmap32, scale: Int, components: List<ColorComponent>, parallel: Boolean): Bitmap32 {
114+
suspend fun scaleRgba(image: Bitmap32, scale: Int, components: List<ColorComponent> = listOf(ColorComponent.Y, ColorComponent.A), parallel: Boolean = true): Bitmap32 {
115115
return when (scale) {
116116
1 -> image
117117
2 -> getScale2xModel().waifu2xCoreRgba("scale$scale", image.scaleNearest(scale, scale), components, parallel)

src/main/kotlin/com/soywiz/kaifu2x/util/Bitmap32Ext.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ enum class ColorComponent(val index: Int) {
4949
}
5050
}
5151

52+
val ColorComponent.Companion.Y get() = ColorComponent.RED
53+
val ColorComponent.Companion.Cb get() = ColorComponent.GREEN
54+
val ColorComponent.Companion.Cr get() = ColorComponent.BLUE
55+
val ColorComponent.Companion.A get() = ColorComponent.ALPHA
56+
5257
fun Bitmap32.writeComponent(dstCmp: ColorComponent, from: Bitmap32, srcCmp: ColorComponent) {
5358
val fdata = from.data
5459
for (n in 0 until area) {

0 commit comments

Comments
 (0)