Class: ChunkyPNG::Chunk::Header

Inherits:
Base
  • Object
show all
Defined in:
lib/chunky_png/chunk.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#write, #write_with_crc

Constructor Details

#initialize(attrs = {}) ⇒ Header

Returns a new instance of Header.



50
51
52
53
54
55
56
57
# File 'lib/chunky_png/chunk.rb', line 50

def initialize(attrs = {})
  super('IHDR', attrs)
  @depth       ||= 8
  @color       ||= ChunkyPNG::COLOR_TRUECOLOR
  @compression ||= ChunkyPNG::COMPRESSION_DEFAULT
  @filtering   ||= ChunkyPNG::FILTERING_DEFAULT
  @interlace   ||= ChunkyPNG::INTERLACING_NONE
end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



48
49
50
# File 'lib/chunky_png/chunk.rb', line 48

def color
  @color
end

#compressionObject

Returns the value of attribute compression.



48
49
50
# File 'lib/chunky_png/chunk.rb', line 48

def compression
  @compression
end

#depthObject

Returns the value of attribute depth.



48
49
50
# File 'lib/chunky_png/chunk.rb', line 48

def depth
  @depth
end

#filteringObject

Returns the value of attribute filtering.



48
49
50
# File 'lib/chunky_png/chunk.rb', line 48

def filtering
  @filtering
end

#heightObject

Returns the value of attribute height.



48
49
50
# File 'lib/chunky_png/chunk.rb', line 48

def height
  @height
end

#interlaceObject

Returns the value of attribute interlace.



48
49
50
# File 'lib/chunky_png/chunk.rb', line 48

def interlace
  @interlace
end

#widthObject

Returns the value of attribute width.



48
49
50
# File 'lib/chunky_png/chunk.rb', line 48

def width
  @width
end

Class Method Details

.read(type, content) ⇒ Object



59
60
61
62
63
# File 'lib/chunky_png/chunk.rb', line 59

def self.read(type, content)
  fields = content.unpack('NNC5')
  self.new(:width => fields[0],  :height => fields[1], :depth => fields[2], :color => fields[3],
                 :compression => fields[4], :filtering => fields[5], :interlace => fields[6])
end

Instance Method Details

#contentObject



65
66
67
# File 'lib/chunky_png/chunk.rb', line 65

def content
  [width, height, depth, color, compression, filtering, interlace].pack('NNC5')
end