Class: PSD::BlendMode

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

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',
  dkCl: 'darker_color',
  lgCl: 'lighter_color',
  fsub: 'subtract',
  fdiv: 'divide'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ BlendMode

Returns a new instance of BlendMode.



38
39
40
41
42
43
44
45
# File 'lib/psd/blend_mode.rb', line 38

def initialize(file)
  @file = file
  
  @blend_key = nil
  @opacity = nil
  @clipping = nil
  @flags = nil
end

Instance Attribute Details

#blend_keyObject (readonly)

Returns the value of attribute blend_key.



3
4
5
# File 'lib/psd/blend_mode.rb', line 3

def blend_key
  @blend_key
end

#clippingObject (readonly)

Returns the value of attribute clipping.



3
4
5
# File 'lib/psd/blend_mode.rb', line 3

def clipping
  @clipping
end

#opacityObject (readonly)

Returns the value of attribute opacity.



3
4
5
# File 'lib/psd/blend_mode.rb', line 3

def opacity
  @opacity
end

Instance Method Details

#clipped?Boolean

Returns:

  • (Boolean)


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

def clipped?
  @clipping == 1
end

#modeObject Also known as: blending_mode



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

def mode
  BLEND_MODES[@blend_key.to_sym]
end

#obsoleteObject



79
80
81
# File 'lib/psd/blend_mode.rb', line 79

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

#opacity_percentageObject



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

def opacity_percentage
  @opacity_percentage ||= @opacity * 100 / 255
end

#parse!Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/psd/blend_mode.rb', line 47

def parse!
  @file.seek 4, IO::SEEK_CUR

  @blend_key = @file.read_string(4).strip
  @opacity = @file.read_byte
  @clipping = @file.read_byte
  @flags = @file.read_byte

  @file.seek 1, IO::SEEK_CUR
end

#pixel_data_irrelevantObject



83
84
85
86
# File 'lib/psd/blend_mode.rb', line 83

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

#transparency_protectedObject



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

def transparency_protected
  @flags & 0x01
end

#visibleObject



75
76
77
# File 'lib/psd/blend_mode.rb', line 75

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