gossamer/uint8_clamped_array

Types

A typed array of 8-bit unsigned integers, clamped to 0255 on write (rather than wrapped). Useful for image pixel data where values should saturate at the boundaries.

See Uint8ClampedArray on MDN.

pub type Uint8ClampedArray

Values

pub fn at(
  array: Uint8ClampedArray,
  index index: Int,
) -> Result(Int, Nil)

Returns the element at index, or Error(Nil) if the index is out of range. Negative indices count from the end.

pub fn byte_length(of array: Uint8ClampedArray) -> Int
pub fn byte_offset(of array: Uint8ClampedArray) -> Int
pub fn fill(
  array: Uint8ClampedArray,
  with value: Int,
) -> Uint8ClampedArray
pub fn from_length(
  length: Int,
) -> Result(Uint8ClampedArray, js_error.JsError)

Creates a zero-filled Uint8ClampedArray of the given length. Returns an error if length is negative or exceeds the maximum allocatable size.

pub fn from_list(list: List(Int)) -> Uint8ClampedArray

Creates a Uint8ClampedArray from a list of byte values. Values outside 0255 are clamped to that range (negative values become 0, values above 255 become 255), unlike Uint8Array which wraps modulo 256.

pub fn includes(
  in array: Uint8ClampedArray,
  value value: Int,
) -> Bool
pub fn index_of(
  in array: Uint8ClampedArray,
  value value: Int,
) -> Result(Int, Nil)

Returns the first index of value, or Error(Nil) if not present.

pub fn last_index_of(
  in array: Uint8ClampedArray,
  value value: Int,
) -> Result(Int, Nil)

Returns the last index of value, or Error(Nil) if not present.

pub fn length(of array: Uint8ClampedArray) -> Int
pub fn set(
  in array: Uint8ClampedArray,
  values values: Uint8ClampedArray,
) -> Result(Nil, js_error.JsError)

Copies values into array starting at index 0. Returns an error if values would extend past the end of array.

pub fn set_with_offset(
  in array: Uint8ClampedArray,
  values values: Uint8ClampedArray,
  offset offset: Int,
) -> Result(Nil, js_error.JsError)

Copies values into array starting at offset. Returns an error if offset is negative or the copy would extend past the end of array.

pub fn slice_range(
  array: Uint8ClampedArray,
  from start: Int,
  to end: Int,
) -> Uint8ClampedArray
pub fn subarray(
  array: Uint8ClampedArray,
  from begin: Int,
  to end: Int,
) -> Uint8ClampedArray
pub fn to_list(array: Uint8ClampedArray) -> List(Int)
pub fn with(
  array: Uint8ClampedArray,
  at_index index: Int,
  value value: Int,
) -> Result(Uint8ClampedArray, js_error.JsError)

Returns a copy of array with the value at index replaced. Negative indices count from the end. Returns an error if index is out of range.

Search Document