Class: Rixmap::Format::PNG::Chunk::TRNSAncillaryChunk

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

Overview

tRNS補助チャンク. 透明度または透過色を扱います.

Constant Summary collapse

TYPE =

tRNSチャンクタイプ

'tRNS'
LAYOUT_GRAYSCALE =

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

'n'
LAYOUT_RGB =

RGBカラー用packレイアウト

'nnn'
LAYOUT_INDEXED =

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

'C*'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseChunk

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

Constructor Details

#initialize(colortype = nil) ⇒ TRNSAncillaryChunk

Returns a new instance of TRNSAncillaryChunk.



256
257
258
259
260
261
262
263
264
# File 'lib/rixmap/format/png/chunk.rb', line 256

def initialize(colortype = nil)
  @colortype = colortype
  @gray    = nil
  @red     = nil
  @green   = nil
  @blue    = nil
  @indexes = nil
  super(TRNSAncillaryChunk::TYPE)
end

Instance Attribute Details

#blueObject

Returns the value of attribute blue.



253
254
255
# File 'lib/rixmap/format/png/chunk.rb', line 253

def blue
  @blue
end

#colortypeObject

Returns the value of attribute colortype.



249
250
251
# File 'lib/rixmap/format/png/chunk.rb', line 249

def colortype
  @colortype
end

#grayObject

Returns the value of attribute gray.



250
251
252
# File 'lib/rixmap/format/png/chunk.rb', line 250

def gray
  @gray
end

#greenObject

Returns the value of attribute green.



252
253
254
# File 'lib/rixmap/format/png/chunk.rb', line 252

def green
  @green
end

#indexesObject

Returns the value of attribute indexes.



254
255
256
# File 'lib/rixmap/format/png/chunk.rb', line 254

def indexes
  @indexes
end

#redObject

Returns the value of attribute red.



251
252
253
# File 'lib/rixmap/format/png/chunk.rb', line 251

def red
  @red
end

Instance Method Details

#packObject



292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/rixmap/format/png/chunk.rb', line 292

def pack()
  case @colortype
  when COLORTYPE_INDEXED
    @data = @indexes.pack(TRNSAncillaryChunk::LAYOUT_INDEXED)
  when COLORTYPE_GRAYSCALE
    @data = [@gray].pack(TRNSAncillaryChunk::LAYOUT_GRAYSCALE)
  when COLORTYPE_TRUECOLOR
    @data = [@red, @green, @blue].pack(TRNSAncillaryChunk::LAYOUT_RGB)
  else
    @data = ''
  end
end

#unpackObject



305
306
307
308
309
310
311
312
313
314
# File 'lib/rixmap/format/png/chunk.rb', line 305

def unpack()
  case @colortype
  when COLORTYPE_INDEXED
    @indexes = @data.unpack(TRNSAncillaryChunk::LAYOUT_INDEXED)
  when COLORTYPE_GRAYSCALE
    @gray = @data.unpack(TRNSAncillaryChunk::LAYOUT_GRAYSCALE)[0]
  when COLORTYPE_TRUECOLOR
    @red, @green, @blue = @data.unpack(TRNSAncillaryChunk::LAYOUT_RGB)
  end
end

#valueObject



266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/rixmap/format/png/chunk.rb', line 266

def value()
  case @colortype
  when COLORTYPE_INDEXED
    return @indexes
  when COLORTYPE_GRAYSCALE
    return @gray
  when COLORTYPE_TRUECOLOR
    return [@red, @green, @blue]
  else
    return nil
  end
end

#value=(val) ⇒ Object



279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/rixmap/format/png/chunk.rb', line 279

def value=(val)
  case @colortype
  when COLORTYPE_INDEXED
    @indexes = Array(val)
  when COLORTYPE_GRAYSCALE
    @gray = val.to_i
  when COLORTYPE_TRUECOLOR
    @red   = val[0]
    @green = val[1]
    @blue  = val[2]
  end
end