Class: ImageMarker

Inherits:
Object
  • Object
show all
Defined in:
lib/focusinspector/ImageMarker.rb

Overview

Focus Inspector - The focus inspection and lens calibration software.

Copyright © 2012 by Chris Schlaeger <[email protected]>

This program is Open Source software; you can redistribute it and/or modify it under the terms of MIT license as shipped with this software.

Instance Method Summary collapse

Constructor Details

#initialize(imageFile, w, h, viewer) ⇒ ImageMarker

Returns a new instance of ImageMarker.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/focusinspector/ImageMarker.rb', line 13

def initialize(imageFile, w, h, viewer)
  begin
    @image = Magick::Image.read(imageFile).first
    # The size of the auto focus area.
    @w = w
    @h = h
  rescue
    Log.error("Cannot open image file #{imageFile}")
  end
  @viewer = viewer
end

Instance Method Details

#mark(x, y, color, bold = false) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/focusinspector/ImageMarker.rb', line 25

def mark(x, y, color, bold = false)
  painter = Magick::Draw.new
  painter.fill_opacity(0.0)
  painter.stroke(color)
  painter.stroke_width = bold ? 13 : 9
  painter.rectangle(x - @w / 2, y - @h / 2, x + @w / 2, y + @h / 2)
  painter.draw(@image)
end

#show(orientation) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/focusinspector/ImageMarker.rb', line 34

def show(orientation)
  # Since we have created a new image, the orientation of the original got
  # lost. We simply rotate the image to match the original orientation.
  case orientation
  when 'Rotate 90 CW'
    @image.rotate!(90)
  when 'Rotate 270 CW'
    @image.rotate!(270)
  end

  ImageViewer.new(@image, @viewer)
end