pixelflut 1.0.2 → 1.0.5

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: e8019d928da022280882ac14842f29fd955e91741aa33fc9bfa3ca4e9706dc96
4
- data.tar.gz: 0adfa74f15e70a8052555991814b017f86892251ad5e0b4d55b9df74d4063533
3
+ metadata.gz: 72c6df29c81c54b5819636736f404a2179a60fdb9ba3d957fa3b466c54963aae
4
+ data.tar.gz: cdc9fbbbe2c5dffb605429e0a2ba27be38c1411f074e1c883462780723a99176
5
5
  SHA512:
6
- metadata.gz: ca1a224e787fcb547cde5cb19fe8707cca753b80bfed6b7ed4ec7a762e079f44e3ce93360a416b5d1d973fafece3f0fa7538cc62ae90bb91164905542886aea2
7
- data.tar.gz: cda338e7116fd4a777a068a53c25fab94f69c2173d2ce282498fd4cd395cefb254c9f88e61bd8a86c244e944337b62ae27f2c517c5c3beadfaae439b025b78cc
6
+ metadata.gz: 5fb329f94c5e744dc5b25aaabf85351f5bad4593ecc46331240a5a22ecdcae67ce8ac5e3b496440092953c27d1f789170cd394371a25d5145d1b8c08128f4f45
7
+ data.tar.gz: ac537008fa8257540dac638117e5925a83a5ab4176f35ba30e7e2ad418b890e79ffc29b12fee41d6a83d07de9bea6e64436044dfb37f609307eeaf23c8e1d925
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Mike Blumtritt
3
+ Copyright (c) 2024-2025 Mike Blumtritt
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  A Pixelflut client written in Ruby.
4
4
 
5
+ - Gem: [rubygems.org](https://rubygems.org/gems/pixelflut)
6
+ - Source: [codeberg.org](https://codeberg.org/mblumtritt/pixelflut)
7
+
5
8
  ## Description
6
9
 
7
10
  Based on the idea of a simple server protocol to collaborate on a shared canvas named [Pixelflut](https://cccgoe.de/wiki/Pixelflut) this gem implements a Ruby version of a client.
@@ -36,5 +39,4 @@ Options:
36
39
  -t, --threads use threads instead of processes
37
40
  -h, --help print this help
38
41
  -v, --version print version information
39
-
40
42
  ```
data/bin/pxf CHANGED
@@ -1,37 +1,32 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env ruby --jit
2
2
  # frozen_string_literal: true
3
3
 
4
4
  $stdout.sync = $stderr.sync = true
5
5
  $name = Process.setproctitle(File.basename(Process.argv0))
6
6
 
7
- if ARGV.index('-h') || ARGV.index('--help')
8
- puts <<~HELP
9
- Usage: #{$name} [options] <png_image>
10
-
11
- Options:
12
- --host <address> target host address (default 127.0.0.1)
13
- -p, --port <port> target port (default 1234)
14
- -c, --connections <count> count of connections (default 4)
15
- -m, --mode <mode> select pixel encoding (TEXT | BIN)
16
- -t, --threads use threads instead of processes
17
- -x, --transpose-x <x> transpose image <x> pixels
18
- -y, --transpose-y <y> transpose image <y> pixels
19
- -h, --help print this help
20
- -v, --version print version information
21
- HELP
22
- exit
23
- end
7
+ puts(<<~HELP) || exit if ARGV.index('-h') || ARGV.index('--help')
8
+ Usage: #{$name} [options] <png_image>
9
+
10
+ Options:
11
+ --host <address> target host address (default 127.0.0.1)
12
+ -p, --port <port> target port (default 1234)
13
+ -c, --connections <count> count of connections (default 4)
14
+ -x, --transpose-x <x> transpose image <x> pixels
15
+ -y, --transpose-y <y> transpose image <y> pixels
16
+ --encode-text encode pixel in text format (default)
17
+ --encode-bin encode pixel in binary format
18
+ --use-processes use seperate processes (default)
19
+ --use-threads use threads instead of processes
20
+ -h, --help print this help
21
+ -v, --version print version information
22
+ HELP
24
23
 
25
24
  if ARGV.index('-v') || ARGV.index('--version')
26
25
  require_relative('../lib/pixelflut/version')
27
- puts("#{$name} - Pixelflut v#{Pixelflut::VERSION}")
28
- exit
26
+ puts("#{$name} - Pixelflut v#{Pixelflut::VERSION}") || exit
29
27
  end
30
28
 
31
- def die!(msg, code: 1)
32
- $stderr.puts("#{$name}: #{msg}")
33
- exit(code)
34
- end
29
+ def die!(msg, code: 1) = $stderr.puts("#{$name}: #{msg}") || exit(code)
35
30
 
36
31
  die!("argument missing - try `#{$name} --help`") if ARGV.empty?
37
32
 
@@ -39,7 +34,7 @@ require_relative('../lib/pixelflut')
39
34
 
40
35
  module Configuration
41
36
  class << self
42
- attr_reader :use_threads
37
+ attr_reader :scheduler
43
38
 
44
39
  def address
45
40
  require_relative('../lib/pixelflut/sender')
@@ -60,10 +55,6 @@ module Configuration
60
55
  def as_uint(value, name)
61
56
  (ret = value.to_i).positive? ? ret : invalid(value, name)
62
57
  end
63
-
64
- def as_mode(value, name)
65
- %w[text bin].include?(v = value.downcase) ? v : invalid(value, name)
66
- end
67
58
  end
68
59
 
69
60
  until ARGV.empty?
@@ -75,16 +66,20 @@ module Configuration
75
66
  when '-c', '--connections'
76
67
  Pixelflut.count = as_uint(ARGV.shift, 'connections')
77
68
  die!("too many connections - #{Pixelflut.count}") if Pixelflut.count > 255
78
- when '-m', '--mode', '--pixel'
79
- Pixelflut.mode = as_mode(ARGV.shift, 'mode')
80
- when '-t', '--use-threads'
81
- @use_threads = true
69
+ when '--encode-text'
70
+ Pixelflut.encoding = 'text'
71
+ when '--encode-bin'
72
+ Pixelflut.encoding = 'bin'
73
+ when '--use-threads'
74
+ @scheduler = :threads
75
+ when '--use-processes'
76
+ @scheduler = :processes
82
77
  when '-x', '--transpose-x'
83
78
  Pixelflut.delta_x = ARGV.shift.to_i
84
79
  when '-y', '--transpose-y'
85
80
  Pixelflut.delta_y = ARGV.shift.to_i
86
81
  else
87
- die!("invalid option - #{arg}") if Pixelflut.file_name
82
+ die!("invalid option - #{arg}") if arg[0] == '-' || Pixelflut.file_name
88
83
  Pixelflut.file_name = arg
89
84
  end
90
85
  end
@@ -92,6 +87,14 @@ module Configuration
92
87
  die!('<image> missing') unless Pixelflut.file_name
93
88
  end
94
89
 
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
+
95
98
  def use_processes(address, data)
96
99
  puts("#{$name}: start #{data.size} processes for #{data.sum(&:size)} bytes")
97
100
  data.size.times do |i|
@@ -99,22 +102,13 @@ def use_processes(address, data)
99
102
  data = data[i]
100
103
  GC.start
101
104
  $name = Process.setproctitle("#{$name}-#{'0' if i < 9}#{i + 1}")
102
- Pixelflut::Sender.send(address, data) do |size|
103
- puts("#{$name}: #{size} bytes")
104
- end
105
+ Pixelflut::Sender.send(address, data) { puts("#{$name}: #{it} bytes") }
105
106
  end
106
- end
107
-
108
- def use_threads(address, data)
109
- puts("#{$name}: start #{data.size} threads for #{data.sum(&:size)} bytes")
110
- Thread.report_on_exception = false
111
- data.map! { |slice| Thread.start { Pixelflut::Sender.send(address, slice) } }
112
107
  GC.start
113
- data.each(&:join)
114
108
  end
115
109
 
116
110
  begin
117
- if Configuration.use_threads
111
+ if Configuration.scheduler == :threads
118
112
  use_threads(Configuration.address, Pixelflut.data)
119
113
  else
120
114
  use_processes(Configuration.address, Pixelflut.data)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pixelflut
4
- VERSION = '1.0.2'
4
+ VERSION = '1.0.5'
5
5
  end
data/lib/pixelflut.rb CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  module Pixelflut
4
4
  class << self
5
- attr_accessor :file_name, :count, :mode, :delta_x, :delta_y
5
+ attr_accessor :file_name, :encoding, :delta_x, :delta_y
6
+ attr_writer :count
6
7
 
7
- def data
8
- sliced(convert(*load).shuffle!, @count).map!(&:join)
9
- end
8
+ def data = sliced(convert(*load).shuffle!, count).map!(&:join)
9
+ def count = (@count ||= find_suggested_thread_count)
10
10
 
11
11
  private
12
12
 
@@ -44,11 +44,8 @@ module Pixelflut
44
44
  end
45
45
 
46
46
  def convert(width, height, blob)
47
- if @mode == 'bin'
48
- to_bin_format(width, height, blob)
49
- else
50
- to_text_format(width, height, blob)
51
- end
47
+ return to_bin_format(width, height, blob) if @encoding == 'bin'
48
+ to_text_format(width, height, blob)
52
49
  end
53
50
 
54
51
  def to_text_format(width, height, blob)
@@ -90,10 +87,19 @@ module Pixelflut
90
87
  end
91
88
  ret
92
89
  end
90
+
91
+ def find_suggested_thread_count
92
+ count = ENV['TC'].to_i
93
+ return count if count > 0
94
+ begin
95
+ require('etc') unless defined?(Etc)
96
+ Etc.nprocessors
97
+ rescue LoadError
98
+ 4
99
+ end
100
+ end
93
101
  end
94
102
 
95
- @count = ENV['TC'].to_i
96
- @count = 4 unless @count.positive?
97
- @mode = 'text'
103
+ @encoding = 'text'
98
104
  @delta_x = @delta_y = 0
99
105
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pixelflut
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Blumtritt
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-05-09 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: chunky_png
@@ -28,13 +27,12 @@ description: |
28
27
  Based on the idea of a simple server protocol to collaborate on a shared
29
28
  canvas named [Pixelflut](https://cccgoe.de/wiki/Pixelflut) this gem
30
29
  implements a fast Ruby client version.
31
- email:
32
30
  executables:
33
31
  - pxf
34
32
  extensions: []
35
33
  extra_rdoc_files:
36
- - README.md
37
34
  - LICENSE
35
+ - README.md
38
36
  files:
39
37
  - LICENSE
40
38
  - README.md
@@ -48,7 +46,6 @@ metadata:
48
46
  source_code_uri: https://github.com/mblumtritt/pixelflut
49
47
  bug_tracker_uri: https://github.com/mblumtritt/pixelflut/issues
50
48
  rubygems_mfa_required: 'true'
51
- post_install_message:
52
49
  rdoc_options: []
53
50
  require_paths:
54
51
  - lib
@@ -56,15 +53,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
53
  requirements:
57
54
  - - ">="
58
55
  - !ruby/object:Gem::Version
59
- version: 2.7.2
56
+ version: '3.0'
60
57
  required_rubygems_version: !ruby/object:Gem::Requirement
61
58
  requirements:
62
59
  - - ">="
63
60
  - !ruby/object:Gem::Version
64
61
  version: '0'
65
62
  requirements: []
66
- rubygems_version: 3.5.10
67
- signing_key:
63
+ rubygems_version: 3.6.9
68
64
  specification_version: 4
69
65
  summary: A fast Pixelflut client written in Ruby.
70
66
  test_files: []