expo-background-remover 0.2.0 → 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.
@@ -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.0'
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.0"
40
+ versionName "0.2.3"
41
41
  }
42
42
  lintOptions {
43
43
  abortOnError false
@@ -13,6 +13,8 @@ import kotlinx.coroutines.withContext
13
13
  import java.io.File
14
14
  import java.io.FileOutputStream
15
15
  import java.util.UUID
16
+ import android.graphics.PorterDuff
17
+ import android.graphics.PorterDuffXfermode
16
18
 
17
19
  class BackgroundRemoverProcessor(private val context: Context) {
18
20
 
@@ -33,10 +35,9 @@ class BackgroundRemoverProcessor(private val context: Context) {
33
35
  val maskBuffer = result.foregroundConfidenceMask
34
36
  ?: throw Exception("Could not detect subjects")
35
37
 
36
- // FIX 2: Use bitmap dimensions (result does not have width/height)
37
- val totalPixels = maskBuffer.remaining()
38
+ // The mask is guaranteed to match the input bitmap size.
38
39
  val maskWidth = bitmap.width
39
- val maskHeight = totalPixels / maskWidth
40
+ val maskHeight = bitmap.height
40
41
 
41
42
  val maskBitmap = createMaskFromBuffer(maskBuffer, maskWidth, maskHeight)
42
43
  val outputBitmap = applyMaskToBitmap(bitmap, maskBitmap)
@@ -3,6 +3,7 @@ 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
+
6
7
 
7
8
  class ExpoBackgroundRemoverModule : Module() {
8
9
  // Each module class must implement the definition function. The definition consists of components
@@ -28,14 +29,18 @@ class ExpoBackgroundRemoverModule : Module() {
28
29
  }
29
30
 
30
31
  AsyncFunction("removeBackgroundAsync") { imageUri: String ->
31
- val processor = BackgroundRemoverProcessor(appContext.reactContext!!)
32
+ // 1. Get the context safely
33
+ val context = appContext.reactContext ?: throw Exception("Context not available")
34
+ val processor = BackgroundRemoverProcessor(context)
32
35
 
33
- try {
34
- return@AsyncFunction processor.processImage(imageUri)
35
- } finally {
36
- processor.close() //ensure cleanup
37
- }
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()
38
42
  }
43
+ }
39
44
 
40
45
 
41
46
  // 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.0",
3
+ "version": "0.2.3",
4
4
  "description": "Expo Module For High Quality Background Remover",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",