pixelflut 0.1.2 → 0.1.3
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/bin/pxf +11 -5
- data/bin/pxf-info +32 -0
- data/lib/pixelflut.rb +2 -2
- data/lib/pixelflut/convert.rb +30 -17
- data/lib/pixelflut/sender.rb +15 -20
- data/lib/pixelflut/version.rb +1 -1
- data/pixelflut.gemspec +1 -4
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e00558ad6f4afeeda5a86d00ee8fcbfffc09bf3978aa02b7997c69541b4ec71
|
4
|
+
data.tar.gz: fb2ec338298452be18a2a9c5352b49100628efb5234b94ee0d25f2f57e759607
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa654604990a4af74b65d074a65635ba04d302b4974b37d68fe1a2d155a9dbc4495e62c5422b2c1ce55b9dfbd63b0ca208111ddbe26cf3426ffaf26a55d03573
|
7
|
+
data.tar.gz: '099c5c9b3d013d26eb19616e0cef6a7fb2a1a391ddd4bae4e5ce77d263eee1ffcf5cb0311a868a7ab7656eb3cbb621ba7ab02d9e83cc19b3722ca16da9ec6b7c'
|
data/bin/pxf
CHANGED
@@ -13,8 +13,8 @@ def err(msg, code = 1)
|
|
13
13
|
end
|
14
14
|
|
15
15
|
OPTS = Struct
|
16
|
-
.new(:host, :port, :count, :x, :y, :scale, :image)
|
17
|
-
.new('127.0.0.1', 1234, 4, 0, 0)
|
16
|
+
.new(:host, :port, :count, :x, :y, :mode, :scale, :image)
|
17
|
+
.new('127.0.0.1', 1234, 4, 0, 0, :rgbx)
|
18
18
|
|
19
19
|
def parse(args)
|
20
20
|
OptionParser.new do |parser|
|
@@ -40,6 +40,11 @@ def parse(args)
|
|
40
40
|
parser.on(
|
41
41
|
'-s', '--scale FACTOR', OptionParser::DecimalNumeric, 'scale image by FACTOR'
|
42
42
|
){ |v| OPTS.scale = v }
|
43
|
+
parser.on(
|
44
|
+
'-m', '--pixel MODE',
|
45
|
+
{'RGBX' => :rgbx, 'RGBA' => :rgba, 'RGB' => :rgb},
|
46
|
+
'select pixel coding (RGBX | RGBA | RGB)'
|
47
|
+
){ |v| OPTS.mode = v }
|
43
48
|
parser.separator(nil)
|
44
49
|
parser.on('-h', '--help', 'print this help') do
|
45
50
|
exit(!puts(parser))
|
@@ -63,15 +68,16 @@ begin
|
|
63
68
|
count: OPTS.count,
|
64
69
|
x: OPTS.x,
|
65
70
|
y: OPTS.y,
|
66
|
-
scale: OPTS.scale
|
71
|
+
scale: OPTS.scale,
|
72
|
+
mode: OPTS.mode
|
67
73
|
)
|
68
74
|
slices.size.times do |i|
|
69
75
|
next unless fork
|
70
76
|
Process.setproctitle($name = format('pxf-%02d', i + 1))
|
71
77
|
sender = Pixelflut::Sender.new(addr, slices[i].join)
|
72
78
|
slices.clear
|
73
|
-
puts
|
74
|
-
sender.run
|
79
|
+
puts("#{$name}: run - #{sender.size} bytes")
|
80
|
+
sender.run{ puts("#{$name}: sent partly") }
|
75
81
|
end
|
76
82
|
rescue SocketError => e
|
77
83
|
err(e, 3)
|
data/bin/pxf-info
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#! /bin/sh
|
2
|
+
|
3
|
+
set -e
|
4
|
+
|
5
|
+
if [ "$1" = '--help' ]
|
6
|
+
then
|
7
|
+
echo "Usage: ${0##*/} [-p|--port PORT] ADDRESS
|
8
|
+
|
9
|
+
Requests screen size of Pixelflut server at ADDRESS.
|
10
|
+
"
|
11
|
+
exit 0
|
12
|
+
fi
|
13
|
+
|
14
|
+
PORT="1234"
|
15
|
+
ADDRESS=""
|
16
|
+
|
17
|
+
while [ $# -gt 0 ]
|
18
|
+
do
|
19
|
+
key="$1"
|
20
|
+
case $key in
|
21
|
+
-p|--port)
|
22
|
+
PORT="$2"
|
23
|
+
shift; shift
|
24
|
+
;;
|
25
|
+
*)
|
26
|
+
ADDRESS="$key"
|
27
|
+
shift
|
28
|
+
;;
|
29
|
+
esac
|
30
|
+
done
|
31
|
+
|
32
|
+
echo "SIZE\nQUIT\n" | nc "$ADDRESS" "$PORT"
|
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.as_slices(source:, count: 4, x: 0, y: 0, scale: nil)
|
14
|
+
def self.as_slices(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.as_slices(image, x, y, count)
|
17
|
+
Convert.as_slices(image, x, y, mode, count)
|
18
18
|
end
|
19
19
|
end
|
data/lib/pixelflut/convert.rb
CHANGED
@@ -1,28 +1,41 @@
|
|
1
|
+
require 'rmagick'
|
2
|
+
|
1
3
|
module Pixelflut
|
2
4
|
module Convert
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
]
|
9
|
-
|
5
|
+
MODE = {
|
6
|
+
rgb: lambda do |pixel|
|
7
|
+
pixel.to_color(Magick::AllCompliance, false, 8, true)[1, 6]
|
8
|
+
end,
|
9
|
+
rgba: lambda do |pixel|
|
10
|
+
pixel.to_color(Magick::AllCompliance, true, 8, true)[1, 8]
|
11
|
+
end,
|
12
|
+
rgbx: lambda do |pixel|
|
13
|
+
if pixel.alpha >= 65535
|
14
|
+
pixel.to_color(Magick::AllCompliance, false, 8, true)[1, 6]
|
15
|
+
else
|
16
|
+
pixel.to_color(Magick::AllCompliance, true, 8, true)[1, 8]
|
17
|
+
end
|
10
18
|
end
|
11
|
-
|
19
|
+
}.freeze
|
12
20
|
|
13
|
-
def self.each_line(image, dx, dy)
|
14
|
-
return to_enum(__method__, image, dx, dy) unless block_given?
|
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
|
15
24
|
image.each_pixel do |x, y, px|
|
16
|
-
|
17
|
-
1, 255 == px.alpha ? 6 : 8
|
18
|
-
]
|
19
|
-
yield("PX #{x + dx} #{y + dy} #{px}\n")
|
25
|
+
yield("PX #{x + dx} #{y + dy} #{mode.call(px)}\n")
|
20
26
|
end
|
21
27
|
end
|
22
28
|
|
23
|
-
def self.as_slices(image, dx, dy, count)
|
24
|
-
ret = each_line(image, dx, dy).to_a.shuffle!
|
25
|
-
ret.each_slice(ret.size / count).to_a
|
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
|
26
39
|
end
|
27
40
|
end
|
28
41
|
end
|
data/lib/pixelflut/sender.rb
CHANGED
@@ -12,34 +12,29 @@ module Pixelflut
|
|
12
12
|
@socket = configure(Socket.new(address.ipv6? ? :INET6 : :INET, :STREAM))
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
15
|
+
def size
|
16
|
+
@data.bytesize
|
17
|
+
end
|
18
|
+
|
19
|
+
def run(&block)
|
20
|
+
@socket.connect(@addr)
|
21
|
+
send(@socket, @data, @data.bytesize, &block)
|
18
22
|
@socket.close
|
19
23
|
end
|
20
24
|
|
21
25
|
private
|
22
26
|
|
23
|
-
def send(socket, data)
|
24
|
-
curr =
|
27
|
+
def send(socket, data, bytesize)
|
28
|
+
index, curr, size = 0, data, bytesize
|
25
29
|
loop do
|
26
30
|
written = socket.write(curr)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def connect
|
37
|
-
loop do
|
38
|
-
(
|
39
|
-
:wait_writable == @socket.connect_nonblock(@addr, exception: false)
|
40
|
-
) and break
|
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
|
41
37
|
end
|
42
|
-
loop{ @socket.wait_writable(10) and break }
|
43
38
|
end
|
44
39
|
|
45
40
|
def configure(socket)
|
data/lib/pixelflut/version.rb
CHANGED
data/pixelflut.gemspec
CHANGED
@@ -29,10 +29,7 @@ GemSpec = Gem::Specification.new do |spec|
|
|
29
29
|
|
30
30
|
spec.require_paths = %w[lib]
|
31
31
|
spec.bindir = 'bin'
|
32
|
-
spec.executables =
|
33
|
-
Dir
|
34
|
-
.glob(File.expand_path('../bin/*', __FILE__))
|
35
|
-
.map!{ |fn| File.basename(fn) }
|
32
|
+
spec.executables = %w[pxf pxf-info]
|
36
33
|
|
37
34
|
all_files = %x(git ls-files -z).split(0.chr)
|
38
35
|
spec.test_files = all_files.grep(%r{^(spec|test)/})
|
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.3
|
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-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rmagick
|
@@ -58,6 +58,7 @@ description: |
|
|
58
58
|
email: mike.blumtritt@pm.me
|
59
59
|
executables:
|
60
60
|
- pxf
|
61
|
+
- pxf-info
|
61
62
|
extensions: []
|
62
63
|
extra_rdoc_files:
|
63
64
|
- README.md
|
@@ -65,6 +66,7 @@ files:
|
|
65
66
|
- ".gitignore"
|
66
67
|
- README.md
|
67
68
|
- bin/pxf
|
69
|
+
- bin/pxf-info
|
68
70
|
- gems.rb
|
69
71
|
- lib/pixelflut.rb
|
70
72
|
- lib/pixelflut/convert.rb
|