Class: Processing::Image

Inherits:
Object
  • Object
show all
Includes:
Xot::Inspectable
Defined in:
lib/processing/image.rb

Overview

Image object.

Instance Method Summary collapse

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

#heightNumeric 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) ⇒ nil

Saves image to file.



147
148
149
150
# File 'lib/processing/image.rb', line 147

def save(filename)
  @image.save filename
  nil
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

#sizeArray<Numeric>

Returns the width and height of image.



38
39
40
# File 'lib/processing/image.rb', line 38

def size()
  @image.size
end

#widthNumeric Also known as: w

Gets width of image.



19
20
21
# File 'lib/processing/image.rb', line 19

def width()
  @image.width
end