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 { hasImageData(): boolean {
return !!this.getContainer(MPImageType.IMAGE_DATA); 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 { hasImageBitmap(): boolean {
return !!this.getContainer(MPImageType.IMAGE_BITMAP); 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 { hasWebGLTexture(): boolean {
return !!this.getContainer(MPImageType.WEBGL_TEXTURE); 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 * involves an expensive GPU to CPU transfer if the current image is only
* available as an `ImageBitmap` or `WebGLTexture`. * available as an `ImageBitmap` or `WebGLTexture`.
* *
* @export
* @return The current image as an ImageData object. * @return The current image as an ImageData object.
*/ */
getAsImageData(): ImageData { getAsImageData(): ImageData {
@ -120,6 +130,7 @@ export class MPImage {
* https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/getContext * https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/getContext
* for a list of supported platforms. * for a list of supported platforms.
* *
* @export
* @return The current image as an ImageBitmap object. * @return The current image as an ImageBitmap object.
*/ */
getAsImageBitmap(): ImageBitmap { getAsImageBitmap(): ImageBitmap {
@ -132,6 +143,7 @@ export class MPImage {
* an `ImageData` object. The returned texture is bound to the current * an `ImageData` object. The returned texture is bound to the current
* canvas (see `.canvas`). * canvas (see `.canvas`).
* *
* @export
* @return The current image as a WebGLTexture. * @return The current image as a WebGLTexture.
*/ */
getAsWebGLTexture(): WebGLTexture { getAsWebGLTexture(): WebGLTexture {
@ -166,6 +178,8 @@ export class MPImage {
* Task. Note that performance critical applications should aim to only use * Task. Note that performance critical applications should aim to only use
* the `MPImage` within the MediaPipe Task callback so that copies can be * the `MPImage` within the MediaPipe Task callback so that copies can be
* avoided. * avoided.
*
* @export
*/ */
clone(): MPImage { clone(): MPImage {
const destinationContainers: MPImageContainer[] = []; const destinationContainers: MPImageContainer[] = [];
@ -410,6 +424,8 @@ export class MPImage {
* Task, as these are freed automatically once you leave the MediaPipe * Task, as these are freed automatically once you leave the MediaPipe
* callback. Additionally, some shared state is freed only once you invoke the * callback. Additionally, some shared state is freed only once you invoke the
* Task's `close()` method. * Task's `close()` method.
*
* @export
*/ */
close(): void { close(): void {
if (this.ownsImageBitmap) { 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 { hasUint8Array(): boolean {
return !!this.getContainer(MPMaskType.UINT8_ARRAY); 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 { hasFloat32Array(): boolean {
return !!this.getContainer(MPMaskType.FLOAT32_ARRAY); 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 { hasWebGLTexture(): boolean {
return !!this.getContainer(MPMaskType.WEBGL_TEXTURE); 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 * expensive GPU to CPU transfer if the current mask is only available as a
* `WebGLTexture`. * `WebGLTexture`.
* *
* @export
* @return The current data as a Uint8Array. * @return The current data as a Uint8Array.
*/ */
getAsUint8Array(): Uint8Array { getAsUint8Array(): Uint8Array {
@ -115,6 +125,7 @@ export class MPMask {
* this involves an expensive GPU to CPU transfer if the current mask is * this involves an expensive GPU to CPU transfer if the current mask is
* only available as a `WebGLTexture`. * only available as a `WebGLTexture`.
* *
* @export
* @return The current mask as a Float32Array. * @return The current mask as a Float32Array.
*/ */
getAsFloat32Array(): Float32Array { getAsFloat32Array(): Float32Array {
@ -127,6 +138,7 @@ export class MPMask {
* a CPU array. The returned texture is bound to the current canvas (see * a CPU array. The returned texture is bound to the current canvas (see
* `.canvas`). * `.canvas`).
* *
* @export
* @return The current mask as a WebGLTexture. * @return The current mask as a WebGLTexture.
*/ */
getAsWebGLTexture(): WebGLTexture { getAsWebGLTexture(): WebGLTexture {
@ -182,6 +194,8 @@ export class MPMask {
* MediaPipe Task. Note that performance critical applications should aim to * MediaPipe Task. Note that performance critical applications should aim to
* only use the `MPMask` within the MediaPipe Task callback so that * only use the `MPMask` within the MediaPipe Task callback so that
* copies can be avoided. * copies can be avoided.
*
* @export
*/ */
clone(): MPMask { clone(): MPMask {
const destinationContainers: MPMaskContainer[] = []; const destinationContainers: MPMaskContainer[] = [];
@ -375,6 +389,8 @@ export class MPMask {
* Task, as these are freed automatically once you leave the MediaPipe * Task, as these are freed automatically once you leave the MediaPipe
* callback. Additionally, some shared state is freed only once you invoke * callback. Additionally, some shared state is freed only once you invoke
* the Task's `close()` method. * the Task's `close()` method.
*
* @export
*/ */
close(): void { close(): void {
if (this.ownsWebGLTexture) { if (this.ownsWebGLTexture) {