rublurhash 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dc2c304918cc0a2252977c6f8b37d0f1fae6bef56ad5fb593e280f10ea6456a6
4
+ data.tar.gz: 9856f1092248faafde566dab16d6f9323970eb3c2aca77bcb0dfc9bbc20ab947
5
+ SHA512:
6
+ metadata.gz: 399abf185bb1341ec074800f0cbb0070db3a0a9806f95ec0dd1bab8c62fd82d564fda595b63b9cf23a574a0a4e7ee9f4f1b27614e5079f9cddc1f1ac54bb69f5
7
+ data.tar.gz: ca4b37959603dcf9f52ed8f2d72fa14b06b14a03854d86d7aab633c46320529d7fbab856d11043de8bfdec04a41ab58fa6683eefa3c7c33781adcf1c908d1db5
data/.document ADDED
@@ -0,0 +1,3 @@
1
+ README.md
2
+ LICENSE
3
+ sig/*.rbs
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ Gemfile.lock
2
+ vendor/
3
+ target/
4
+ lib/rublurhash.bundle
5
+ ext/.future-incompat-report.json
6
+ ext/.rustc_info.json
7
+ ext/release/
8
+ .yardoc/
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,30 @@
1
+ default:
2
+ image: registry.gitlab.com/kitaitimakoto/ruby-rust:ruby-4.0
3
+ before_script:
4
+ - gem update --system
5
+ - bundle config set path vendor/bundle
6
+ - bundle install
7
+ cache:
8
+ key: ruby:4.0
9
+ paths:
10
+ - vendoe/bundle
11
+ - ext/target
12
+
13
+ test:
14
+ variables:
15
+ RB_SYS_FORCE_INSTALL_RUST_TOOLCHAIN: 'true'
16
+ script:
17
+ - bundle exec rake
18
+
19
+ create-pages:
20
+ stage: deploy
21
+ script:
22
+ - bundle exec rake yard
23
+ - mv doc public
24
+ pages: true
25
+ artifacts:
26
+ paths:
27
+ - public
28
+ rules:
29
+ - if: $CI_COMMIT_BRANCH == "main"
30
+
data/.yardopts ADDED
@@ -0,0 +1,4 @@
1
+ --title RuBlurHash
2
+ --exclude sig/test/**/*
3
+ -
4
+ LICENSE
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kitaiti Makoto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,127 @@
1
+ RuBlurHash
2
+ ==========
3
+
4
+ A Ruby binding for [blurhash-core][], a fast Rust implementation of [BlurHash][].
5
+
6
+ SYNOPSIS
7
+ --------
8
+
9
+ require "rublurhash"
10
+ require "magro"
11
+ require "ndav/numo/narray"
12
+
13
+ image = Magro::IO.imread("path/to/image") # => Numo::UInt8[height, width, channels]
14
+ encoded = RuBlurHash.encode(image, components_x: 4, components_y: 3)
15
+ puts encoded # => Base83-encoded String
16
+
17
+ decoded = RuBlurHash.decode(encoded, width: 400, height: 320, punch: 1.0) # => RuBlurHash::ImageString
18
+ Magro::IO.imsave "path/to/output", NDAV::Converter::NumoNArray(decoded)
19
+
20
+ INSTALLATION
21
+ ------------
22
+
23
+ % gem install rublurhash
24
+
25
+ Or,
26
+
27
+ % bundle add rublurhash
28
+
29
+ USAGE
30
+ -----
31
+
32
+ `RuBlurHash` provides two module functions: `encode` and `decode`.
33
+
34
+ ### Encoding ###
35
+
36
+ `RuBlurHash.encode` and `RuBlurHash#encode` accept a MemoryView producer along with the component counts, `components_x` and `components_y`.
37
+
38
+ The first argument must be contiguous image data, with the shape of `[height, width, channels]` and the number of channels must be `3` which means RGB color pixels, and the format of `"C"` (unsigned 8-bit integers) or `NULL`.
39
+
40
+ For an explanation of the components, see [BlurHash's README][components].
41
+
42
+ require "rublurhash"
43
+ require "magro"
44
+ require "ndav/numo/narray"
45
+
46
+ image = Magro::IO.imread("path/to/image") # => Numo::UInt8[height, width, channels]
47
+ # Loading "ndav/numo/narray" makes Numo::NArray a MemoryView producer
48
+ encoded = RuBlurHash.encode(image, components_x: 4, components_y: 3)
49
+ puts encoded # => Base83-encoded String
50
+
51
+ They also accept a flat Ruby `Array` of RGB pixel values, with the image with width and height.
52
+
53
+ The array must be flat, which means `[R, G, B, R, G, B, ...]`. Its length should be width * height * channels(3).
54
+
55
+ require "rublurhash"
56
+ require "rmagick"
57
+
58
+ images = Magick::Image.read("path/to/image")
59
+ image = images[0]
60
+ encoded = RuBlurHash.encode(image.export_pixels, width: image.columns, height: image.rows, components_x: 4, components_y: 3)
61
+ puts encoded # => Base83-encoded String
62
+
63
+ They also accept a binary Ruby `String` equivalent to the `Array` explained above.
64
+
65
+ encoded = RuBlurHash.encode(image.export_pixels_to_str, width: image.columns, height: image.rows, components_x: 4, components_y: 3)
66
+
67
+ ### Decoding ###
68
+
69
+ `RuBlurHash.decode` and `RuBlurHash#decode` accept a Base83-encoded BlurHash `String` with `width`, `height` and `punch`.
70
+
71
+ For an explanation of the `punch`, see [BlurHash's README][punch].
72
+
73
+ require "rublurhash"
74
+
75
+ decoded = RuBlurHash.decode("...blurhashstring...", width: 32, height: 32, punch: 1.0)
76
+ p decoded # => RuBlurHash::ImageString
77
+
78
+ They return a `RuBlurHash::ImageString` object, which is a subclass of `String` and can be used wherever a `String` is expected.
79
+
80
+ File.write "raw-image", decoded
81
+ pixels = decoded.unpack("C*") # => Array
82
+ p pixels # => [R, G, B, R, G, B, ...]
83
+
84
+ image = Magick::Image.new(width, height)
85
+ image.import_pixels 0, 0, width, height, "RGB", decoded
86
+
87
+ `RuBlurHash::ImageString` exports a MemoryView.
88
+
89
+ require "fiddle"
90
+
91
+ Fiddle::MemoryView.export decoded do |view|
92
+ view.shape # => [height, width, channels]
93
+ view.format # => "C"
94
+ end
95
+
96
+ require "magro"
97
+ require "ndav/numo/narray"
98
+
99
+ numo = NDAV::Converter::NumoNArray(decoded) # => Numo::UInt8
100
+ Magro::IO.imsave "path/to/image", numo
101
+
102
+ It also has attributes `width` and `height`.
103
+
104
+ decoded.width # => Integer
105
+ decoded.height # => Integer
106
+
107
+ LIMITATIONS
108
+ -----------
109
+
110
+ * The encoding algorithm is suitable for practical use but not identical to the reference BlurHash implementation.
111
+
112
+ SEE ALSO
113
+ --------
114
+
115
+ * [BlurHash official site][BlurHash]
116
+ * [blurhash-core documentation][]
117
+
118
+ LICENSE
119
+ -------
120
+
121
+ MIT license. See {file:LICENSE} file.
122
+
123
+ [BlurHash]: https://blurha.sh/
124
+ [blurhash-core]: https://crates.io/crates/blurhash-core
125
+ [blurhash-core documentation]: https://docs.rs/blurhash-core/0.1.0/blurhash_core/
126
+ [components]: https://github.com/woltapp/blurhash#how-do-i-pick-the-number-of-x-and-y-components
127
+ [punch]: https://github.com/woltapp/blurhash#what-is-the-punch-parameter-in-some-of-these-implementations
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require "rake/clean"
2
+ require "rake/testtask"
3
+ require "rubygems/tasks"
4
+ require "kar/dsl"
5
+ require "steep/rake_task"
6
+ require "yard"
7
+ require "rdoc/task"
8
+
9
+ multitask default: [:test, :steep]
10
+
11
+ cargo "rublurhash"
12
+
13
+ Rake::TestTask.new test: :cargo
14
+ Gem::Tasks.new
15
+ Steep::RakeTask.new
16
+ YARD::Rake::YardocTask.new
17
+ RDoc::Task.new do |t|
18
+ t.main = "README.md"
19
+ end
data/Steepfile ADDED
@@ -0,0 +1,34 @@
1
+ D = Steep::Diagnostic
2
+
3
+ target :lib do
4
+ signature "sig"
5
+ ignore_signature "sig/test"
6
+
7
+ check "lib" # Directory name
8
+ # check "path/to/source.rb" # File name
9
+ # check "app/models/**/*.rb" # Glob
10
+ # ignore "lib/templates/*.rb"
11
+
12
+ # RBSs for the gems in Gemfile.lock are loaded via rbs collection automatically.
13
+ # Set it up with `rbs collection init` and `rbs collection install`.
14
+ # library "monitor" # Load an RBS that rbs collection doesn't manage
15
+
16
+ # configure_code_diagnostics(D::Ruby.default) # `default` diagnostics setting (applies by default)
17
+ # configure_code_diagnostics(D::Ruby.strict) # `strict` diagnostics setting
18
+ # configure_code_diagnostics(D::Ruby.lenient) # `lenient` diagnostics setting
19
+ # configure_code_diagnostics(D::Ruby.silent) # `silent` diagnostics setting
20
+ # configure_code_diagnostics do |hash| # You can setup everything yourself
21
+ # hash[D::Ruby::NoMethod] = :information
22
+ # end
23
+ end
24
+
25
+ target :test do
26
+ unreferenced! # Skip type checking the `lib` code when types in `test` target is changed
27
+ signature "sig/test" # Put RBS files for tests under `sig/test`
28
+ check "test" # Type check Ruby scripts under `test`
29
+
30
+ configure_code_diagnostics(D::Ruby.lenient) # Weak type checking for test code
31
+
32
+ library "fileutils", "tmpdir"
33
+ # library "monitor" # Load an RBS that rbs collection doesn't manage
34
+ end