Add API exports for MPMask and MPImage

PiperOrigin-RevId: 564527405
This commit is contained in:
Sebastian Schmidt 2023-09-11 16:00:23 -07:00 committed by Copybara-Service
parent 56c26dba84
commit 0fec532ebe
2 changed files with 38 additions and 6 deletions

View File

@ -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) {

View File

@ -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) {