Class: PSD::Levels

Inherits:
LayerInfo show all
Defined in:
lib/psd/layer/info/levels.rb

Instance Attribute Summary collapse

Attributes inherited from LayerInfo

#data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from LayerInfo

#initialize, #skip

Constructor Details

This class inherits a constructor from PSD::LayerInfo

Instance Attribute Details

#recordsObject (readonly)

Returns the value of attribute records.



9
10
11
# File 'lib/psd/layer/info/levels.rb', line 9

def records
  @records
end

Class Method Details

.should_parse?(key) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/psd/layer/info/levels.rb', line 5

def self.should_parse?(key)
  key == 'levl'
end

Instance Method Details

#parseObject



11
12
13
14
15
16
17
18
19
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
# File 'lib/psd/layer/info/levels.rb', line 11

def parse
  @file.seek 2, IO::SEEK_CUR

  @records = 29.times.map do
    {
      input_floor: @file.read_short,
      input_ceiling: @file.read_short,
      output_floor: @file.read_short,
      output_ceiling: @file.read_short,
      gamma: @file.read_short / 100.0,
    }
  end

  # Photoshop CS (8.0) additional information
  if @file.tell < @section_end - 4
    tag = @file.read_string(4)
    raise 'Extra levels key error' if tag != 'Lvls'

    @file.seek 2, IO::SEEK_CUR

    # Count of total level record structures. Subtract the legacy number of
    # level record structures, 29, to determine how many are remaining in
    # the file for reading.
    extra_levels = @file.read_short - 29

    extra_levels.times do
      @records << {
        input_floor: @file.read_short,
        input_ceiling: @file.read_short,
        output_floor: @file.read_short,
        output_ceiling: @file.read_short,
        gamma: @file.read_short / 100.0
      }
    end
  end
end