fast_thumbhash 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3dd0e9e710dfa53775b6c718fd674fdc26fb0a17932058ca18e495b229d43e30
4
- data.tar.gz: dc6e6c4203596d64bb3fb7e84fa63b72dda92cd5b7612a97371cb4ae418ae2af
3
+ metadata.gz: 7ca1251a50f86a6d61d03d4aca11a98b30336a72c12f5d5e8a15992c8d694638
4
+ data.tar.gz: e77931c369a56aec1f619b4da9ef822623d5e0f4e839aab43e88ebc80ad5b748
5
5
  SHA512:
6
- metadata.gz: 29c037a813de79ec9a791484823fc42291e2bbc6dd5c8c6a8ecc4d5e17b9de52dfcc64cd554372604bd8068cc5239e898b982f875e0f1efd62cac53967dabf05
7
- data.tar.gz: 2d0f21baac23f3c28e024d6755a45cdae2c9f4b1dd78243ccd98e6fa6e9b01520f1ff28f9c113d4ab0a9c2ecc0988a0fa801c141310d760337c8f1ec37cc002b
6
+ metadata.gz: 66332f36f6e8d43256725abeb3c6a0e1f59a0cf8601516a3d5d8f6c0820259e7a7c2fa00afa5ece7b7eb834d78fd156407726d135d61e31d16b06a1e33547d52
7
+ data.tar.gz: cb3673f55f78c9a64b00d5ebe442ff44fa966df878f2bcc1f511a0d7a4ca672412510d55c891afeddf53e65c864f678ea87ffcdbd679f1bcc385d63acc8e78e0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fast_thumbhash (0.6.0)
4
+ fast_thumbhash (0.7.0)
5
5
  ffi
6
6
 
7
7
  GEM
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FastThumbhash
4
- VERSION = "0.6.0"
4
+ VERSION = "0.7.0"
5
5
  end
@@ -33,29 +33,66 @@ module FastThumbhash
33
33
  homogeneous_transform: nil,
34
34
  saturation: 0
35
35
  )
36
+ %i[solid blur clamp].include?(fill_mode) or
37
+ raise ArgumentError, "Invalid `fill_mode` option"
38
+
39
+ if fill_color
40
+ fill_color.length == 4 or
41
+ raise ArgumentError, "You need to pass [r, g, b, a] to the `fill_color` option"
42
+ end
43
+
44
+ raise ArgumentError, "Option `fill_color` is required for :solid fill_mode" if fill_mode == :solid && fill_color.nil?
45
+
46
+ if homogeneous_transform
47
+ (homogeneous_transform.size == 3 && homogeneous_transform.all? { |row| row.size == 3 }) or
48
+ raise ArgumentError, "`homogeneous_transform` option must be a 3x3 matrix"
49
+ end
50
+
51
+ if size
52
+ size.length == 2 or
53
+ raise ArgumentError, "You need to pass [width, height] to the `size` option"
54
+
55
+ size.all? { |dimension| dimension < 100 } or
56
+ raise ArgumentError, "Cannot generate images bigger then 100 pixels"
57
+ end
58
+
59
+ if max_size
60
+ max_size <= 100 or
61
+ raise ArgumentError, "Cannot generate images bigger then 100 pixels"
62
+ end
63
+
36
64
  !max_size.nil? ^ !size.nil? or
37
65
  raise ArgumentError, "Pass either the `max_size` option, or an explicit `size`"
38
66
 
39
- %i[solid blur clamp].include?(fill_mode) or
40
- raise ArgumentError, "Invalid `fill_mode` option"
67
+ binary_thumbhash_to_rgba!(
68
+ binary_thumbhash,
69
+ max_size: max_size,
70
+ size: size,
71
+ fill_mode: fill_mode,
72
+ fill_color: fill_color,
73
+ homogeneous_transform: homogeneous_transform,
74
+ saturation: saturation
75
+ )
76
+ end
41
77
 
78
+ def self.binary_thumbhash_to_rgba!(
79
+ binary_thumbhash,
80
+ max_size: nil,
81
+ size: nil,
82
+ fill_mode: :solid,
83
+ fill_color: [255, 255, 255, 0],
84
+ homogeneous_transform: nil,
85
+ saturation: 0
86
+ )
42
87
  fill_color_pointer =
43
88
  if fill_color
44
- fill_color.length == 4 or
45
- raise ArgumentError, "You need to pass [r, g, b, a] to the `fill_color` option"
46
-
47
89
  FFI::MemoryPointer.new(:uint8, 4).tap do |p|
48
90
  p.write_array_of_uint8(fill_color)
49
91
  end
50
92
  end
51
93
 
52
- raise ArgumentError, "Option `fill_color` is required for :solid fill_mode" if fill_mode == :solid && fill_color.nil?
53
-
54
94
  transform_pointer =
55
95
  if homogeneous_transform
56
- (homogeneous_transform.size == 3 && homogeneous_transform.all? { |row| row.size == 3 }) or
57
- raise ArgumentError, "`homogeneous_transform` option must be a 3x3 matrix"
58
-
59
96
  FFI::MemoryPointer.new(:double, 6).tap do |p|
60
97
  p.write_array_of_double(
61
98
  [
@@ -75,17 +112,8 @@ module FastThumbhash
75
112
 
76
113
  width, height =
77
114
  if size
78
- size.length == 2 or
79
- raise ArgumentError, "You need to pass [width, height] to the `size` option"
80
-
81
- size.all? { |dimension| dimension < 100 } or
82
- raise ArgumentError, "Cannot generate images bigger then 100 pixels"
83
-
84
115
  size
85
116
  else
86
- max_size <= 100 or
87
- raise ArgumentError, "Cannot generate images bigger then 100 pixels"
88
-
89
117
  thumb_size_pointer = FFI::MemoryPointer.new(:uint8, 2)
90
118
  Library.thumb_size(thumbhash_pointer, max_size, thumb_size_pointer)
91
119
  thumb_size_pointer.read_array_of_uint8(2)
@@ -93,6 +121,7 @@ module FastThumbhash
93
121
 
94
122
  rgba_size = width * height * 4
95
123
  rgba_pointer = FFI::MemoryPointer.new(:uint8, rgba_size)
124
+
96
125
  Library.thumbhash_to_rgba(
97
126
  thumbhash_pointer,
98
127
  width,
@@ -100,7 +129,7 @@ module FastThumbhash
100
129
  fill_mode.to_sym,
101
130
  fill_color_pointer,
102
131
  transform_pointer,
103
- saturation,
132
+ saturation.clamp(-100, 100),
104
133
  rgba_pointer
105
134
  )
106
135
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_thumbhash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Verna
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-07 00:00:00.000000000 Z
11
+ date: 2023-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi