From 0fec532ebe12bf6a7152f3253f97b1b5d907de98 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Mon, 11 Sep 2023 16:00:23 -0700 Subject: [PATCH] Add API exports for MPMask and MPImage PiperOrigin-RevId: 564527405 --- mediapipe/tasks/web/vision/core/image.ts | 22 +++++++++++++++++++--- mediapipe/tasks/web/vision/core/mask.ts | 22 +++++++++++++++++++--- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/mediapipe/tasks/web/vision/core/image.ts b/mediapipe/tasks/web/vision/core/image.ts index 9a5d0de8..570d3231 100644 --- a/mediapipe/tasks/web/vision/core/image.ts +++ b/mediapipe/tasks/web/vision/core/image.ts @@ -84,17 +84,26 @@ export class MPImage { } } - /** Returns whether this `MPImage` contains a mask of type `ImageData`. */ + /** + * Returns whether this `MPImage` contains a mask of type `ImageData`. + * @export + */ hasImageData(): boolean { return !!this.getContainer(MPImageType.IMAGE_DATA); } - /** Returns whether this `MPImage` contains a mask of type `ImageBitmap`. */ + /** + * Returns whether this `MPImage` contains a mask of type `ImageBitmap`. + * @export + */ hasImageBitmap(): boolean { return !!this.getContainer(MPImageType.IMAGE_BITMAP); } - /** Returns whether this `MPImage` contains a mask of type `WebGLTexture`. */ + /** + * Returns whether this `MPImage` contains a mask of type `WebGLTexture`. + * @export + */ hasWebGLTexture(): boolean { return !!this.getContainer(MPImageType.WEBGL_TEXTURE); } @@ -104,6 +113,7 @@ export class MPImage { * involves an expensive GPU to CPU transfer if the current image is only * available as an `ImageBitmap` or `WebGLTexture`. * + * @export * @return The current image as an ImageData object. */ getAsImageData(): ImageData { @@ -120,6 +130,7 @@ export class MPImage { * https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/getContext * for a list of supported platforms. * + * @export * @return The current image as an ImageBitmap object. */ getAsImageBitmap(): ImageBitmap { @@ -132,6 +143,7 @@ export class MPImage { * an `ImageData` object. The returned texture is bound to the current * canvas (see `.canvas`). * + * @export * @return The current image as a WebGLTexture. */ getAsWebGLTexture(): WebGLTexture { @@ -166,6 +178,8 @@ export class MPImage { * Task. Note that performance critical applications should aim to only use * the `MPImage` within the MediaPipe Task callback so that copies can be * avoided. + * + * @export */ clone(): MPImage { const destinationContainers: MPImageContainer[] = []; @@ -410,6 +424,8 @@ export class MPImage { * Task, as these are freed automatically once you leave the MediaPipe * callback. Additionally, some shared state is freed only once you invoke the * Task's `close()` method. + * + * @export */ close(): void { if (this.ownsImageBitmap) { diff --git a/mediapipe/tasks/web/vision/core/mask.ts b/mediapipe/tasks/web/vision/core/mask.ts index 396f8cc8..6ef85250 100644 --- a/mediapipe/tasks/web/vision/core/mask.ts +++ b/mediapipe/tasks/web/vision/core/mask.ts @@ -84,17 +84,26 @@ export class MPMask { } } - /** Returns whether this `MPMask` contains a mask of type `Uint8Array`. */ + /** + * Returns whether this `MPMask` contains a mask of type `Uint8Array`. + * @export + */ hasUint8Array(): boolean { return !!this.getContainer(MPMaskType.UINT8_ARRAY); } - /** Returns whether this `MPMask` contains a mask of type `Float32Array`. */ + /** + * Returns whether this `MPMask` contains a mask of type `Float32Array`. + * @export + */ hasFloat32Array(): boolean { return !!this.getContainer(MPMaskType.FLOAT32_ARRAY); } - /** Returns whether this `MPMask` contains a mask of type `WebGLTexture`. */ + /** + * Returns whether this `MPMask` contains a mask of type `WebGLTexture`. + * @export + */ hasWebGLTexture(): boolean { return !!this.getContainer(MPMaskType.WEBGL_TEXTURE); } @@ -104,6 +113,7 @@ export class MPMask { * expensive GPU to CPU transfer if the current mask is only available as a * `WebGLTexture`. * + * @export * @return The current data as a Uint8Array. */ getAsUint8Array(): Uint8Array { @@ -115,6 +125,7 @@ export class MPMask { * this involves an expensive GPU to CPU transfer if the current mask is * only available as a `WebGLTexture`. * + * @export * @return The current mask as a Float32Array. */ getAsFloat32Array(): Float32Array { @@ -127,6 +138,7 @@ export class MPMask { * a CPU array. The returned texture is bound to the current canvas (see * `.canvas`). * + * @export * @return The current mask as a WebGLTexture. */ getAsWebGLTexture(): WebGLTexture { @@ -182,6 +194,8 @@ export class MPMask { * MediaPipe Task. Note that performance critical applications should aim to * only use the `MPMask` within the MediaPipe Task callback so that * copies can be avoided. + * + * @export */ clone(): MPMask { const destinationContainers: MPMaskContainer[] = []; @@ -375,6 +389,8 @@ export class MPMask { * Task, as these are freed automatically once you leave the MediaPipe * callback. Additionally, some shared state is freed only once you invoke * the Task's `close()` method. + * + * @export */ close(): void { if (this.ownsWebGLTexture) {