Skip to content

Instantly share code, notes, and snippets.

@athas
Created April 29, 2020 20:57
Show Gist options
  • Select an option

  • Save athas/fb501348b0413c8b9c6109d873483728 to your computer and use it in GitHub Desktop.

Select an option

Save athas/fb501348b0413c8b9c6109d873483728 to your computer and use it in GitHub Desktop.
let get_keys_from_image [rows][cols] 'a 'b (f: (u8,u8) -> a -> b) (img: [rows][cols]a): []b =
let size = rows*cols
let n_r = \r -> (norm_to_u8 r rows)
let n_c = \c -> (norm_to_u8 c cols)
let xys = tabulate_2d rows cols (\r c -> (n_r r, n_c c)) |> flatten_to size
let img = flatten_to size img
in map2 (\a b -> f a b) xys img
let get_keys_from_lum_image =
get_keys_from_image (\(x, y) lum -> u8s_encoded_3d [x, y, lum])
let get_keys_from_rgb_image =
get_keys_from_image (\(x, y) (r, g, b) -> u8s_encoded_5d [x, y, r, g, b])
let get_keys_from_rgba_image =
get_keys_from_image (\(x, y) (r, g, b, a) -> u8s_encoded_6d [x, y, r, g, b, a])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment