Class: Processing::Image
- Inherits:
-
Object
- Object
- Processing::Image
- Includes:
- Xot::Inspectable
- Defined in:
- lib/processing/image.rb
Overview
Image object.
Instance Attribute Summary collapse
-
#pixels ⇒ Array
readonly
An array of all pixels.
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.
-
#loadPixels ⇒ nil
Loads all pixels to the ‘pixels’ array.
-
#resize(width, height) ⇒ nil
Resizes image.
-
#save(filename) ⇒ nil
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.
-
#updatePixels ⇒ nil
Update the image pixels with the ‘pixels’ array.
-
#width ⇒ Numeric
(also: #w)
Gets width of image.
Instance Attribute Details
#pixels ⇒ Array (readonly)
An array of all pixels. Call loadPixels() before accessing the array.
113 114 115 |
# File 'lib/processing/image.rb', line 113 def pixels @pixels end |
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.
199 200 201 202 203 204 205 |
# File 'lib/processing/image.rb', line 199 def blend(img = nil, sx, sy, sw, sh, dx, dy, dw, dh, mode) img ||= self getInternal__.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.
169 170 171 |
# File 'lib/processing/image.rb', line 169 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)
128 129 130 |
# File 'lib/processing/image.rb', line 128 def filter(*args) @filter = Shader.createFilter__(*args) end |
#get(x, y) ⇒ Integer
Returns the color of the pixel.
75 76 77 78 79 |
# File 'lib/processing/image.rb', line 75 def get(x, y) getInternal__.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.
37 38 39 |
# File 'lib/processing/image.rb', line 37 def height() @image&.height || (@error ? -1 : 0) end |
#loadPixels ⇒ nil
Loads all pixels to the ‘pixels’ array.
88 89 90 |
# File 'lib/processing/image.rb', line 88 def loadPixels() @pixels = getInternal__.pixels end |
#resize(width, height) ⇒ nil
Resizes image.
142 143 144 145 146 147 |
# File 'lib/processing/image.rb', line 142 def resize(width, height) @image = Rays::Image.new(width, height).paint do |painter| painter.image getInternal__, 0, 0, width, height end nil end |
#save(filename) ⇒ nil
Saves image to file.
256 257 258 259 |
# File 'lib/processing/image.rb', line 256 def save(filename) getInternal__.save filename nil end |
#set(x, y, c) ⇒ nil
Sets the color of the pixel.
63 64 65 66 |
# File 'lib/processing/image.rb', line 63 def set(x, y, c) getInternal__.bitmap(true)[x, y] = self.class.fromColor__(c).map {|n| n / 255.0} nil end |
#size ⇒ Array<Numeric>
Returns the width and height of image.
48 49 50 |
# File 'lib/processing/image.rb', line 48 def size() [width, height] end |
#updatePixels ⇒ nil
Update the image pixels with the ‘pixels’ array.
99 100 101 102 103 |
# File 'lib/processing/image.rb', line 99 def updatePixels() return unless @pixels getInternal__.pixels = @pixels @pixels = nil end |
#width ⇒ Numeric Also known as: w
Gets width of image.
26 27 28 |
# File 'lib/processing/image.rb', line 26 def width() @image&.width || (@error ? -1 : 0) end |