Class: ImageCompare::Image
- Inherits:
-
ChunkyPNG::Image
- Object
- ChunkyPNG::Image
- ImageCompare::Image
show all
- Includes:
- ColorMethods
- Defined in:
- lib/image_compare/image.rb
Instance Method Summary
collapse
#blue, #brightness, #green, #orange, #red, #transparent, #yellow
Instance Method Details
#bounding_rect ⇒ Object
59
60
61
|
# File 'lib/image_compare/image.rb', line 59
def bounding_rect
Rectangle.new(0, 0, width - 1, height - 1)
end
|
#compare_each_pixel(image, area: nil) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/image_compare/image.rb', line 18
def compare_each_pixel(image, area: nil)
area = bounding_rect if area.nil?
(area.top..area.bot).each do |y|
current_row = row(y) || []
range = (area.left..area.right)
next if image.row(y).slice(range) == current_row.slice(range)
(area.left..area.right).each do |x|
yield(self[x, y], image[x, y], x, y)
end
end
end
|
#each_pixel ⇒ Object
9
10
11
12
13
14
15
16
|
# File 'lib/image_compare/image.rb', line 9
def each_pixel
height.times do |y|
current_row = row(y) || []
current_row.each_with_index do |pixel, x|
yield(pixel, x, y)
end
end
end
|
#highlight_rectangle(rect, color = :red) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/image_compare/image.rb', line 52
def highlight_rectangle(rect, color = :red)
raise ArgumentError, "Undefined color: #{color}" unless respond_to?(color)
return self if rect.nil?
rect(*rect.bounds, send(color))
self
end
|
#inspect ⇒ Object
48
49
50
|
# File 'lib/image_compare/image.rb', line 48
def inspect
"Image:#{object_id}<#{width}x#{height}>"
end
|
#sizes_match?(image) ⇒ Boolean
44
45
46
|
# File 'lib/image_compare/image.rb', line 44
def sizes_match?(image)
[width, height] == [image.width, image.height]
end
|
#to_grayscale ⇒ Object
30
31
32
33
34
35
|
# File 'lib/image_compare/image.rb', line 30
def to_grayscale
each_pixel do |pixel, x, y|
self[x, y] = grayscale(brightness(pixel).round)
end
self
end
|
#with_alpha(value) ⇒ Object
37
38
39
40
41
42
|
# File 'lib/image_compare/image.rb', line 37
def with_alpha(value)
each_pixel do |pixel, x, y|
self[x, y] = rgba(r(pixel), g(pixel), b(pixel), value)
end
self
end
|