blurhash 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5b0ff9856430593e1b492182c357638d27c26781befa870ec63d2b045f68e1d
4
- data.tar.gz: 65838972c020362dc506f5008c9967a67aed4b937a3ea711a54d980dfb3abd9a
3
+ metadata.gz: 07712bc76961884962616ca6f121e3494f12e1d88f480f6b30557edb6b999019
4
+ data.tar.gz: 86488722517bdf4913fafddeba721b1ac03177ec1b734609634475cd9136d875
5
5
  SHA512:
6
- metadata.gz: c273dc1cdc119883defbe1551a8ab6a20bd4ae0aa9fa1959be8192e6a6cfbc42d9b1226e1a4202c3a8a7e16bd828442f45ed8a5d14a5690e00bf3da2d3213b60
7
- data.tar.gz: 59f5d327864de4557c467965da90dad9a4302b24e77ff1f6268bc2a4bd6f4250cb55d15a0b4e6c1805278ef16beb025486fd0a077310ba434ff84511d37d2b31
6
+ metadata.gz: 44bfe3fea7b2a9ad4f59d9d6437d093256ccfa1bd002fea0aac0fb95c71106b4534f90a9ff67e08c5f62b171eef7f997d2912a2c9435b54da1beeb5cfd6fe5a3
7
+ data.tar.gz: 8034dd5a8c647858918a0d49c75bddc7dafdb5456d1e0374510e5a4fa2dd3177e7a88fa22412c28001067eceb707947bc851c9679c0c5a57e9aaa6b9e755bdab
@@ -1,6 +1,7 @@
1
1
  name: Ruby Gem
2
2
 
3
3
  on:
4
+ workflow_dispatch:
4
5
  push:
5
6
  tags:
6
7
  - v*
@@ -12,11 +13,9 @@ jobs:
12
13
 
13
14
  steps:
14
15
  - uses: actions/checkout@master
15
- - name: Set up Ruby 2.6
16
- uses: actions/setup-ruby@v1
16
+ - uses: ruby/setup-ruby@v1.137.0
17
17
  with:
18
- ruby-version: 2.6.x
19
-
18
+ ruby-version: '3.0'
20
19
  - name: Publish to RubyGems
21
20
  run: |
22
21
  mkdir -p $HOME/.gem
data/Gemfile.lock CHANGED
@@ -1,14 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- blurhash (0.1.5)
5
- ffi (~> 1.14)
4
+ blurhash (0.1.8)
6
5
 
7
6
  GEM
8
7
  remote: https://rubygems.org/
9
8
  specs:
10
9
  diff-lcs (1.4.4)
11
- ffi (1.14.2)
12
10
  rake (13.0.3)
13
11
  rake-compiler (1.1.1)
14
12
  rake
@@ -37,4 +35,4 @@ DEPENDENCIES
37
35
  rspec (~> 3.0)
38
36
 
39
37
  BUNDLED WITH
40
- 2.2.7
38
+ 2.3.23
data/Rakefile CHANGED
@@ -8,8 +8,7 @@ require "rake/extensiontask"
8
8
  task :build => :compile
9
9
 
10
10
  Rake::ExtensionTask.new("blurhash") do |ext|
11
- ext.name = "encode"
12
- ext.lib_dir = "ext/blurhash"
11
+ ext.name = "blurhash_ext"
13
12
  end
14
13
 
15
14
  task :default => [:clobber, :compile, :spec]
data/blurhash.gemspec CHANGED
@@ -21,8 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ['lib']
22
22
  spec.extensions = ['ext/blurhash/extconf.rb']
23
23
 
24
- spec.add_dependency 'ffi', '~> 1.14'
25
-
26
24
  spec.add_development_dependency 'bundler', '~> 2.0'
27
25
  spec.add_development_dependency 'rake', '~> 13.0'
28
26
  spec.add_development_dependency 'rake-compiler'
@@ -2,6 +2,7 @@
2
2
 
3
3
  #include <string.h>
4
4
  #include <math.h>
5
+ #include <ruby.h>
5
6
 
6
7
  #ifndef M_PI
7
8
  #define M_PI 3.14159265358979323846
@@ -135,3 +136,22 @@ static char *encode_int(int value, int length, char *destination) {
135
136
  }
136
137
  return destination;
137
138
  }
139
+
140
+ VALUE rb_blur_hash_for_pixels(VALUE m, VALUE x_comp, VALUE y_comp, VALUE width, VALUE height, VALUE p)
141
+ {
142
+ const char * buf = blurHashForPixels(NUM2INT(x_comp),
143
+ NUM2INT(y_comp),
144
+ NUM2INT(width),
145
+ NUM2INT(height),
146
+ (uint8_t *)StringValuePtr(p),
147
+ NUM2INT(width) * 3);
148
+
149
+ return rb_str_new2(buf);
150
+ }
151
+
152
+ void Init_blurhash_ext()
153
+ {
154
+ VALUE mBlurhash = rb_define_module("Blurhash");
155
+ VALUE mUnstable = rb_define_module_under(mBlurhash, "Unstable");
156
+ rb_define_singleton_method(mUnstable, "blurHashForPixels", rb_blur_hash_for_pixels, 5);
157
+ }
@@ -2,7 +2,4 @@ require 'mkmf'
2
2
 
3
3
  $CFLAGS += ' -std=c99 -lm'
4
4
 
5
- # Don't link to libruby
6
- $LIBRUBYARG = nil
7
-
8
- create_makefile 'encode'
5
+ create_makefile 'blurhash_ext'
@@ -1,3 +1,3 @@
1
1
  module Blurhash
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.8"
3
3
  end
data/lib/blurhash.rb CHANGED
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'blurhash/version'
4
- require 'ffi'
4
+ require 'blurhash_ext'
5
5
 
6
6
  module Blurhash
7
7
  def self.encode(width, height, pixels, x_comp: 4, y_comp: 3)
8
- FFI::MemoryPointer.new(:u_int8_t, pixels.size) do |p|
9
- p.write_array_of_uint8(pixels)
10
- return Unstable.blurHashForPixels(x_comp, y_comp, width, height, p, width * 3)
11
- end
8
+ raise 'Pixels array has wrong size' if pixels.size != width * height * 3
9
+
10
+ p = pixels.pack("C#{pixels.size}")
11
+ return Unstable.blurHashForPixels(x_comp, y_comp, width, height, p)
12
12
  end
13
13
 
14
14
  def self.components(str)
@@ -21,12 +21,6 @@ module Blurhash
21
21
  [x_comp, y_comp]
22
22
  end
23
23
 
24
- module Unstable
25
- extend FFI::Library
26
- ffi_lib File.join(File.expand_path(File.dirname(__FILE__)), '..', 'ext', 'blurhash', 'encode.' + RbConfig::CONFIG['DLEXT'])
27
- attach_function :blurHashForPixels, %i(int int int int pointer size_t), :string
28
- end
29
-
30
24
  module Base83
31
25
  DIGIT_CHARACTERS = %w(
32
26
  0 1 2 3 4 5 6 7 8 9
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blurhash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugen Rochko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-28 00:00:00.000000000 Z
11
+ date: 2024-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: ffi
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.14'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.14'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -126,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
112
  - !ruby/object:Gem::Version
127
113
  version: '0'
128
114
  requirements: []
129
- rubygems_version: 3.2.32
115
+ rubygems_version: 3.5.16
130
116
  signing_key:
131
117
  specification_version: 4
132
118
  summary: Encode an image as a small string that can saved in the database and used