Sha256: 8e057b235fbe52573a73c69df5c62eb6f8570f3484282de8f8c926b436662d21

Contents?: true

Size: 1.31 KB

Versions: 12

Compression:

Stored size: 1.31 KB

Contents

class PSD
  class Header
    attr_reader :sig, :version, :channels, :rows, :cols, :depth, :mode

    # All of the color modes are stored internally as a short from 0-15.
    # This is a mapping of that value to a human-readable name.
    MODES = [
      'Bitmap',
      'GrayScale',
      'IndexedColor',
      'RGBColor',
      'CMYKColor',
      'HSLColor',
      'HSBColor',
      'Multichannel',
      'Duotone',
      'LabColor',
      'Gray16',
      'RGB48',
      'Lab48',
      'CMYK64',
      'DeepMultichannel',
      'Duotone16'
    ].freeze

    alias_method :width, :cols
    alias_method :height, :rows

    def initialize(file)
      @file = file

      @sig = nil
      @version = nil
      @channels = nil
      @rows = nil
      @cols = nil
      @depth = nil
      @mode = nil
    end

    def parse!
      @sig = @file.read_string(4)
      @version = @file.read_ushort

      # Reserved bytes, must be 0
      @file.seek 6, IO::SEEK_CUR

      @channels = @file.read_ushort
      @rows = @file.read_uint
      @cols = @file.read_uint
      @depth = @file.read_ushort
      @mode = @file.read_ushort

      color_data_len = @file.read_uint
      @file.seek color_data_len, IO::SEEK_CUR
    end

    def mode_name
      MODES[@mode]
    end

    def rgb?
      mode == 3
    end

    def cmyk?
      mode == 4
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
psd-3.3.3 lib/psd/header.rb
psd-3.3.2 lib/psd/header.rb
psd-3.3.1 lib/psd/header.rb
psd-3.2.4 lib/psd/header.rb
psd-3.2.3 lib/psd/header.rb
psd-3.2.2 lib/psd/header.rb
psd-3.2.1 lib/psd/header.rb
psd-3.2.0 lib/psd/header.rb
psd-3.1.5 lib/psd/header.rb
psd-3.1.4 lib/psd/header.rb
psd-3.1.3 lib/psd/header.rb
psd-3.1.2 lib/psd/header.rb