pixelflut 1.0.5 → 1.1.2

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: 72c6df29c81c54b5819636736f404a2179a60fdb9ba3d957fa3b466c54963aae
4
- data.tar.gz: cdc9fbbbe2c5dffb605429e0a2ba27be38c1411f074e1c883462780723a99176
3
+ metadata.gz: 9a8c4704485bf4a35acc4f0b1c9b65ef293ded291aa5417968e4780774a83b41
4
+ data.tar.gz: '00348e57cbe2fcfda2df1fcd5746ea81dc5f0e06601bdff720d49ca6b69a94ed'
5
5
  SHA512:
6
- metadata.gz: 5fb329f94c5e744dc5b25aaabf85351f5bad4593ecc46331240a5a22ecdcae67ce8ac5e3b496440092953c27d1f789170cd394371a25d5145d1b8c08128f4f45
7
- data.tar.gz: ac537008fa8257540dac638117e5925a83a5ab4176f35ba30e7e2ad418b890e79ffc29b12fee41d6a83d07de9bea6e64436044dfb37f609307eeaf23c8e1d925
6
+ metadata.gz: 8e26260e01d19e3f40d7da2e58f34549407f110b4ad6e0f7caba4906391e248363ddb54d2ee6386dddd8b0f2a3da228ae269e171044ef64adbc931f1c25d1a94
7
+ data.tar.gz: 9968b5a018fceb59827a2e1011f27ac2cbeb14dc1bf654956db6a8eab531d9e16f827304972ff5a7131b7c05c1b72360f174bfd9e091eacfd0f87cdf5be24c5c
data/README.md CHANGED
@@ -27,16 +27,16 @@ You'll find some help on the command line:
27
27
 
28
28
  ```
29
29
  $ pxf
30
- Usage: pxf [options] <image>
30
+ Usage: pxf [options] <png_image>
31
31
 
32
32
  Options:
33
33
  --host <address> target host address (default 127.0.0.1)
34
- -p, --port <port> target port (default 1337)
34
+ -p, --port <port> target port (default 1234)
35
35
  -c, --connections <count> count of connections (default 4)
36
36
  -x, --transpose-x <x> transpose image <x> pixels
37
37
  -y, --transpose-y <y> transpose image <y> pixels
38
- -m, --mode <mode> select pixel encoding (TEXT | BIN)
39
- -t, --threads use threads instead of processes
38
+ --encode-text encode pixel in text format (default)
39
+ --encode-bin encode pixel in binary format
40
40
  -h, --help print this help
41
41
  -v, --version print version information
42
42
  ```
data/bin/pxf CHANGED
@@ -1,11 +1,11 @@
1
- #!/usr/bin/env ruby --jit
1
+ #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
4
  $stdout.sync = $stderr.sync = true
5
- $name = Process.setproctitle(File.basename(Process.argv0))
5
+ @me = Process.setproctitle(File.basename(Process.argv0))
6
6
 
7
7
  puts(<<~HELP) || exit if ARGV.index('-h') || ARGV.index('--help')
8
- Usage: #{$name} [options] <png_image>
8
+ Usage: #{@me} [options] <png_image>
9
9
 
10
10
  Options:
11
11
  --host <address> target host address (default 127.0.0.1)
@@ -15,37 +15,32 @@ puts(<<~HELP) || exit if ARGV.index('-h') || ARGV.index('--help')
15
15
  -y, --transpose-y <y> transpose image <y> pixels
16
16
  --encode-text encode pixel in text format (default)
17
17
  --encode-bin encode pixel in binary format
18
- --use-processes use seperate processes (default)
19
- --use-threads use threads instead of processes
20
18
  -h, --help print this help
21
19
  -v, --version print version information
22
20
  HELP
23
21
 
24
22
  if ARGV.index('-v') || ARGV.index('--version')
25
23
  require_relative('../lib/pixelflut/version')
26
- puts("#{$name} - Pixelflut v#{Pixelflut::VERSION}") || exit
24
+ puts("#{@me} - Pixelflut v#{Pixelflut::VERSION}") || exit
27
25
  end
28
26
 
29
- def die!(msg, code: 1) = $stderr.puts("#{$name}: #{msg}") || exit(code)
30
-
31
- die!("argument missing - try `#{$name} --help`") if ARGV.empty?
27
+ def die!(msg, code: 1) = $stderr.puts("#{@me}: #{msg}") || exit(code)
28
+ die!("argument missing - try `#{@me} --help`") if ARGV.empty?
32
29
 
33
30
  require_relative('../lib/pixelflut')
34
31
 
35
32
  module Configuration
36
33
  class << self
37
- attr_reader :scheduler
38
-
39
- def address
34
+ def target
40
35
  require_relative('../lib/pixelflut/sender')
41
- Pixelflut::Sender.as_address(@host || '127.0.0.1', @port || 1234)
36
+ Pixelflut::Sender.target(@host || '127.0.0.1', @port || 1234)
42
37
  end
43
38
 
44
39
  private
45
40
 
46
41
  def invalid(value, name)
47
42
  die!("value for #{name} missing") if value.nil?
48
- die!("invalid value for #{name} - '#{value}'")
43
+ die!("invalid value for #{name} - #{value.inspect}")
49
44
  end
50
45
 
51
46
  def as_str(value, name)
@@ -70,10 +65,6 @@ module Configuration
70
65
  Pixelflut.encoding = 'text'
71
66
  when '--encode-bin'
72
67
  Pixelflut.encoding = 'bin'
73
- when '--use-threads'
74
- @scheduler = :threads
75
- when '--use-processes'
76
- @scheduler = :processes
77
68
  when '-x', '--transpose-x'
78
69
  Pixelflut.delta_x = ARGV.shift.to_i
79
70
  when '-y', '--transpose-y'
@@ -87,32 +78,24 @@ module Configuration
87
78
  die!('<image> missing') unless Pixelflut.file_name
88
79
  end
89
80
 
90
- def use_threads(address, data)
91
- puts("#{$name}: start #{data.size} threads for #{data.sum(&:size)} bytes")
92
- Thread.report_on_exception = false
93
- data.map! { Thread.start { Pixelflut::Sender.send(address, it) } }
94
- GC.start
95
- data.each(&:join)
96
- end
97
-
98
- def use_processes(address, data)
99
- puts("#{$name}: start #{data.size} processes for #{data.sum(&:size)} bytes")
100
- data.size.times do |i|
101
- next unless fork
102
- data = data[i]
103
- GC.start
104
- $name = Process.setproctitle("#{$name}-#{'0' if i < 9}#{i + 1}")
105
- Pixelflut::Sender.send(address, data) { puts("#{$name}: #{it} bytes") }
106
- end
81
+ def send_part(index, data, address)
82
+ @me = Process.setproctitle("#{@me}-#{'0' if index < 9}#{index + 1}")
107
83
  GC.start
84
+ Pixelflut::Sender.send(address, data) { puts("#{@me}: #{it} bytes") }
108
85
  end
109
86
 
110
87
  begin
111
- if Configuration.scheduler == :threads
112
- use_threads(Configuration.address, Pixelflut.data)
113
- else
114
- use_processes(Configuration.address, Pixelflut.data)
115
- end
88
+ name, address = Configuration.target
89
+ data = Pixelflut.data
90
+ puts <<~INFO
91
+ ruby: #{RUBY_VERSION}
92
+ image: #{Pixelflut.file_name}
93
+ server: #{name}
94
+ data: #{data.sum(&:size)} bytes
95
+ encoding: #{Pixelflut.encoding}
96
+ processes: #{data.size}
97
+ INFO
98
+ data.each_with_index { |part, idx| send_part(idx, part, address) if fork }
116
99
  rescue Errno::ECONNREFUSED
117
100
  die!('unable to connect', code: 2)
118
101
  rescue Errno::EPIPE
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
+ printf "SIZE\nQUIT\n" | nc "$ADDRESS" "$PORT"
@@ -2,13 +2,18 @@
2
2
 
3
3
  module Pixelflut
4
4
  module Sender
5
- def self.as_address(host, port)
5
+ def self.target(host, port)
6
6
  require('socket') unless defined?(Addrinfo)
7
7
  info = Addrinfo.tcp(host, port)
8
- Address.new(
9
- Socket.pack_sockaddr_in(info.ip_port, info.ip_address),
10
- info.ipv6? ? :INET6 : :INET
11
- )
8
+ address = info.ip_address
9
+ port = info.ip_port
10
+ [
11
+ address.index(':') ? "[#{address}]:#{port}" : "#{address}:#{port}",
12
+ Address.new(
13
+ Socket.pack_sockaddr_in(port, address),
14
+ info.ipv6? ? :INET6 : :INET
15
+ )
16
+ ]
12
17
  end
13
18
 
14
19
  def self.send(address, data)
@@ -22,7 +27,7 @@ module Pixelflut
22
27
  socket.connect(address.sockaddr_in)
23
28
  socket.setsockopt(:TCP, :NODELAY, 1)
24
29
  socket.setsockopt(:SOCKET, :KEEPALIVE, 0)
25
- socket.sync = socket.do_not_reverse_lookup = true
30
+ socket.do_not_reverse_lookup = true
26
31
  socket
27
32
  end
28
33
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pixelflut
4
- VERSION = '1.0.5'
4
+ VERSION = '1.1.2'
5
5
  end
data/lib/pixelflut.rb CHANGED
@@ -55,13 +55,7 @@ module Pixelflut
55
55
  width.times do |x|
56
56
  next if (a = blob.getbyte(pos += 4)) == 0
57
57
  ret << format(
58
- (
59
- if a == 255
60
- "PX %d %d %02x%02x%02x\n"
61
- else
62
- "PX %d %d %02x%02x%02x%02x\n"
63
- end
64
- ),
58
+ "PX %d %d %02x%02x%02x#{'%02x' if a != 255}\n",
65
59
  x + @delta_x,
66
60
  y + @delta_y,
67
61
  blob.getbyte(pos - 3),
data/pixelflut.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/pixelflut/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'pixelflut'
7
+ spec.version = Pixelflut::VERSION
8
+ spec.summary = 'A fast Pixelflut client written in Ruby.'
9
+ spec.description = <<~DESCRIPTION.tr("\n", '')
10
+ Based on the idea of a simple server protocol to collaborate on a shared
11
+ canvas named [Pixelflut](https://cccgoe.de/wiki/Pixelflut) this gem
12
+ implements a fast Ruby client version.
13
+ DESCRIPTION
14
+ spec.author = 'Mike Blumtritt'
15
+ spec.licenses = %w[MIT Ruby]
16
+ spec.homepage = 'https://codeberg.org/mblumtritt/pixelflut'
17
+ spec.metadata['source_code_uri'] = spec.homepage
18
+ spec.metadata['bug_tracker_uri'] = "#{spec.homepage}/issues"
19
+ spec.metadata['rubygems_mfa_required'] = 'true'
20
+
21
+ spec.required_ruby_version = '> 3.0'
22
+
23
+ spec.add_dependency 'chunky_png'
24
+
25
+ spec.executables = %w[pxf pxf-info]
26
+ spec.files = Dir['lib/**/*.rb'] + %w[pixelflut.gemspec]
27
+ spec.extra_rdoc_files = %w[README.md]
28
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pixelflut
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Blumtritt
@@ -23,35 +23,37 @@ dependencies:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
25
  version: '0'
26
- description: |
27
- Based on the idea of a simple server protocol to collaborate on a shared
28
- canvas named [Pixelflut](https://cccgoe.de/wiki/Pixelflut) this gem
29
- implements a fast Ruby client version.
26
+ description: Based on the idea of a simple server protocol to collaborate on a sharedcanvas
27
+ named [Pixelflut](https://cccgoe.de/wiki/Pixelflut) this gemimplements a fast Ruby
28
+ client version.
30
29
  executables:
31
30
  - pxf
31
+ - pxf-info
32
32
  extensions: []
33
33
  extra_rdoc_files:
34
- - LICENSE
35
34
  - README.md
36
35
  files:
37
- - LICENSE
38
36
  - README.md
39
37
  - bin/pxf
38
+ - bin/pxf-info
40
39
  - lib/pixelflut.rb
41
40
  - lib/pixelflut/sender.rb
42
41
  - lib/pixelflut/version.rb
43
- homepage: https://github.com/mblumtritt/pixelflut
44
- licenses: []
42
+ - pixelflut.gemspec
43
+ homepage: https://codeberg.org/mblumtritt/pixelflut
44
+ licenses:
45
+ - MIT
46
+ - Ruby
45
47
  metadata:
46
- source_code_uri: https://github.com/mblumtritt/pixelflut
47
- bug_tracker_uri: https://github.com/mblumtritt/pixelflut/issues
48
+ source_code_uri: https://codeberg.org/mblumtritt/pixelflut
49
+ bug_tracker_uri: https://codeberg.org/mblumtritt/pixelflut/issues
48
50
  rubygems_mfa_required: 'true'
49
51
  rdoc_options: []
50
52
  require_paths:
51
53
  - lib
52
54
  required_ruby_version: !ruby/object:Gem::Requirement
53
55
  requirements:
54
- - - ">="
56
+ - - ">"
55
57
  - !ruby/object:Gem::Version
56
58
  version: '3.0'
57
59
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -60,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
62
  - !ruby/object:Gem::Version
61
63
  version: '0'
62
64
  requirements: []
63
- rubygems_version: 3.6.9
65
+ rubygems_version: 4.0.20
64
66
  specification_version: 4
65
67
  summary: A fast Pixelflut client written in Ruby.
66
68
  test_files: []
data/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024-2025 Mike Blumtritt
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.