Class: ZPNG::Chunk::IHDR

Inherits:
ZPNG::Chunk show all
Defined in:
lib/zpng/chunk.rb

Constant Summary collapse

PALETTE_USED =
1
COLOR_USED =
2
ALPHA_USED =
4
COLOR_GRAYSCALE =

Each pixel is a grayscale sample

0
COLOR_RGB =

Each pixel is an R,G,B triple.

2
COLOR_INDEXED =

Each pixel is a palette index; a PLTE chunk must appear.

3
COLOR_GRAY_ALPHA =

Each pixel is a grayscale sample, followed by an alpha sample.

4
COLOR_RGBA =

Each pixel is an R,G,B triple, followed by an alpha sample.

6
SAMPLES_PER_COLOR =
{
  COLOR_GRAYSCALE  => 1,
  COLOR_RGB        => 3,
  COLOR_INDEXED    => 1,
  COLOR_GRAY_ALPHA => 2,
  COLOR_RGBA       => 4
}
FORMAT =
'NNC5'

Instance Attribute Summary collapse

Attributes inherited from ZPNG::Chunk

#crc, #data, #size, #type

Instance Method Summary collapse

Methods inherited from ZPNG::Chunk

#crc_ok?, #export, from_stream

Constructor Details

#initialize(io) ⇒ IHDR

Returns a new instance of IHDR.



73
74
75
76
# File 'lib/zpng/chunk.rb', line 73

def initialize io
  super
  @width, @height, @depth, @color, @compression, @filter, @interlace = data.unpack(FORMAT)
end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



51
52
53
# File 'lib/zpng/chunk.rb', line 51

def color
  @color
end

#compressionObject

Returns the value of attribute compression.



51
52
53
# File 'lib/zpng/chunk.rb', line 51

def compression
  @compression
end

#depthObject

Returns the value of attribute depth.



51
52
53
# File 'lib/zpng/chunk.rb', line 51

def depth
  @depth
end

#filterObject

Returns the value of attribute filter.



51
52
53
# File 'lib/zpng/chunk.rb', line 51

def filter
  @filter
end

#heightObject

Returns the value of attribute height.



51
52
53
# File 'lib/zpng/chunk.rb', line 51

def height
  @height
end

#interlaceObject

Returns the value of attribute interlace.



51
52
53
# File 'lib/zpng/chunk.rb', line 51

def interlace
  @interlace
end

#widthObject

Returns the value of attribute width.



51
52
53
# File 'lib/zpng/chunk.rb', line 51

def width
  @width
end

Instance Method Details

#alpha_used?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/zpng/chunk.rb', line 99

def alpha_used?
  (@color & ALPHA_USED) != 0
end

#bppObject

bits per pixel



83
84
85
# File 'lib/zpng/chunk.rb', line 83

def bpp
  SAMPLES_PER_COLOR[@color] * depth
end

#color_used?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/zpng/chunk.rb', line 87

def color_used?
  (@color & COLOR_USED) != 0
end

#export_dataObject



78
79
80
# File 'lib/zpng/chunk.rb', line 78

def export_data
  [@width, @height, @depth, @color, @compression, @filter, @interlace].pack(FORMAT)
end

#grayscale?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/zpng/chunk.rb', line 91

def grayscale?
  !color_used?
end

#inspectObject



103
104
105
106
107
108
# File 'lib/zpng/chunk.rb', line 103

def inspect
  super.sub(/ *>$/,'') + ", " +
    (instance_variables-[:@type, :@crc, :@data, :@size]).
    map{ |var| "#{var.to_s.tr('@','')}=#{instance_variable_get(var)}" }.
    join(", ") + ">"
end

#palette_used?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/zpng/chunk.rb', line 95

def palette_used?
  (@color & PALETTE_USED) != 0
end