Class: CineSync::ColorGrading

Inherits:
Object
  • Object
show all
Defined in:
lib/cinesync/xml.rb,
lib/cinesync/color_grading.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeColorGrading

Returns a new instance of ColorGrading.



8
9
10
11
12
13
14
15
16
# File 'lib/cinesync/color_grading.rb', line 8

def initialize
  @offset = RGBArray.new([0.0] * 3)
  @brightness = BrightnessArray.new([1.0] * 4)
  @saturation = 1.0
  @gamma = 1.0
  @contrast = 1.0
  @linear_to_log = false
  @lut_path = nil
end

Instance Attribute Details

#brightnessObject (readonly)

Returns the value of attribute brightness.



3
4
5
# File 'lib/cinesync/color_grading.rb', line 3

def brightness
  @brightness
end

#contrastObject

Returns the value of attribute contrast.



4
5
6
# File 'lib/cinesync/color_grading.rb', line 4

def contrast
  @contrast
end

#gammaObject

Returns the value of attribute gamma.



4
5
6
# File 'lib/cinesync/color_grading.rb', line 4

def gamma
  @gamma
end

#linear_to_logObject Also known as: linear_to_log?

Returns the value of attribute linear_to_log.



4
5
6
# File 'lib/cinesync/color_grading.rb', line 4

def linear_to_log
  @linear_to_log
end

#lut_pathObject

Returns the value of attribute lut_path.



4
5
6
# File 'lib/cinesync/color_grading.rb', line 4

def lut_path
  @lut_path
end

#offsetObject (readonly)

Returns the value of attribute offset.



3
4
5
# File 'lib/cinesync/color_grading.rb', line 3

def offset
  @offset
end

#saturationObject

Returns the value of attribute saturation.



4
5
6
# File 'lib/cinesync/color_grading.rb', line 4

def saturation
  @saturation
end

Class Method Details

.load(elem) ⇒ Object



377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'lib/cinesync/xml.rb', line 377

def self.load(elem)
  returning self.new do |cg|
    offset_elem = elem.elements['offset']
    if offset_elem
      %w(red green blue).each do |attr|
        cg.offset[attr] = offset_elem.attribute(attr).value.to_f
      end
    end

    brightness_elem = elem.elements['brightness']
    if brightness_elem
      %w(rgb red green blue).each do |attr|
        cg.brightness[attr] = brightness_elem.attribute(attr).value.to_f
      end
    end

    # Everything is optional
    (cg.saturation = elem.elements['saturation/attribute::value'].value.to_f) rescue :ignore
    (cg.gamma      = elem.elements['gamma/attribute::value'].value.to_f     ) rescue :ignore
    (cg.contrast   = elem.elements['contrast/attribute::value'].value.to_f  ) rescue :ignore

    (cg.linear_to_log = elem.elements['linearToLog/attribute::value'].value == 'true') rescue :ignore
    (cg.lut_path = elem.elements['lutPath/attribute::value']) rescue :ignore
  end
end

Instance Method Details

#default?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/cinesync/color_grading.rb', line 18

def default?
  offset == [0.0]*3 and brightness == [1.0]*4 and
  [saturation, gamma, contrast].all? {|f| f == 1.0 } and
  not linear_to_log? and lut_path.nil?
end

#to_xml(x) ⇒ Object

eColorGrading = element colorGrading {

element offset {
  attribute red  	 	{ tColorOff } &
  attribute green	 	{ tColorOff } &
  attribute blue 	 	{ tColorOff } }? &

element brightness {
  attribute rgb  	 	{ tColorExp } &
  attribute red  	 	{ tColorExp } &
  attribute green	 	{ tColorExp } &
  attribute blue 	 	{ tColorExp } }? &

element saturation  { attribute value { tColorExp } }? &
element gamma       { attribute value { tColorExp } }? &
element contrast    { attribute value { tColorExp } }? &

element linearToLog { aBoolValue }? &
element lutPath     { attribute value { tFilePath } }? }


360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'lib/cinesync/xml.rb', line 360

def to_xml(x)
  fail "#{self.inspect}: Invalid" unless valid?
  return if default?

  x.colorGrading {
    x.offset(:red => offset[:r], :green => offset[:g], :blue => offset[:b])
    br = brightness
    x.brightness(:rgb => br[:rgb], :red => br[:r], :green => br[:g], :blue => br[:b])
    x.saturation(:value => saturation)
    x.gamma(:value => gamma)
    x.contrast(:value => contrast)
    x.linearToLog(:value => linear_to_log?)
    x.lutPath(:value => lut_path) if lut_path
  }
end

#valid?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
# File 'lib/cinesync/color_grading.rb', line 24

def valid?
  exp_range = Math.exp(-1)..Math.exp(1)
  default? or (offset.length == 3 and brightness.length == 4 and
  offset.all? {|o| (-0.2..0.2) === o } and
  [saturation, gamma, contrast, *brightness].all? {|b| exp_range === b }) rescue false
end