Sha256: 8e7ec2f48b51646a64bd4d9ce5c9054bdbedc49a9065cd19e882aff1b25cc786

Contents?: true

Size: 1.24 KB

Versions: 5

Compression:

Stored size: 1.24 KB

Contents

class PSD
  # Describes the Header for the PSD file, which is the first section of the file.
  class Header < BinData::Record
    endian :big

    string  :sig, read_length: 4
    uint16  :version

    # Reserved bytes
    skip    length: 6

    uint16  :channels
    uint32  :rows
    uint32  :cols
    uint16  :depth
    uint16  :mode

    uint32  :color_data_len
    skip    length: :color_data_len

    # 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'
    ]

    # Get the human-readable color mode name.
    def mode_name
      if mode >= 0 && mode <= 15
        MODES[mode]
      else
        "(#{mode})"
      end
    end

    # Width of the entire document in pixels.
    def width
      cols
    end

    # Height of the entire document in pixels.
    def height
      rows
    end

    def rgb?
      mode == 3
    end

    def cmyk?
      mode == 4
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
bench9000-0.1 vendor/psd.rb/lib/psd/header.rb
psd-2.1.2 lib/psd/header.rb
psd-2.1.1 lib/psd/header.rb
psd-2.1.0 lib/psd/header.rb
psd-2.0.0 lib/psd/header.rb