Sha256: 99fa46e676037ead740cf8700eae4a1ff3ea3dbfff261bbfa15565c3159a67b0

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 KB

Contents

require 'psd/layer_info'

class PSD
  class Levels < LayerInfo
    def self.should_parse?(key)
      key == 'levl'
    end

    attr_reader :records

    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
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
psd-3.9.0 lib/psd/layer/info/levels.rb
psd-3.8.0 lib/psd/layer/info/levels.rb
psd-3.7.0 lib/psd/layer/info/levels.rb
psd-3.6.0 lib/psd/layer/info/levels.rb
psd-3.5.0 lib/psd/layer/info/levels.rb