image_util 0.1.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.
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImageUtil
4
+ module Util
5
+ module_function
6
+
7
+ # Applies configuration tweaks for IRB, if available.
8
+ def irb_fixup
9
+ IRB.conf[:USE_PAGER] = false
10
+ IRB.CurrentContext.echo_on_assignment = true
11
+ rescue StandardError
12
+ nil
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImageUtil
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImageUtil
4
+ module View
5
+ # Allows fractional coordinates by distributing values to
6
+ # neighbouring pixels using bilinear interpolation.
7
+ Interpolated = Data.define(:image) do
8
+ def generate_subpixel_hash(location)
9
+ arrays = location.map do |i|
10
+ frac = i % 1
11
+ if frac.zero?
12
+ [[i.floor, 1.0]]
13
+ else
14
+ [[i.floor, 1 - frac], [i.floor + 1, frac]]
15
+ end
16
+ end
17
+
18
+ hash = {}
19
+ arrays.shift.product(*arrays) do |combination|
20
+ loc, weight = combination.transpose
21
+ hash[loc] = weight.reduce(:*)
22
+ end
23
+ hash
24
+ end
25
+
26
+ def [](*location)
27
+ accum = Array.new(image.color_length, 0.0)
28
+ generate_subpixel_hash(location).each do |loc, weight|
29
+ image[*loc].each_with_index do |val, idx|
30
+ accum[idx] += val * weight
31
+ end
32
+ end
33
+ Color.new(*accum)
34
+ end
35
+
36
+ def []=(*location, value)
37
+ value = Color[value]
38
+
39
+ generate_subpixel_hash(location).each do |loc, weight|
40
+ image[*loc] += value * weight
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImageUtil
4
+ module View
5
+ # Access pixels by rounding coordinates to the nearest integer.
6
+ Rounded = Data.define(:image) do
7
+ def [](*location)
8
+ image[*location.map(&:round)]
9
+ end
10
+
11
+ def []=(*location, value)
12
+ image[*location.map(&:round)] = value
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImageUtil
4
+ module View
5
+ autoload :Interpolated, "image_util/view/interpolated"
6
+ autoload :Rounded, "image_util/view/rounded"
7
+ end
8
+ end
data/lib/image_util.rb ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "image_util/version"
4
+
5
+ module ImageUtil
6
+ class Error < StandardError; end
7
+ # Your code goes here...
8
+
9
+ autoload :Color, "image_util/color"
10
+ autoload :Image, "image_util/image"
11
+ autoload :Util, "image_util/util"
12
+ autoload :Codec, "image_util/codec"
13
+ autoload :Magic, "image_util/magic"
14
+ autoload :Filter, "image_util/filter"
15
+ autoload :Statistic, "image_util/statistic"
16
+ autoload :View, "image_util/view"
17
+ end
@@ -0,0 +1,4 @@
1
+ module ImageUtil
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: image_util
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - hmdne
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: ffi
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.16'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.16'
26
+ description: Lightweight Color and Image classes for manipulating pixels. Provides
27
+ SIXEL output plus FFI bindings for libpng, libturbojpeg and libsixel.
28
+ email:
29
+ - 54514036+hmdne@users.noreply.github.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - ".rubocop.yml"
36
+ - AGENTS.md
37
+ - CHANGELOG.md
38
+ - LICENSE.txt
39
+ - README.md
40
+ - Rakefile
41
+ - lib/image_util.rb
42
+ - lib/image_util/codec.rb
43
+ - lib/image_util/codec/_guard.rb
44
+ - lib/image_util/codec/image_magick.rb
45
+ - lib/image_util/codec/libpng.rb
46
+ - lib/image_util/codec/libsixel.rb
47
+ - lib/image_util/codec/libturbojpeg.rb
48
+ - lib/image_util/codec/pam.rb
49
+ - lib/image_util/codec/ruby_sixel.rb
50
+ - lib/image_util/color.rb
51
+ - lib/image_util/filter.rb
52
+ - lib/image_util/filter/_mixin.rb
53
+ - lib/image_util/filter/background.rb
54
+ - lib/image_util/filter/dither.rb
55
+ - lib/image_util/filter/draw.rb
56
+ - lib/image_util/filter/paste.rb
57
+ - lib/image_util/filter/resize.rb
58
+ - lib/image_util/image.rb
59
+ - lib/image_util/image/buffer.rb
60
+ - lib/image_util/magic.rb
61
+ - lib/image_util/statistic.rb
62
+ - lib/image_util/statistic/color.rb
63
+ - lib/image_util/util.rb
64
+ - lib/image_util/version.rb
65
+ - lib/image_util/view.rb
66
+ - lib/image_util/view/interpolated.rb
67
+ - lib/image_util/view/rounded.rb
68
+ - sig/image_util.rbs
69
+ homepage: https://github.com/rbutils/image_util
70
+ licenses:
71
+ - MIT
72
+ metadata:
73
+ allowed_push_host: https://rubygems.org
74
+ source_code_uri: https://github.com/rbutils/image_util
75
+ changelog_uri: https://github.com/rbutils/image_util/blob/master/CHANGELOG.md
76
+ documentation_uri: https://github.com/rbutils/image_util#readme
77
+ bug_tracker_uri: https://github.com/rbutils/image_util/issues
78
+ rubygems_mfa_required: 'true'
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 3.2.0
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubygems_version: 3.6.7
94
+ specification_version: 4
95
+ summary: Simple pixel buffers with SIXEL and codec helpers
96
+ test_files: []