image_filter_dsl 0.0.6 → 0.1.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: f36219d0037d3f5d26ca5d4aa9c06465964094c89afe256ad3d79e63dda611d6
4
- data.tar.gz: 310be0964d3c2f293b43c2022437effbdefa1df00588d27b36743642c0502ac8
3
+ metadata.gz: 64f070bf94d94ef0c6e0de6a78fa7ccd8f29f181e866d4aa374f26a4e427f18f
4
+ data.tar.gz: 6347c8d1b350387e369e2e56d023f0fa944dd70a4870035af55619287e11bd7f
5
5
  SHA512:
6
- metadata.gz: db69c17700799b782c73169fab41f56fcec07ba2695dcb15815eb8aa53944bc65af5684205a09f0bdc99164e01a6e24939fb15603375fd0cfc2991422bdcfa7a
7
- data.tar.gz: 9b765299f432bab3d67d40ce3e29568461409ec83b394cb248979b4826d73dfe5e9a4c04d4a52c69208d73e4bcf863fe224d61029f5379d235eaae0d2bf89457
6
+ metadata.gz: a8c55bf124bf7e454021ec8b644373566467eeec81786875bc9fa4d89ee0fa86e7e7044c71c83aa0396a3e97c7b0347d3cdd55e952e98c256c02b9f48a524d4e
7
+ data.tar.gz: 4590228397df810c7b75a5c59c1a4a1510e4e7ce723dd36e168f7a9f377dc6decf1b434cdca926e0c6ecc7a4196dae96b7ba6d0beda91b3743994b6e96bd910d
data/README.md CHANGED
@@ -18,23 +18,23 @@ _An Image Filter DSL (duh)_
18
18
 
19
19
  Using `ImageFilterDsl::Dsl::Filter`
20
20
 
21
-
22
- # - First array contains input variables
23
- # x, y, r, g, b, a, :width and :hght are automatically
24
- # populated by image filter process
25
- # - Second array contains output vars; r,g,b,a and optionally
26
- # x,y for images
27
- filter = Filter.define [:x,:y,:r,:g,:b], [:r,:g,:b] do
28
- # Instructions go here
29
- # instruction [input(s)], output
30
- add [:x,:r], :g
31
-
32
- # output can be an existing symbol in out, or a custom one up to 5 letters
33
- # long (longer will be trimmed if serialized to a binary file)
34
-
35
- # input can be any declared input or custom variable
36
- end
37
-
21
+ ```ruby
22
+ # - First array contains input variables
23
+ # x, y, r, g, b, a, :width and :hght are automatically
24
+ # populated by image filter process
25
+ # - Second array contains output vars; r,g,b,a and optionally
26
+ # x,y for images
27
+ filter = Filter.define [:x,:y,:r,:g,:b], [:r,:g,:b] do
28
+ # Instructions go here
29
+ # instruction [input(s)], output
30
+ add [:x,:r], :g
31
+
32
+ # output can be an existing symbol in out, or a custom one up to 5 letters
33
+ # long (longer will be trimmed if serialized to a binary file)
34
+
35
+ # input can be any declared input or custom variable
36
+ end
37
+ ```
38
38
 
39
39
  ### Instructions
40
40
 
@@ -47,19 +47,19 @@ __Math__
47
47
  - `add` add 2 or more input values, storing in output (<code>a+b</code>)
48
48
 
49
49
  ```ruby
50
- add [:r,5], :r # replace r with r + 5
50
+ add [:r,5], :r # replace r with r + 5
51
51
  ```
52
52
 
53
53
  - `mult` add 2 or more inputs, storing in out (<code>a*b</code>)
54
54
 
55
55
  ```ruby
56
- mult [:r,2], :r # Replace r with r * 2
56
+ mult [:r,2], :r # Replace r with r * 2
57
57
  ```
58
58
 
59
59
  - `div` divide 2 inputs
60
60
 
61
61
  ```ruby
62
- div [:r, 2], :g # Write r/2 to g
62
+ div [:r, 2], :g # Write r/2 to g
63
63
  ```
64
64
 
65
65
  - `mod` store modulo of two inputs in output
@@ -97,20 +97,29 @@ __Collection__
97
97
 
98
98
  __Logic/Conversion/Memory__
99
99
 
100
- - `above` choose one of two values based on greater than comparison (4 values) `[n1,n1,true_val,false_val]`
100
+ - `above` choose one of two values based on greater than comparison (2 or 4 values) `[n1,n1,true_val,false_val]` (If not specified, `true_val` is 1 and `false_val` is 0)
101
101
 
102
102
  ```ruby
103
103
  # if r > g, store 0 in g, else store g in g (keep g the same)
104
104
  above [:r,:g,0,:g], :g
105
105
  ```
106
106
 
107
- - `below` choose one of two values based on less than comparison (4 values) `[n1,n1,true_val,false_val]`
107
+ - `below` choose one of two values based on less than comparison (2 or 4 values) `[n1,n1,true_val,false_val]` (If not specified, `true_val` is 1 and `false_val` is 0)
108
108
 
109
109
  ```ruby
110
110
  # if r < g, store 0 in r, else store r in r (keep r the same)
111
111
  below [:r,:g,0,:r], :r
112
112
  ```
113
113
 
114
+ - `between` choose one of two values based on whether value is between two others (3 or 5 values) `[min,max,value,true_val,false_val]` (If not specified, `true_val` is 1 and `false_val` is 0)
115
+
116
+ ```ruby
117
+ # Returns value since val > 1 && val < 3
118
+ below [1,3,2], :r
119
+ # Returns 1 since -1 < 1
120
+ below [1,-1,5], :r
121
+ ```
122
+
114
123
  - `switch` choose one of two values based on condition value (1/1.0 = true, 0/0.0 = false) `[cond,true_val,false_val]`
115
124
 
116
125
  ```ruby
@@ -118,11 +127,15 @@ __Logic/Conversion/Memory__
118
127
  switch [:c,:r,:g], :a
119
128
  ```
120
129
 
121
- - `eq` if two input values are equal, store 1, else 0 (`[val1,val2]`)
122
- - `bnot` if input is 1 or 1.0, store 0, else 1 (`[bool]`)
130
+ - `eq` if two input values are equal, store 1, else 0 (_2 values_) (`[val1,val2]`)
131
+ - `bnot` if input is 1 or 1.0, store 0, else 1 (_1 value_) (`[bool]`)
132
+ - `band` if _all_ input values are 1 or 1.0, store 1, else 0 (_1+ values_) (`[val1,val2,...]`)
133
+ - `bor` if _any_ input values are 1 or 1.0, store 1, else 0 (_1+ values_) (`[val1,val2,...]`)
123
134
  - `copy` copy input directly to output (`[src]`)
124
- - `ceil` nearest whole integer of input, rounded up (`[val]`)
125
- - `float` cast input to float (`[val]`)
135
+ - `ceil` nearest whole integer of input, rounded up (_1 value_) (`[val]`)
136
+ - `floor` nearest whole integer of input, rounded down (_1 value_) (`[val]`)
137
+ - `clamp` input clamped to be no less than min, no greater than max (`[min,max,val]`)
138
+ - `float` cast input to float (_1 value_) (`[val]`)
126
139
  - `round` round first input value to second value decimals (`[value,decimal_count]`)
127
140
  - `mix` Mix two values together with a ratio (0*a + (1-r)*b) (`[ratio,a,b]`)
128
141
 
@@ -142,24 +155,24 @@ __Generators__
142
155
 
143
156
  Define filter
144
157
 
145
- <!--```ruby-->
158
+ ```
146
159
  swizzle = Filter.define [:r,:g,:b], [:r,:g,:b] do
147
160
  copy [:g], :t # copy green to temp
148
161
  copy [:r], :g # copy red to green
149
162
  copy [:b], :r # copy blue to red
150
163
  copy [:t], :b # copy temp (original green) to blue
151
164
  end
152
- <!--```-->
165
+ ```
153
166
 
154
167
  Optionally write filter kernal to binary file on disk
155
168
 
156
- <!--```ruby-->
169
+ ```ruby
157
170
  ImageFilterDsl::Engine::IO.write("./swizzle.ifdk", swizzle)
158
- <!--```-->
171
+ ```
159
172
 
160
173
  Use filter kernal to process image
161
174
 
162
- <!--```ruby-->
175
+ ```ruby
163
176
  # From binary kernal file
164
177
  processor = ImageFilterDsl::Engine::ImageProcessor.new('./swizzle.ifdk')
165
178
  # OR from filter object
@@ -169,7 +182,7 @@ Use filter kernal to process image
169
182
 
170
183
  # Process image and store output
171
184
  processor.process_image('./my_source.png', './my_output.png')
172
- <!--```-->
185
+ ```
173
186
 
174
187
  - See `./sample_filters/samples.rb` for sample filters
175
188
  - See Also: [image_filter_dsl_samples](https://bitbucket.org/WadeH/image_filter_dsl_samples/src/master/) for more samples
@@ -22,7 +22,7 @@ module ImageFilterDsl
22
22
  # Constants used in header
23
23
  HEADER_VALUES = {
24
24
  header: "ifdKernel",
25
- version: 0.01
25
+ version: 0.02
26
26
  }
27
27
 
28
28
  ##
@@ -36,6 +36,10 @@ module ImageFilterDsl
36
36
  eq: 0xd8,
37
37
  bnot: 0xd9,
38
38
  mix: 0xda,
39
+ between: 0xdb,
40
+ clamp: 0xdc,
41
+ band: 0xdd,
42
+ bor: 0xde,
39
43
  # generation
40
44
  rand: 0xf0,
41
45
  sin: 0xf1,
@@ -122,9 +126,11 @@ module ImageFilterDsl
122
126
 
123
127
  ##
124
128
  # Above instruction
125
- # @param [Array] i input values (a,b,trueVal,falseVal)
129
+ # @param [Array] i input values `(a,b,trueVal,falseVal)`
130
+ # `trueVal` defaults to `1`, `falseVal` defaults to `0`
126
131
  # @return [Integer|Float] output value
127
132
  def self.above(i)
133
+ i = [i,1,0].flatten if i.length == 2
128
134
  if(i[0]>i[1])
129
135
  if i.length < 3
130
136
  1
@@ -142,9 +148,11 @@ module ImageFilterDsl
142
148
 
143
149
  ##
144
150
  # Below instruction
145
- # @param [Array] i input values (a,b,trueVal,falseVal)
151
+ # @param [Array] i input values `(a,b,trueVal,falseVal)`
152
+ # `trueVal` defaults to `1`, `falseVal` defaults to `0`
146
153
  # @return [Integer|Float] output value
147
154
  def self.below(i)
155
+ i = [i,1,0].flatten if i.length == 2
148
156
  if(i[0]<i[1])
149
157
  if i.length < 3
150
158
  1
@@ -160,6 +168,28 @@ module ImageFilterDsl
160
168
  end
161
169
  end
162
170
 
171
+ ##
172
+ # Between instruction (check if value is between two others)
173
+ # @param [Array] i input values `[min, max, value, trueVal, falseVal]`
174
+ # `trueVal` defaults to `1`, `falseVal` defaults to `0`
175
+ # @return [Integer] 1 if true, 0 if false
176
+ def self.between(i)
177
+ i = [i,1,0].flatten if i.length == 3
178
+ a,b,v,t,f = i
179
+ r = (v>=a) && (v<=b)
180
+ (r)? t : f
181
+ end
182
+
183
+ ##
184
+ # Clamp value between a min and a max
185
+ # @param [Array] i input values `[min,max,val]`
186
+ # @return [Integer|Float] Value forced to be no greater than `max`
187
+ # and no less than `min`
188
+ def self.clamp(i)
189
+ a,b,v = i
190
+ [b,[a,v].max].min
191
+ end
192
+
163
193
  ##
164
194
  # Floor instruction
165
195
  # @param [Array] i input value (v)
@@ -230,6 +260,22 @@ module ImageFilterDsl
230
260
  end
231
261
  end
232
262
 
263
+ ##
264
+ # Logical AND instruction
265
+ # @param [Array] i input values (ints or floats)
266
+ # @return [Integer] 1 if all values are `1` or `1.0`, else 0
267
+ def self.band(i)
268
+ (i.reduce(:+).to_i == i.length)? 1 : 0
269
+ end
270
+
271
+ ##
272
+ # Logical OR instruction
273
+ # @param [Array] i input values (ints or floats)
274
+ # @return [Integer] 1 if any values are `1` or `1.0`, else 0
275
+ def self.bor(i)
276
+ (i.reduce(:+).to_i > 0)? 1 : 0
277
+ end
278
+
233
279
  ##
234
280
  # Mix two values with a ratio
235
281
  # @param [Array] i input values (ratio (0-1.0), a, b)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_filter_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wade H.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-02 00:00:00.000000000 Z
11
+ date: 2020-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chunky_png
@@ -96,7 +96,7 @@ licenses:
96
96
  - MIT
97
97
  metadata:
98
98
  source_code_uri: https://bitbucket.org/WadeH/image_filter_dsl
99
- documentation_uri: https://rubydoc.info/gems/image_filter_dsl/0.0.6
99
+ documentation_uri: https://rubydoc.info/gems/image_filter_dsl/0.1.0
100
100
  post_install_message:
101
101
  rdoc_options: []
102
102
  require_paths:
@@ -112,8 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  - !ruby/object:Gem::Version
113
113
  version: '0'
114
114
  requirements: []
115
- rubyforge_project:
116
- rubygems_version: 2.7.8
115
+ rubygems_version: 3.0.1
117
116
  signing_key:
118
117
  specification_version: 4
119
118
  summary: Image Filter DSL