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
19
20
# File 'lib/psd/mask.rb', line 12

def initialize(file)
  @file = file
  @top = 0
  @left = 0
  @bottom = 0
  @right = 0
  @default_color = 0
  @flags = 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



51
52
53
# File 'lib/psd/mask.rb', line 51

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

#from_other_dataObject



59
60
61
# File 'lib/psd/mask.rb', line 59

def from_other_data
  (@flags & (0x01 << 3)) > 0
end

#heightObject



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

def height
  bottom - top
end

#invertObject



55
56
57
# File 'lib/psd/mask.rb', line 55

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

#parseObject



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

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



47
48
49
# File 'lib/psd/mask.rb', line 47

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

#to_hashObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/psd/mask.rb', line 63

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



39
40
41
# File 'lib/psd/mask.rb', line 39

def width
  right - left
end