@capacitor-mlkit/selfie-segmentation 7.0.0-next.2 → 7.0.0-next.4

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.
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
11
11
  s.author = package['author']
12
12
  s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
13
  s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
- s.ios.deployment_target = '13.0'
14
+ s.ios.deployment_target = '14.0'
15
15
  s.dependency 'Capacitor'
16
16
  s.dependency 'GoogleMLKit/SegmentationSelfie', '7.0.0'
17
17
  s.swift_version = '5.1'
package/README.md CHANGED
@@ -5,19 +5,17 @@ Unofficial Capacitor plugin for [ML Kit Selfie Segmentation](https://developers.
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @capacitor-mlkit/selfie-segmentation@next
8
+ npm install @capacitor-mlkit/selfie-segmentation
9
9
  npx cap sync
10
10
  ```
11
11
 
12
- **Attention**: Please use the `next` tag to install the latest version of the plugin due to issue [#179](https://github.com/capawesome-team/capacitor-mlkit/pull/179).
13
-
14
12
  ### Android
15
13
 
16
14
  #### Variables
17
15
 
18
16
  This plugin will use the following project variables (defined in your app’s `variables.gradle` file):
19
17
 
20
- - `$mlkitSelfieSegmentationVersion` version of `com.google.mlkit:segmentation-selfie` (default: `16.0.0-beta4`)
18
+ - `$mlkitSelfieSegmentationVersion` version of `com.google.mlkit:segmentation-selfie` (default: `16.0.0-beta6`)
21
19
 
22
20
  ### iOS
23
21
 
@@ -1,9 +1,9 @@
1
1
  ext {
2
2
  junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
- androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
4
- androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
5
- androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
6
- mlkitSelfieSegmentationVersion = project.hasProperty('mlkitSelfieSegmentationVersion') ? rootProject.ext.mlkitSelfieSegmentationVersion : '16.0.0-beta5'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
6
+ mlkitSelfieSegmentationVersion = project.hasProperty('mlkitSelfieSegmentationVersion') ? rootProject.ext.mlkitSelfieSegmentationVersion : '16.0.0-beta6'
7
7
  }
8
8
 
9
9
  buildscript {
@@ -12,7 +12,7 @@ buildscript {
12
12
  mavenCentral()
13
13
  }
14
14
  dependencies {
15
- classpath 'com.android.tools.build:gradle:8.2.1'
15
+ classpath 'com.android.tools.build:gradle:8.7.2'
16
16
  }
17
17
  }
18
18
 
@@ -20,10 +20,10 @@ apply plugin: 'com.android.library'
20
20
 
21
21
  android {
22
22
  namespace "io.capawesome.capacitorjs.plugins.mlkit.selfiesegmentation"
23
- compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
23
+ compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
24
24
  defaultConfig {
25
- minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
26
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
25
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
26
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
27
27
  versionCode 1
28
28
  versionName "1.0"
29
29
  testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -38,8 +38,8 @@ android {
38
38
  abortOnError false
39
39
  }
40
40
  compileOptions {
41
- sourceCompatibility JavaVersion.VERSION_17
42
- targetCompatibility JavaVersion.VERSION_17
41
+ sourceCompatibility JavaVersion.VERSION_21
42
+ targetCompatibility JavaVersion.VERSION_21
43
43
  }
44
44
  }
45
45
 
@@ -50,83 +50,76 @@ public class SelfieSegmentation {
50
50
 
51
51
  plugin
52
52
  .getActivity()
53
- .runOnUiThread(
54
- () ->
55
- segmenter
56
- .process(inputImage)
57
- .addOnSuccessListener(
58
- segmentationMask -> {
59
- segmenter.close();
60
-
61
- ByteBuffer mask = segmentationMask.getBuffer();
62
-
63
- Bitmap bitmap = inputImage.getBitmapInternal();
64
- Objects.requireNonNull(bitmap).setHasAlpha(true);
65
-
66
- ByteBuffer pixels = ByteBuffer.allocateDirect(bitmap.getAllocationByteCount());
67
- bitmap.copyPixelsToBuffer(pixels);
68
-
69
- final boolean bigEndian = pixels.order() == ByteOrder.BIG_ENDIAN;
70
- final int ALPHA = bigEndian ? 3 : 0;
71
- final int RED = bigEndian ? 2 : 1;
72
- final int GREEN = bigEndian ? 1 : 2;
73
- final int BLUE = bigEndian ? 0 : 3;
74
-
75
- for (int i = 0; i < pixels.capacity() >> 2; i++) {
76
- float confidence = mask.getFloat();
77
-
78
- if (confidence >= threshold) {
79
- byte red = pixels.get((i << 2) + RED);
80
- byte green = pixels.get((i << 2) + GREEN);
81
- byte blue = pixels.get((i << 2) + BLUE);
82
-
83
- pixels.put((i << 2) + ALPHA, (byte) (0xff));
84
- pixels.put((i << 2) + RED, (byte) (red * confidence));
85
- pixels.put((i << 2) + GREEN, (byte) (green * confidence));
86
- pixels.put((i << 2) + BLUE, (byte) (blue * confidence));
87
- } else {
88
- pixels.putInt(i << 2, 0x00000000); // transparent
89
- }
90
- }
91
-
92
- bitmap.copyPixelsFromBuffer(pixels.rewind());
93
-
94
- // Create an image file name
95
- @SuppressLint("SimpleDateFormat")
96
- String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
97
- String imageFileName = "PNG_" + timeStamp + "_";
98
-
99
- try {
100
- File image = File.createTempFile(imageFileName, ".png");
101
-
102
- OutputStream stream = new FileOutputStream(image);
103
- bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
104
- stream.close();
105
-
106
- ProcessImageResult result = new ProcessImageResult(
107
- image.getAbsolutePath(),
108
- bitmap.getWidth(),
109
- bitmap.getHeight()
110
- );
111
-
112
- callback.success(result);
113
- } catch (Exception exception) {
114
- callback.error(exception);
115
- }
53
+ .runOnUiThread(() ->
54
+ segmenter
55
+ .process(inputImage)
56
+ .addOnSuccessListener(segmentationMask -> {
57
+ segmenter.close();
58
+
59
+ ByteBuffer mask = segmentationMask.getBuffer();
60
+
61
+ Bitmap bitmap = inputImage.getBitmapInternal();
62
+ Objects.requireNonNull(bitmap).setHasAlpha(true);
63
+
64
+ ByteBuffer pixels = ByteBuffer.allocateDirect(bitmap.getAllocationByteCount());
65
+ bitmap.copyPixelsToBuffer(pixels);
66
+
67
+ final boolean bigEndian = pixels.order() == ByteOrder.BIG_ENDIAN;
68
+ final int ALPHA = bigEndian ? 3 : 0;
69
+ final int RED = bigEndian ? 2 : 1;
70
+ final int GREEN = bigEndian ? 1 : 2;
71
+ final int BLUE = bigEndian ? 0 : 3;
72
+
73
+ for (int i = 0; i < pixels.capacity() >> 2; i++) {
74
+ float confidence = mask.getFloat();
75
+
76
+ if (confidence >= threshold) {
77
+ byte red = pixels.get((i << 2) + RED);
78
+ byte green = pixels.get((i << 2) + GREEN);
79
+ byte blue = pixels.get((i << 2) + BLUE);
80
+
81
+ pixels.put((i << 2) + ALPHA, (byte) (0xff));
82
+ pixels.put((i << 2) + RED, (byte) (red * confidence));
83
+ pixels.put((i << 2) + GREEN, (byte) (green * confidence));
84
+ pixels.put((i << 2) + BLUE, (byte) (blue * confidence));
85
+ } else {
86
+ pixels.putInt(i << 2, 0x00000000); // transparent
116
87
  }
117
- )
118
- .addOnCanceledListener(
119
- () -> {
120
- segmenter.close();
121
- callback.cancel();
122
- }
123
- )
124
- .addOnFailureListener(
125
- exception -> {
126
- segmenter.close();
127
- callback.error(exception);
128
- }
129
- )
88
+ }
89
+
90
+ bitmap.copyPixelsFromBuffer(pixels.rewind());
91
+
92
+ // Create an image file name
93
+ @SuppressLint("SimpleDateFormat")
94
+ String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
95
+ String imageFileName = "PNG_" + timeStamp + "_";
96
+
97
+ try {
98
+ File image = File.createTempFile(imageFileName, ".png");
99
+
100
+ OutputStream stream = new FileOutputStream(image);
101
+ bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
102
+ stream.close();
103
+
104
+ ProcessImageResult result = new ProcessImageResult(
105
+ image.getAbsolutePath(),
106
+ bitmap.getWidth(),
107
+ bitmap.getHeight()
108
+ );
109
+
110
+ callback.success(result);
111
+ } catch (Exception exception) {
112
+ callback.error(exception);
113
+ }
114
+ })
115
+ .addOnCanceledListener(() -> {
116
+ segmenter.close();
117
+ callback.cancel();
118
+ })
119
+ .addOnFailureListener(exception -> {
120
+ segmenter.close();
121
+ callback.error(exception);
122
+ })
130
123
  );
131
124
  }
132
125
  }
@@ -25,11 +25,12 @@ public class ProcessImageOptions {
25
25
  }
26
26
 
27
27
  private InputImage scaledImage(InputImage inputImage, Integer width, Integer height) {
28
- float scaleX = (width != null) ? width * 1f / inputImage.getWidth() : 0f;
29
- float scaleY = (height != null) ? height * 1f / inputImage.getHeight() : 0f;
28
+ float scaleX = (width != null) ? (width * 1f) / inputImage.getWidth() : 0f;
29
+ float scaleY = (height != null) ? (height * 1f) / inputImage.getHeight() : 0f;
30
30
 
31
31
  if (scaleX > 0f || scaleY > 0f) {
32
- if (scaleX > 0f && scaleY == 0f) scaleY = scaleX; else if (scaleY > 0f && scaleX == 0f) scaleX = scaleY;
32
+ if (scaleX > 0f && scaleY == 0f) scaleY = scaleX;
33
+ else if (scaleY > 0f && scaleX == 0f) scaleX = scaleY;
33
34
 
34
35
  return InputImage.fromBitmap(
35
36
  Bitmap.createScaledBitmap(
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var core = require('@capacitor/core');
6
4
 
7
5
  const SelfieSegmentation = core.registerPlugin('SelfieSegmentation', {
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst SelfieSegmentation = registerPlugin('SelfieSegmentation', {\n web: () => import('./web').then(m => new m.SelfieSegmentationWeb()),\n});\nexport * from './definitions';\nexport { SelfieSegmentation };\n//# sourceMappingURL=index.js.map","import { CapacitorException, ExceptionCode, WebPlugin } from '@capacitor/core';\nexport class SelfieSegmentationWeb extends WebPlugin {\n async processImage(_options) {\n throw this.createUnavailableException();\n }\n createUnavailableException() {\n return new CapacitorException('This Selfie Segmentation plugin method is not available on this platform.', ExceptionCode.Unavailable);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin","CapacitorException","ExceptionCode"],"mappings":";;;;;;AACK,MAAC,kBAAkB,GAAGA,mBAAc,CAAC,oBAAoB,EAAE;AAChE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,qBAAqB,EAAE,CAAC;AACvE,CAAC;;ACFM,MAAM,qBAAqB,SAASC,cAAS,CAAC;AACrD,IAAI,MAAM,YAAY,CAAC,QAAQ,EAAE;AACjC,QAAQ,MAAM,IAAI,CAAC,0BAA0B,EAAE,CAAC;AAChD,KAAK;AACL,IAAI,0BAA0B,GAAG;AACjC,QAAQ,OAAO,IAAIC,uBAAkB,CAAC,2EAA2E,EAAEC,kBAAa,CAAC,WAAW,CAAC,CAAC;AAC9I,KAAK;AACL;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst SelfieSegmentation = registerPlugin('SelfieSegmentation', {\n web: () => import('./web').then(m => new m.SelfieSegmentationWeb()),\n});\nexport * from './definitions';\nexport { SelfieSegmentation };\n//# sourceMappingURL=index.js.map","import { CapacitorException, ExceptionCode, WebPlugin } from '@capacitor/core';\nexport class SelfieSegmentationWeb extends WebPlugin {\n async processImage(_options) {\n throw this.createUnavailableException();\n }\n createUnavailableException() {\n return new CapacitorException('This Selfie Segmentation plugin method is not available on this platform.', ExceptionCode.Unavailable);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin","CapacitorException","ExceptionCode"],"mappings":";;;;AACK,MAAC,kBAAkB,GAAGA,mBAAc,CAAC,oBAAoB,EAAE;AAChE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,qBAAqB,EAAE,CAAC;AACvE,CAAC;;ACFM,MAAM,qBAAqB,SAASC,cAAS,CAAC;AACrD,IAAI,MAAM,YAAY,CAAC,QAAQ,EAAE;AACjC,QAAQ,MAAM,IAAI,CAAC,0BAA0B,EAAE;AAC/C;AACA,IAAI,0BAA0B,GAAG;AACjC,QAAQ,OAAO,IAAIC,uBAAkB,CAAC,2EAA2E,EAAEC,kBAAa,CAAC,WAAW,CAAC;AAC7I;AACA;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -21,8 +21,6 @@ var capacitorSelfieSegmentation = (function (exports, core) {
21
21
 
22
22
  exports.SelfieSegmentation = SelfieSegmentation;
23
23
 
24
- Object.defineProperty(exports, '__esModule', { value: true });
25
-
26
24
  return exports;
27
25
 
28
26
  })({}, capacitorExports);
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst SelfieSegmentation = registerPlugin('SelfieSegmentation', {\n web: () => import('./web').then(m => new m.SelfieSegmentationWeb()),\n});\nexport * from './definitions';\nexport { SelfieSegmentation };\n//# sourceMappingURL=index.js.map","import { CapacitorException, ExceptionCode, WebPlugin } from '@capacitor/core';\nexport class SelfieSegmentationWeb extends WebPlugin {\n async processImage(_options) {\n throw this.createUnavailableException();\n }\n createUnavailableException() {\n return new CapacitorException('This Selfie Segmentation plugin method is not available on this platform.', ExceptionCode.Unavailable);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin","CapacitorException","ExceptionCode"],"mappings":";;;AACK,UAAC,kBAAkB,GAAGA,mBAAc,CAAC,oBAAoB,EAAE;IAChE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,qBAAqB,EAAE,CAAC;IACvE,CAAC;;ICFM,MAAM,qBAAqB,SAASC,cAAS,CAAC;IACrD,IAAI,MAAM,YAAY,CAAC,QAAQ,EAAE;IACjC,QAAQ,MAAM,IAAI,CAAC,0BAA0B,EAAE,CAAC;IAChD,KAAK;IACL,IAAI,0BAA0B,GAAG;IACjC,QAAQ,OAAO,IAAIC,uBAAkB,CAAC,2EAA2E,EAAEC,kBAAa,CAAC,WAAW,CAAC,CAAC;IAC9I,KAAK;IACL;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst SelfieSegmentation = registerPlugin('SelfieSegmentation', {\n web: () => import('./web').then(m => new m.SelfieSegmentationWeb()),\n});\nexport * from './definitions';\nexport { SelfieSegmentation };\n//# sourceMappingURL=index.js.map","import { CapacitorException, ExceptionCode, WebPlugin } from '@capacitor/core';\nexport class SelfieSegmentationWeb extends WebPlugin {\n async processImage(_options) {\n throw this.createUnavailableException();\n }\n createUnavailableException() {\n return new CapacitorException('This Selfie Segmentation plugin method is not available on this platform.', ExceptionCode.Unavailable);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin","CapacitorException","ExceptionCode"],"mappings":";;;AACK,UAAC,kBAAkB,GAAGA,mBAAc,CAAC,oBAAoB,EAAE;IAChE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,qBAAqB,EAAE,CAAC;IACvE,CAAC;;ICFM,MAAM,qBAAqB,SAASC,cAAS,CAAC;IACrD,IAAI,MAAM,YAAY,CAAC,QAAQ,EAAE;IACjC,QAAQ,MAAM,IAAI,CAAC,0BAA0B,EAAE;IAC/C;IACA,IAAI,0BAA0B,GAAG;IACjC,QAAQ,OAAO,IAAIC,uBAAkB,CAAC,2EAA2E,EAAEC,kBAAa,CAAC,WAAW,CAAC;IAC7I;IACA;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor-mlkit/selfie-segmentation",
3
- "version": "7.0.0-next.2",
3
+ "version": "7.0.0-next.4",
4
4
  "description": "Capacitor plugin for ML Kit Selfie Segmentation.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -49,30 +49,30 @@
49
49
  "prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
50
50
  "swiftlint": "node-swiftlint",
51
51
  "docgen": "docgen --api SelfieSegmentationPlugin --output-readme README.md --output-json dist/docs.json",
52
- "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js",
52
+ "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
53
53
  "clean": "rimraf ./dist",
54
54
  "watch": "tsc --watch",
55
55
  "ios:pod:install": "cd ios && pod install --repo-update && cd ..",
56
56
  "prepublishOnly": "npm run build"
57
57
  },
58
58
  "devDependencies": {
59
- "@capacitor/android": "6.0.0",
60
- "@capacitor/cli": "6.0.0",
61
- "@capacitor/core": "6.0.0",
62
- "@capacitor/docgen": "0.2.1",
63
- "@capacitor/ios": "6.0.0",
64
- "@ionic/eslint-config": "0.3.0",
65
- "@ionic/swiftlint-config": "1.1.2",
66
- "eslint": "7.32.0",
67
- "prettier": "2.3.2",
68
- "prettier-plugin-java": "1.0.2",
69
- "rimraf": "3.0.2",
70
- "rollup": "2.77.2",
71
- "swiftlint": "1.0.1",
59
+ "@capacitor/android": "7.0.0",
60
+ "@capacitor/cli": "7.0.0",
61
+ "@capacitor/core": "7.0.0",
62
+ "@capacitor/docgen": "0.3.0",
63
+ "@capacitor/ios": "7.0.0",
64
+ "@ionic/eslint-config": "0.4.0",
65
+ "@ionic/swiftlint-config": "2.0.0",
66
+ "eslint": "8.57.0",
67
+ "prettier": "3.4.2",
68
+ "prettier-plugin-java": "2.6.7",
69
+ "rimraf": "6.0.1",
70
+ "rollup": "4.30.1",
71
+ "swiftlint": "2.0.0",
72
72
  "typescript": "4.1.5"
73
73
  },
74
74
  "peerDependencies": {
75
- "@capacitor/core": "^6.0.0"
75
+ "@capacitor/core": ">=7.0.0"
76
76
  },
77
77
  "swiftlint": "@ionic/swiftlint-config",
78
78
  "eslintConfig": {