Class: FocusInspector

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

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ FocusInspector

Returns a new instance of FocusInspector.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/focusinspector/FocusInspector.rb', line 20

def initialize(args)
  @config = AppConfig.new(args)

  @imageFile = @config.imageFile
  # Conver the raw file to jpg if we have one.
  convertRaw

  focusInfo = Camera.new(@imageFile)
  x, y = focusInfo.primaryAutoFocusPoint

  case @config.command
  when 'list'
    focusInfo.printDetails
  when 'measure'
    sm = SharpnessMeter.new(@jpgFile)
    puts "Sharpness:  %.2f%%  (%s)" % [ (sm.measure(x, y) * 100.0),
         focusInfo.contrastDetectAF? ? 'Contrast Detection AF' :
         "FP: #{focusInfo.focusPoint}  AFFT: #{focusInfo.focusFineTune}" ]
  when 'show'
    im = ImageMarker.new(@jpgFile, *focusInfo.focusAreaSize, @config.viewer)
    im.mark(x, y, 'red', true)

    activeFPxy = focusInfo.activeFocusPoints
    inactiveFPxy = focusInfo.inactiveFocusPoints

    activeFPxy.each { |xy| im.mark(*xy, 'red') }
    inactiveFPxy.each { |xy| im.mark(*xy, 'grey') }

    im.show(focusInfo.orientation)
  end
end

Instance Method Details

#convertRawObject



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/focusinspector/FocusInspector.rb', line 52

def convertRaw
  if @imageFile[-4..-1] == '.NEF' || @imageFile[-4..-1] == '.nef'
    @tmpJPGfile = Tempfile.new('lenstuner-jpg')
    @tmpJPGfile.close
    @jpgFile = @tmpJPGfile.path
    command = "dcraw -c -e #{@imageFile} > #{@jpgFile}"
    unless system(command)
      Log.error("Cannot execute '#{command}'")
    end
  else
    @jpgFile = @imageFile
  end
end