expo-background-remover 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/android/build.gradle
CHANGED
|
@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
|
|
|
2
2
|
apply plugin: 'kotlin-android'
|
|
3
3
|
|
|
4
4
|
group = 'expo.modules.backgroundremover'
|
|
5
|
-
version = '0.2.
|
|
5
|
+
version = '0.2.3'
|
|
6
6
|
|
|
7
7
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
8
8
|
apply from: expoModulesCorePlugin
|
|
@@ -37,7 +37,7 @@ android {
|
|
|
37
37
|
namespace "expo.modules.backgroundremover"
|
|
38
38
|
defaultConfig {
|
|
39
39
|
versionCode 1
|
|
40
|
-
versionName "0.2.
|
|
40
|
+
versionName "0.2.3"
|
|
41
41
|
}
|
|
42
42
|
lintOptions {
|
|
43
43
|
abortOnError false
|
|
@@ -35,10 +35,9 @@ class BackgroundRemoverProcessor(private val context: Context) {
|
|
|
35
35
|
val maskBuffer = result.foregroundConfidenceMask
|
|
36
36
|
?: throw Exception("Could not detect subjects")
|
|
37
37
|
|
|
38
|
-
//
|
|
39
|
-
val totalPixels = maskBuffer.remaining()
|
|
38
|
+
// The mask is guaranteed to match the input bitmap size.
|
|
40
39
|
val maskWidth = bitmap.width
|
|
41
|
-
val maskHeight =
|
|
40
|
+
val maskHeight = bitmap.height
|
|
42
41
|
|
|
43
42
|
val maskBitmap = createMaskFromBuffer(maskBuffer, maskWidth, maskHeight)
|
|
44
43
|
val outputBitmap = applyMaskToBitmap(bitmap, maskBitmap)
|
|
@@ -29,14 +29,18 @@ class ExpoBackgroundRemoverModule : Module() {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
AsyncFunction("removeBackgroundAsync") { imageUri: String ->
|
|
32
|
-
|
|
32
|
+
// 1. Get the context safely
|
|
33
|
+
val context = appContext.reactContext ?: throw Exception("Context not available")
|
|
34
|
+
val processor = BackgroundRemoverProcessor(context)
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
// 2. Simply call the suspend function.
|
|
37
|
+
// Expo's AsyncFunction supports 'suspend' naturally.
|
|
38
|
+
try {
|
|
39
|
+
processor.processImage(imageUri)
|
|
40
|
+
} finally {
|
|
41
|
+
processor.close()
|
|
39
42
|
}
|
|
43
|
+
}
|
|
40
44
|
|
|
41
45
|
|
|
42
46
|
// Defines a JavaScript function that always returns a Promise and whose native code
|