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

Hierarchy (View Summary)

Constructors

  • Parameters

    • Optionalname: string = "TextureCompressor"

      The worker name to be initialized

    • Optionalconfig: { controlHash?: boolean; debug?: boolean } = {}

      Worker initialization options

      • OptionalcontrolHash?: boolean

        Should use control hash?

      • Optionaldebug?: boolean

        Should the worker run in debug mode?

    Returns TextureCompressor

Properties

name: string

The name of this worker.

WORKER_HARNESS_JS: string = "scripts/worker.js"

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

Accessors

  • get ready(): Promise<any>

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

    Returns Promise<any>

Methods

  • 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.

    • Optionaloptions: { debug?: boolean; hash?: string } = {}
      • Optionaldebug?: boolean

        The debug option.

      • Optionalhash?: string

        The precomputed hash.

    Returns Promise<any>

  • Copy a buffer.

    Parameters

    • buffer: Uint8ClampedArray

      Buffer used to create the image data.

    • Optionaloptions: { debug?: boolean; hash?: string; out?: ArrayBuffer } = {}
      • Optionaldebug?: boolean

        The debug option.

      • Optionalhash?: string

        The precomputed hash.

      • Optionalout?: ArrayBuffer

        The output buffer to copy the pixels to. May be detached.

    Returns 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.

    • Optionalargs: any[] = []

      An array of parameters with which to call the requested function

    • Optionaltransfer: 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.

  • 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.

    • Optionaloptions: { debug?: boolean; hash?: string; out?: ArrayBuffer } = {}
      • Optionaldebug?: boolean

        The debug option.

      • Optionalhash?: string

        The precomputed hash.

      • Optionalout?: ArrayBuffer

        The output buffer to write the expanded pixels to. May be detached.

    Returns 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.

  • 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.

    • Optionaloptions: { debug?: boolean; hash?: string; out?: ArrayBuffer } = {}
      • Optionaldebug?: boolean

        The debug option.

      • Optionalhash?: string

        The precomputed hash.

      • Optionalout?: ArrayBuffer

        The output buffer to write the reduced pixels to. May be detached.

    Returns Promise<unknown>