mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-27 01:14:43 +01:00
Format native code
This commit is contained in:
parent
6809503e0b
commit
68007d5d3e
45 changed files with 2888 additions and 3107 deletions
|
@ -42,10 +42,7 @@ interface BitmapUtil {
|
|||
): Bitmap {
|
||||
val opt = loadImageBounds(context, uri)
|
||||
val subsample = calcBitmapSubsample(
|
||||
opt.outWidth,
|
||||
opt.outHeight,
|
||||
targetW,
|
||||
targetH,
|
||||
opt.outWidth, opt.outHeight, targetW, targetH,
|
||||
BitmapResizeMethod.FILL
|
||||
)
|
||||
if (subsample > 1) {
|
||||
|
@ -127,17 +124,13 @@ interface BitmapUtil {
|
|||
}
|
||||
val result = when (resizeMethod) {
|
||||
BitmapResizeMethod.FIT -> Bitmap.createScaledBitmap(
|
||||
bitmap,
|
||||
minOf(dstW, (dstH * bitmap.aspectRatio()).toInt()),
|
||||
minOf(dstH, (dstW / bitmap.aspectRatio()).toInt()),
|
||||
true
|
||||
bitmap, minOf(dstW, (dstH * bitmap.aspectRatio()).toInt()),
|
||||
minOf(dstH, (dstW / bitmap.aspectRatio()).toInt()), true
|
||||
)
|
||||
|
||||
BitmapResizeMethod.FILL -> Bitmap.createScaledBitmap(
|
||||
bitmap,
|
||||
maxOf(dstW, (dstH * bitmap.aspectRatio()).toInt()),
|
||||
maxOf(dstH, (dstW / bitmap.aspectRatio()).toInt()),
|
||||
true
|
||||
bitmap, maxOf(dstW, (dstH * bitmap.aspectRatio()).toInt()),
|
||||
maxOf(dstH, (dstW / bitmap.aspectRatio()).toInt()), true
|
||||
)
|
||||
}
|
||||
return if (shouldFixOrientation) {
|
||||
|
@ -222,10 +215,7 @@ interface BitmapUtil {
|
|||
}
|
||||
|
||||
private fun calcBitmapSubsample(
|
||||
originalW: Int,
|
||||
originalH: Int,
|
||||
targetW: Int,
|
||||
targetH: Int,
|
||||
originalW: Int, originalH: Int, targetW: Int, targetH: Int,
|
||||
resizeMethod: BitmapResizeMethod
|
||||
): Int {
|
||||
return when (resizeMethod) {
|
||||
|
|
|
@ -113,8 +113,8 @@ interface MediaStoreUtil {
|
|||
throw PermissionException("Permission not granted")
|
||||
}
|
||||
|
||||
@Suppress("Deprecation")
|
||||
val path = Environment.getExternalStoragePublicDirectory(
|
||||
@Suppress("Deprecation") val path =
|
||||
Environment.getExternalStoragePublicDirectory(
|
||||
Environment.DIRECTORY_DOWNLOADS
|
||||
)
|
||||
val prefix = if (subDir != null) "$subDir/" else ""
|
||||
|
@ -142,8 +142,8 @@ interface MediaStoreUtil {
|
|||
|
||||
private fun triggerMediaScan(context: Context, uri: Uri) {
|
||||
val scanIntent = Intent().apply {
|
||||
@Suppress("Deprecation")
|
||||
action = Intent.ACTION_MEDIA_SCANNER_SCAN_FILE
|
||||
@Suppress("Deprecation") action =
|
||||
Intent.ACTION_MEDIA_SCANNER_SCAN_FILE
|
||||
data = uri
|
||||
}
|
||||
context.sendBroadcast(scanIntent)
|
||||
|
|
|
@ -11,8 +11,7 @@ class Rgba8Image(
|
|||
) {
|
||||
companion object {
|
||||
fun fromJson(json: Map<String, Any>) = Rgba8Image(
|
||||
json["pixel"] as ByteArray,
|
||||
json["width"] as Int,
|
||||
json["pixel"] as ByteArray, json["width"] as Int,
|
||||
json["height"] as Int
|
||||
)
|
||||
|
||||
|
|
|
@ -7,13 +7,11 @@ import java.io.Serializable
|
|||
import java.net.HttpURLConnection
|
||||
|
||||
fun getPendingIntentFlagImmutable(): Int {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
|
||||
PendingIntent.FLAG_IMMUTABLE else 0
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) PendingIntent.FLAG_IMMUTABLE else 0
|
||||
}
|
||||
|
||||
fun getPendingIntentFlagMutable(): Int {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
|
||||
PendingIntent.FLAG_MUTABLE else 0
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) PendingIntent.FLAG_MUTABLE else 0
|
||||
}
|
||||
|
||||
inline fun <T> HttpURLConnection.use(block: (HttpURLConnection) -> T): T {
|
||||
|
|
|
@ -33,14 +33,12 @@ internal class ImageProcessorChannelHandler(context: Context) :
|
|||
"zeroDce" -> {
|
||||
try {
|
||||
zeroDce(
|
||||
call.argument("fileUrl")!!,
|
||||
call.argument("headers"),
|
||||
call.argument("fileUrl")!!, call.argument("headers"),
|
||||
call.argument("filename")!!,
|
||||
call.argument("maxWidth")!!,
|
||||
call.argument("maxHeight")!!,
|
||||
call.argument<Boolean>("isSaveToServer")!!,
|
||||
call.argument("iteration")!!,
|
||||
result
|
||||
call.argument("iteration")!!, result
|
||||
)
|
||||
} catch (e: Throwable) {
|
||||
logE(TAG, "Uncaught exception", e)
|
||||
|
@ -51,14 +49,12 @@ internal class ImageProcessorChannelHandler(context: Context) :
|
|||
"deepLab3Portrait" -> {
|
||||
try {
|
||||
deepLab3Portrait(
|
||||
call.argument("fileUrl")!!,
|
||||
call.argument("headers"),
|
||||
call.argument("fileUrl")!!, call.argument("headers"),
|
||||
call.argument("filename")!!,
|
||||
call.argument("maxWidth")!!,
|
||||
call.argument("maxHeight")!!,
|
||||
call.argument<Boolean>("isSaveToServer")!!,
|
||||
call.argument("radius")!!,
|
||||
result
|
||||
call.argument("radius")!!, result
|
||||
)
|
||||
} catch (e: Throwable) {
|
||||
logE(TAG, "Uncaught exception", e)
|
||||
|
@ -69,13 +65,11 @@ internal class ImageProcessorChannelHandler(context: Context) :
|
|||
"esrgan" -> {
|
||||
try {
|
||||
esrgan(
|
||||
call.argument("fileUrl")!!,
|
||||
call.argument("headers"),
|
||||
call.argument("fileUrl")!!, call.argument("headers"),
|
||||
call.argument("filename")!!,
|
||||
call.argument("maxWidth")!!,
|
||||
call.argument("maxHeight")!!,
|
||||
call.argument<Boolean>("isSaveToServer")!!,
|
||||
result
|
||||
call.argument<Boolean>("isSaveToServer")!!, result
|
||||
)
|
||||
} catch (e: Throwable) {
|
||||
logE(TAG, "Uncaught exception", e)
|
||||
|
@ -86,14 +80,12 @@ internal class ImageProcessorChannelHandler(context: Context) :
|
|||
"arbitraryStyleTransfer" -> {
|
||||
try {
|
||||
arbitraryStyleTransfer(
|
||||
call.argument("fileUrl")!!,
|
||||
call.argument("headers"),
|
||||
call.argument("fileUrl")!!, call.argument("headers"),
|
||||
call.argument("filename")!!,
|
||||
call.argument("maxWidth")!!,
|
||||
call.argument("maxHeight")!!,
|
||||
call.argument<Boolean>("isSaveToServer")!!,
|
||||
call.argument("styleUri")!!,
|
||||
call.argument("weight")!!,
|
||||
call.argument("styleUri")!!, call.argument("weight")!!,
|
||||
result
|
||||
)
|
||||
} catch (e: Throwable) {
|
||||
|
@ -105,14 +97,12 @@ internal class ImageProcessorChannelHandler(context: Context) :
|
|||
"deepLab3ColorPop" -> {
|
||||
try {
|
||||
deepLab3ColorPop(
|
||||
call.argument("fileUrl")!!,
|
||||
call.argument("headers"),
|
||||
call.argument("fileUrl")!!, call.argument("headers"),
|
||||
call.argument("filename")!!,
|
||||
call.argument("maxWidth")!!,
|
||||
call.argument("maxHeight")!!,
|
||||
call.argument<Boolean>("isSaveToServer")!!,
|
||||
call.argument("weight")!!,
|
||||
result
|
||||
call.argument("weight")!!, result
|
||||
)
|
||||
} catch (e: Throwable) {
|
||||
logE(TAG, "Uncaught exception", e)
|
||||
|
@ -123,13 +113,11 @@ internal class ImageProcessorChannelHandler(context: Context) :
|
|||
"neurOp" -> {
|
||||
try {
|
||||
neurOp(
|
||||
call.argument("fileUrl")!!,
|
||||
call.argument("headers"),
|
||||
call.argument("fileUrl")!!, call.argument("headers"),
|
||||
call.argument("filename")!!,
|
||||
call.argument("maxWidth")!!,
|
||||
call.argument("maxHeight")!!,
|
||||
call.argument<Boolean>("isSaveToServer")!!,
|
||||
result
|
||||
call.argument<Boolean>("isSaveToServer")!!, result
|
||||
)
|
||||
} catch (e: Throwable) {
|
||||
logE(TAG, "Uncaught exception", e)
|
||||
|
@ -140,14 +128,12 @@ internal class ImageProcessorChannelHandler(context: Context) :
|
|||
"filter" -> {
|
||||
try {
|
||||
filter(
|
||||
call.argument("fileUrl")!!,
|
||||
call.argument("headers"),
|
||||
call.argument("fileUrl")!!, call.argument("headers"),
|
||||
call.argument("filename")!!,
|
||||
call.argument("maxWidth")!!,
|
||||
call.argument("maxHeight")!!,
|
||||
call.argument<Boolean>("isSaveToServer")!!,
|
||||
call.argument("filters")!!,
|
||||
result
|
||||
call.argument("filters")!!, result
|
||||
)
|
||||
} catch (e: Throwable) {
|
||||
logE(TAG, "Uncaught exception", e)
|
||||
|
@ -158,8 +144,7 @@ internal class ImageProcessorChannelHandler(context: Context) :
|
|||
"filterPreview" -> {
|
||||
try {
|
||||
filterPreview(
|
||||
call.argument("rgba8")!!,
|
||||
call.argument("filters")!!,
|
||||
call.argument("rgba8")!!, call.argument("filters")!!,
|
||||
result
|
||||
)
|
||||
} catch (e: Throwable) {
|
||||
|
@ -181,84 +166,38 @@ internal class ImageProcessorChannelHandler(context: Context) :
|
|||
}
|
||||
|
||||
private fun zeroDce(
|
||||
fileUrl: String,
|
||||
headers: Map<String, String>?,
|
||||
filename: String,
|
||||
maxWidth: Int,
|
||||
maxHeight: Int,
|
||||
isSaveToServer: Boolean,
|
||||
iteration: Int,
|
||||
fileUrl: String, headers: Map<String, String>?, filename: String,
|
||||
maxWidth: Int, maxHeight: Int, isSaveToServer: Boolean, iteration: Int,
|
||||
result: MethodChannel.Result
|
||||
) = method(fileUrl,
|
||||
headers,
|
||||
filename,
|
||||
maxWidth,
|
||||
maxHeight,
|
||||
isSaveToServer,
|
||||
ImageProcessorService.METHOD_ZERO_DCE,
|
||||
result,
|
||||
onIntent = {
|
||||
) = method(fileUrl, headers, filename, maxWidth, maxHeight, isSaveToServer,
|
||||
ImageProcessorService.METHOD_ZERO_DCE, result, onIntent = {
|
||||
it.putExtra(ImageProcessorService.EXTRA_ITERATION, iteration)
|
||||
})
|
||||
|
||||
private fun deepLab3Portrait(
|
||||
fileUrl: String,
|
||||
headers: Map<String, String>?,
|
||||
filename: String,
|
||||
maxWidth: Int,
|
||||
maxHeight: Int,
|
||||
isSaveToServer: Boolean,
|
||||
radius: Int,
|
||||
fileUrl: String, headers: Map<String, String>?, filename: String,
|
||||
maxWidth: Int, maxHeight: Int, isSaveToServer: Boolean, radius: Int,
|
||||
result: MethodChannel.Result
|
||||
) = method(fileUrl,
|
||||
headers,
|
||||
filename,
|
||||
maxWidth,
|
||||
maxHeight,
|
||||
isSaveToServer,
|
||||
ImageProcessorService.METHOD_DEEP_LAP_PORTRAIT,
|
||||
result,
|
||||
onIntent = {
|
||||
) = method(fileUrl, headers, filename, maxWidth, maxHeight, isSaveToServer,
|
||||
ImageProcessorService.METHOD_DEEP_LAP_PORTRAIT, result, onIntent = {
|
||||
it.putExtra(ImageProcessorService.EXTRA_RADIUS, radius)
|
||||
})
|
||||
|
||||
private fun esrgan(
|
||||
fileUrl: String,
|
||||
headers: Map<String, String>?,
|
||||
filename: String,
|
||||
maxWidth: Int,
|
||||
maxHeight: Int,
|
||||
isSaveToServer: Boolean,
|
||||
fileUrl: String, headers: Map<String, String>?, filename: String,
|
||||
maxWidth: Int, maxHeight: Int, isSaveToServer: Boolean,
|
||||
result: MethodChannel.Result
|
||||
) = method(
|
||||
fileUrl,
|
||||
headers,
|
||||
filename,
|
||||
maxWidth,
|
||||
maxHeight,
|
||||
isSaveToServer,
|
||||
ImageProcessorService.METHOD_ESRGAN,
|
||||
result
|
||||
fileUrl, headers, filename, maxWidth, maxHeight, isSaveToServer,
|
||||
ImageProcessorService.METHOD_ESRGAN, result
|
||||
)
|
||||
|
||||
private fun arbitraryStyleTransfer(
|
||||
fileUrl: String,
|
||||
headers: Map<String, String>?,
|
||||
filename: String,
|
||||
maxWidth: Int,
|
||||
maxHeight: Int,
|
||||
isSaveToServer: Boolean,
|
||||
styleUri: String,
|
||||
weight: Float,
|
||||
result: MethodChannel.Result
|
||||
) = method(fileUrl,
|
||||
headers,
|
||||
filename,
|
||||
maxWidth,
|
||||
maxHeight,
|
||||
isSaveToServer,
|
||||
ImageProcessorService.METHOD_ARBITRARY_STYLE_TRANSFER,
|
||||
result,
|
||||
fileUrl: String, headers: Map<String, String>?, filename: String,
|
||||
maxWidth: Int, maxHeight: Int, isSaveToServer: Boolean,
|
||||
styleUri: String, weight: Float, result: MethodChannel.Result
|
||||
) = method(fileUrl, headers, filename, maxWidth, maxHeight, isSaveToServer,
|
||||
ImageProcessorService.METHOD_ARBITRARY_STYLE_TRANSFER, result,
|
||||
onIntent = {
|
||||
it.putExtra(
|
||||
ImageProcessorService.EXTRA_STYLE_URI, Uri.parse(styleUri)
|
||||
|
@ -267,74 +206,39 @@ internal class ImageProcessorChannelHandler(context: Context) :
|
|||
})
|
||||
|
||||
private fun deepLab3ColorPop(
|
||||
fileUrl: String,
|
||||
headers: Map<String, String>?,
|
||||
filename: String,
|
||||
maxWidth: Int,
|
||||
maxHeight: Int,
|
||||
isSaveToServer: Boolean,
|
||||
weight: Float,
|
||||
fileUrl: String, headers: Map<String, String>?, filename: String,
|
||||
maxWidth: Int, maxHeight: Int, isSaveToServer: Boolean, weight: Float,
|
||||
result: MethodChannel.Result
|
||||
) = method(fileUrl,
|
||||
headers,
|
||||
filename,
|
||||
maxWidth,
|
||||
maxHeight,
|
||||
isSaveToServer,
|
||||
ImageProcessorService.METHOD_DEEP_LAP_COLOR_POP,
|
||||
result,
|
||||
onIntent = {
|
||||
) = method(fileUrl, headers, filename, maxWidth, maxHeight, isSaveToServer,
|
||||
ImageProcessorService.METHOD_DEEP_LAP_COLOR_POP, result, onIntent = {
|
||||
it.putExtra(ImageProcessorService.EXTRA_WEIGHT, weight)
|
||||
})
|
||||
|
||||
private fun neurOp(
|
||||
fileUrl: String,
|
||||
headers: Map<String, String>?,
|
||||
filename: String,
|
||||
maxWidth: Int,
|
||||
maxHeight: Int,
|
||||
isSaveToServer: Boolean,
|
||||
fileUrl: String, headers: Map<String, String>?, filename: String,
|
||||
maxWidth: Int, maxHeight: Int, isSaveToServer: Boolean,
|
||||
result: MethodChannel.Result
|
||||
) = method(
|
||||
fileUrl,
|
||||
headers,
|
||||
filename,
|
||||
maxWidth,
|
||||
maxHeight,
|
||||
isSaveToServer,
|
||||
ImageProcessorService.METHOD_NEUR_OP,
|
||||
result
|
||||
fileUrl, headers, filename, maxWidth, maxHeight, isSaveToServer,
|
||||
ImageProcessorService.METHOD_NEUR_OP, result
|
||||
)
|
||||
|
||||
private fun filter(
|
||||
fileUrl: String,
|
||||
headers: Map<String, String>?,
|
||||
filename: String,
|
||||
maxWidth: Int,
|
||||
maxHeight: Int,
|
||||
isSaveToServer: Boolean,
|
||||
filters: List<Map<String, Any>>,
|
||||
result: MethodChannel.Result
|
||||
fileUrl: String, headers: Map<String, String>?, filename: String,
|
||||
maxWidth: Int, maxHeight: Int, isSaveToServer: Boolean,
|
||||
filters: List<Map<String, Any>>, result: MethodChannel.Result
|
||||
) {
|
||||
// convert to serializable
|
||||
val l = arrayListOf<Serializable>()
|
||||
filters.mapTo(l, { HashMap(it) })
|
||||
method(fileUrl,
|
||||
headers,
|
||||
filename,
|
||||
maxWidth,
|
||||
maxHeight,
|
||||
isSaveToServer,
|
||||
ImageProcessorService.METHOD_FILTER,
|
||||
result,
|
||||
onIntent = {
|
||||
method(fileUrl, headers, filename, maxWidth, maxHeight, isSaveToServer,
|
||||
ImageProcessorService.METHOD_FILTER, result, onIntent = {
|
||||
it.putExtra(ImageProcessorService.EXTRA_FILTERS, l)
|
||||
})
|
||||
}
|
||||
|
||||
private fun filterPreview(
|
||||
rgba8: Map<String, Any>,
|
||||
filters: List<Map<String, Any>>,
|
||||
rgba8: Map<String, Any>, filters: List<Map<String, Any>>,
|
||||
result: MethodChannel.Result
|
||||
) {
|
||||
var img = Rgba8Image.fromJson(rgba8)
|
||||
|
@ -345,15 +249,9 @@ internal class ImageProcessorChannelHandler(context: Context) :
|
|||
}
|
||||
|
||||
private fun method(
|
||||
fileUrl: String,
|
||||
headers: Map<String, String>?,
|
||||
filename: String,
|
||||
maxWidth: Int,
|
||||
maxHeight: Int,
|
||||
isSaveToServer: Boolean,
|
||||
method: String,
|
||||
result: MethodChannel.Result,
|
||||
onIntent: ((Intent) -> Unit)? = null
|
||||
fileUrl: String, headers: Map<String, String>?, filename: String,
|
||||
maxWidth: Int, maxHeight: Int, isSaveToServer: Boolean, method: String,
|
||||
result: MethodChannel.Result, onIntent: ((Intent) -> Unit)? = null
|
||||
) {
|
||||
val intent = Intent(context, ImageProcessorService::class.java).apply {
|
||||
putExtra(ImageProcessorService.EXTRA_METHOD, method)
|
||||
|
@ -389,10 +287,8 @@ internal interface ImageFilter {
|
|||
"tint" -> Tint((json["weight"] as Double).toFloat())
|
||||
"orientation" -> Orientation(json["degree"] as Int)
|
||||
"crop" -> Crop(
|
||||
json["top"] as Double,
|
||||
json["left"] as Double,
|
||||
json["bottom"] as Double,
|
||||
json["right"] as Double
|
||||
json["top"] as Double, json["left"] as Double,
|
||||
json["bottom"] as Double, json["right"] as Double
|
||||
)
|
||||
|
||||
else -> throw IllegalArgumentException(
|
||||
|
|
|
@ -161,8 +161,8 @@ internal class ImageProcessorService : Service() {
|
|||
}
|
||||
|
||||
private fun onEsrgan(startId: Int, extras: Bundle) {
|
||||
return onMethod(startId, extras,
|
||||
{ params -> ImageProcessorEsrganCommand(params) })
|
||||
return onMethod(
|
||||
startId, extras, { params -> ImageProcessorEsrganCommand(params) })
|
||||
}
|
||||
|
||||
private fun onArbitraryStyleTransfer(startId: Int, extras: Bundle) {
|
||||
|
|
|
@ -13,8 +13,7 @@ class NpPlatformImageProcessorPlugin : FlutterPlugin {
|
|||
|
||||
const val ACTION_SHOW_IMAGE_PROCESSOR_RESULT =
|
||||
K.ACTION_SHOW_IMAGE_PROCESSOR_RESULT
|
||||
const val EXTRA_IMAGE_RESULT_URI =
|
||||
K.EXTRA_IMAGE_RESULT_URI
|
||||
const val EXTRA_IMAGE_RESULT_URI = K.EXTRA_IMAGE_RESULT_URI
|
||||
}
|
||||
|
||||
override fun onAttachedToEngine(
|
||||
|
|
|
@ -10,10 +10,7 @@ import com.nkming.nc_photos.np_android_core.logI
|
|||
import com.nkming.nc_photos.np_android_core.use
|
||||
|
||||
internal class ArbitraryStyleTransfer(
|
||||
context: Context,
|
||||
maxWidth: Int,
|
||||
maxHeight: Int,
|
||||
styleUri: Uri,
|
||||
context: Context, maxWidth: Int, maxHeight: Int, styleUri: Uri,
|
||||
weight: Float
|
||||
) {
|
||||
companion object {
|
||||
|
@ -24,13 +21,8 @@ internal class ArbitraryStyleTransfer(
|
|||
val width: Int
|
||||
val height: Int
|
||||
val rgb8Image = BitmapUtil.loadImage(
|
||||
context,
|
||||
imageUri,
|
||||
maxWidth,
|
||||
maxHeight,
|
||||
BitmapResizeMethod.FIT,
|
||||
isAllowSwapSide = true,
|
||||
shouldUpscale = false,
|
||||
context, imageUri, maxWidth, maxHeight, BitmapResizeMethod.FIT,
|
||||
isAllowSwapSide = true, shouldUpscale = false,
|
||||
shouldFixOrientation = true
|
||||
).use {
|
||||
width = it.width
|
||||
|
@ -38,13 +30,8 @@ internal class ArbitraryStyleTransfer(
|
|||
TfLiteHelper.bitmapToRgb8Array(it)
|
||||
}
|
||||
val rgb8Style = BitmapUtil.loadImage(
|
||||
context,
|
||||
styleUri,
|
||||
256,
|
||||
256,
|
||||
BitmapResizeMethod.FILL,
|
||||
isAllowSwapSide = false,
|
||||
shouldUpscale = true
|
||||
context, styleUri, 256, 256, BitmapResizeMethod.FILL,
|
||||
isAllowSwapSide = false, shouldUpscale = true
|
||||
).use {
|
||||
val styleBitmap = if (it.width != 256 || it.height != 256) {
|
||||
val x = (it.width - 256) / 2
|
||||
|
@ -72,12 +59,8 @@ internal class ArbitraryStyleTransfer(
|
|||
}
|
||||
|
||||
private external fun inferNative(
|
||||
am: AssetManager,
|
||||
image: ByteArray,
|
||||
width: Int,
|
||||
height: Int,
|
||||
style: ByteArray,
|
||||
weight: Float
|
||||
am: AssetManager, image: ByteArray, width: Int, height: Int,
|
||||
style: ByteArray, weight: Float
|
||||
): ByteArray
|
||||
|
||||
private val context = context
|
||||
|
|
|
@ -6,8 +6,7 @@ import com.nkming.nc_photos.np_platform_image_processor.ImageFilter
|
|||
internal class BlackPoint(val weight: Float) : ImageFilter {
|
||||
override fun apply(rgba8: Rgba8Image) = Rgba8Image(
|
||||
applyNative(rgba8.pixel, rgba8.width, rgba8.height, weight),
|
||||
rgba8.width,
|
||||
rgba8.height
|
||||
rgba8.width, rgba8.height
|
||||
)
|
||||
|
||||
private external fun applyNative(
|
||||
|
|
|
@ -6,8 +6,7 @@ import com.nkming.nc_photos.np_platform_image_processor.ImageFilter
|
|||
internal class Brightness(val weight: Float) : ImageFilter {
|
||||
override fun apply(rgba8: Rgba8Image) = Rgba8Image(
|
||||
applyNative(rgba8.pixel, rgba8.width, rgba8.height, weight),
|
||||
rgba8.width,
|
||||
rgba8.height
|
||||
rgba8.width, rgba8.height
|
||||
)
|
||||
|
||||
private external fun applyNative(
|
||||
|
|
|
@ -6,8 +6,7 @@ import com.nkming.nc_photos.np_platform_image_processor.ImageFilter
|
|||
internal class Contrast(val weight: Float) : ImageFilter {
|
||||
override fun apply(rgba8: Rgba8Image) = Rgba8Image(
|
||||
applyNative(rgba8.pixel, rgba8.width, rgba8.height, weight),
|
||||
rgba8.width,
|
||||
rgba8.height
|
||||
rgba8.width, rgba8.height
|
||||
)
|
||||
|
||||
private external fun applyNative(
|
||||
|
|
|
@ -6,8 +6,7 @@ import com.nkming.nc_photos.np_platform_image_processor.ImageFilter
|
|||
internal class Cool(val weight: Float) : ImageFilter {
|
||||
override fun apply(rgba8: Rgba8Image) = Rgba8Image(
|
||||
applyNative(rgba8.pixel, rgba8.width, rgba8.height, weight),
|
||||
rgba8.width,
|
||||
rgba8.height
|
||||
rgba8.width, rgba8.height
|
||||
)
|
||||
|
||||
private external fun applyNative(
|
||||
|
|
|
@ -20,12 +20,7 @@ internal class Crop(
|
|||
}
|
||||
|
||||
private external fun applyNative(
|
||||
rgba8: ByteArray,
|
||||
width: Int,
|
||||
height: Int,
|
||||
top: Int,
|
||||
left: Int,
|
||||
dstWidth: Int,
|
||||
dstHeight: Int
|
||||
rgba8: ByteArray, width: Int, height: Int, top: Int, left: Int,
|
||||
dstWidth: Int, dstHeight: Int
|
||||
): ByteArray
|
||||
}
|
||||
|
|
|
@ -22,13 +22,8 @@ internal class DeepLab3Portrait(
|
|||
val width: Int
|
||||
val height: Int
|
||||
val rgb8Image = BitmapUtil.loadImage(
|
||||
context,
|
||||
imageUri,
|
||||
maxWidth,
|
||||
maxHeight,
|
||||
BitmapResizeMethod.FIT,
|
||||
isAllowSwapSide = true,
|
||||
shouldUpscale = false,
|
||||
context, imageUri, maxWidth, maxHeight, BitmapResizeMethod.FIT,
|
||||
isAllowSwapSide = true, shouldUpscale = false,
|
||||
shouldFixOrientation = true
|
||||
).use {
|
||||
width = it.width
|
||||
|
@ -59,13 +54,8 @@ class DeepLab3ColorPop(
|
|||
val width: Int
|
||||
val height: Int
|
||||
val rgb8Image = BitmapUtil.loadImage(
|
||||
context,
|
||||
imageUri,
|
||||
maxWidth,
|
||||
maxHeight,
|
||||
BitmapResizeMethod.FIT,
|
||||
isAllowSwapSide = true,
|
||||
shouldUpscale = false,
|
||||
context, imageUri, maxWidth, maxHeight, BitmapResizeMethod.FIT,
|
||||
isAllowSwapSide = true, shouldUpscale = false,
|
||||
shouldFixOrientation = true
|
||||
).use {
|
||||
width = it.width
|
||||
|
@ -80,10 +70,7 @@ class DeepLab3ColorPop(
|
|||
}
|
||||
|
||||
private external fun inferNative(
|
||||
am: AssetManager,
|
||||
image: ByteArray,
|
||||
width: Int,
|
||||
height: Int,
|
||||
am: AssetManager, image: ByteArray, width: Int, height: Int,
|
||||
weight: Float
|
||||
): ByteArray
|
||||
|
||||
|
|
|
@ -13,14 +13,9 @@ internal class Esrgan(context: Context, maxWidth: Int, maxHeight: Int) {
|
|||
val width: Int
|
||||
val height: Int
|
||||
val rgb8Image = BitmapUtil.loadImage(
|
||||
context,
|
||||
imageUri,
|
||||
maxWidth / 4,
|
||||
maxHeight / 4,
|
||||
BitmapResizeMethod.FIT,
|
||||
isAllowSwapSide = true,
|
||||
shouldUpscale = false,
|
||||
shouldFixOrientation = true
|
||||
context, imageUri, maxWidth / 4, maxHeight / 4,
|
||||
BitmapResizeMethod.FIT, isAllowSwapSide = true,
|
||||
shouldUpscale = false, shouldFixOrientation = true
|
||||
).use {
|
||||
width = it.width
|
||||
height = it.height
|
||||
|
|
|
@ -18,13 +18,8 @@ internal class ImageFilterProcessor(
|
|||
|
||||
fun apply(imageUri: Uri): Bitmap {
|
||||
var img = BitmapUtil.loadImage(
|
||||
context,
|
||||
imageUri,
|
||||
maxWidth,
|
||||
maxHeight,
|
||||
BitmapResizeMethod.FIT,
|
||||
isAllowSwapSide = true,
|
||||
shouldUpscale = false,
|
||||
context, imageUri, maxWidth, maxHeight, BitmapResizeMethod.FIT,
|
||||
isAllowSwapSide = true, shouldUpscale = false,
|
||||
shouldFixOrientation = true
|
||||
).use {
|
||||
Rgba8Image(TfLiteHelper.bitmapToRgba8Array(it), it.width, it.height)
|
||||
|
|
|
@ -13,13 +13,8 @@ internal class NeurOp(context: Context, maxWidth: Int, maxHeight: Int) {
|
|||
val width: Int
|
||||
val height: Int
|
||||
val rgb8Image = BitmapUtil.loadImage(
|
||||
context,
|
||||
imageUri,
|
||||
maxWidth,
|
||||
maxHeight,
|
||||
BitmapResizeMethod.FIT,
|
||||
isAllowSwapSide = true,
|
||||
shouldUpscale = false,
|
||||
context, imageUri, maxWidth, maxHeight, BitmapResizeMethod.FIT,
|
||||
isAllowSwapSide = true, shouldUpscale = false,
|
||||
shouldFixOrientation = true
|
||||
).use {
|
||||
width = it.width
|
||||
|
|
|
@ -8,8 +8,7 @@ internal class Orientation(val degree: Int) : ImageFilter {
|
|||
override fun apply(rgba8: Rgba8Image): Rgba8Image {
|
||||
val data = applyNative(rgba8.pixel, rgba8.width, rgba8.height, degree)
|
||||
return Rgba8Image(
|
||||
data,
|
||||
if (abs(degree) == 90) rgba8.height else rgba8.width,
|
||||
data, if (abs(degree) == 90) rgba8.height else rgba8.width,
|
||||
if (abs(degree) == 90) rgba8.width else rgba8.height
|
||||
)
|
||||
}
|
||||
|
|
|
@ -6,8 +6,7 @@ import com.nkming.nc_photos.np_platform_image_processor.ImageFilter
|
|||
internal class Saturation(val weight: Float) : ImageFilter {
|
||||
override fun apply(rgba8: Rgba8Image) = Rgba8Image(
|
||||
applyNative(rgba8.pixel, rgba8.width, rgba8.height, weight),
|
||||
rgba8.width,
|
||||
rgba8.height
|
||||
rgba8.width, rgba8.height
|
||||
)
|
||||
|
||||
private external fun applyNative(
|
||||
|
|
|
@ -6,8 +6,7 @@ import com.nkming.nc_photos.np_platform_image_processor.ImageFilter
|
|||
internal class Tint(val weight: Float) : ImageFilter {
|
||||
override fun apply(rgba8: Rgba8Image) = Rgba8Image(
|
||||
applyNative(rgba8.pixel, rgba8.width, rgba8.height, weight),
|
||||
rgba8.width,
|
||||
rgba8.height
|
||||
rgba8.width, rgba8.height
|
||||
)
|
||||
|
||||
private external fun applyNative(
|
||||
|
|
|
@ -6,8 +6,7 @@ import com.nkming.nc_photos.np_platform_image_processor.ImageFilter
|
|||
internal class Warmth(val weight: Float) : ImageFilter {
|
||||
override fun apply(rgba8: Rgba8Image) = Rgba8Image(
|
||||
applyNative(rgba8.pixel, rgba8.width, rgba8.height, weight),
|
||||
rgba8.width,
|
||||
rgba8.height
|
||||
rgba8.width, rgba8.height
|
||||
)
|
||||
|
||||
private external fun applyNative(
|
||||
|
|
|
@ -6,8 +6,7 @@ import com.nkming.nc_photos.np_platform_image_processor.ImageFilter
|
|||
internal class WhitePoint(val weight: Float) : ImageFilter {
|
||||
override fun apply(rgba8: Rgba8Image) = Rgba8Image(
|
||||
applyNative(rgba8.pixel, rgba8.width, rgba8.height, weight),
|
||||
rgba8.width,
|
||||
rgba8.height
|
||||
rgba8.width, rgba8.height
|
||||
)
|
||||
|
||||
private external fun applyNative(
|
||||
|
|
|
@ -9,22 +9,14 @@ import com.nkming.nc_photos.np_android_core.BitmapUtil
|
|||
import com.nkming.nc_photos.np_android_core.use
|
||||
|
||||
internal class ZeroDce(
|
||||
context: Context,
|
||||
maxWidth: Int,
|
||||
maxHeight: Int,
|
||||
iteration: Int
|
||||
context: Context, maxWidth: Int, maxHeight: Int, iteration: Int
|
||||
) {
|
||||
fun infer(imageUri: Uri): Bitmap {
|
||||
val width: Int
|
||||
val height: Int
|
||||
val rgb8Image = BitmapUtil.loadImage(
|
||||
context,
|
||||
imageUri,
|
||||
maxWidth,
|
||||
maxHeight,
|
||||
BitmapResizeMethod.FIT,
|
||||
isAllowSwapSide = true,
|
||||
shouldUpscale = false,
|
||||
context, imageUri, maxWidth, maxHeight, BitmapResizeMethod.FIT,
|
||||
isAllowSwapSide = true, shouldUpscale = false,
|
||||
shouldFixOrientation = true
|
||||
).use {
|
||||
width = it.width
|
||||
|
@ -39,10 +31,7 @@ internal class ZeroDce(
|
|||
}
|
||||
|
||||
private external fun inferNative(
|
||||
am: AssetManager,
|
||||
image: ByteArray,
|
||||
width: Int,
|
||||
height: Int,
|
||||
am: AssetManager, image: ByteArray, width: Int, height: Int,
|
||||
iteration: Int
|
||||
): ByteArray
|
||||
|
||||
|
|
|
@ -83,8 +83,7 @@ class LockChannelHandler : MethodChannel.MethodCallHandler {
|
|||
result.success(null)
|
||||
} else {
|
||||
result.error(
|
||||
"notLockedException",
|
||||
"Cannot unlock without first locking",
|
||||
"notLockedException", "Cannot unlock without first locking",
|
||||
null
|
||||
)
|
||||
}
|
||||
|
|
|
@ -20,14 +20,12 @@ internal class ImageLoaderChannelHandler(context: Context) :
|
|||
"loadUri" -> {
|
||||
try {
|
||||
loadUri(
|
||||
call.argument("fileUri")!!,
|
||||
call.argument("maxWidth")!!,
|
||||
call.argument("fileUri")!!, call.argument("maxWidth")!!,
|
||||
call.argument("maxHeight")!!,
|
||||
call.argument("resizeMethod")!!,
|
||||
call.argument("isAllowSwapSide")!!,
|
||||
call.argument("shouldUpscale")!!,
|
||||
call.argument("shouldFixOrientation")!!,
|
||||
result
|
||||
call.argument("shouldFixOrientation")!!, result
|
||||
)
|
||||
} catch (e: Throwable) {
|
||||
result.error("systemException", e.toString(), null)
|
||||
|
@ -51,24 +49,14 @@ internal class ImageLoaderChannelHandler(context: Context) :
|
|||
* @param result
|
||||
*/
|
||||
private fun loadUri(
|
||||
fileUri: String,
|
||||
maxWidth: Int,
|
||||
maxHeight: Int,
|
||||
resizeMethod: Int,
|
||||
isAllowSwapSide: Boolean,
|
||||
shouldUpscale: Boolean,
|
||||
shouldFixOrientation: Boolean,
|
||||
result: MethodChannel.Result
|
||||
fileUri: String, maxWidth: Int, maxHeight: Int, resizeMethod: Int,
|
||||
isAllowSwapSide: Boolean, shouldUpscale: Boolean,
|
||||
shouldFixOrientation: Boolean, result: MethodChannel.Result
|
||||
) {
|
||||
val image = BitmapUtil.loadImage(
|
||||
context,
|
||||
Uri.parse(fileUri),
|
||||
maxWidth,
|
||||
maxHeight,
|
||||
BitmapResizeMethod.values()[resizeMethod],
|
||||
isAllowSwapSide,
|
||||
shouldUpscale,
|
||||
shouldFixOrientation
|
||||
context, Uri.parse(fileUri), maxWidth, maxHeight,
|
||||
BitmapResizeMethod.values()[resizeMethod], isAllowSwapSide,
|
||||
shouldUpscale, shouldFixOrientation
|
||||
).use {
|
||||
Rgba8Image.fromBitmap(it)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,9 @@ import io.flutter.embedding.engine.plugins.FlutterPlugin
|
|||
import io.flutter.plugin.common.MethodChannel
|
||||
|
||||
class NpPlatformRawImagePlugin : FlutterPlugin {
|
||||
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
|
||||
override fun onAttachedToEngine(
|
||||
@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding
|
||||
) {
|
||||
val imageLoaderChannelHandler =
|
||||
ImageLoaderChannelHandler(flutterPluginBinding.applicationContext)
|
||||
imageLoaderMethodChannel = MethodChannel(
|
||||
|
@ -15,7 +17,9 @@ class NpPlatformRawImagePlugin : FlutterPlugin {
|
|||
imageLoaderMethodChannel.setMethodCallHandler(imageLoaderChannelHandler)
|
||||
}
|
||||
|
||||
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
|
||||
override fun onDetachedFromEngine(
|
||||
@NonNull binding: FlutterPlugin.FlutterPluginBinding
|
||||
) {
|
||||
imageLoaderMethodChannel.setMethodCallHandler(null)
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ import android.provider.MediaStore
|
|||
import com.nkming.nc_photos.np_android_core.MediaStoreUtil
|
||||
import com.nkming.nc_photos.np_android_core.PermissionException
|
||||
import com.nkming.nc_photos.np_android_core.PermissionUtil
|
||||
import com.nkming.nc_photos.np_android_core.logD
|
||||
import com.nkming.nc_photos.np_android_core.logE
|
||||
import com.nkming.nc_photos.np_android_core.logI
|
||||
import io.flutter.embedding.engine.plugins.activity.ActivityAware
|
||||
|
@ -33,8 +32,8 @@ import java.io.File
|
|||
* fun queryFiles(relativePath: String): List<Map>
|
||||
*/
|
||||
internal class MediaStoreChannelHandler(context: Context) :
|
||||
MethodChannel.MethodCallHandler, EventChannel.StreamHandler,
|
||||
ActivityAware, PluginRegistry.ActivityResultListener {
|
||||
MethodChannel.MethodCallHandler, EventChannel.StreamHandler, ActivityAware,
|
||||
PluginRegistry.ActivityResultListener {
|
||||
companion object {
|
||||
const val EVENT_CHANNEL = "${K.LIB_ID}/media_store"
|
||||
const val METHOD_CHANNEL = "${K.LIB_ID}/media_store_method"
|
||||
|
@ -169,17 +168,15 @@ internal class MediaStoreChannelHandler(context: Context) :
|
|||
pathColumnName = MediaStore.Images.Media.RELATIVE_PATH
|
||||
pathArg = "${relativePath}/%"
|
||||
} else {
|
||||
@Suppress("Deprecation")
|
||||
pathColumnName = MediaStore.Images.Media.DATA
|
||||
@Suppress("Deprecation") pathColumnName =
|
||||
MediaStore.Images.Media.DATA
|
||||
pathArg = "%/${relativePath}/%"
|
||||
}
|
||||
val projection = arrayOf(
|
||||
MediaStore.Images.Media._ID,
|
||||
MediaStore.Images.Media.DATE_MODIFIED,
|
||||
MediaStore.Images.Media._ID, MediaStore.Images.Media.DATE_MODIFIED,
|
||||
MediaStore.Images.Media.MIME_TYPE,
|
||||
MediaStore.Images.Media.DATE_TAKEN,
|
||||
MediaStore.Images.Media.DISPLAY_NAME,
|
||||
pathColumnName
|
||||
MediaStore.Images.Media.DISPLAY_NAME, pathColumnName
|
||||
)
|
||||
val selection = StringBuilder().apply {
|
||||
append("${MediaStore.Images.Media.MIME_TYPE} LIKE ?")
|
||||
|
@ -187,8 +184,8 @@ internal class MediaStoreChannelHandler(context: Context) :
|
|||
}.toString()
|
||||
val selectionArgs = arrayOf("image/%", pathArg)
|
||||
val files = context.contentResolver.query(
|
||||
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
||||
projection, selection, selectionArgs, null
|
||||
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, selection,
|
||||
selectionArgs, null
|
||||
)!!.use {
|
||||
val idColumn = it.getColumnIndexOrThrow(MediaStore.Images.Media._ID)
|
||||
val dateModifiedColumn =
|
||||
|
|
|
@ -52,8 +52,7 @@ internal class NotificationChannelHandler(context: Context) :
|
|||
notifyDownloadSuccessful(
|
||||
call.argument("fileUris")!!,
|
||||
call.argument("mimeTypes")!!,
|
||||
call.argument("notificationId"),
|
||||
result
|
||||
call.argument("notificationId"), result
|
||||
)
|
||||
} catch (e: Throwable) {
|
||||
result.error("systemException", e.toString(), null)
|
||||
|
@ -63,11 +62,9 @@ internal class NotificationChannelHandler(context: Context) :
|
|||
"notifyDownloadProgress" -> {
|
||||
try {
|
||||
notifyDownloadProgress(
|
||||
call.argument("progress")!!,
|
||||
call.argument("max")!!,
|
||||
call.argument("progress")!!, call.argument("max")!!,
|
||||
call.argument("currentItemTitle"),
|
||||
call.argument("notificationId"),
|
||||
result
|
||||
call.argument("notificationId"), result
|
||||
)
|
||||
} catch (e: Throwable) {
|
||||
result.error("systemException", e.toString(), null)
|
||||
|
@ -99,9 +96,7 @@ internal class NotificationChannelHandler(context: Context) :
|
|||
}
|
||||
|
||||
private fun notifyDownloadSuccessful(
|
||||
fileUris: List<String>,
|
||||
mimeTypes: List<String?>,
|
||||
notificationId: Int?,
|
||||
fileUris: List<String>, mimeTypes: List<String?>, notificationId: Int?,
|
||||
result: MethodChannel.Result
|
||||
) {
|
||||
assert(fileUris.isNotEmpty())
|
||||
|
@ -167,8 +162,7 @@ internal class NotificationChannelHandler(context: Context) :
|
|||
} else Intent().apply {
|
||||
action = Intent.ACTION_SEND_MULTIPLE
|
||||
putParcelableArrayListExtra(Intent.EXTRA_STREAM, ArrayList(uris))
|
||||
type =
|
||||
if (mimeTypes.all {
|
||||
type = if (mimeTypes.all {
|
||||
it?.startsWith(
|
||||
"image/"
|
||||
) == true
|
||||
|
@ -199,11 +193,8 @@ internal class NotificationChannelHandler(context: Context) :
|
|||
}
|
||||
|
||||
private fun notifyDownloadProgress(
|
||||
progress: Int,
|
||||
max: Int,
|
||||
currentItemTitle: String?,
|
||||
notificationId: Int?,
|
||||
result: MethodChannel.Result
|
||||
progress: Int, max: Int, currentItemTitle: String?,
|
||||
notificationId: Int?, result: MethodChannel.Result
|
||||
) {
|
||||
val id = notificationId ?: getNextNotificationId()
|
||||
val builder = NotificationCompat.Builder(_context, DOWNLOAD_CHANNEL_ID)
|
||||
|
@ -326,8 +317,7 @@ internal class NotificationChannelHandler(context: Context) :
|
|||
} catch (e: Throwable) {
|
||||
logE(
|
||||
"NotificationChannelHandler::loadNotificationImage",
|
||||
"Failed generating preview image",
|
||||
e
|
||||
"Failed generating preview image", e
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
@ -347,8 +337,7 @@ internal class NotificationChannelHandler(context: Context) :
|
|||
description = descriptionStr
|
||||
}
|
||||
|
||||
val manager =
|
||||
context.getSystemService(
|
||||
val manager = context.getSystemService(
|
||||
Context.NOTIFICATION_SERVICE
|
||||
) as NotificationManager
|
||||
manager.createNotificationChannel(channel)
|
||||
|
|
|
@ -16,10 +16,8 @@ internal class PreferenceChannelHandler(context: Context) :
|
|||
"setBool" -> {
|
||||
try {
|
||||
setBool(
|
||||
call.argument("prefName")!!,
|
||||
call.argument("key")!!,
|
||||
call.argument("value")!!,
|
||||
result
|
||||
call.argument("prefName")!!, call.argument("key")!!,
|
||||
call.argument("value")!!, result
|
||||
)
|
||||
} catch (e: Throwable) {
|
||||
result.error("systemException", e.toString(), null)
|
||||
|
@ -29,10 +27,8 @@ internal class PreferenceChannelHandler(context: Context) :
|
|||
"getBool" -> {
|
||||
try {
|
||||
getBool(
|
||||
call.argument("prefName")!!,
|
||||
call.argument("key")!!,
|
||||
call.argument("defValue"),
|
||||
result
|
||||
call.argument("prefName")!!, call.argument("key")!!,
|
||||
call.argument("defValue"), result
|
||||
)
|
||||
} catch (e: Throwable) {
|
||||
result.error("systemException", e.toString(), null)
|
||||
|
@ -44,9 +40,7 @@ internal class PreferenceChannelHandler(context: Context) :
|
|||
}
|
||||
|
||||
private fun setBool(
|
||||
prefName: String,
|
||||
key: String,
|
||||
value: Boolean,
|
||||
prefName: String, key: String, value: Boolean,
|
||||
result: MethodChannel.Result
|
||||
) {
|
||||
openPref(prefName).run {
|
||||
|
@ -58,9 +52,7 @@ internal class PreferenceChannelHandler(context: Context) :
|
|||
}
|
||||
|
||||
private fun getBool(
|
||||
prefName: String,
|
||||
key: String,
|
||||
defValue: Boolean?,
|
||||
prefName: String, key: String, defValue: Boolean?,
|
||||
result: MethodChannel.Result
|
||||
) {
|
||||
val product = openPref(prefName).run {
|
||||
|
|
Loading…
Add table
Reference in a new issue