Module: ImageFilterDsl::Dsl::FilterInstructions
- Defined in:
- lib/image_filter_dsl/dsl/filter_instructions.rb
Overview
Module defining filter kernel instruction logic
Constant Summary collapse
- OP_INS =
Hash of binary instruction symbols
{ # math = 0x0X-0xAF add: 0x01, mult: 0x02, div: 0x03, mod: 0x04, abs: 0x05, # collection op = 0xB0-0xCF min: 0xb0, max: 0xb1, avg: 0xb2, # logic/mem/conv op = 0xD0-?? copy: 0xd0, above: 0xd1, below: 0xd2, floor: 0xd3, ceil: 0xd4, float: 0xd5, round: 0xd6, switch: 0xd7, eq: 0xd8, bnot: 0xd9, mix: 0xda, # generation rand: 0xf0, sin: 0xf1, cos: 0xf2, tan: 0xf3 }
- OPS =
Array of all valid filter instructions
OP_INS.keys
Class Method Summary collapse
-
.above(i) ⇒ Integer|Float
Above instruction.
-
.abs(i) ⇒ Integer|Float
Absolute value.
-
.add(i) ⇒ Integer|Float
Add instruction.
-
.avg(i) ⇒ Integer|Float
Average instruction.
-
.below(i) ⇒ Integer|Float
Below instruction.
-
.bnot(i) ⇒ Integer|Float
Logic invert instruction.
-
.ceil(i) ⇒ Integer|Float
Ceil instruction.
-
.copy(i) ⇒ Integer|Float
Copy instruction.
-
.cos(i) ⇒ Float
Cosine function.
-
.div(i) ⇒ Integer|Float
Multiply instruction.
-
.eq(i) ⇒ Integer|Float
Equal condition instruction.
-
.float(i) ⇒ Integer|Float
Float cast instruction.
-
.floor(i) ⇒ Integer|Float
Floor instruction.
-
.max(i) ⇒ Integer|Float
Maximum instruction.
-
.min(i) ⇒ Integer|Float
Minimum instruction.
-
.mix(i) ⇒ Float
Mix two values with a ratio.
-
.mod(i) ⇒ Integer|
Calculate modulo.
-
.mult(i) ⇒ Integer|Float
Multiply instruction.
-
.rand(i) ⇒ Float
Random number instruction.
-
.round(i) ⇒ Integer|Float
Round instruction.
-
.sin(i) ⇒ Float
Sine function.
-
.switch(i) ⇒ Integer|Float
‘Switch’ instruction (basically if).
-
.tan(i) ⇒ Float
Tangent function.
Class Method Details
.above(i) ⇒ Integer|Float
Above instruction
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 127 def self.above(i) if(i[0]>i[1]) if i.length < 3 1 else i[2] end else if i.length < 4 0 else i[3] end end end |
.abs(i) ⇒ Integer|Float
Absolute value
87 88 89 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 87 def self.abs(i) i[0].abs end |
.add(i) ⇒ Integer|Float
Add instruction
54 55 56 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 54 def self.add(i) i.sum end |
.avg(i) ⇒ Integer|Float
Average instruction
111 112 113 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 111 def self.avg(i) i.sum / (1.0 * i.length) end |
.below(i) ⇒ Integer|Float
Below instruction
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 147 def self.below(i) if(i[0]<i[1]) if i.length < 3 1 else i[2] end else if i.length < 4 0 else i[3] end end end |
.bnot(i) ⇒ Integer|Float
Logic invert instruction
225 226 227 228 229 230 231 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 225 def self.bnot(i) if i[0].to_i == 1 0 else 1 end end |
.ceil(i) ⇒ Integer|Float
Ceil instruction
175 176 177 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 175 def self.ceil(i) i[0].ceil end |
.copy(i) ⇒ Integer|Float
Copy instruction
119 120 121 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 119 def self.copy(i) i[0] end |
.cos(i) ⇒ Float
Cosine function
264 265 266 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 264 def self.cos(i) Math.cos(i[0]) end |
.div(i) ⇒ Integer|Float
Multiply instruction
72 73 74 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 72 def self.div(i) i[0]/i[1] end |
.eq(i) ⇒ Integer|Float
Equal condition instruction
213 214 215 216 217 218 219 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 213 def self.eq(i) if i[0] == i[1] 1 else 0 end end |
.float(i) ⇒ Integer|Float
Float cast instruction
183 184 185 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 183 def self.float(i) i[0].to_f end |
.floor(i) ⇒ Integer|Float
Floor instruction
167 168 169 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 167 def self.floor(i) i[0].floor end |
.max(i) ⇒ Integer|Float
Maximum instruction
103 104 105 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 103 def self.max(i) i.max end |
.min(i) ⇒ Integer|Float
Minimum instruction
95 96 97 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 95 def self.min(i) i.min end |
.mix(i) ⇒ Float
Mix two values with a ratio
237 238 239 240 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 237 def self.mix(i) ratio, a, b = i (ratio*a)+((1.0-ratio)*b) end |
.mod(i) ⇒ Integer|
Calculate modulo
79 80 81 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 79 def self.mod(i) i[0] % i[1] end |
.mult(i) ⇒ Integer|Float
Multiply instruction
62 63 64 65 66 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 62 def self.mult(i) v=1; i.each{|n|v=v*n} v end |
.rand(i) ⇒ Float
Random number instruction
246 247 248 249 250 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 246 def self.rand(i) r=Random.new min,max = i (-min) + (r.rand * (max + min)) end |
.round(i) ⇒ Integer|Float
Round instruction
191 192 193 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 191 def self.round(i) i[0].round(i[1]) end |
.sin(i) ⇒ Float
Sine function
256 257 258 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 256 def self.sin(i) Math.sin(i[0]) end |
.switch(i) ⇒ Integer|Float
‘Switch’ instruction (basically if)
switch condition (0/1/0.0/1.0), trueval, falseval]
201 202 203 204 205 206 207 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 201 def self.switch(i) if i[0].to_i == 1 i[1] else i[2] end end |
.tan(i) ⇒ Float
Tangent function
272 273 274 |
# File 'lib/image_filter_dsl/dsl/filter_instructions.rb', line 272 def self.tan(i) Math.tan(i[0]) end |