pnm 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fdfdb7ac32419e9381856654116f77070fabb87713e2353c10230fb6ac9c79c9
4
- data.tar.gz: 06042a5b1c3d26d5b4e982b3e2e4983b652d1e1ffab8987d5f8b183a017c4abb
3
+ metadata.gz: ef6f55635bbaa23976ceb49f1547b92cf78e2ad04d51363054ac12dbfe6943e0
4
+ data.tar.gz: 4b7c8730c80b28b6a98a4b27fc3a000a4e28eb11be34bf5c2717da188f833d9a
5
5
  SHA512:
6
- metadata.gz: 17970b6a53282e449e76f9225e65c914f92084e4060b5fbe3b9bbbd56cae9ae830e122fbf8ed0bbb321bf443ef1c9538d4b8a2b859759528aa8862d479375796
7
- data.tar.gz: b66f7f50567bb137a5b091293c7b77206966e570e300157a0ebde66647e46f2c09d07cb093499f3527a5b6149d01a0f88baa235c5450e61d9b0ba02db2a2cb5e
6
+ metadata.gz: f3b07074daa3fd1601d8d0c4f05dc2764c1c2434b24368d0e69c4752ecc9af1153751f14f1af679d2319d46b20b74cff4c9e10e50341eb12fbb82abc97ca69d5
7
+ data.tar.gz: 5356021622e4656db38f8f7c7b918c5e3bbffc63670e4b39b851ca542f55f5a51b7748b2384540426d7e154ebb3b151c4d106cd1adee00c526d6e249753e54c6
data/README.md CHANGED
@@ -98,11 +98,11 @@ Requirements
98
98
 
99
99
  - No additional Ruby gems or native libraries are needed.
100
100
 
101
- - PNM has been tested with
101
+ - PNM's current version has been tested with
102
102
 
103
- - Ruby 3.1, 3.0,
104
- - Ruby 2.7, 2.6, 2.5, 2.4, 2.3, 2.2, 2.1, 2.0.0,
105
- - JRuby 9.3.4.0.
103
+ - Ruby 3.3, 3.2, 3.1, 3.0,
104
+ - Ruby 2.7, 2.6,
105
+ - JRuby 9.4.5.0.
106
106
 
107
107
  Documentation
108
108
  -------------
@@ -118,7 +118,7 @@ Report bugs on the PNM home page: <https://github.com/stomar/pnm/>
118
118
  License
119
119
  -------
120
120
 
121
- Copyright &copy; 2013-2022 Marcus Stollsteimer
121
+ Copyright &copy; 2013-2024 Marcus Stollsteimer
122
122
 
123
123
  `PNM` is free software: you can redistribute it and/or modify
124
124
  it under the terms of the GNU General Public License version 3 or later (GPLv3+),
data/Rakefile CHANGED
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rakefile for the PNM library.
4
- #
5
- # Copyright (C) 2013-2022 Marcus Stollsteimer
6
-
7
3
  require "rake/testtask"
8
4
 
9
5
  require_relative "lib/pnm"
@@ -25,7 +21,7 @@ end
25
21
 
26
22
  desc "Run benchmarks"
27
23
  task :benchmark do
28
- Dir["benchmark/**/bm_*.rb"].each {|f| require_relative f }
24
+ Dir["benchmark/**/bm_*.rb"].sort.each {|f| require_relative f }
29
25
  end
30
26
 
31
27
 
@@ -1,10 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- # bm_converter.rb: Benchmarks for the PNM library.
5
- #
6
- # Copyright (C) 2013-2022 Marcus Stollsteimer
7
-
8
4
  require "benchmark"
9
5
  require_relative "../lib/pnm"
10
6
 
@@ -12,8 +8,8 @@ require_relative "../lib/pnm"
12
8
  class ConverterBenchmark
13
9
 
14
10
  def initialize
15
- @repetitions = ARGV[0].to_i if ARGV[0] =~ /[0-9]+/
16
- @repetitions ||= 10
11
+ @repetitions = ENV.fetch("BM_RUNS", "")
12
+ @repetitions = @repetitions.match?(/\A[0-9]+\z/) ? @repetitions.to_i : 10
17
13
 
18
14
  @srcpath = File.dirname(__FILE__)
19
15
 
data/lib/pnm/converter.rb CHANGED
@@ -53,14 +53,14 @@ module PNM
53
53
  bytes_per_row = byte_width(type, width)
54
54
  expected_size = bytes_per_row * height
55
55
 
56
- data.slice!(-1) if data.size == expected_size + 1 && data[-1] =~ /[ \t\r\n]/
56
+ data.slice!(-1) if data.size == expected_size + 1 && data[-1].match?(/[ \t\r\n]/)
57
57
 
58
58
  assert_data_size(data.size, expected_size)
59
59
 
60
60
  pixel_matrix = case type
61
61
  when :pbm
62
62
  rows = data.scan(/.{#{bytes_per_row}}/m)
63
- rows.map {|row| row.unpack("B*").first[0, width].each_char.map(&:to_i) }
63
+ rows.map {|row| row.unpack1("B*")[0, width].each_char.map(&:to_i) }
64
64
  when :pgm
65
65
  data.each_byte.each_slice(bytes_per_row).to_a
66
66
  when :ppm
@@ -109,7 +109,7 @@ module PNM
109
109
  values_as_string = if type == :pbm
110
110
  data.gsub(/[ \t\r\n]+/, "").chars
111
111
  else
112
- data.gsub(/\A[ \t\r\n]+/, "").split(/[ \t\r\n]+/)
112
+ data.sub(/\A[ \t\r\n]+/, "").split(/[ \t\r\n]+/)
113
113
  end
114
114
 
115
115
  values_as_string.map {|value| Integer(value) }
data/lib/pnm/image.rb CHANGED
@@ -181,7 +181,7 @@ module PNM
181
181
 
182
182
  def self.assert_valid_maxgray(maxgray) # :nodoc:
183
183
  return unless maxgray
184
- return if maxgray.is_a?(Integer) && maxgray > 0 && maxgray <= 255
184
+ return if maxgray.is_a?(Integer) && maxgray.positive? && maxgray <= 255
185
185
 
186
186
  msg = "invalid maxgray value - #{maxgray.inspect}"
187
187
  raise PNM::ArgumentError, msg
@@ -258,7 +258,7 @@ module PNM
258
258
  return [""] if comment.empty?
259
259
 
260
260
  keep_trailing_null_fields = -1 # magic value for split limit
261
- comment.split(/\n/, keep_trailing_null_fields)
261
+ comment.split("\n", keep_trailing_null_fields)
262
262
  end
263
263
 
264
264
  def to_ascii # :nodoc:
data/lib/pnm/parser.rb CHANGED
@@ -29,7 +29,7 @@ module PNM
29
29
  token = next_token!(content)
30
30
 
31
31
  if token.start_with?("#")
32
- comments << token.gsub(/# */, "")
32
+ comments << strip_comment_prefix(token)
33
33
  else
34
34
  magic_number = token
35
35
  end
@@ -38,11 +38,11 @@ module PNM
38
38
  assert_valid_magic_number(magic_number)
39
39
 
40
40
  while tokens.size < token_number[magic_number]
41
- content.gsub!(/\A[ \t\r\n]+/, "")
41
+ content.sub!(/\A[ \t\r\n]+/, "")
42
42
  token = next_token!(content)
43
43
 
44
44
  if token.start_with?("#")
45
- comments << token.gsub(/# */, "")
45
+ comments << strip_comment_prefix(token)
46
46
  else
47
47
  tokens << token
48
48
  end
@@ -100,6 +100,10 @@ module PNM
100
100
  token
101
101
  end
102
102
 
103
+ def self.strip_comment_prefix(comment)
104
+ comment.sub(/\A# */, "")
105
+ end
106
+
103
107
  def self.assert_valid_magic_number(magic_number)
104
108
  return if %w[P1 P2 P3 P4 P5 P6].include?(magic_number)
105
109
 
@@ -108,21 +112,21 @@ module PNM
108
112
  end
109
113
 
110
114
  def self.assert_integer(value_string, value_name)
111
- return if value_string =~ /\A[0-9]+\Z/
115
+ return if value_string.match?(/\A[0-9]+\z/)
112
116
 
113
117
  msg = "#{value_name} must be an integer - `#{value_string}'"
114
118
  raise PNM::ParserError, msg
115
119
  end
116
120
 
117
121
  def self.assert_positive(value, name)
118
- return if value > 0
122
+ return if value.positive?
119
123
 
120
124
  msg = "#{name} must be greater than 0 - `#{value}'"
121
125
  raise PNM::ParserError, msg
122
126
  end
123
127
 
124
128
  def self.assert_in_maxgray_range(value)
125
- return if value > 0 && value <= 255
129
+ return if value.positive? && value <= 255
126
130
 
127
131
  msg = "invalid maxgray value - `#{value}'"
128
132
  raise PNM::ParserError, msg
data/lib/pnm/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PNM
4
- VERSION = "0.6.1"
5
- DATE = "2022-05-09"
4
+ VERSION = "0.7.0"
5
+ DATE = "2024-01-05"
6
6
  end
data/lib/pnm.rb CHANGED
@@ -87,7 +87,7 @@ require_relative "pnm/exceptions"
87
87
  #
88
88
  # == Author
89
89
  #
90
- # Copyright (C) 2013-2022 Marcus Stollsteimer
90
+ # Copyright (C) 2013-2024 Marcus Stollsteimer
91
91
  #
92
92
  # License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
93
93
  #
@@ -97,8 +97,8 @@ module PNM
97
97
  HOMEPAGE = "https://github.com/stomar/pnm"
98
98
  TAGLINE = "create/read/write PNM image files (PBM, PGM, PPM)"
99
99
 
100
- COPYRIGHT = <<-TEXT.gsub(/^ +/, "")
101
- Copyright (C) 2013-2022 Marcus Stollsteimer.
100
+ COPYRIGHT = <<~TEXT
101
+ Copyright (C) 2013-2024 Marcus Stollsteimer.
102
102
  License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
103
103
  This is free software: you are free to change and redistribute it.
104
104
  There is NO WARRANTY, to the extent permitted by law.
data/pnm.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
25
25
 
26
26
  s.license = "GPL-3.0"
27
27
 
28
- s.required_ruby_version = ">= 2.0.0"
28
+ s.required_ruby_version = ">= 2.6.0"
29
29
 
30
30
  s.require_paths = ["lib"]
31
31
 
@@ -1,14 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # test_converter.rb: Unit tests for the PNM library.
4
- #
5
- # Copyright (C) 2013-2022 Marcus Stollsteimer
6
-
7
3
  require "minitest/autorun"
8
4
  require "pnm/converter"
9
5
 
10
- require_relative "backports"
11
-
12
6
 
13
7
  describe PNM::Converter do
14
8
 
@@ -1,15 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # test_exceptions.rb: Unit tests for the PNM library.
4
- #
5
- # Copyright (C) 2013-2022 Marcus Stollsteimer
6
-
7
3
  require "minitest/autorun"
8
4
  require "stringio"
9
5
  require "pnm"
10
6
 
11
- require_relative "backports"
12
-
13
7
 
14
8
  describe "PNM.create" do
15
9
 
data/test/test_image.rb CHANGED
@@ -1,14 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # test_image.rb: Unit tests for the PNM library.
4
- #
5
- # Copyright (C) 2013-2022 Marcus Stollsteimer
6
-
7
3
  require "minitest/autorun"
8
4
  require "pnm"
9
5
 
10
- require_relative "backports"
11
-
12
6
 
13
7
  describe PNM::Image do
14
8
 
data/test/test_parser.rb CHANGED
@@ -1,14 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # test_parser.rb: Unit tests for the PNM library.
4
- #
5
- # Copyright (C) 2013-2022 Marcus Stollsteimer
6
-
7
3
  require "minitest/autorun"
8
4
  require "pnm/parser"
9
5
 
10
- require_relative "backports"
11
-
12
6
 
13
7
  describe PNM::Parser do
14
8
 
@@ -17,7 +11,7 @@ describe PNM::Parser do
17
11
  end
18
12
 
19
13
  it "can parse ASCII encoded PBM data" do
20
- content = <<-PBM.chomp.gsub(/^ */, "")
14
+ content = <<~PBM.chomp
21
15
  P1 6 2
22
16
  0 1 0 0 1 1
23
17
  0 0 0 1 1 1
@@ -33,7 +27,7 @@ describe PNM::Parser do
33
27
  end
34
28
 
35
29
  it "can parse ASCII encoded PGM data" do
36
- content = <<-PGM.chomp.gsub(/^ */, "")
30
+ content = <<~PGM.chomp
37
31
  P2 4 2 100
38
32
  10 20 30 40
39
33
  50 60 70 80
@@ -98,7 +92,7 @@ describe PNM::Parser do
98
92
  end
99
93
 
100
94
  it "can parse comments" do
101
- content = <<-PBM.chomp.gsub(/^ */, "")
95
+ content = <<~PBM.chomp
102
96
  # Comment 1
103
97
  P1 # Comment 2
104
98
  6# Comment 3
@@ -119,4 +113,25 @@ describe PNM::Parser do
119
113
 
120
114
  _(@parser.parse(content)).must_equal expected
121
115
  end
116
+
117
+ it "can parse a comment containing a # character" do
118
+ content = <<~PBM.chomp
119
+ # Comment 1 with # character
120
+ P1
121
+ # Comment 2: '# foo' is a comment
122
+ 3
123
+ 2
124
+ 0 1 0
125
+ 1 0 1
126
+ PBM
127
+ expected = {
128
+ magic_number: "P1",
129
+ width: 3,
130
+ height: 2,
131
+ comments: ["Comment 1 with # character", "Comment 2: '# foo' is a comment"],
132
+ data: "0 1 0\n1 0 1"
133
+ }
134
+
135
+ _(@parser.parse(content)).must_equal expected
136
+ end
122
137
  end
data/test/test_pnm.rb CHANGED
@@ -1,14 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # test_pnm.rb: Unit tests for the PNM library.
4
- #
5
- # Copyright (C) 2013-2022 Marcus Stollsteimer
6
-
7
3
  require "minitest/autorun"
8
4
  require "pnm"
9
5
 
10
- require_relative "backports"
11
-
12
6
 
13
7
  describe PNM do
14
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pnm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcus Stollsteimer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-09 00:00:00.000000000 Z
11
+ date: 2024-01-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'PNM is a pure Ruby library for creating, reading, and writing of PNM
14
14
  image files (Portable Anymap): PBM (Portable Bitmap), PGM (Portable Graymap), and
@@ -33,7 +33,6 @@ files:
33
33
  - lib/pnm/parser.rb
34
34
  - lib/pnm/version.rb
35
35
  - pnm.gemspec
36
- - test/backports.rb
37
36
  - test/bilevel_2_binary.pbm
38
37
  - test/bilevel_ascii.pbm
39
38
  - test/bilevel_binary.pbm
@@ -61,14 +60,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
60
  requirements:
62
61
  - - ">="
63
62
  - !ruby/object:Gem::Version
64
- version: 2.0.0
63
+ version: 2.6.0
65
64
  required_rubygems_version: !ruby/object:Gem::Requirement
66
65
  requirements:
67
66
  - - ">="
68
67
  - !ruby/object:Gem::Version
69
68
  version: '0'
70
69
  requirements: []
71
- rubygems_version: 3.3.7
70
+ rubygems_version: 3.5.3
72
71
  signing_key:
73
72
  specification_version: 4
74
73
  summary: PNM - create/read/write PNM image files (PBM, PGM, PPM)
data/test/backports.rb DELETED
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PNM
4
- module Backports # :nodoc:
5
- module Minitest # :nodoc:
6
-
7
- # Provides workaround for missing value wrappers in minitest < 5.6.0.
8
- def _(value = nil, &block)
9
- block || value
10
- end
11
- end
12
- end
13
- end
14
-
15
-
16
- if Gem.loaded_specs["minitest"].version < Gem::Version.new("5.6.0")
17
- warn "Using workaround for missing value wrappers in minitest < 5.6.0."
18
- MiniTest::Spec.send(:include, PNM::Backports::Minitest)
19
- end