blurhash_ruby 0.0.14
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 +7 -0
- data/.gitignore +4 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +15 -0
- data/README.md +1 -0
- data/Rakefile +9 -0
- data/blurhash_ruby.gemspec +17 -0
- data/ext/blurhash_decoder/blurhash_decoder.c +39 -0
- data/ext/blurhash_decoder/decode.c +148 -0
- data/ext/blurhash_decoder/decode.h +54 -0
- data/ext/blurhash_decoder/extconf.rb +6 -0
- data/ext/blurhash_decoder/stb_writer.h +1690 -0
- data/ext/blurhash_encoder/blurhash_encoder.c +52 -0
- data/ext/blurhash_encoder/encode.c +116 -0
- data/ext/blurhash_encoder/encode.h +9 -0
- data/ext/blurhash_encoder/extconf.rb +6 -0
- data/ext/blurhash_encoder/stb_image.h +7177 -0
- data/ext/common.h +26 -0
- data/lib/blurhash_decoder/blurhash_decoder.rb +15 -0
- data/lib/blurhash_encoder/blurhash_encoder.rb +12 -0
- data/lib/blurhash_ruby.rb +15 -0
- metadata +64 -0
data/ext/common.h
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#ifndef __BLURHASH_COMMON_H__
|
2
|
+
#define __BLURHASH_COMMON_H__
|
3
|
+
|
4
|
+
#include<math.h>
|
5
|
+
|
6
|
+
#ifndef M_PI
|
7
|
+
#define M_PI 3.14159265358979323846
|
8
|
+
#endif
|
9
|
+
|
10
|
+
static inline int linearTosRGB(float value) {
|
11
|
+
float v = fmaxf(0, fminf(1, value));
|
12
|
+
if(v <= 0.0031308) return v * 12.92 * 255 + 0.5;
|
13
|
+
else return (1.055 * powf(v, 1 / 2.4) - 0.055) * 255 + 0.5;
|
14
|
+
}
|
15
|
+
|
16
|
+
static inline float sRGBToLinear(int value) {
|
17
|
+
float v = (float)value / 255;
|
18
|
+
if(v <= 0.04045) return v / 12.92;
|
19
|
+
else return powf((v + 0.055) / 1.055, 2.4);
|
20
|
+
}
|
21
|
+
|
22
|
+
static inline float signPow(float value, float exp) {
|
23
|
+
return copysignf(powf(fabsf(value), exp), value);
|
24
|
+
}
|
25
|
+
|
26
|
+
#endif
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path('lib/blurhash_decoder/binary/blurhash_decoder')
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
class BlurhashDecoder
|
5
|
+
include DECODER
|
6
|
+
|
7
|
+
def decode_blurhash(blurhash, height, width, punch)
|
8
|
+
decode(blurhash, height, width, punch)
|
9
|
+
base64_image = File.open("tmp/out.png", "rb") do |file|
|
10
|
+
Base64.strict_encode64(file.read)
|
11
|
+
end
|
12
|
+
base64_image
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path('../blurhash_encoder/blurhash_encoder', __FILE__)
|
2
|
+
require File.expand_path('../blurhash_decoder/blurhash_decoder', __FILE__)
|
3
|
+
|
4
|
+
class Blurhash
|
5
|
+
def self.encode(image_url, x_comp = 4, y_comp = 3)
|
6
|
+
# Usage: Blurhash.encode('https://cdn.pixabay.com/photo/2018/01/14/23/12/nature-3082832__480.jpg')
|
7
|
+
BlurhashEncoder.new.blurhash(image_url, x_comp, y_comp)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.decode(blurhash, height = 2, width = 4, punch = 1, as_img = false)
|
11
|
+
# Usage: Blurhash.decode('LHB3~nxvjYax0Mo#o#t7-cayWBWE')
|
12
|
+
hash = BlurhashDecoder.new.decode_blurhash(blurhash, height, width, punch)
|
13
|
+
as_img ? 'data:image/png;base64,' + hash : hash
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blurhash_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.14
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rabin Poudyal
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-02-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A fast blurhash encoder/decoder gem.
|
14
|
+
email: rabin@trip101.com
|
15
|
+
executables: []
|
16
|
+
extensions:
|
17
|
+
- ext/blurhash_decoder/extconf.rb
|
18
|
+
- ext/blurhash_encoder/extconf.rb
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".gitignore"
|
22
|
+
- Gemfile
|
23
|
+
- Gemfile.lock
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- blurhash_ruby.gemspec
|
27
|
+
- ext/blurhash_decoder/blurhash_decoder.c
|
28
|
+
- ext/blurhash_decoder/decode.c
|
29
|
+
- ext/blurhash_decoder/decode.h
|
30
|
+
- ext/blurhash_decoder/extconf.rb
|
31
|
+
- ext/blurhash_decoder/stb_writer.h
|
32
|
+
- ext/blurhash_encoder/blurhash_encoder.c
|
33
|
+
- ext/blurhash_encoder/encode.c
|
34
|
+
- ext/blurhash_encoder/encode.h
|
35
|
+
- ext/blurhash_encoder/extconf.rb
|
36
|
+
- ext/blurhash_encoder/stb_image.h
|
37
|
+
- ext/common.h
|
38
|
+
- lib/blurhash_decoder/blurhash_decoder.rb
|
39
|
+
- lib/blurhash_encoder/blurhash_encoder.rb
|
40
|
+
- lib/blurhash_ruby.rb
|
41
|
+
homepage: https://rubygems.org/gems/blurhash_ruby
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubygems_version: 3.1.4
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: A fast blurhash encoder/decoder gem!
|
64
|
+
test_files: []
|