Class: PSD::LayerMask

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

Overview

Covers parsing the global mask and controls parsing of all the layers/folders in the document.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, header, options) ⇒ LayerMask

Store a reference to the file and the header and initialize the defaults.



8
9
10
11
12
13
14
15
16
# File 'lib/psd/layer_mask.rb', line 8

def initialize(file, header, options)
  @file = file
  @header = header
  @options = options

  @layers = []
  @merged_alpha = false
  @global_mask = nil
end

Instance Attribute Details

#global_maskObject (readonly)

Returns the value of attribute global_mask.



5
6
7
# File 'lib/psd/layer_mask.rb', line 5

def global_mask
  @global_mask
end

#layersObject (readonly)

Returns the value of attribute layers.



5
6
7
# File 'lib/psd/layer_mask.rb', line 5

def layers
  @layers
end

Instance Method Details

#parseObject

Parse this section, including all of the layers and folders.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/psd/layer_mask.rb', line 26

def parse
  mask_size = parse_mask_size

  start_position = @file.tell
  finish = start_position + mask_size

  PSD.logger.debug "Layer mask section: #{start_position} - #{finish}"

  return self if mask_size <= 0

  parse_layers
  parse_global_mask

  consumed_bytes = @file.tell - start_position
  parse_layer_tagged_blocks(mask_size - consumed_bytes)

  # Layers are parsed in reverse order
  layers.reverse!

  # Ensure we're at the end of this section
  @file.seek finish

  self
end

#skipObject

Allows us to skip this section because it starts with the length of the section stored as an integer.



20
21
22
23
# File 'lib/psd/layer_mask.rb', line 20

def skip
  @file.seek parse_mask_size, IO::SEEK_CUR
  return self
end