Sha256: eccf0e890597667fc1538dd62ba1148280de282d8b7755617c965b665d62c4f6

Contents?: true

Size: 601 Bytes

Versions: 1

Compression:

Stored size: 601 Bytes

Contents

# frozen_string_literal: true

require 'blurhash/version'
require 'ffi'

module Blurhash
  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

  module Unstable
    extend FFI::Library
    ffi_lib File.join(File.expand_path(__dir__), 'encode.' + RbConfig::CONFIG['DLEXT'])
    attach_function :blurHashForPixels, %i(int int int int pointer size_t), :string
  end

  private_constant :Unstable
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blurhash-0.1.1 lib/blurhash.rb