Method: PSD::ChannelImage#parse

Defined in:
lib/psd/channel_image.rb

#parseObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/psd/channel_image.rb', line 34

def parse
  PSD.logger.debug "Layer = #{@layer.name}, Size = #{width}x#{height}"

  @chan_pos = 0

  @channels_info.each do |ch_info|
    @ch_info = ch_info
    if ch_info[:length] <= 0
      parse_compression! and next
    end

    # If the ID of this current channel is -2, then we assume the dimensions
    # of the layer mask.
    if ch_info[:id] == -2
      @width = @layer.mask.width
      @height = @layer.mask.height
    else
      @width = @layer.width
      @height = @layer.height
    end

    start = @file.tell

    PSD.logger.debug "Channel ##{ch_info[:id]}, length = #{ch_info[:length]}"
    parse_image_data!

    finish = @file.tell

    if finish != start + ch_info[:length]
      PSD.logger.error "Read incorrect number of bytes for channel ##{ch_info[:id]}. Expected = #{ch_info[:length]}, Actual = #{finish - start}"
      @file.seek start + @ch_info[:length]
    end
  end

  if @channel_data.length != @length
    PSD.logger.error "#{@channel_data.length} read; expected #{@length}"
  end

  process_image_data
end