expo-background-remover 0.2.2 → 0.2.9

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.
@@ -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.2'
5
+ version = '0.2.9'
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.2"
40
+ versionName "0.2.9"
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
- // FIX 2: Use bitmap dimensions (result does not have width/height)
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 = totalPixels / maskWidth
40
+ val maskHeight = bitmap.height
42
41
 
43
42
  val maskBitmap = createMaskFromBuffer(maskBuffer, maskWidth, maskHeight)
44
43
  val outputBitmap = applyMaskToBitmap(bitmap, maskBitmap)
@@ -3,6 +3,8 @@ package expo.modules.backgroundremover
3
3
  import expo.modules.kotlin.modules.Module
4
4
  import expo.modules.kotlin.modules.ModuleDefinition
5
5
  import java.net.URL
6
+ import kotlinx.coroutines.Dispatchers
7
+ import kotlinx.coroutines.withContext
6
8
 
7
9
 
8
10
  class ExpoBackgroundRemoverModule : Module() {
@@ -28,15 +30,22 @@ class ExpoBackgroundRemoverModule : Module() {
28
30
  "Hello world! 👋"
29
31
  }
30
32
 
31
- AsyncFunction("removeBackgroundAsync") { imageUri: String ->
32
- val processor = BackgroundRemoverProcessor(appContext.reactContext!!)
33
+
33
34
 
34
- try {
35
- return@AsyncFunction processor.processImage(imageUri)
36
- } finally {
37
- processor.close() //ensure cleanup
38
- }
39
- }
35
+ AsyncFunction("removeBackgroundAsync") { imageUri: String ->
36
+ val context = appContext.reactContext
37
+ ?: throw Exception("Context not available")
38
+
39
+ val processor = BackgroundRemoverProcessor(context)
40
+
41
+ try {
42
+ return@AsyncFunction withContext(Dispatchers.IO) {
43
+ processor.processImage(imageUri)
44
+ }
45
+ } finally {
46
+ processor.close()
47
+ }
48
+ }
40
49
 
41
50
 
42
51
  // Defines a JavaScript function that always returns a Promise and whose native code
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-background-remover",
3
- "version": "0.2.2",
3
+ "version": "0.2.9",
4
4
  "description": "Expo Module For High Quality Background Remover",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",