Class: PSD::BlendMode

Inherits:
BinData::Record
  • Object
show all
Defined in:
lib/psd/blend_mode.rb

Overview

Describes the blend mode for a single layer or folder.

Constant Summary collapse

BLEND_MODES =

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.

{
  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',
  pass: 'passthru'
}

Instance Method Summary collapse

Instance Method Details

#modeObject

Get the readable name for this blend mode.



43
44
45
# File 'lib/psd/blend_mode.rb', line 43

def mode
  BLEND_MODES[blend_key.strip.to_sym]
end

#mode=(val) ⇒ Object

Set the blend mode with the readable name.



48
49
50
# File 'lib/psd/blend_mode.rb', line 48

def mode=(val)
  blend_key = BLEND_MODES.invert[val.strip.downcase]
end

#obsoleteObject



67
68
69
# File 'lib/psd/blend_mode.rb', line 67

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

#opacity_percentageObject

Opacity is stored as an integer between 0-255. This converts the opacity to a percentage value to match the Photoshop interface.



54
55
56
# File 'lib/psd/blend_mode.rb', line 54

def opacity_percentage
  opacity * 100 / 255
end

#pixel_data_irrelevantObject



71
72
73
74
# File 'lib/psd/blend_mode.rb', line 71

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

#transparency_protectedObject



58
59
60
# File 'lib/psd/blend_mode.rb', line 58

def transparency_protected
  flags & 0x01
end

#visibleObject

Is this layer/folder visible?



63
64
65
# File 'lib/psd/blend_mode.rb', line 63

def visible
  !((flags & (0x01 << 1)) > 0)
end