From a4f2fb0bce2b4545e590cb4bcadf8c3be3a67163 Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Tue, 6 Sep 2022 13:39:42 +0800 Subject: [PATCH] Rename color filter to filter to be more generic --- app/lib/widget/image_editor.dart | 2 +- .../plugin/ImageProcessorChannelHandler.kt | 14 +++++++------- .../nc_photos/plugin/ImageProcessorService.kt | 10 +++++----- .../nc_photos/plugin/image_processor/BlackPoint.kt | 4 ++-- .../nc_photos/plugin/image_processor/Brightness.kt | 4 ++-- .../nc_photos/plugin/image_processor/Contrast.kt | 4 ++-- .../nc_photos/plugin/image_processor/Cool.kt | 4 ++-- ...rFilterProcessor.kt => ImageFilterProcessor.kt} | 8 ++++---- .../nc_photos/plugin/image_processor/Saturation.kt | 4 ++-- .../nc_photos/plugin/image_processor/Tint.kt | 4 ++-- .../nc_photos/plugin/image_processor/Warmth.kt | 4 ++-- .../nc_photos/plugin/image_processor/WhitePoint.kt | 4 ++-- plugin/lib/src/image_processor.dart | 4 ++-- 13 files changed, 35 insertions(+), 35 deletions(-) rename plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/{ColorFilterProcessor.kt => ImageFilterProcessor.kt} (83%) diff --git a/app/lib/widget/image_editor.dart b/app/lib/widget/image_editor.dart index 3668f159..e87f6fc7 100644 --- a/app/lib/widget/image_editor.dart +++ b/app/lib/widget/image_editor.dart @@ -189,7 +189,7 @@ class _ImageEditorState extends State { } Future _onSavePressed(BuildContext context) async { - await ImageProcessor.colorFilter( + await ImageProcessor.filter( "${widget.account.url}/${widget.file.path}", widget.file.filename, 4096, diff --git a/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/ImageProcessorChannelHandler.kt b/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/ImageProcessorChannelHandler.kt index 9c6dab53..30c85dce 100644 --- a/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/ImageProcessorChannelHandler.kt +++ b/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/ImageProcessorChannelHandler.kt @@ -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?, filename: String, maxWidth: Int, maxHeight: Int, filters: List>, 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): ColorFilter { + fun fromJson(json: Map): ImageFilter { return when (json["type"]) { "brightness" -> Brightness((json["weight"] as Double).toFloat()) "contrast" -> Contrast((json["weight"] as Double).toFloat()) diff --git a/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/ImageProcessorService.kt b/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/ImageProcessorService.kt index 09abf16c..4891750a 100644 --- a/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/ImageProcessorService.kt +++ b/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/ImageProcessorService.kt @@ -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>() .map { it.asType>() } return onMethod( - startId, extras, METHOD_COLOR_FILTER, + startId, extras, METHOD_FILTER, args = mapOf( "filters" to filters, ) diff --git a/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/BlackPoint.kt b/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/BlackPoint.kt index 2b4f47f0..3e75fd9b 100644 --- a/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/BlackPoint.kt +++ b/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/BlackPoint.kt @@ -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 diff --git a/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Brightness.kt b/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Brightness.kt index 04174c2e..53c2a382 100644 --- a/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Brightness.kt +++ b/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Brightness.kt @@ -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 diff --git a/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Contrast.kt b/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Contrast.kt index 766fac6e..7b465f3f 100644 --- a/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Contrast.kt +++ b/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Contrast.kt @@ -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 diff --git a/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Cool.kt b/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Cool.kt index f844062f..d188524b 100644 --- a/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Cool.kt +++ b/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Cool.kt @@ -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 diff --git a/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/ColorFilterProcessor.kt b/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/ImageFilterProcessor.kt similarity index 83% rename from plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/ColorFilterProcessor.kt rename to plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/ImageFilterProcessor.kt index 2a50f770..7c5c4c2e 100644 --- a/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/ColorFilterProcessor.kt +++ b/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/ImageFilterProcessor.kt @@ -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> ) { 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() diff --git a/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Saturation.kt b/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Saturation.kt index 0569055f..08706686 100644 --- a/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Saturation.kt +++ b/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Saturation.kt @@ -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 diff --git a/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Tint.kt b/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Tint.kt index 41d7c26a..b07ac00e 100644 --- a/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Tint.kt +++ b/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Tint.kt @@ -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 diff --git a/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Warmth.kt b/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Warmth.kt index a9593c07..66ff5da8 100644 --- a/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Warmth.kt +++ b/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/Warmth.kt @@ -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 diff --git a/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/WhitePoint.kt b/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/WhitePoint.kt index 23751936..64d45b69 100644 --- a/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/WhitePoint.kt +++ b/plugin/android/src/main/kotlin/com/nkming/nc_photos/plugin/image_processor/WhitePoint.kt @@ -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 diff --git a/plugin/lib/src/image_processor.dart b/plugin/lib/src/image_processor.dart index 4720cb8a..6f6e61e6 100644 --- a/plugin/lib/src/image_processor.dart +++ b/plugin/lib/src/image_processor.dart @@ -113,7 +113,7 @@ class ImageProcessor { "weight": weight, }); - static Future colorFilter( + static Future filter( String fileUrl, String filename, int maxWidth, @@ -121,7 +121,7 @@ class ImageProcessor { List filters, { Map? headers, }) => - _methodChannel.invokeMethod("colorFilter", { + _methodChannel.invokeMethod("filter", { "fileUrl": fileUrl, "headers": headers, "filename": filename,