image_util 0.3.0 → 0.4.0

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: 31687d0660e040e340b6ed26f581f95de0746e33f992acf7dfcdb4fa4a88f4cd
4
- data.tar.gz: 4fee3793295fb2207a54caa1ed430bdc43ddc8307f96ef597ba0ed777618b8e6
3
+ metadata.gz: 893e648382567326c70c82a4b3e3b6580889229c9d56c7a20ec4d182b45332b4
4
+ data.tar.gz: 70fd8a63b0551a0aaca12dae391c076fb01621443ec1ae5e5f92c680655277f2
5
5
  SHA512:
6
- metadata.gz: c02064cb968adae5e5d5b5328922e77fd542d6ca4322a9259d27b513339ff44ca71e272f8cf01055d864f3dbc3fef702d3187a745e98af09a95f2dc9907470c4
7
- data.tar.gz: 97c9852b31aab0d2b71f19579968d856fd87eed7339c3b2ec9e6bd1dcee3b674862821f6d4a033148db8d45b0a8228d890670d43c2f0ba921dc98d7d5ed774de
6
+ metadata.gz: 89a0a3bf90307337674acae7e1315505bc4a8363e58c041388dc6e6beeaab3f03e4534d2ff41e9a97c23f5775e62db6ebe5493658ac2b81e06f3a650a197d28a
7
+ data.tar.gz: 6b425b6539c389431e78cdc98744a82888a3f55e0fdeed64062bf69a3e0448fec84e83264b3dd1380133a5adafa87e5751dd36595c7c3dc413e4ead3173d21ae
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## [0.4.0] - 2025-10-04
2
+ - BREAKING: Float color components now share the 0..255 range with integers instead of being scaled from 0..1.
3
+ - Add `define_mutable_version` helper to create bang versions from immutable methods
4
+ - Add `background!` and `resize!` filters
5
+
1
6
  ## [0.3.0] - 2025-07-25
2
7
  - Rename `dither!` to `palette_reduce!`
3
8
  - Rename `#set_each_pixel_by_location` to `#set_each_pixel_by_location!` since it's mutable
data/README.md CHANGED
@@ -96,13 +96,13 @@ the earlier system packages. Both Kitty and SIXEL outputs also accept one-dimens
96
96
  - Symbols or strings containing CSS color names (`:rebeccapurple`, 'papayawhip')
97
97
  - Hex strings like `'#abc'`, `'#aabbcc'` or `'#rrggbbaa'`
98
98
 
99
- When numeric components are given, integers are first clamped to the `0..255`
100
- range. Float values are treated as fractions of 255, so `0.5` becomes `127.5`
101
- and `1.0` becomes `255`. After scaling, values are again clamped to this range.
102
- If the alpha channel is omitted it defaults to `255`.
99
+ When numeric components are given, values are clamped directly to the `0..255`
100
+ range regardless of whether they are integers or floats. Floating point inputs
101
+ are no longer scaled from `0..1`; instead they are treated in the same units as
102
+ integers. If the alpha channel is omitted it defaults to `255`.
103
103
 
104
104
  ```ruby
105
- ImageUtil::Color[0.5] # => #808080
105
+ ImageUtil::Color[128.5] # => #808080
106
106
  ImageUtil::Color[:red] # => #ff0000
107
107
  ImageUtil::Color["#fc0"] # => #ffcc00
108
108
  ```
@@ -177,7 +177,8 @@ Flatten an RGBA image on a solid color.
177
177
  img = ImageUtil::Image.new(128, 128) { |x, y| [255, 0, 0, x + y] }
178
178
 
179
179
  # put it on a blue background
180
- img.background([0, 0, 255])
180
+ img.background!([0, 0, 255])
181
+ # img.background([0, 0, 255]) # returns a new image
181
182
  ```
182
183
 
183
184
  ![Background example](docs/samples/background.png)
@@ -216,6 +217,7 @@ Scale an image to new dimensions.
216
217
  img = ImageUtil::Image.new(128, 128) { |x, y| [x, y, 30] }
217
218
  img[20, 20] = img.resize(64, 64)
218
219
  img
220
+ # img.resize!(64, 64) # modifies in place
219
221
  ```
220
222
 
221
223
  ![Resize example](docs/samples/resize.png)
@@ -64,20 +64,15 @@ module ImageUtil
64
64
  img = img.redimension(img.width, img.height + pad) if pad > 0
65
65
  end
66
66
  pam = Codec::Pam.encode(:pam, img)
67
-
68
- IO.popen(["magick", "pam:-", "#{fmt}:-"], "r+b") do |proc_io|
69
- proc_io << pam
70
- proc_io.close_write
71
- proc_io.read
72
- end
73
67
  else
74
68
  frames = image.buffer.last_dimension_split.map { |b| Image.from_buffer(b) }
75
- stream = frames.map { |f| Codec::Pam.encode(:pam, f) }.join
76
- IO.popen(["magick", "pam:-", "#{fmt}:-"], "r+b") do |proc_io|
77
- proc_io << stream
78
- proc_io.close_write
79
- proc_io.read
80
- end
69
+ pam = frames.map { |f| Codec::Pam.encode(:pam, f) }.join
70
+ end
71
+
72
+ IO.popen(["magick", "pam:-", "#{fmt}:-"], "r+b") do |proc_io|
73
+ proc_io << pam
74
+ proc_io.close_write
75
+ proc_io.read
81
76
  end
82
77
  end
83
78
 
@@ -24,7 +24,7 @@ module ImageUtil
24
24
  when Integer
25
25
  number.clamp(0, 255)
26
26
  when Float
27
- (number * 255).clamp(0, 255)
27
+ number.clamp(0, 255)
28
28
  else
29
29
  raise ArgumentError, "wrong type passed as component (passed: #{number})"
30
30
  end
@@ -11,6 +11,15 @@ module ImageUtil
11
11
  end
12
12
  end
13
13
 
14
+ def define_mutable_version(*names)
15
+ names.each do |name|
16
+ define_method("#{name}!") do |*args, **kwargs, &block|
17
+ initialize_from_buffer(public_send(name, *args, **kwargs, &block).buffer)
18
+ self
19
+ end
20
+ end
21
+ end
22
+
14
23
  def axis_to_number(axis)
15
24
  axis = 0 if axis == :x
16
25
  axis = 1 if axis == :y
@@ -3,6 +3,7 @@
3
3
  module ImageUtil
4
4
  module Filter
5
5
  module Background
6
+ extend ImageUtil::Filter::Mixin
6
7
  def background(bgcolor)
7
8
  return self if channels == 3
8
9
 
@@ -18,6 +19,8 @@ module ImageUtil
18
19
  end
19
20
  img
20
21
  end
22
+
23
+ define_mutable_version :background
21
24
  end
22
25
  end
23
26
  end
@@ -3,6 +3,7 @@
3
3
  module ImageUtil
4
4
  module Filter
5
5
  module Resize
6
+ extend ImageUtil::Filter::Mixin
6
7
  def resize(*new_dimensions, view: View::Interpolated)
7
8
  src = self.view(view)
8
9
 
@@ -15,6 +16,8 @@ module ImageUtil
15
16
  src[*src_loc]
16
17
  end
17
18
  end
19
+
20
+ define_mutable_version :resize
18
21
  end
19
22
  end
20
23
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ImageUtil
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_util
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - hmdne
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  - !ruby/object:Gem::Version
169
169
  version: '0'
170
170
  requirements: []
171
- rubygems_version: 3.6.7
171
+ rubygems_version: 3.6.9
172
172
  specification_version: 4
173
173
  summary: Simple pixel buffers with SIXEL and codec helpers
174
174
  test_files: []