image_filter_dsl 0.0.5 → 0.0.6

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: 11cb37a368d81f59215c62674f34ede4fa48628aec1836cb42d70529afca1fab
4
- data.tar.gz: e3a48733e741052828f1a894179990fb2aa964b0f5964ccce2db5650f2667cd6
3
+ metadata.gz: f36219d0037d3f5d26ca5d4aa9c06465964094c89afe256ad3d79e63dda611d6
4
+ data.tar.gz: 310be0964d3c2f293b43c2022437effbdefa1df00588d27b36743642c0502ac8
5
5
  SHA512:
6
- metadata.gz: cc94cd228532001187ce242a1aa266ac7cf0281166fa74e61b939773f385c6d89f5e3a0136d4e33c595211d4427f679103e43eda87cdf73cee460b573d3fd584
7
- data.tar.gz: a7c47d86d6487be190bc0b73589d0562a43a769cbca2c8a8cb1301d7e4c5bc099373d1c8f35a138afe4a77b63035236b3bf150dc00eb382c214ef3584a4ec0b2
6
+ metadata.gz: db69c17700799b782c73169fab41f56fcec07ba2695dcb15815eb8aa53944bc65af5684205a09f0bdc99164e01a6e24939fb15603375fd0cfc2991422bdcfa7a
7
+ data.tar.gz: 9b765299f432bab3d67d40ce3e29568461409ec83b394cb248979b4826d73dfe5e9a4c04d4a52c69208d73e4bcf863fe224d61029f5379d235eaae0d2bf89457
data/README.md CHANGED
@@ -4,48 +4,175 @@ _An Image Filter DSL (duh)_
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/image_filter_dsl.svg)](https://badge.fury.io/rb/image_filter_dsl)
6
6
 
7
+ {file:CHANGELOG.md Change Log}
8
+
7
9
  ## Features
8
10
 
9
11
  - DSL with customizable input and output variables, and a set of basic instructions
10
12
  - IO with serialization so Kernels can be written to binary files and loaded from binary files
11
13
  - Image Processor that generates image file by applying Filter Kernel to every pixel of input image (supports multi-threading)
12
14
 
15
+ ## DSL
16
+
17
+ ### Filter Block
18
+
19
+ Using `ImageFilterDsl::Dsl::Filter`
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
+
38
+
39
+ ### Instructions
40
+
41
+ Basic Use:
42
+
43
+ ``instruction [argument1,argument2,...], :output_variable``
44
+
45
+ __Math__
46
+
47
+ - `add` add 2 or more input values, storing in output (<code>a+b</code>)
48
+
49
+ ```ruby
50
+ add [:r,5], :r # replace r with r + 5
51
+ ```
52
+
53
+ - `mult` add 2 or more inputs, storing in out (<code>a*b</code>)
54
+
55
+ ```ruby
56
+ mult [:r,2], :r # Replace r with r * 2
57
+ ```
58
+
59
+ - `div` divide 2 inputs
60
+
61
+ ```ruby
62
+ div [:r, 2], :g # Write r/2 to g
63
+ ```
64
+
65
+ - `mod` store modulo of two inputs in output
66
+
67
+ ```ruby
68
+ mod [2,4], :t # Write 2$4 (2) to t
69
+ ```
70
+
71
+ - `abs` store absolute value of input in output
72
+
73
+ ```ruby
74
+ abs [-5], :r # Writes abs(5) to r
75
+ ```
76
+
77
+ __Collection__
78
+
79
+ - `min` store smallest of inputs in output (accepts 2 or more values)
80
+
81
+ ```ruby
82
+ min [:r,255,:g], :s # Writes smallest of r, 255 and g to s
83
+ ```
84
+
85
+ - `max` store largest of inputs in output (accepts 2 or more values)
86
+
87
+ ```ruby
88
+ max [:r,0,:g], :s # Writes largest of r, 0 and g to s
89
+ ```
90
+
91
+ - `avg` store average of inputs in output (accepts 2 or more values)
92
+
93
+ ```ruby
94
+ avg [:r,:g,:b], :ca # Writes (r+g+b)/3 to ca
95
+ ```
96
+
97
+
98
+ __Logic/Conversion/Memory__
99
+
100
+ - `above` choose one of two values based on greater than comparison (4 values) `[n1,n1,true_val,false_val]`
101
+
102
+ ```ruby
103
+ # if r > g, store 0 in g, else store g in g (keep g the same)
104
+ above [:r,:g,0,:g], :g
105
+ ```
106
+
107
+ - `below` choose one of two values based on less than comparison (4 values) `[n1,n1,true_val,false_val]`
108
+
109
+ ```ruby
110
+ # if r < g, store 0 in r, else store r in r (keep r the same)
111
+ below [:r,:g,0,:r], :r
112
+ ```
113
+
114
+ - `switch` choose one of two values based on condition value (1/1.0 = true, 0/0.0 = false) `[cond,true_val,false_val]`
115
+
116
+ ```ruby
117
+ # If c is true, store r in a, else store g in a
118
+ switch [:c,:r,:g], :a
119
+ ```
120
+
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]`)
123
+ - `copy` copy input directly to output (`[src]`)
124
+ - `ceil` nearest whole integer of input, rounded up (`[val]`)
125
+ - `float` cast input to float (`[val]`)
126
+ - `round` round first input value to second value decimals (`[value,decimal_count]`)
127
+ - `mix` Mix two values together with a ratio (0*a + (1-r)*b) (`[ratio,a,b]`)
128
+
129
+ ```ruby
130
+ # store (0.3*r) + (0.7*g) in b
131
+ mix [0.3,:r,:g], :b
132
+ ```
133
+
134
+ __Generators__
135
+
136
+ - `rand` random float between min and max (`[min,max]`)
137
+ - `sin` sine function on single value
138
+ - `cos` cosine function on single value
139
+ - `tan` tangent function on single value
140
+
13
141
  ### Sample
14
142
 
15
143
  Define filter
16
144
 
17
- ```ruby
18
- swizzle = Filter.define [:r,:g,:b], [:r,:g,:b] do
19
- copy [:g], :t # copy green to temp
20
- copy [:r], :g # copy red to green
21
- copy [:b], :r # copy blue to red
22
- copy [:t], :b # copy temp (original green) to blue
23
- end
24
- ```
145
+ <!--```ruby-->
146
+ swizzle = Filter.define [:r,:g,:b], [:r,:g,:b] do
147
+ copy [:g], :t # copy green to temp
148
+ copy [:r], :g # copy red to green
149
+ copy [:b], :r # copy blue to red
150
+ copy [:t], :b # copy temp (original green) to blue
151
+ end
152
+ <!--```-->
25
153
 
26
154
  Optionally write filter kernal to binary file on disk
27
155
 
28
- ```ruby
29
- ImageFilterDsl::Engine::IO.write("./swizzle.ifdkk", swizzle)
30
- ```
156
+ <!--```ruby-->
157
+ ImageFilterDsl::Engine::IO.write("./swizzle.ifdk", swizzle)
158
+ <!--```-->
31
159
 
32
160
  Use filter kernal to process image
33
161
 
34
- ```ruby
35
- # From binary kernal file
36
- processor = ImageFilterDsl::Engine::ImageProcessor.new('./swizzle.ifdk')
37
- # OR from filter object
38
- processor = ImageFilterDsl::Engine::ImageProcessor.new(swizzle)
39
- # or use aliases in main module
40
- processor = ImageFilterDsl.image_processor(swizzle)
41
-
42
- # Process image and store output
43
- processor.process_image('./my_source.png', './my_output.png')
44
- ```
45
-
46
- - See {ImageFilterDsl::Dsl} for instruction overview (or go directly to {file:docs/dsl.md DSL summary} )
47
- - See `./sample_filters/samples.rb`
48
- - See Also: [image_filter_dsl_samples](https://bitbucket.org/WadeH/image_filter_dsl_samples/src/master/) for samples
162
+ <!--```ruby-->
163
+ # From binary kernal file
164
+ processor = ImageFilterDsl::Engine::ImageProcessor.new('./swizzle.ifdk')
165
+ # OR from filter object
166
+ processor = ImageFilterDsl::Engine::ImageProcessor.new(swizzle)
167
+ # or use aliases in main module
168
+ processor = ImageFilterDsl.image_processor(swizzle)
169
+
170
+ # Process image and store output
171
+ processor.process_image('./my_source.png', './my_output.png')
172
+ <!--```-->
173
+
174
+ - See `./sample_filters/samples.rb` for sample filters
175
+ - See Also: [image_filter_dsl_samples](https://bitbucket.org/WadeH/image_filter_dsl_samples/src/master/) for more samples
49
176
 
50
177
  ## Gem
51
178
 
@@ -5,7 +5,7 @@
5
5
  module ImageFilterDsl
6
6
  ##
7
7
  # Module defining DSL
8
- # {include:file:docs/dsl.md}
8
+ # {include:file:dsl.md}
9
9
  module Dsl
10
10
  ##
11
11
  # Module defining filter kernel instruction logic
@@ -37,7 +37,10 @@ module ImageFilterDsl
37
37
  bnot: 0xd9,
38
38
  mix: 0xda,
39
39
  # generation
40
- rand: 0xe0
40
+ rand: 0xf0,
41
+ sin: 0xf1,
42
+ cos: 0xf2,
43
+ tan: 0xf3
41
44
  }
42
45
 
43
46
  ##
@@ -192,7 +195,7 @@ module ImageFilterDsl
192
195
  ##
193
196
  # 'Switch' instruction (basically if)
194
197
  #
195
- # switch [condition (0/1/0.0/1.0), trueval, falseval]
198
+ # switch condition (0/1/0.0/1.0), trueval, falseval]
196
199
  # @param [Array] i input value (condition, true val, false val)
197
200
  # @return [Integer|Float] output value
198
201
  def self.switch(i)
@@ -245,6 +248,30 @@ module ImageFilterDsl
245
248
  min,max = i
246
249
  (-min) + (r.rand * (max + min))
247
250
  end
251
+
252
+ ##
253
+ # Sine function
254
+ # @param [Array] i input value to use sin on
255
+ # @return [Float] Sine of input value
256
+ def self.sin(i)
257
+ Math.sin(i[0])
258
+ end
259
+
260
+ ##
261
+ # Cosine function
262
+ # @param [Array] i input value to use cos on
263
+ # @return [Float] Cosine of input value
264
+ def self.cos(i)
265
+ Math.cos(i[0])
266
+ end
267
+
268
+ ##
269
+ # Tangent function
270
+ # @param [Array] i input value to use tan on
271
+ # @return [Float] Tangent of input value
272
+ def self.tan(i)
273
+ Math.tan(i[0])
274
+ end
248
275
  end
249
276
  end
250
277
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_filter_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wade H.
@@ -96,6 +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
100
  post_install_message:
100
101
  rdoc_options: []
101
102
  require_paths:
@@ -111,7 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
112
  - !ruby/object:Gem::Version
112
113
  version: '0'
113
114
  requirements: []
114
- rubygems_version: 3.0.1
115
+ rubyforge_project:
116
+ rubygems_version: 2.7.8
115
117
  signing_key:
116
118
  specification_version: 4
117
119
  summary: Image Filter DSL