Class: Rixmap::Format::PNG::Chunk::PLTEChunk

Inherits:
BaseChunk
  • Object
show all
Defined in:
lib/rixmap/format/png/chunk.rb

Overview

PLTパレットチャンク

Constant Summary collapse

TYPE =

PLTEチャンクタイプ

'PLTE'
LAYOUT =

pack用PLTEチャンクデータレイアウト

'C*'

Instance Method Summary collapse

Methods inherited from BaseChunk

#copysafe?, #data, #data=, #optional?, #private?, #standard?, #type

Constructor Details

#initializePLTEChunk

Returns a new instance of PLTEChunk.



174
175
176
177
# File 'lib/rixmap/format/png/chunk.rb', line 174

def initialize()
  @colors = []
  super(PLTEChunk::TYPE)
end

Instance Method Details

#[](offset) ⇒ Array

指定番号のカラーデータ (3バイト) を取得します.

データオフセットではなく、3バイトごとに区切られたカラーのオフセットであることに注意.

Parameters:

  • offset (Integer)

    カラー番号

Returns:

  • (Array)

    RGBカラーデータ



185
186
187
# File 'lib/rixmap/format/png/chunk.rb', line 185

def [](offset)
  return @colors[offset * 3, 3]
end

#[]=(offset, rgb) ⇒ Object

指定番号のカラーデータを更新します.

Parameters:

  • offset (Integer)

    カラー番号

  • rgb (Array)

    カラーデータ



193
194
195
# File 'lib/rixmap/format/png/chunk.rb', line 193

def []=(offset, rgb)
  @colors[offset * 3, 3] = rgb
end

#packObject



197
198
199
# File 'lib/rixmap/format/png/chunk.rb', line 197

def pack()
  @data = @colors.pack(PLTEChunk::LAYOUT)
end

#unpackObject



201
202
203
# File 'lib/rixmap/format/png/chunk.rb', line 201

def unpack()
  @colors = @data.unpack(PLTEChunk::LAYOUT)
end