Sha256: 9daac76942457f8d88feb0f0717fdd7aed967ac30278b2090d3357be871bbc1d

Contents?: true

Size: 1.77 KB

Versions: 16

Compression:

Stored size: 1.77 KB

Contents

class PSD
  # Describes the blend mode for a single layer or folder.
  class BlendMode < BinData::Record
    endian  :big

    string  :sig, read_length: 4
    string  :blend_key, read_length: 4, trim_value: true
    uint8   :opacity
    uint8   :clipping
    bit8    :flags
    skip    length: 1

    # All of the blend modes are stored in the PSD file with a specific key.
    # This is the mapping of that key to its readable name.
    BLEND_MODES = {
      norm: 'normal',
      dark: 'darken',
      lite: 'lighten',
      hue:  'hue',
      sat:  'saturation',
      colr: 'color',
      lum:  'luminosity',
      mul:  'multiply',
      scrn: 'screen',
      diss: 'dissolve',
      over: 'overlay',
      hLit: 'hard light',
      sLit: 'soft light',
      diff: 'difference',
      smud: 'exclusion',
      div:  'color dodge',
      idiv: 'color burn',
      lbrn: 'linear burn',
      lddg: 'linear dodge',
      vLit: 'vivid light',
      lLit: 'linear light',
      pLit: 'pin light',
      hMix: 'hard mix'
    }

    # Get the readable name for this blend mode.
    def mode
      BLEND_MODES[blend_key.to_sym]
    end

    # Set the blend mode with the readable name.
    def mode=(val)
      blend_key = BLEND_MODES.invert[val.downcase]
    end

    # Opacity is stored as an integer between 0-255. This converts the opacity
    # to a percentage value to match the Photoshop interface.
    def opacity_percentage
      opacity * 100 / 255
    end

    def transparency_protected
      flags & 0x01
    end

    # Is this layer/folder visible?
    def visible
      !((flags & (0x01 << 1)) > 0)
    end

    def obsolete
      (flags & (0x01 << 2)) > 0
    end

    def pixel_data_irrelevant
      return nil unless (flags & (0x01 << 3)) > 0
      (flags & (0x01 << 4)) > 0
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
psd-1.3.3 lib/psd/blend_mode.rb
psd-1.3.2 lib/psd/blend_mode.rb
psd-1.3.0 lib/psd/blend_mode.rb
psd-1.2.2 lib/psd/blend_mode.rb
psd-1.2.1 lib/psd/blend_mode.rb
psd-1.2.0 lib/psd/blend_mode.rb
psd-1.1.1 lib/psd/blend_mode.rb
psd-1.1.0 lib/psd/blend_mode.rb
psd-1.0.0 lib/psd/blend_mode.rb
psd-0.4.2 lib/psd/blend_mode.rb
psd-0.4.1 lib/psd/blend_mode.rb
psd-0.4.0 lib/psd/blend_mode.rb
psd-0.3.5 lib/psd/blend_mode.rb
psd-0.3.4 lib/psd/blend_mode.rb
psd-0.3.3 lib/psd/blend_mode.rb
psd-0.3.2 lib/psd/blend_mode.rb