Function resliceBufferWithPadding

  • Creates a new buffer while removing any unnecessary empty bytes. Useful for when wanting to save an image as a specific format.

    Parameters

    • buffer: Uint8Array

      The buffer to reslice.

    • width: number

      The width of the output buffer.

    • height: number

      The height of the output buffer.

    Returns Uint8Array

    The resliced buffer.

    import { resliceBufferWithPadding } from "@std/webgpu/row-padding";
    import { assertEquals } from "@std/assert";

    const input = new Uint8Array([0, 255, 0, 255, 120, 120, 120]);
    const result = resliceBufferWithPadding(input, 1, 1);

    assertEquals(result, new Uint8Array([0, 255, 0, 255]));