shattered_machine 0.0.9 → 0.1.0
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 +4 -4
- data/CHANGELOG +10 -0
- data/README.md +18 -0
- data/doc/ShatteredMachine.html +5 -7
- data/doc/ShatteredMachine/Brush.html +2 -2
- data/doc/ShatteredMachine/ChangeByte.html +1 -1
- data/doc/ShatteredMachine/Converter.html +2 -2
- data/doc/ShatteredMachine/Defect.html +1 -1
- data/doc/ShatteredMachine/Exchange.html +1 -1
- data/doc/ShatteredMachine/Glitcher.html +13 -13
- data/doc/ShatteredMachine/Io.html +23 -44
- data/doc/ShatteredMachine/Io/Paths.html +1 -187
- data/doc/ShatteredMachine/PixelSorter.html +2 -2
- data/doc/ShatteredMachine/ProgressivePixelSorter.html +318 -0
- data/doc/ShatteredMachine/Sampler.html +14 -29
- data/doc/ShatteredMachine/Slim.html +3 -3
- data/doc/ShatteredMachine/Transpose.html +1 -1
- data/doc/ShatteredMachine/WrongFilter.html +1 -1
- data/doc/_index.html +5 -13
- data/doc/class_list.html +1 -1
- data/doc/index.html +50 -17
- data/doc/method_list.html +48 -48
- data/doc/top-level-namespace.html +1 -1
- data/lib/shattered_machine.rb +2 -1
- data/lib/shattered_machine/progressive_pixel_sorter.rb +66 -0
- data/lib/shattered_machine/sampler.rb +4 -5
- data/lib/shattered_machine/slim.rb +4 -2
- data/shattered_machine.gemspec +1 -1
- metadata +4 -2
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'pixel_sorter'
|
4
|
+
module ShatteredMachine
|
5
|
+
# Call the pixel sorter multiple time in steps for given png image(s)
|
6
|
+
class ProgressivePixelSorter
|
7
|
+
# @param io [ShatteredMachine::Io] Io containing paths for images to glitch
|
8
|
+
# @param options [Hash] options for the pixel sorting algorithm
|
9
|
+
def initialize(io, options)
|
10
|
+
@io = io
|
11
|
+
@options = options
|
12
|
+
@images_count = @io.png_images.count
|
13
|
+
@steps = define_steps
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
@io.png_images.sort_by { |path| [path.input[/\d+/].to_i, path.input] }.each_with_index do |item, index|
|
18
|
+
PixelSorter.new(sorter_options(index)).call(item.input, item.output)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def sorter_options(index)
|
25
|
+
return @options unless @options[:smart_sorting]
|
26
|
+
|
27
|
+
step_options = @options.clone
|
28
|
+
step_options[:multiple_ranges] = false
|
29
|
+
step_options[:detection_min] = (define_new_min_limit(index)).round.to_s
|
30
|
+
step_options[:detection_max] = (define_new_max_limit(index)).round.to_s
|
31
|
+
step_options
|
32
|
+
end
|
33
|
+
|
34
|
+
def define_steps
|
35
|
+
{ min: min_step, max: max_step }
|
36
|
+
end
|
37
|
+
|
38
|
+
def min_step
|
39
|
+
positive_subtraction(@options[:detection_min].to_f, @options[:detection_min_two].to_f) / (@images_count - 1)
|
40
|
+
end
|
41
|
+
|
42
|
+
def max_step
|
43
|
+
positive_subtraction(@options[:detection_max].to_f, @options[:detection_max_two].to_f) / (@images_count - 1)
|
44
|
+
end
|
45
|
+
|
46
|
+
def positive_subtraction(value1, value2)
|
47
|
+
value1 > value2 ? value1 - value2 : value2 - value1
|
48
|
+
end
|
49
|
+
|
50
|
+
def define_new_min_limit(index)
|
51
|
+
if @options[:detection_min].to_f > @options[:detection_min_two].to_f
|
52
|
+
(@options[:detection_min].to_f - (index * @steps[:min]))
|
53
|
+
else
|
54
|
+
(@options[:detection_min].to_f + (index * @steps[:min]))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def define_new_max_limit(index)
|
59
|
+
if @options[:detection_max].to_f > @options[:detection_max_two].to_f
|
60
|
+
(@options[:detection_max].to_f - (index * @steps[:max]))
|
61
|
+
else
|
62
|
+
(@options[:detection_max].to_f + (index * @steps[:max]))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -11,7 +11,7 @@ module ShatteredMachine
|
|
11
11
|
# @param options [Hash] options for specifying which
|
12
12
|
def initialize(io, options = {})
|
13
13
|
@io = io
|
14
|
-
@base_output_filename = io.output_filename.
|
14
|
+
@base_output_filename = io.output_filename.empty? ? 'sample' : io.output_filename
|
15
15
|
@algorithms_to_sample = options[:algorithms_to_sample] || ALL_ALGORITHMS
|
16
16
|
end
|
17
17
|
|
@@ -30,8 +30,7 @@ module ShatteredMachine
|
|
30
30
|
private
|
31
31
|
|
32
32
|
FILTERS = %w[none sub up average paeth].freeze
|
33
|
-
|
34
|
-
BRUSH_DIRECTION = %w[vertical vertical_inverted horizontal horizontal_inverted].freeze
|
33
|
+
DIRECTION = %w[vertical vertical_inverted horizontal horizontal_inverted].freeze
|
35
34
|
|
36
35
|
def update_io(output_filename_appendix)
|
37
36
|
@io.output_filename = "#{@base_output_filename}_#{output_filename_appendix}"
|
@@ -65,7 +64,7 @@ module ShatteredMachine
|
|
65
64
|
def sample_slim
|
66
65
|
return unless @algorithms_to_sample.include? 'slim'
|
67
66
|
|
68
|
-
|
67
|
+
DIRECTION.each do |direction|
|
69
68
|
update_io("slim_#{direction}")
|
70
69
|
slim_options = { direction: direction.to_sym }
|
71
70
|
Glitcher.new('Slim', @io, slim_options).call
|
@@ -75,7 +74,7 @@ module ShatteredMachine
|
|
75
74
|
def sample_brush
|
76
75
|
return unless @algorithms_to_sample.include? 'brush'
|
77
76
|
|
78
|
-
|
77
|
+
DIRECTION.each do |direction|
|
79
78
|
update_io("brush_#{direction}")
|
80
79
|
brush_options = { direction: direction.to_sym }
|
81
80
|
Glitcher.new('Brush', @io, brush_options).call
|
@@ -11,7 +11,7 @@ module ShatteredMachine
|
|
11
11
|
# @param options [Hash] options for slim algorithm
|
12
12
|
def initialize(options = {})
|
13
13
|
@colors = options[:colors] || ALL_COLORS
|
14
|
-
@direction = options[:direction] || :
|
14
|
+
@direction = options[:direction] || :vertical_inverted
|
15
15
|
@probability = (options[:probability] || 95).to_s
|
16
16
|
@probability_area = options[:probability_area] || 'global'
|
17
17
|
@colors_with_proba = colors_with_proba(options[:colors_with_proba])
|
@@ -38,7 +38,9 @@ module ShatteredMachine
|
|
38
38
|
|
39
39
|
def rust_formatted_direction
|
40
40
|
ruby_to_rust_directions = { up_to_down: '1', down_to_up: '2',
|
41
|
-
left_to_right: '3', right_to_left: '4'
|
41
|
+
left_to_right: '3', right_to_left: '4',
|
42
|
+
vertical: '1', vertical_inverted: '2',
|
43
|
+
horizontal: '3', horizontal_inverted: '4' }
|
42
44
|
ruby_to_rust_directions[@direction]
|
43
45
|
end
|
44
46
|
|
data/shattered_machine.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shattered_machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Flo Girardo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rusty_engine_ffi
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- doc/ShatteredMachine/Io.html
|
76
76
|
- doc/ShatteredMachine/Io/Paths.html
|
77
77
|
- doc/ShatteredMachine/PixelSorter.html
|
78
|
+
- doc/ShatteredMachine/ProgressivePixelSorter.html
|
78
79
|
- doc/ShatteredMachine/Sampler.html
|
79
80
|
- doc/ShatteredMachine/Slim.html
|
80
81
|
- doc/ShatteredMachine/Transpose.html
|
@@ -103,6 +104,7 @@ files:
|
|
103
104
|
- lib/shattered_machine/glitcher.rb
|
104
105
|
- lib/shattered_machine/io.rb
|
105
106
|
- lib/shattered_machine/pixel_sorter.rb
|
107
|
+
- lib/shattered_machine/progressive_pixel_sorter.rb
|
106
108
|
- lib/shattered_machine/sampler.rb
|
107
109
|
- lib/shattered_machine/slim.rb
|
108
110
|
- lib/shattered_machine/transpose.rb
|