module Blurhash

Constants

VERSION

Public Class Methods

components(str) click to toggle source
# File lib/blurhash.rb, line 14
def self.components(str)
  size_flag = Base83.decode83(str[0])
  y_comp    = (size_flag / 9) + 1
  x_comp    = (size_flag % 9) + 1

  return if str.size != 4 + 2 * x_comp * y_comp

  [x_comp, y_comp]
end
encode(width, height, pixels, x_comp: 4, y_comp: 3) click to toggle source
# File lib/blurhash.rb, line 7
def self.encode(width, height, pixels, x_comp: 4, y_comp: 3)
  FFI::MemoryPointer.new(:u_int8_t, pixels.size) do |p|
    p.write_array_of_uint8(pixels)
    return Unstable.blurHashForPixels(x_comp, y_comp, width, height, p, width * 3)
  end
end