Module: Blurhash

Defined in:
lib/blurhash.rb,
lib/blurhash/version.rb

Defined Under Namespace

Modules: Base83

Constant Summary collapse

VERSION =
"0.1.5"

Class Method Summary collapse

Class Method Details

.components(str) ⇒ Object



14
15
16
17
18
19
20
21
22
# 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) ⇒ Object



7
8
9
10
11
12
# 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