pixelflut 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/pxf +10 -8
- data/lib/pixelflut.rb +2 -2
- data/lib/pixelflut/convert.rb +10 -20
- data/lib/pixelflut/sender.rb +14 -34
- data/lib/pixelflut/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 289cd742f8feabae71182b94738bf9b21246bf1f3afae4a4b2bc1c5b1be87d4c
|
4
|
+
data.tar.gz: 2ba98d609131de67a2be99f55681087b45eeaf4deb6bf488b393894c1b31c6c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a8b53a0309a0c52a8898bab91f9c1ba95bb1622f733fee1236914b036dabae5ad2b375a55b6bb5c5cb3d1d9ba33f9d200cde650d014232e193f598ce8d3de8f
|
7
|
+
data.tar.gz: ba1480300f12b1fae6dba2fcec945537b519dd04fabffd345288a5b3c2c1f1c8e5ae6d9115314663772feeaa6d74c8b8198c8d905f6c8c8e0fab51c27a8594e2
|
data/bin/pxf
CHANGED
@@ -12,7 +12,8 @@ def err(msg, code = 1)
|
|
12
12
|
exit(code)
|
13
13
|
end
|
14
14
|
|
15
|
-
OPTS =
|
15
|
+
OPTS =
|
16
|
+
Struct
|
16
17
|
.new(:host, :port, :count, :x, :y, :mode, :scale, :image)
|
17
18
|
.new('127.0.0.1', 1234, 4, 0, 0, :rgbx)
|
18
19
|
|
@@ -62,8 +63,8 @@ end
|
|
62
63
|
|
63
64
|
begin
|
64
65
|
parse(ARGV)
|
65
|
-
|
66
|
-
|
66
|
+
address = Pixelflut::Sender.address(OPTS.host, OPTS.port)
|
67
|
+
data = Pixelflut.sliced(
|
67
68
|
source: OPTS.image,
|
68
69
|
count: OPTS.count,
|
69
70
|
x: OPTS.x,
|
@@ -71,18 +72,19 @@ begin
|
|
71
72
|
scale: OPTS.scale,
|
72
73
|
mode: OPTS.mode
|
73
74
|
)
|
74
|
-
|
75
|
+
data.size.times do |i|
|
75
76
|
next unless fork
|
76
77
|
Process.setproctitle($name = format('pxf-%02d', i + 1))
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
sender.run{ puts("#{$name}: sent partly") }
|
78
|
+
data = data[i].join
|
79
|
+
puts("#{$name}: run - #{data.bytesize} bytes")
|
80
|
+
Pixelflut::Sender.send(address, data)
|
81
81
|
end
|
82
82
|
rescue SocketError => e
|
83
83
|
err(e, 3)
|
84
84
|
rescue LoadError => e
|
85
85
|
err(e, 4)
|
86
|
+
rescue Errno::ECONNREFUSED
|
87
|
+
err('unable to connect', 2)
|
86
88
|
rescue Errno::EPIPE
|
87
89
|
err('connection lost', 2)
|
88
90
|
rescue Interrupt
|
data/lib/pixelflut.rb
CHANGED
@@ -11,9 +11,9 @@ module Pixelflut
|
|
11
11
|
Convert.each_line(image, x, y)
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.
|
14
|
+
def self.sliced(source:, count: 4, x: 0, y: 0, scale: nil, mode: :rgbx)
|
15
15
|
image = Image.new(source)
|
16
16
|
image.scale(scale) if scale
|
17
|
-
Convert.
|
17
|
+
Convert.random_slices(image, x, y, mode, count)
|
18
18
|
end
|
19
19
|
end
|
data/lib/pixelflut/convert.rb
CHANGED
@@ -2,6 +2,16 @@ require 'rmagick'
|
|
2
2
|
|
3
3
|
module Pixelflut
|
4
4
|
module Convert
|
5
|
+
def self.random_slices(image, dx, dy, mode, count)
|
6
|
+
mode = MODE.fetch(mode) if Symbol === mode
|
7
|
+
ret, idx = Array.new(count){ [] }, 0
|
8
|
+
image.each_pixel.to_a.shuffle!.each do |x, y, px|
|
9
|
+
ret[idx % count] << "PX #{x + dx} #{y + dy} #{mode.call(px)}\n"
|
10
|
+
idx += 1
|
11
|
+
end
|
12
|
+
ret
|
13
|
+
end
|
14
|
+
|
5
15
|
MODE = {
|
6
16
|
rgb: lambda do |pixel|
|
7
17
|
pixel.to_color(Magick::AllCompliance, false, 8, true)[1, 6]
|
@@ -17,25 +27,5 @@ module Pixelflut
|
|
17
27
|
end
|
18
28
|
end
|
19
29
|
}.freeze
|
20
|
-
|
21
|
-
def self.each_line(image, dx, dy, mode)
|
22
|
-
return to_enum(__method__, image, dx, dy, mode) unless block_given?
|
23
|
-
mode = MODE.fetch(mode) if Symbol === mode
|
24
|
-
image.each_pixel do |x, y, px|
|
25
|
-
yield("PX #{x + dx} #{y + dy} #{mode.call(px)}\n")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.as_slices(image, dx, dy, mode, count)
|
30
|
-
ret = each_line(image, dx, dy, mode).to_a.shuffle!
|
31
|
-
ret = ret.each_slice(ret.size / (count + 1)).to_a
|
32
|
-
rest = ret.pop
|
33
|
-
i = 0
|
34
|
-
rest.each do |line|
|
35
|
-
ret[i] << line
|
36
|
-
i = 0 if (i+= 1) == ret.size
|
37
|
-
end
|
38
|
-
ret
|
39
|
-
end
|
40
30
|
end
|
41
31
|
end
|
data/lib/pixelflut/sender.rb
CHANGED
@@ -1,47 +1,27 @@
|
|
1
1
|
require 'socket'
|
2
2
|
|
3
3
|
module Pixelflut
|
4
|
-
|
5
|
-
|
6
|
-
Addrinfo.tcp(host, port)
|
7
|
-
end
|
8
|
-
|
9
|
-
def initialize(address, data)
|
10
|
-
@data = data.freeze
|
11
|
-
@addr = Socket.pack_sockaddr_in(address.ip_port, address.ip_address)
|
12
|
-
@socket = configure(Socket.new(address.ipv6? ? :INET6 : :INET, :STREAM))
|
13
|
-
end
|
4
|
+
module Sender
|
5
|
+
module_function
|
14
6
|
|
15
|
-
def
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
def run(&block)
|
20
|
-
@socket.connect(@addr)
|
21
|
-
send(@socket, @data, @data.bytesize, &block)
|
22
|
-
@socket.close
|
7
|
+
def address(host, port)
|
8
|
+
Addrinfo.tcp(host, port)
|
23
9
|
end
|
24
10
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
index, curr, size = 0, data, bytesize
|
29
|
-
loop do
|
30
|
-
written = socket.write(curr)
|
31
|
-
if (size -= written) > 0
|
32
|
-
yield(self) if block_given?
|
33
|
-
curr = data.byteslice(index += written, size)
|
34
|
-
else
|
35
|
-
index, curr, size = 0, data, bytesize
|
36
|
-
end
|
37
|
-
end
|
11
|
+
def send(address, data)
|
12
|
+
socket = create_socket(address)
|
13
|
+
loop{ socket.write(data) }
|
38
14
|
end
|
39
15
|
|
40
|
-
def
|
41
|
-
socket
|
42
|
-
socket.
|
16
|
+
def create_socket(address)
|
17
|
+
socket = Socket.new(address.ipv6? ? :INET6 : :INET, :STREAM)
|
18
|
+
# socket.sync = true
|
19
|
+
# socket.setsockopt(:TCP, :NODELAY, 1)
|
43
20
|
socket.setsockopt(:SOCKET, :KEEPALIVE, 0)
|
44
21
|
socket.do_not_reverse_lookup = true
|
22
|
+
socket.connect(
|
23
|
+
Socket.pack_sockaddr_in(address.ip_port, address.ip_address)
|
24
|
+
)
|
45
25
|
socket
|
46
26
|
end
|
47
27
|
end
|
data/lib/pixelflut/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pixelflut
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Blumtritt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rmagick
|