Class: Processing::Image
- Inherits:
-
Object
- Object
- Processing::Image
- Includes:
- Xot::Inspectable
- Defined in:
- lib/processing/image.rb
Overview
Image object.
Instance Method Summary collapse
-
#blend(img = nil, sx, sy, sw, sh, dx, dy, dw, dh, mode) ⇒ nil
Blends image.
-
#copy(img = nil, sx, sy, sw, sh, dx, dy, dw, dh) ⇒ nil
Copies image.
-
#filter(*args) ⇒ Object
Applies an image filter.
-
#get(x, y) ⇒ Integer
Returns the color of the pixel.
-
#height ⇒ Numeric
(also: #h)
Gets height of image.
-
#resize(width, height) ⇒ nil
Resizes image.
-
#save(filename) ⇒ Object
Saves image to file.
-
#set(x, y, c) ⇒ nil
Sets the color of the pixel.
-
#size ⇒ Array<Numeric>
Returns the width and height of image.
-
#width ⇒ Numeric
(also: #w)
Gets width of image.
Instance Method Details
#blend(sx, sy, sw, sh, dx, dy, dw, dh, mode) ⇒ nil #blend(img, sx, sy, sw, sh, dx, dy, dw, dh, mode) ⇒ nil
Blends image.
133 134 135 136 137 138 139 |
# File 'lib/processing/image.rb', line 133 def blend(img = nil, sx, sy, sw, sh, dx, dy, dw, dh, mode) img ||= self @image.paint do |painter| img.drawImage__ painter, sx, sy, sw, sh, dx, dy, dw, dh, blend_mode: mode end nil end |
#copy(sx, sy, sw, sh, dx, dy, dw, dh) ⇒ nil #copy(img, sx, sy, sw, sh, dx, dy, dw, dh) ⇒ nil
Copies image.
111 112 113 |
# File 'lib/processing/image.rb', line 111 def copy(img = nil, sx, sy, sw, sh, dx, dy, dw, dh) blend img, sx, sy, sw, sh, dx, dy, dw, dh, :normal end |
#filter(*args) ⇒ Object
Applies an image filter.
overload filter(shader) overload filter(type) overload filter(type, param)
76 77 78 |
# File 'lib/processing/image.rb', line 76 def filter(*args) @filter = Shader.createFilter__(*args) end |
#get(x, y) ⇒ Integer
Returns the color of the pixel.
60 61 62 63 64 |
# File 'lib/processing/image.rb', line 60 def get(x, y) @image.bitmap[x, y] .map {|n| (n * 255).to_i.clamp 0, 255} .then {|r, g, b, a| self.class.toColor__ r, g, b, a} end |
#height ⇒ Numeric Also known as: h
Gets height of image.
27 28 29 |
# File 'lib/processing/image.rb', line 27 def height() @image.height end |
#resize(width, height) ⇒ nil
Resizes image.
87 88 89 90 91 92 |
# File 'lib/processing/image.rb', line 87 def resize(width, height) @image = Rays::Image.new(width, height).paint do |painter| painter.image @image, 0, 0, width, height end nil end |
#save(filename) ⇒ Object
Saves image to file.
145 146 147 |
# File 'lib/processing/image.rb', line 145 def save(filename) @image.save filename end |
#set(x, y, c) ⇒ nil
Sets the color of the pixel.
50 51 52 53 |
# File 'lib/processing/image.rb', line 50 def set(x, y, c) @image.bitmap[x, y] = self.class.fromColor__ c nil end |
#size ⇒ Array<Numeric>
Returns the width and height of image.
38 39 40 |
# File 'lib/processing/image.rb', line 38 def size() @image.size end |
#width ⇒ Numeric Also known as: w
Gets width of image.
19 20 21 |
# File 'lib/processing/image.rb', line 19 def width() @image.width end |