Class: PSD::Mask

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Mask

Returns a new instance of Mask.



12
13
14
15
16
17
18
# File 'lib/psd/mask.rb', line 12

def initialize(file)
  @file = file
  @top = 0
  @left = 0
  @bottom = 0
  @right = 0
end

Instance Attribute Details

#bottomObject (readonly)

Returns the value of attribute bottom.



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

def bottom
  @bottom
end

#default_colorObject (readonly)

Returns the value of attribute default_color.



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

def default_color
  @default_color
end

#leftObject (readonly)

Returns the value of attribute left.



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

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



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

def right
  @right
end

#sizeObject (readonly)

Returns the value of attribute size.



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

def size
  @size
end

#topObject (readonly)

Returns the value of attribute top.



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

def top
  @top
end

Class Method Details

.read(file) ⇒ Object



5
6
7
8
9
10
# File 'lib/psd/mask.rb', line 5

def self.read(file)
  mask = Mask.new(file)
  mask.parse

  mask
end

Instance Method Details

#disabledObject



49
50
51
# File 'lib/psd/mask.rb', line 49

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

#heightObject



41
42
43
# File 'lib/psd/mask.rb', line 41

def height
  bottom - top
end

#invertObject



53
54
55
# File 'lib/psd/mask.rb', line 53

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

#parseObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/psd/mask.rb', line 20

def parse
  @size = @file.read_int
  return if @size == 0

  @mask_end = @file.tell + @size

  @top = @file.read_int
  @left = @file.read_int
  @bottom = @file.read_int
  @right = @file.read_int

  @default_color = @file.read_byte
  @flags = @file.read_byte

  @file.seek @mask_end # Useless info/padding
end

#relativeObject



45
46
47
# File 'lib/psd/mask.rb', line 45

def relative
  (@flags & 0x01) > 0
end

#to_hashObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/psd/mask.rb', line 57

def to_hash
  return {} if @size == 0

  {
    top: top,
    left: left,
    bottom: bottom,
    right: right,
    width: width,
    height: height,
    default_color: default_color,
    relative: relative,
    disabled: disabled,
    invert: invert
  }
end

#widthObject



37
38
39
# File 'lib/psd/mask.rb', line 37

def width
  right - left
end