rublurhash 0.0.1 → 0.0.2

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: dc2c304918cc0a2252977c6f8b37d0f1fae6bef56ad5fb593e280f10ea6456a6
4
- data.tar.gz: 9856f1092248faafde566dab16d6f9323970eb3c2aca77bcb0dfc9bbc20ab947
3
+ metadata.gz: f500e0ca8972561fb894a2d6c7e6293b727d67ee83544be2c4cb120c88ebbf80
4
+ data.tar.gz: 33697fd9d932fd1da383f19fdc671931260e8e38e25b537453a76ec4b7993d19
5
5
  SHA512:
6
- metadata.gz: 399abf185bb1341ec074800f0cbb0070db3a0a9806f95ec0dd1bab8c62fd82d564fda595b63b9cf23a574a0a4e7ee9f4f1b27614e5079f9cddc1f1ac54bb69f5
7
- data.tar.gz: ca4b37959603dcf9f52ed8f2d72fa14b06b14a03854d86d7aab633c46320529d7fbab856d11043de8bfdec04a41ab58fa6683eefa3c7c33781adcf1c908d1db5
6
+ metadata.gz: 11e2ad4bc03b4de075c944674550c37fd995e7f9bb214754189d63b82bf84dd3ebe96197eb909c7241898116c277abd40623e3dac5fed7d88cca2f663650cfc6
7
+ data.tar.gz: a05836243c35d30715cc66c347a2e48ae5be6804c7282a24a463ce9792427d62a0f379fc7922881b009600cc61cb87de4f713694431117677ccd6296b934d286
data/.gitlab-ci.yml CHANGED
@@ -27,4 +27,3 @@ create-pages:
27
27
  - public
28
28
  rules:
29
29
  - if: $CI_COMMIT_BRANCH == "main"
30
-
data/README.md CHANGED
@@ -1,8 +1,13 @@
1
1
  RuBlurHash
2
2
  ==========
3
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/rublurhash.svg)](https://badge.fury.io/rb/rublurhash)
5
+
4
6
  A Ruby binding for [blurhash-core][], a fast Rust implementation of [BlurHash][].
5
7
 
8
+ * Homepage: https://kitaitimakoto.gitlab.io/rublurhash/
9
+ * Source Code: https://gitlab.com/KitaitiMakoto/rublurhash
10
+
6
11
  SYNOPSIS
7
12
  --------
8
13
 
@@ -104,6 +109,14 @@ It also has attributes `width` and `height`.
104
109
  decoded.width # => Integer
105
110
  decoded.height # => Integer
106
111
 
112
+ ### Components ###
113
+
114
+ `RuBlurHash.components` and `RuBlurHash#components` extracts components from BlurHash String.
115
+
116
+ require "rublurhash"
117
+
118
+ cx, cy = RuBlurHash.components("LEHV6nWB2yk8pyo0adR*.7kCMdnj")
119
+
107
120
  LIMITATIONS
108
121
  -----------
109
122
 
data/ext/Cargo.lock CHANGED
@@ -455,9 +455,9 @@ dependencies = [
455
455
 
456
456
  [[package]]
457
457
  name = "js-sys"
458
- version = "0.3.106"
458
+ version = "0.3.107"
459
459
  source = "registry+https://github.com/rust-lang/crates.io-index"
460
- checksum = "7883d941dae510fb2d978fc3fe018c71c9e2892fd38854de3e8b92c2e5ad9cc5"
460
+ checksum = "8dc09d2154098bbf4ef54eab6b117a3c24cbbffe94046b16ee6d6d4510584d3a"
461
461
  dependencies = [
462
462
  "cfg-if",
463
463
  "futures-util",
@@ -520,9 +520,9 @@ dependencies = [
520
520
 
521
521
  [[package]]
522
522
  name = "log"
523
- version = "0.4.34"
523
+ version = "0.4.35"
524
524
  source = "registry+https://github.com/rust-lang/crates.io-index"
525
- checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6"
525
+ checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c"
526
526
 
527
527
  [[package]]
528
528
  name = "magnus"
@@ -822,7 +822,7 @@ checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832"
822
822
 
823
823
  [[package]]
824
824
  name = "rublurhash"
825
- version = "0.0.1"
825
+ version = "0.0.2"
826
826
  dependencies = [
827
827
  "blurhash-core",
828
828
  "grey-knights",
@@ -908,9 +908,9 @@ dependencies = [
908
908
 
909
909
  [[package]]
910
910
  name = "smallvec"
911
- version = "1.16.3"
911
+ version = "1.16.4"
912
912
  source = "registry+https://github.com/rust-lang/crates.io-index"
913
- checksum = "5b3dc8af474f516a851ff4bd12db780f948b9250ad37211e4eec0bccea54e01b"
913
+ checksum = "d0d5d4b1981b8bbbb7aed204cae5726d683d5d6ac7e74ec54122ea28f315e7c8"
914
914
 
915
915
  [[package]]
916
916
  name = "spirv"
@@ -1022,9 +1022,9 @@ dependencies = [
1022
1022
 
1023
1023
  [[package]]
1024
1024
  name = "tokio"
1025
- version = "1.54.0"
1025
+ version = "1.54.1"
1026
1026
  source = "registry+https://github.com/rust-lang/crates.io-index"
1027
- checksum = "a0c168a474b95bfecfe908a65d4bdffc523144b649a74c09c286afb35d53e0bc"
1027
+ checksum = "b52fd3255258d26fac7264ab5a76b53c13367136dc011d3d6ad4f8ed070396a3"
1028
1028
  dependencies = [
1029
1029
  "pin-project-lite",
1030
1030
  ]
@@ -1055,12 +1055,11 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
1055
1055
 
1056
1056
  [[package]]
1057
1057
  name = "wasm-bindgen"
1058
- version = "0.2.129"
1058
+ version = "0.2.130"
1059
1059
  source = "registry+https://github.com/rust-lang/crates.io-index"
1060
- checksum = "9bb54f33acc68fd454578d9820b0bde1a1a3d17aa17bb7b6595806d02886d409"
1060
+ checksum = "a0181c14ddd6c7b8b0b0132a5f1ea2f32be0d893cd3ea97b6e3b28886b8a3d1c"
1061
1061
  dependencies = [
1062
1062
  "cfg-if",
1063
- "once_cell",
1064
1063
  "rustversion",
1065
1064
  "wasm-bindgen-macro",
1066
1065
  "wasm-bindgen-shared",
@@ -1068,9 +1067,9 @@ dependencies = [
1068
1067
 
1069
1068
  [[package]]
1070
1069
  name = "wasm-bindgen-futures"
1071
- version = "0.4.79"
1070
+ version = "0.4.80"
1072
1071
  source = "registry+https://github.com/rust-lang/crates.io-index"
1073
- checksum = "3cbab34de2d982e9b48e18d216d04c4a6f641066ff19ffb699980f591ee3610e"
1072
+ checksum = "5e14e0327cb5368ad60ccb22d04a9827a693c95a926d8d125e9fa39e0baec501"
1074
1073
  dependencies = [
1075
1074
  "js-sys",
1076
1075
  "tokio",
@@ -1079,9 +1078,9 @@ dependencies = [
1079
1078
 
1080
1079
  [[package]]
1081
1080
  name = "wasm-bindgen-macro"
1082
- version = "0.2.129"
1081
+ version = "0.2.130"
1083
1082
  source = "registry+https://github.com/rust-lang/crates.io-index"
1084
- checksum = "2e29d0c35b16e224a7eeb5cd2d25e3e1968fbd65604117b44d3b789d00ee8535"
1083
+ checksum = "6e931a02a39abdbf66966fc35902b5ed58344750a70885bed4ebb3d8eaf28ed9"
1085
1084
  dependencies = [
1086
1085
  "quote",
1087
1086
  "wasm-bindgen-macro-support",
@@ -1089,9 +1088,9 @@ dependencies = [
1089
1088
 
1090
1089
  [[package]]
1091
1090
  name = "wasm-bindgen-macro-support"
1092
- version = "0.2.129"
1091
+ version = "0.2.130"
1093
1092
  source = "registry+https://github.com/rust-lang/crates.io-index"
1094
- checksum = "6f501a8bc3719dba86ef8ae4728879c08001bea749eb1333ac5b91e040e2a6b7"
1093
+ checksum = "2ca4b54280e455bd831e33a6b8e734baf432fe63fbc35c42ac14ce67a043a53a"
1095
1094
  dependencies = [
1096
1095
  "bumpalo",
1097
1096
  "proc-macro2",
@@ -1102,18 +1101,18 @@ dependencies = [
1102
1101
 
1103
1102
  [[package]]
1104
1103
  name = "wasm-bindgen-shared"
1105
- version = "0.2.129"
1104
+ version = "0.2.130"
1106
1105
  source = "registry+https://github.com/rust-lang/crates.io-index"
1107
- checksum = "23f0c9c52aa7cd7d77769a4cfe2a9adb1b331f489a41d912ce14513d5ab995c6"
1106
+ checksum = "3b1f9c3798725016c6ee5f2f57869ec0831e8bbc0ab0310a86e787e97f41389e"
1108
1107
  dependencies = [
1109
1108
  "unicode-ident",
1110
1109
  ]
1111
1110
 
1112
1111
  [[package]]
1113
1112
  name = "web-sys"
1114
- version = "0.3.106"
1113
+ version = "0.3.107"
1115
1114
  source = "registry+https://github.com/rust-lang/crates.io-index"
1116
- checksum = "88261b9deccee56594c11a3460c462c41f58d148598fe70ad77070126a68aba4"
1115
+ checksum = "d7d179596ff5ec0f6de4db64d54011bde6289cc49603d3a6e4ce3f329207ab88"
1117
1116
  dependencies = [
1118
1117
  "js-sys",
1119
1118
  "wasm-bindgen",
data/ext/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "rublurhash"
3
- version = "0.0.1"
3
+ version = "0.0.2"
4
4
  edition = "2024"
5
5
  authors = ["Kitait Makoto <KitaitiMakoto@gmail.com>"]
6
6
  publish = false
data/ext/src/lib.rs CHANGED
@@ -151,7 +151,19 @@ fn encode(ruby: &Ruby, arguments: &[Value]) -> Result<String> {
151
151
  struct ImageString();
152
152
 
153
153
  impl ImageString {
154
- fn init(ruby: &Ruby, rb_self: Value, width: u32, height: u32) -> Result<()> {
154
+ fn init(module: &RModule, ruby: &Ruby) -> Result<()> {
155
+ let image_string = module.define_class("ImageString", ruby.class_string())?;
156
+ let _: Value = image_string
157
+ .singleton_class()?
158
+ .funcall("private", ("new",))?;
159
+ image_string.define_attr("width", Attr::Read)?;
160
+ image_string.define_attr("height", Attr::Read)?;
161
+ register::<ImageString>(image_string)?;
162
+
163
+ Ok(())
164
+ }
165
+
166
+ fn initialize(ruby: &Ruby, rb_self: Value, width: u32, height: u32) -> Result<()> {
155
167
  let s = RString::from_value(rb_self)
156
168
  .ok_or_else(|| Error::Runtime("Failed to create new instance of ImageString".into()))?;
157
169
  s.ivar_set("@width", ruby.integer_from_u64(width.into()))?;
@@ -198,10 +210,6 @@ impl Entry for ImageString {
198
210
 
199
211
  Ok(())
200
212
  }
201
-
202
- fn is_available(_obj: Value) -> bool {
203
- true
204
- }
205
213
  }
206
214
 
207
215
  fn decode(ruby: &Ruby, arguments: &[Value]) -> Result<Value> {
@@ -220,24 +228,24 @@ fn decode(ruby: &Ruby, arguments: &[Value]) -> Result<Value> {
220
228
  let module: RModule = ruby.class_object().const_get("RuBlurHash")?;
221
229
  let img_class: RClass = module.const_get("ImageString")?;
222
230
  let instance = img_class.funcall("__send__", ("new", rstring))?;
223
- ImageString::init(ruby, instance, width, height)?;
231
+ ImageString::initialize(ruby, instance, width, height)?;
224
232
 
225
233
  Ok(instance)
226
234
  }
227
235
 
236
+ fn components(ruby: &Ruby, blurhash: String) -> Result<RArray> {
237
+ let (cx, cy) = blurhash_core::components(&blurhash)?;
238
+ Ok(ruby.ary_from_vec(vec![cx, cy]))
239
+ }
240
+
228
241
  #[magnus::init]
229
242
  fn init(ruby: &Ruby) -> Result<()> {
230
243
  let module = ruby.define_module("RuBlurHash")?;
231
244
  module.define_module_function("encode", function!(encode, -1))?;
232
245
  module.define_module_function("decode", function!(decode, -1))?;
246
+ module.define_module_function("components", function!(components, 1))?;
233
247
 
234
- let image_string = module.define_class("ImageString", ruby.class_string())?;
235
- let _: Value = image_string
236
- .singleton_class()?
237
- .funcall("private", ("new",))?;
238
- image_string.define_attr("width", Attr::Read)?;
239
- image_string.define_attr("height", Attr::Read)?;
240
- register::<ImageString>(image_string)?;
248
+ ImageString::init(&module, ruby)?;
241
249
 
242
250
  Ok(())
243
251
  }
data/rublurhash.gemspec CHANGED
@@ -9,7 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.licenses = "MIT"
10
10
  s.summary = "Fast BlurHash implementation."
11
11
  s.description = "Ruby binding for blurhash-core, a fast Rust implementation of BlurHash."
12
- s.homepage = "https://gitlab.com/KitaitiMakoto/rublurhash"
12
+ s.homepage = "https://kitaitimakoto.gitlab.io/rublurhash/"
13
+ s.metadata["source_code_uri"] = "https://gitlab.com/KitaitiMakoto/rublurhash"
13
14
 
14
15
  s.files = Dir.chdir(__dir__) {`git ls-files -z`.split("\x0")}
15
16
  s.extensions = ["ext/Cargo.toml"]
data/sig/rublurhash.rbs CHANGED
@@ -3,6 +3,7 @@ module RuBlurHash
3
3
  | (Array[Integer] pixels, components_x: Integer, components_y: Integer, width: Integer, height: Integer) -> String
4
4
  | (String binary_data, components_x: Integer, components_y: Integer, width: Integer, height: Integer) -> String
5
5
  def self?.decode: (String blur_hash_string, width: Integer, height: Integer, punch: Float) -> ImageString
6
+ def self?.components: (String blur_hash_string) -> [Integer, Integer]
6
7
 
7
8
  # Binary string of image data
8
9
  #
data/sig/test/fiddle.rbs CHANGED
@@ -1,4 +1,12 @@
1
+ interface _ToPtr
2
+ def to_ptr: -> Fiddle::Pointer
3
+ end
4
+
1
5
  module Fiddle
6
+ class Pointer
7
+ def self.[]: (String | IO | _ToPtr | Integer | _ToInt) -> instance
8
+ end
9
+
2
10
  class MemoryView
3
11
  def self.export: (untyped) { (instance) -> untyped } -> untyped
4
12
  def format: -> String
data/sig/test/test.rbs CHANGED
@@ -11,6 +11,7 @@ class TestRuBlurHash < Test::Unit::TestCase
11
11
  def test_encode: -> void
12
12
  def test_encode_memory_view: -> void
13
13
  def test_decode: -> void
14
+ def test_components: -> void
14
15
  def test_image_string: -> void
15
16
  def test_module_functions: -> void
16
17
 
data/test/helper.rb CHANGED
@@ -4,4 +4,4 @@ require "fiddle"
4
4
  require "ndav"
5
5
  require "rublurhash"
6
6
  require "fileutils"
7
- require "tmpdir"
7
+ require "tmpdir"
data/test/test_package.rb CHANGED
@@ -21,7 +21,7 @@ class TestPackage < Test::Unit::TestCase
21
21
  FileUtils.mkdir install_dir
22
22
  system "gem", "install", "--install-dir", install_dir, "--no-document", gem_file, exception: true
23
23
 
24
- assert_path_exist File.join(install_dir, "extensions", Gem::Platform.local.to_s, RbConfig::CONFIG["ruby_version"], @gemspec.full_name, "rublurhash.#{RbConfig::CONFIG['DLEXT']}")
24
+ assert_path_exist File.join(install_dir, "extensions", Gem::Platform.local.to_s, Gem.extension_api_version, @gemspec.full_name, "rublurhash.#{RbConfig::CONFIG['DLEXT']}")
25
25
  end
26
26
  end
27
27
  end
@@ -77,6 +77,14 @@ class TestRuBlurHash < Test::Unit::TestCase
77
77
  end
78
78
  end
79
79
 
80
+ def test_components
81
+ assert_equal [4, 3], components("LEHV6nWB2yk8pyo0adR*.7kCMdnj")
82
+
83
+ assert_raise do
84
+ components ""
85
+ end
86
+ end
87
+
80
88
  def test_image_string
81
89
  assert_raise do
82
90
  ImageString.new("123")
@@ -86,6 +94,7 @@ class TestRuBlurHash < Test::Unit::TestCase
86
94
  def test_module_functions
87
95
  assert_equal encode(@img, width: 2, height: 2, components_x: @components_x, components_y: @components_y), RuBlurHash.encode(@img, width: 2, height: 2, components_x: @components_x, components_y: @components_y)
88
96
  assert_equal decode(ENCODED, width: 32, height: 32, punch: 1.0), ::RuBlurHash.decode(ENCODED, width: 32, height: 32, punch: 1.0)
97
+ assert_equal components("LEHV6nWB2yk8pyo0adR*.7kCMdnj"), ::RuBlurHash.components("LEHV6nWB2yk8pyo0adR*.7kCMdnj")
89
98
  end
90
99
 
91
100
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rublurhash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kitaiti Makoto
@@ -176,10 +176,11 @@ files:
176
176
  - test/helper.rb
177
177
  - test/test_package.rb
178
178
  - test/test_rublurhash.rb
179
- homepage: https://gitlab.com/KitaitiMakoto/rublurhash
179
+ homepage: https://kitaitimakoto.gitlab.io/rublurhash/
180
180
  licenses:
181
181
  - MIT
182
- metadata: {}
182
+ metadata:
183
+ source_code_uri: https://gitlab.com/KitaitiMakoto/rublurhash
183
184
  rdoc_options: []
184
185
  require_paths:
185
186
  - lib