Class: Rixmap::Format::PNG::Chunk::BKGDAncillaryChunk

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

Overview

bKGD補助チャンク. 背景色を保存しています.

Constant Summary collapse

TYPE =

bKGDチャンクタイプ

'bKGD'
LAYOUT_INDEXED =

インデックスカラー用packレイアウト

'C'
LAYOUT_GRAYSCALE =

グレースケール用packレイアウト

'n'
LAYOUT_RGB =

RGBカラー用packレイアウト

'nnn'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseChunk

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

Constructor Details

#initialize(colortype = nil) ⇒ BKGDAncillaryChunk

Returns a new instance of BKGDAncillaryChunk.



341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/rixmap/format/png/chunk.rb', line 341

def initialize(colortype = nil)
  # 画像形式
  @colortype = colortype

  # グレースケール用
  @luminance = nil

  # RGBカラー用
  @red   = nil
  @green = nil
  @blue  = nil

  # パレット形式用
  @palette = nil
  super(BKGDAncillaryChunk::TYPE)
end

Instance Attribute Details

#blueObject

Returns the value of attribute blue.



338
339
340
# File 'lib/rixmap/format/png/chunk.rb', line 338

def blue
  @blue
end

#colortypeObject

Returns the value of attribute colortype.



334
335
336
# File 'lib/rixmap/format/png/chunk.rb', line 334

def colortype
  @colortype
end

#greenObject

Returns the value of attribute green.



337
338
339
# File 'lib/rixmap/format/png/chunk.rb', line 337

def green
  @green
end

#luminanceObject

Returns the value of attribute luminance.



335
336
337
# File 'lib/rixmap/format/png/chunk.rb', line 335

def luminance
  @luminance
end

#paletteObject

Returns the value of attribute palette.



339
340
341
# File 'lib/rixmap/format/png/chunk.rb', line 339

def palette
  @palette
end

#redObject

Returns the value of attribute red.



336
337
338
# File 'lib/rixmap/format/png/chunk.rb', line 336

def red
  @red
end

Instance Method Details

#packObject



384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/rixmap/format/png/chunk.rb', line 384

def pack()
  case @colortype
  when COLORTYPE_INDEXED
    @data = [@palette.to_i].pack(BKGDAncillaryChunk::LAYOUT_INDEXED)
  when COLORTYPE_GRAYSCALE, COLORTYPE_GRAYSCALE_WITH_ALPHA
    @data = [@luminance.to_i].pack(BKGDAncillaryChunk::LAYOUT_GRAYSCALE)
  when COLORTYPE_TRUECOLOR, COLORTYPE_TRUECOLOR_WITH_ALPHA
    @data = [@red.to_i, @green.to_i, @blue.to_i].pack(BKGDAncillaryChunk::LAYOUT_RGB)
  else
    @data = ''
  end
end

#unpackObject



397
398
399
400
401
402
403
404
405
406
# File 'lib/rixmap/format/png/chunk.rb', line 397

def unpack()
  case @colortype
  when COLORTYPE_INDEXED
    @palette = @data.unpack(BKGDAncillaryChunk::LAYOUT_INDEXED)[0]
  when COLORTYPE_GRAYSCALE, COLORTYPE_GRAYSCALE_WITH_ALPHA
    @luminance = @data.unpack(BKGDAncillaryChunk::LAYOUT_GRAYSCALE)[0]
  when COLORTYPE_TRUECOLOR, COLORTYPE_TRUECOLOR_WITH_ALPHA
    @red, @green, @blue = @data.unpack(BKGDAncillaryChunk::LAYOUT_RGB)
  end
end

#valueObject



358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/rixmap/format/png/chunk.rb', line 358

def value()
  case @colortype
  when COLORTYPE_INDEXED
    return @palette
  when COLORTYPE_GRAYSCALE, COLORTYPE_GRAYSCALE_WITH_ALPHA
    return @luminance
  when COLORTYPE_TRUECOLOR, COLORTYPE_TRUECOLOR_WITH_ALPHA
    return [@red, @green, @blue]
  else
    return nil
  end
end

#value=(val) ⇒ Object



371
372
373
374
375
376
377
378
379
380
381
382
# File 'lib/rixmap/format/png/chunk.rb', line 371

def value=(val)
  case @colortype
  when COLORTYPE_INDEXED
    @palette = val.to_i
  when COLORTYPE_GRAYSCALE, COLORTYPE_GRAYSCALE_WITH_ALPHA
    @luminance = val.to_i
  when COLORTYPE_TRUECOLOR, COLORTYPE_TRUECOLOR_WITH_ALPHA
    @red   = val[0] # color.red
    @green = val[1] # color.green
    @blue  = val[2] # color.blue
  end
end