Class: PhotoUtils::Brightness

Inherits:
Value show all
Defined in:
lib/photo_utils/brightness.rb

Constant Summary collapse

N =

N = 2 ** Rational(-7, 4)

0.3
K =
11.4
NK =
N * K

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Value

#<=>, #==, #decr, #incr, #initialize

Methods inherited from Float

#format, #prec

Constructor Details

This class inherits a constructor from PhotoUtils::Value

Class Method Details

.new_from_cdm2(n) ⇒ Object



16
17
18
# File 'lib/photo_utils/brightness.rb', line 16

def self.new_from_cdm2(n)
  new(n)
end

.new_from_v(v) ⇒ Object

amount specified in cd/m2



12
13
14
# File 'lib/photo_utils/brightness.rb', line 12

def self.new_from_v(v)
  new((2 ** v.to_f) * NK)
end

Instance Method Details

#format_cdm2Object



28
29
30
# File 'lib/photo_utils/brightness.rb', line 28

def format_cdm2
  to_cdm2.format(10) + ' cd/m2'
end

#format_valueObject



32
33
34
# File 'lib/photo_utils/brightness.rb', line 32

def format_value
  "Bv:#{to_v.format}"
end

#to_cdm2Object



24
25
26
# File 'lib/photo_utils/brightness.rb', line 24

def to_cdm2
  to_f
end

#to_s(format = :cdm2) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/photo_utils/brightness.rb', line 36

def to_s(format=:cdm2)
  case format
  when :cdm2
    format_cdm2
  when :value
    format_value
  else
    raise "Unknown format: #{format.inspect}"
  end
end

#to_vObject



20
21
22
# File 'lib/photo_utils/brightness.rb', line 20

def to_v
  Math.log2(to_f / NK)
end