Options
All
  • Public
  • Public/Protected
  • All
Menu

Wrapper for a web worker meant to convert a pixel buffer to the specified image format and quality and return a base64 image

param name

The worker name to be initialized

param [config={}]

Worker initialization options

param [config.debug=false]

Should the worker run in debug mode?

Hierarchy

Index

Constructors

Methods

  • compressBufferBase64(buffer: Uint8ClampedArray, width: number, height: number, options?: { type: string; quality: number; debug: boolean }): Promise<any>
  • Process the non-blocking image compression to a base64 string.

    Parameters

    • buffer: Uint8ClampedArray

      Buffer used to create the image data.

    • width: number

      Buffered image width.

    • height: number

      Buffered image height.

    • options: { type: string; quality: number; debug: boolean } = {}
      • type: string
      • quality: number
      • debug: boolean

    Returns Promise<any>

  • expandBufferRedToBufferRGBA(buffer: Uint8ClampedArray, width: number, height: number, options?: { debug: boolean }): Promise<any>
  • Expand a buffer in RED format to a buffer in RGBA format.

    Parameters

    • buffer: Uint8ClampedArray

      Buffer used to create the image data.

    • width: number

      Buffered image width.

    • height: number

      Buffered image height.

    • options: { debug: boolean } = {}
      • debug: boolean

    Returns Promise<any>

  • reduceBufferRGBAToBufferRED(buffer: Uint8ClampedArray, width: number, height: number, options?: { debug: boolean }): Promise<any>
  • Reduce a buffer in RGBA format to a buffer in RED format.

    Parameters

    • buffer: Uint8ClampedArray

      Buffer used to create the image data.

    • width: number

      Buffered image width.

    • height: number

      Buffered image height.

    • options: { debug: boolean } = {}
      • debug: boolean

    Returns Promise<any>

  • loadFunction(functionName: string, functionRef: Function): Promise<unknown>
  • Load a function onto a given Worker. The function must be a pure function with no external dependencies or requirements on global scope.

    Parameters

    • functionName: string

      The name of the function to load

    • functionRef: Function

      A reference to the function that should be loaded

    Returns Promise<unknown>

    A Promise which resolves once the Worker has loaded the function.

  • executeFunction(functionName: string, args?: any[], transfer?: any[]): Promise<unknown>
  • Execute a task on a specific Worker.

    Parameters

    • functionName: string

      The named function to execute on the worker. This function must first have been loaded.

    • args: any[] = []

      An array of parameters with which to call the requested function

    • transfer: any[] = []

      An array of transferable objects which are transferred to the worker thread. See https://developer.mozilla.org/en-US/docs/Glossary/Transferable_objects

    Returns Promise<unknown>

    A Promise which resolves with the returned result of the function once complete.

  • #onMessage(event: MessageEvent<any>): any
  • Handle messages emitted by the Worker thread.

    Parameters

    • event: MessageEvent<any>

      The dispatched message event

    Returns any

  • #onError(error: ErrorEvent): void
  • Handle errors emitted by the Worker thread.

    Parameters

    • error: ErrorEvent

      The dispatched error event

    Returns void

Properties

name: any
ready: Promise<any>

A Promise which resolves once the Worker is ready to accept tasks

tasks: Map<number, Object> = ...

A queue of active tasks that this Worker is executing.

#controlHash: boolean

Boolean to know if the texture compressor should control the hash.

#textureHash: string = ""

Previous texture hash.

#taskIndex: number = 0

An auto-incrementing task index.

WORKER_HARNESS_JS: string = "scripts/worker.js"

A path reference to the JavaScript file which provides companion worker-side functionality.