mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +01:00
Rename color filter to filter to be more generic
This commit is contained in:
parent
839ef8bb03
commit
a4f2fb0bce
13 changed files with 35 additions and 35 deletions
|
@ -189,7 +189,7 @@ class _ImageEditorState extends State<ImageEditor> {
|
|||
}
|
||||
|
||||
Future<void> _onSavePressed(BuildContext context) async {
|
||||
await ImageProcessor.colorFilter(
|
||||
await ImageProcessor.filter(
|
||||
"${widget.account.url}/${widget.file.path}",
|
||||
widget.file.filename,
|
||||
4096,
|
||||
|
|
|
@ -88,9 +88,9 @@ class ImageProcessorChannelHandler(context: Context) :
|
|||
}
|
||||
}
|
||||
|
||||
"colorFilter" -> {
|
||||
"filter" -> {
|
||||
try {
|
||||
colorFilter(
|
||||
filter(
|
||||
call.argument("fileUrl")!!,
|
||||
call.argument("headers"),
|
||||
call.argument("filename")!!,
|
||||
|
@ -174,7 +174,7 @@ class ImageProcessorChannelHandler(context: Context) :
|
|||
}
|
||||
)
|
||||
|
||||
private fun colorFilter(
|
||||
private fun filter(
|
||||
fileUrl: String, headers: Map<String, String>?, filename: String,
|
||||
maxWidth: Int, maxHeight: Int, filters: List<Map<String, Any>>,
|
||||
result: MethodChannel.Result
|
||||
|
@ -184,7 +184,7 @@ class ImageProcessorChannelHandler(context: Context) :
|
|||
filters.mapTo(l, { HashMap(it) })
|
||||
method(
|
||||
fileUrl, headers, filename, maxWidth, maxHeight,
|
||||
ImageProcessorService.METHOD_COLOR_FILTER, result,
|
||||
ImageProcessorService.METHOD_FILTER, result,
|
||||
onIntent = {
|
||||
it.putExtra(ImageProcessorService.EXTRA_FILTERS, l)
|
||||
}
|
||||
|
@ -196,7 +196,7 @@ class ImageProcessorChannelHandler(context: Context) :
|
|||
result: MethodChannel.Result
|
||||
) {
|
||||
var img = Rgba8Image.fromJson(rgba8)
|
||||
for (f in filters.map(ColorFilter::fromJson)) {
|
||||
for (f in filters.map(ImageFilter::fromJson)) {
|
||||
img = f.apply(img)
|
||||
}
|
||||
result.success(img.toJson())
|
||||
|
@ -226,9 +226,9 @@ class ImageProcessorChannelHandler(context: Context) :
|
|||
private var eventSink: EventChannel.EventSink? = null
|
||||
}
|
||||
|
||||
interface ColorFilter {
|
||||
interface ImageFilter {
|
||||
companion object {
|
||||
fun fromJson(json: Map<String, Any>): ColorFilter {
|
||||
fun fromJson(json: Map<String, Any>): ImageFilter {
|
||||
return when (json["type"]) {
|
||||
"brightness" -> Brightness((json["weight"] as Double).toFloat())
|
||||
"contrast" -> Contrast((json["weight"] as Double).toFloat())
|
||||
|
|
|
@ -30,7 +30,7 @@ class ImageProcessorService : Service() {
|
|||
const val METHOD_DEEP_LAP_PORTRAIT = "DeepLab3Portrait"
|
||||
const val METHOD_ESRGAN = "Esrgan"
|
||||
const val METHOD_ARBITRARY_STYLE_TRANSFER = "ArbitraryStyleTransfer"
|
||||
const val METHOD_COLOR_FILTER = "ColorFilter"
|
||||
const val METHOD_FILTER = "Filter"
|
||||
const val EXTRA_FILE_URL = "fileUrl"
|
||||
const val EXTRA_HEADERS = "headers"
|
||||
const val EXTRA_FILENAME = "filename"
|
||||
|
@ -49,7 +49,7 @@ class ImageProcessorService : Service() {
|
|||
METHOD_ARBITRARY_STYLE_TRANSFER,
|
||||
)
|
||||
val EDIT_METHODS = listOf(
|
||||
METHOD_COLOR_FILTER,
|
||||
METHOD_FILTER,
|
||||
)
|
||||
|
||||
private const val ACTION_CANCEL = "cancel"
|
||||
|
@ -126,7 +126,7 @@ class ImageProcessorService : Service() {
|
|||
METHOD_ARBITRARY_STYLE_TRANSFER -> onArbitraryStyleTransfer(
|
||||
startId, intent.extras!!
|
||||
)
|
||||
METHOD_COLOR_FILTER -> onColorFilter(startId, intent.extras!!)
|
||||
METHOD_FILTER -> onFilter(startId, intent.extras!!)
|
||||
else -> {
|
||||
logE(TAG, "Unknown method: $method")
|
||||
// we can't call stopSelf here as it'll stop the service even if
|
||||
|
@ -170,12 +170,12 @@ class ImageProcessorService : Service() {
|
|||
)
|
||||
}
|
||||
|
||||
private fun onColorFilter(startId: Int, extras: Bundle) {
|
||||
private fun onFilter(startId: Int, extras: Bundle) {
|
||||
val filters = extras.getSerializable(EXTRA_FILTERS)!!
|
||||
.asType<ArrayList<Serializable>>()
|
||||
.map { it.asType<HashMap<String, Any>>() }
|
||||
return onMethod(
|
||||
startId, extras, METHOD_COLOR_FILTER,
|
||||
startId, extras, METHOD_FILTER,
|
||||
args = mapOf(
|
||||
"filters" to filters,
|
||||
)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.nkming.nc_photos.plugin.image_processor
|
||||
|
||||
import com.nkming.nc_photos.plugin.ColorFilter
|
||||
import com.nkming.nc_photos.plugin.ImageFilter
|
||||
|
||||
class BlackPoint(val weight: Float) : ColorFilter {
|
||||
class BlackPoint(val weight: Float) : ImageFilter {
|
||||
override fun apply(rgba8: Rgba8Image) = Rgba8Image(
|
||||
applyNative(rgba8.pixel, rgba8.width, rgba8.height, weight),
|
||||
rgba8.width, rgba8.height
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.nkming.nc_photos.plugin.image_processor
|
||||
|
||||
import com.nkming.nc_photos.plugin.ColorFilter
|
||||
import com.nkming.nc_photos.plugin.ImageFilter
|
||||
|
||||
class Brightness(val weight: Float) : ColorFilter {
|
||||
class Brightness(val weight: Float) : ImageFilter {
|
||||
override fun apply(rgba8: Rgba8Image) = Rgba8Image(
|
||||
applyNative(rgba8.pixel, rgba8.width, rgba8.height, weight),
|
||||
rgba8.width, rgba8.height
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.nkming.nc_photos.plugin.image_processor
|
||||
|
||||
import com.nkming.nc_photos.plugin.ColorFilter
|
||||
import com.nkming.nc_photos.plugin.ImageFilter
|
||||
|
||||
class Contrast(val weight: Float) : ColorFilter {
|
||||
class Contrast(val weight: Float) : ImageFilter {
|
||||
override fun apply(rgba8: Rgba8Image) = Rgba8Image(
|
||||
applyNative(rgba8.pixel, rgba8.width, rgba8.height, weight),
|
||||
rgba8.width, rgba8.height
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.nkming.nc_photos.plugin.image_processor
|
||||
|
||||
import com.nkming.nc_photos.plugin.ColorFilter
|
||||
import com.nkming.nc_photos.plugin.ImageFilter
|
||||
|
||||
class Cool(val weight: Float) : ColorFilter {
|
||||
class Cool(val weight: Float) : ImageFilter {
|
||||
override fun apply(rgba8: Rgba8Image) = Rgba8Image(
|
||||
applyNative(rgba8.pixel, rgba8.width, rgba8.height, weight),
|
||||
rgba8.width, rgba8.height
|
||||
|
|
|
@ -5,15 +5,15 @@ import android.graphics.Bitmap
|
|||
import android.net.Uri
|
||||
import com.nkming.nc_photos.plugin.BitmapResizeMethod
|
||||
import com.nkming.nc_photos.plugin.BitmapUtil
|
||||
import com.nkming.nc_photos.plugin.ColorFilter
|
||||
import com.nkming.nc_photos.plugin.ImageFilter
|
||||
import com.nkming.nc_photos.plugin.use
|
||||
|
||||
class ColorFilterProcessor(
|
||||
class ImageFilterProcessor(
|
||||
context: Context, maxWidth: Int, maxHeight: Int,
|
||||
filters: List<Map<String, Any>>
|
||||
) {
|
||||
companion object {
|
||||
const val TAG = "ColorFilterProcessor"
|
||||
const val TAG = "ImageFilterProcessor"
|
||||
}
|
||||
|
||||
fun apply(imageUri: Uri): Bitmap {
|
||||
|
@ -24,7 +24,7 @@ class ColorFilterProcessor(
|
|||
Rgba8Image(TfLiteHelper.bitmapToRgba8Array(it), it.width, it.height)
|
||||
}
|
||||
|
||||
for (f in filters.map(ColorFilter::fromJson)) {
|
||||
for (f in filters.map(ImageFilter::fromJson)) {
|
||||
img = f.apply(img)
|
||||
}
|
||||
return img.toBitmap()
|
|
@ -1,8 +1,8 @@
|
|||
package com.nkming.nc_photos.plugin.image_processor
|
||||
|
||||
import com.nkming.nc_photos.plugin.ColorFilter
|
||||
import com.nkming.nc_photos.plugin.ImageFilter
|
||||
|
||||
class Saturation(val weight: Float) : ColorFilter {
|
||||
class Saturation(val weight: Float) : ImageFilter {
|
||||
override fun apply(rgba8: Rgba8Image) = Rgba8Image(
|
||||
applyNative(rgba8.pixel, rgba8.width, rgba8.height, weight),
|
||||
rgba8.width, rgba8.height
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.nkming.nc_photos.plugin.image_processor
|
||||
|
||||
import com.nkming.nc_photos.plugin.ColorFilter
|
||||
import com.nkming.nc_photos.plugin.ImageFilter
|
||||
|
||||
class Tint(val weight: Float) : ColorFilter {
|
||||
class Tint(val weight: Float) : ImageFilter {
|
||||
override fun apply(rgba8: Rgba8Image) = Rgba8Image(
|
||||
applyNative(rgba8.pixel, rgba8.width, rgba8.height, weight),
|
||||
rgba8.width, rgba8.height
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.nkming.nc_photos.plugin.image_processor
|
||||
|
||||
import com.nkming.nc_photos.plugin.ColorFilter
|
||||
import com.nkming.nc_photos.plugin.ImageFilter
|
||||
|
||||
class Warmth(val weight: Float) : ColorFilter {
|
||||
class Warmth(val weight: Float) : ImageFilter {
|
||||
override fun apply(rgba8: Rgba8Image) = Rgba8Image(
|
||||
applyNative(rgba8.pixel, rgba8.width, rgba8.height, weight),
|
||||
rgba8.width, rgba8.height
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.nkming.nc_photos.plugin.image_processor
|
||||
|
||||
import com.nkming.nc_photos.plugin.ColorFilter
|
||||
import com.nkming.nc_photos.plugin.ImageFilter
|
||||
|
||||
class WhitePoint(val weight: Float) : ColorFilter {
|
||||
class WhitePoint(val weight: Float) : ImageFilter {
|
||||
override fun apply(rgba8: Rgba8Image) = Rgba8Image(
|
||||
applyNative(rgba8.pixel, rgba8.width, rgba8.height, weight),
|
||||
rgba8.width, rgba8.height
|
||||
|
|
|
@ -113,7 +113,7 @@ class ImageProcessor {
|
|||
"weight": weight,
|
||||
});
|
||||
|
||||
static Future<void> colorFilter(
|
||||
static Future<void> filter(
|
||||
String fileUrl,
|
||||
String filename,
|
||||
int maxWidth,
|
||||
|
@ -121,7 +121,7 @@ class ImageProcessor {
|
|||
List<ImageFilter> filters, {
|
||||
Map<String, String>? headers,
|
||||
}) =>
|
||||
_methodChannel.invokeMethod("colorFilter", <String, dynamic>{
|
||||
_methodChannel.invokeMethod("filter", <String, dynamic>{
|
||||
"fileUrl": fileUrl,
|
||||
"headers": headers,
|
||||
"filename": filename,
|
||||
|
|
Loading…
Reference in a new issue