Class: ZPNG::BMP::BmpPaletteChunk
- Inherits:
-
Chunk::PLTE
- Object
- Chunk
- Chunk::PLTE
- ZPNG::BMP::BmpPaletteChunk
- Defined in:
- lib/zpng/bmp/reader.rb
Constant Summary
Constants inherited from Chunk
Chunk::KNOWN_TYPES, Chunk::VALID_SIZE_RANGE
Instance Attribute Summary
Attributes inherited from Chunk::PLTE
Attributes inherited from Chunk
#crc, #data, #idx, #offset, #size, #type
Instance Method Summary collapse
- #[](idx) ⇒ Object
- #[]=(idx, color) ⇒ Object
-
#initialize(data) ⇒ BmpPaletteChunk
constructor
A new instance of BmpPaletteChunk.
- #inspect(*args) ⇒ Object
- #ncolors ⇒ Object
Methods inherited from Chunk::PLTE
#add, #each, #each_with_index, #find_or_add, #index, #to_a
Methods inherited from Chunk
#check, #crc_ok?, #export, #export_data, #fix_crc!, from_stream, #valid?
Methods included from DeepCopyable
Constructor Details
#initialize(data) ⇒ BmpPaletteChunk
Returns a new instance of BmpPaletteChunk.
104 105 106 107 108 109 110 |
# File 'lib/zpng/bmp/reader.rb', line 104 def initialize data super( :crc => :no_crc, :data => data, :type => 'PALETTE' ) end |
Instance Method Details
#[](idx) ⇒ Object
112 113 114 115 |
# File 'lib/zpng/bmp/reader.rb', line 112 def [] idx rgbx = @data[idx*4,4] rgbx && Color.new(*rgbx.unpack('C4')) end |
#[]=(idx, color) ⇒ Object
117 118 119 120 |
# File 'lib/zpng/bmp/reader.rb', line 117 def []= idx, color @data ||= '' @data[idx*4,4] = [color.r, color.g, color.b, color.a].pack('C4') end |
#inspect(*args) ⇒ Object
126 127 128 |
# File 'lib/zpng/bmp/reader.rb', line 126 def inspect *args "<%s ncolors=%d>" % ["PALETTE", size/4] end |
#ncolors ⇒ Object
122 123 124 |
# File 'lib/zpng/bmp/reader.rb', line 122 def ncolors @data.to_s.size/4 end |