Class: Nakal::Common::BaseScreen
- Inherits:
-
Object
- Object
- Nakal::Common::BaseScreen
show all
- Defined in:
- lib/nakal/base_screen.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(file_name, mode = :load, image = nil) ⇒ BaseScreen
Returns a new instance of BaseScreen.
7
8
9
10
11
12
|
# File 'lib/nakal/base_screen.rb', line 7
def initialize file_name, mode = :load, image = nil
@name = file_name
@image = image
capture if mode.eql?(:capture)
image.nil? ? @image = Magick::Image.read("#{Nakal.image_location}/#{@name}.png")[0] : @image=image
end
|
Instance Attribute Details
#image ⇒ Object
Returns the value of attribute image.
5
6
7
|
# File 'lib/nakal/base_screen.rb', line 5
def image
@image
end
|
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/nakal/base_screen.rb', line 5
def name
@name
end
|
Instance Method Details
#apply_mask ⇒ Object
38
39
40
41
42
43
44
45
46
|
# File 'lib/nakal/base_screen.rb', line 38
def apply_mask
image_mask_params = Nakal.default_crop_params[Nakal.device_name][image_relative_path.gsub("_current", "")]
return self if image_mask_params.nil?
image_mask_params.each do |region, params|
gc = Magick::Draw.new.fill('black').rectangle(*params)
gc.draw @image
end
self
end
|
#compare(screen) ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/nakal/base_screen.rb', line 29
def compare screen
@image.fuzz= Nakal.fuzz * Magick::QuantumRange / 100.0
total_pixel = @image.rows * @image.columns
diff_img, no_of_pixels_mismatch = self.apply_mask.strip.compare_channel(screen.apply_mask.strip, Magick::AbsoluteErrorMetric)
diff_screen = Nakal.current_platform::Screen.new("#{@name}_diff", :none, diff_img)
percentage_diff = (no_of_pixels_mismatch/total_pixel)*100
return diff_screen,percentage_diff
end
|
#delete! ⇒ Object
52
53
54
|
# File 'lib/nakal/base_screen.rb', line 52
def delete!
FileUtils.rm "#{Nakal.image_location}/#{@name}.png"
end
|
#image_relative_path ⇒ Object
#save ⇒ Object
56
57
58
|
# File 'lib/nakal/base_screen.rb', line 56
def save
@image.write("#{Nakal.image_location}/#{@name}.png")
end
|
#strip ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/nakal/base_screen.rb', line 14
def strip
crop_params = Nakal.default_crop_params[Nakal.device_name]
if crop_params.nil?
@image
else
width = @image.columns
height = @image.rows
x_start = crop_params["left"]
y_start = crop_params["top"]
width_to_consider = width-crop_params["right"]-x_start
height_to_consider = height-crop_params["bottom"]-y_start
@image.crop(x_start, y_start, width_to_consider, height_to_consider)
end
end
|