Skip to content

Commit

Permalink
Add API exports for MPMask and MPImage
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 564527405
  • Loading branch information
schmidt-sebastian authored and copybara-github committed Sep 11, 2023
1 parent 56c26db commit 0fec532
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
22 changes: 19 additions & 3 deletions mediapipe/tasks/web/vision/core/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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[] = [];
Expand Down Expand Up @@ -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) {
Expand Down
22 changes: 19 additions & 3 deletions mediapipe/tasks/web/vision/core/mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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[] = [];
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 0fec532

Please sign in to comment.