Class: PNG::IHDR

Inherits:
Chunk show all
Defined in:
lib/spittle/png/ihdr.rb

Constant Summary collapse

SUPPORTED_COLOR_TYPES =
[2,3,6]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Chunk

#to_chunk

Constructor Details

#initialize(width, height, depth = 8, color_type = 2, compression = 0, filter = 0, interlace = 0) ⇒ IHDR

Returns a new instance of IHDR.



13
14
15
16
17
18
19
20
# File 'lib/spittle/png/ihdr.rb', line 13

def initialize( width, height, depth=8, color_type=2, compression=0, filter=0, interlace=0 )
  raise "for now, spittle only supports non-interlaced images" unless interlace == 0
  raise "for now, spittle only supports images with a bit depth of 8" unless depth == 8
  unless SUPPORTED_COLOR_TYPES.include? color_type
    raise "for now, spittle only supports color types #{SUPPORTED_COLOR_TYPES.JOIN(',')} color type was #{color_type}"
  end
  @width, @height, @depth, @color_type = width, height, depth, color_type
end

Instance Attribute Details

#color_typeObject

Returns the value of attribute color_type.



4
5
6
# File 'lib/spittle/png/ihdr.rb', line 4

def color_type
  @color_type
end

#depthObject

Returns the value of attribute depth.



4
5
6
# File 'lib/spittle/png/ihdr.rb', line 4

def depth
  @depth
end

#heightObject

Returns the value of attribute height.



4
5
6
# File 'lib/spittle/png/ihdr.rb', line 4

def height
  @height
end

#widthObject

Returns the value of attribute width.



4
5
6
# File 'lib/spittle/png/ihdr.rb', line 4

def width
  @width
end

Class Method Details

.new_from_raw(data) ⇒ Object

attr_accessor :compression_method, :filter_method, :interlace_method



7
8
9
10
11
# File 'lib/spittle/png/ihdr.rb', line 7

def self.new_from_raw( data )
  raw = data.unpack("N2C5")

  new( *raw[0..6] )
end

Instance Method Details

#chunk_nameObject



30
31
32
# File 'lib/spittle/png/ihdr.rb', line 30

def chunk_name
  "IHDR"
end

#encodeObject



22
23
24
# File 'lib/spittle/png/ihdr.rb', line 22

def encode
  to_a.pack("N2C5")
end

#to_aObject



26
27
28
# File 'lib/spittle/png/ihdr.rb', line 26

def to_a
  [@width, @height, @depth, @color_type, 0, 0, 0]
end