rixmap 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77e26b472bc191ddd69675d65ee6f895f996154a
4
- data.tar.gz: 2c4fcc4f88a872a2ca9931a1c1bc76318fabcbb7
3
+ metadata.gz: 9f6435a7962daf5424c697df94925bc26b079704
4
+ data.tar.gz: abcd536696bc451ca7577ef7b2b3b235d041e329
5
5
  SHA512:
6
- metadata.gz: 8102c25bd276e0c609955339d9021f3f2225ed763b2960b393b193f3e98e2370c21816884f784229b4b52a554ef4f1f2880780f3d21f50e19ea0b1153e5d5506
7
- data.tar.gz: d23775f951cf185d353bf86ad918cb18c2fdce7f49e5f6adfeb54e29abdadd14b5b30dbe58c2887728aad2f79d92c5a3f3ec1be3779cbf0c6fcd44630843dd38
6
+ metadata.gz: fc3fd8f1a09baa47230ebfcf3eba97b674c051f0c4a1333243e45b0c3ab5bebf592920701d02dcf3509d34e7050e51d19a587da99b97ac374905724b39300c5d
7
+ data.tar.gz: ac6c1e5b85fd0865b73fff73d35afe9c91d6d927349113a91a0ebecbe1c3655c2a93fc1edf812f66f957c72d2a07958f59ddbed26696f36f3f8259bc9fb386ae
data/Rakefile CHANGED
@@ -109,7 +109,9 @@ if defined?(YARD::Rake::YardocTask)
109
109
  yd.options << '--charset=utf-8'
110
110
  yd.options << '--output-dir=doc'
111
111
  yd.options << '--no-cache'
112
+ yd.options << '--hide-void-return'
112
113
  yd.options << '--debug'
114
+ yd.options << '--no-yardopts'
113
115
  #yd.options << '--single-db'
114
116
  #yd.options << '--one-file'
115
117
  end
@@ -152,5 +154,5 @@ end
152
154
 
153
155
 
154
156
  #==============================================================================#
155
- # $Id: Rakefile,v 753dbf70cab3 2014/05/16 16:13:38 chikuchikugonzalez $
157
+ # $Id: Rakefile,v e37e8dfe0f98 2014/05/22 14:14:05 chikuchikugonzalez $
156
158
  # vim: set sts=2 ts=2 sw=2 expandtab:
@@ -270,6 +270,9 @@ module Rixmap
270
270
 
271
271
  # パレットを復元
272
272
  ncolors = bi.used_color_count
273
+ if ncolors <= 0
274
+ ncolors = 2 ** bi.bit_count
275
+ end
273
276
  palbytes = data.byteslice((FILEHEADER_SIZE + bi.size), (ncolors * 4))
274
277
  palbytes.unpack('C*').each_slice(4).each_with_index do |c, i|
275
278
  break if i >= image.palette.size
@@ -322,5 +325,5 @@ end
322
325
 
323
326
 
324
327
  #==============================================================================#
325
- # $Id: bmp.rb,v 57b1fb2cd6a6 2014/04/20 12:21:27 chikuchikugonzalez $
328
+ # $Id: bmp.rb,v b9cbf891f8da 2014/05/24 16:23:15 chikuchikugonzalez $
326
329
  # vim: set sts=2 ts=2 sw=2 expandtab:
@@ -112,12 +112,10 @@ module Rixmap
112
112
  # #data から呼び出されます
113
113
  def pack()
114
114
  end
115
- protected :pack
116
115
 
117
116
  # データ更新後の、内部プロパティ更新処理を行います.
118
117
  def unpack()
119
118
  end
120
- protected :unpack
121
119
 
122
120
  end
123
121
 
@@ -156,12 +154,10 @@ module Rixmap
156
154
  def pack()
157
155
  @data = [@width, @height, @depth, @colortype, @compress, @filter, @interlace].pack(IHDRChunk::LAYOUT)
158
156
  end
159
- protected :pack
160
157
 
161
158
  def unpack()
162
159
  @width, @height, @depth, @colortype, @compress, @filter, @interlace = @data.unpack(IHDRChunk::LAYOUT)
163
160
  end
164
- protected :unpack
165
161
 
166
162
  # チャンクリストへ登録
167
163
  Chunk.set(self::TYPE, self)
@@ -201,12 +197,10 @@ module Rixmap
201
197
  def pack()
202
198
  @data = @colors.pack(PLTEChunk::LAYOUT)
203
199
  end
204
- protected :pack
205
200
 
206
201
  def unpack()
207
202
  @colors = @data.unpack(PLTEChunk::LAYOUT)
208
203
  end
209
- protected :unpack
210
204
 
211
205
  # チャンクリストへ登録
212
206
  Chunk.set(self::TYPE, self)
@@ -238,6 +232,183 @@ module Rixmap
238
232
  Chunk.set(self::TYPE, self)
239
233
  end
240
234
 
235
+ # tRNS補助チャンク. 透明度または透過色を扱います.
236
+ class TRNSAncillaryChunk < BaseChunk
237
+ # tRNSチャンクタイプ
238
+ TYPE = 'tRNS'
239
+
240
+ # グレースケール用packレイアウト
241
+ LAYOUT_GRAYSCALE = 'n'
242
+
243
+ # RGBカラー用packレイアウト
244
+ LAYOUT_RGB = 'nnn'
245
+
246
+ # インデックスカラー用packレイアウト
247
+ LAYOUT_INDEXED = 'C*'
248
+
249
+ attr_accessor :colortype
250
+ attr_accessor :gray
251
+ attr_accessor :red
252
+ attr_accessor :green
253
+ attr_accessor :blue
254
+ attr_accessor :indexes
255
+
256
+ def initialize(colortype = nil)
257
+ @colortype = colortype
258
+ @gray = nil
259
+ @red = nil
260
+ @green = nil
261
+ @blue = nil
262
+ @indexes = nil
263
+ super(TRNSAncillaryChunk::TYPE)
264
+ end
265
+
266
+ def value()
267
+ case @colortype
268
+ when COLORTYPE_INDEXED
269
+ return @indexes
270
+ when COLORTYPE_GRAYSCALE
271
+ return @gray
272
+ when COLORTYPE_TRUECOLOR
273
+ return [@red, @green, @blue]
274
+ else
275
+ return nil
276
+ end
277
+ end
278
+
279
+ def value=(val)
280
+ case @colortype
281
+ when COLORTYPE_INDEXED
282
+ @indexes = Array(val)
283
+ when COLORTYPE_GRAYSCALE
284
+ @gray = val.to_i
285
+ when COLORTYPE_TRUECOLOR
286
+ @red = val[0]
287
+ @green = val[1]
288
+ @blue = val[2]
289
+ end
290
+ end
291
+
292
+ def pack()
293
+ case @colortype
294
+ when COLORTYPE_INDEXED
295
+ @data = @indexes.pack(TRNSAncillaryChunk::LAYOUT_INDEXED)
296
+ when COLORTYPE_GRAYSCALE
297
+ @data = [@gray].pack(TRNSAncillaryChunk::LAYOUT_GRAYSCALE)
298
+ when COLORTYPE_TRUECOLOR
299
+ @data = [@red, @green, @blue].pack(TRNSAncillaryChunk::LAYOUT_RGB)
300
+ else
301
+ @data = ''
302
+ end
303
+ end
304
+
305
+ def unpack()
306
+ case @colortype
307
+ when COLORTYPE_INDEXED
308
+ @indexes = @data.unpack(TRNSAncillaryChunk::LAYOUT_INDEXED)
309
+ when COLORTYPE_GRAYSCALE
310
+ @gray = @data.unpack(TRNSAncillaryChunk::LAYOUT_GRAYSCALE)[0]
311
+ when COLORTYPE_TRUECOLOR
312
+ @red, @green, @blue = @data.unpack(TRNSAncillaryChunk::LAYOUT_RGB)
313
+ end
314
+ end
315
+
316
+ # チャンクリストへ登録
317
+ Chunk.set(self::TYPE, self)
318
+ end
319
+
320
+ # bKGD補助チャンク. 背景色を保存しています.
321
+ class BKGDAncillaryChunk < BaseChunk
322
+ # bKGDチャンクタイプ
323
+ TYPE = 'bKGD'
324
+
325
+ # インデックスカラー用packレイアウト
326
+ LAYOUT_INDEXED = 'C'
327
+
328
+ # グレースケール用packレイアウト
329
+ LAYOUT_GRAYSCALE = 'n'
330
+
331
+ # RGBカラー用packレイアウト
332
+ LAYOUT_RGB = 'nnn'
333
+
334
+ attr_accessor :colortype
335
+ attr_accessor :luminance
336
+ attr_accessor :red
337
+ attr_accessor :green
338
+ attr_accessor :blue
339
+ attr_accessor :palette
340
+
341
+ def initialize(colortype = nil)
342
+ # 画像形式
343
+ @colortype = colortype
344
+
345
+ # グレースケール用
346
+ @luminance = nil
347
+
348
+ # RGBカラー用
349
+ @red = nil
350
+ @green = nil
351
+ @blue = nil
352
+
353
+ # パレット形式用
354
+ @palette = nil
355
+ super(BKGDAncillaryChunk::TYPE)
356
+ end
357
+
358
+ def value()
359
+ case @colortype
360
+ when COLORTYPE_INDEXED
361
+ return @palette
362
+ when COLORTYPE_GRAYSCALE, COLORTYPE_GRAYSCALE_WITH_ALPHA
363
+ return @luminance
364
+ when COLORTYPE_TRUECOLOR, COLORTYPE_TRUECOLOR_WITH_ALPHA
365
+ return [@red, @green, @blue]
366
+ else
367
+ return nil
368
+ end
369
+ end
370
+
371
+ def value=(val)
372
+ case @colortype
373
+ when COLORTYPE_INDEXED
374
+ @palette = val.to_i
375
+ when COLORTYPE_GRAYSCALE, COLORTYPE_GRAYSCALE_WITH_ALPHA
376
+ @luminance = val.to_i
377
+ when COLORTYPE_TRUECOLOR, COLORTYPE_TRUECOLOR_WITH_ALPHA
378
+ @red = val[0] # color.red
379
+ @green = val[1] # color.green
380
+ @blue = val[2] # color.blue
381
+ end
382
+ end
383
+
384
+ def pack()
385
+ case @colortype
386
+ when COLORTYPE_INDEXED
387
+ @data = [@palette.to_i].pack(BKGDAncillaryChunk::LAYOUT_INDEXED)
388
+ when COLORTYPE_GRAYSCALE, COLORTYPE_GRAYSCALE_WITH_ALPHA
389
+ @data = [@luminance.to_i].pack(BKGDAncillaryChunk::LAYOUT_GRAYSCALE)
390
+ when COLORTYPE_TRUECOLOR, COLORTYPE_TRUECOLOR_WITH_ALPHA
391
+ @data = [@red.to_i, @green.to_i, @blue.to_i].pack(BKGDAncillaryChunk::LAYOUT_RGB)
392
+ else
393
+ @data = ''
394
+ end
395
+ end
396
+
397
+ def unpack()
398
+ case @colortype
399
+ when COLORTYPE_INDEXED
400
+ @palette = @data.unpack(BKGDAncillaryChunk::LAYOUT_INDEXED)[0]
401
+ when COLORTYPE_GRAYSCALE, COLORTYPE_GRAYSCALE_WITH_ALPHA
402
+ @luminance = @data.unpack(BKGDAncillaryChunk::LAYOUT_GRAYSCALE)[0]
403
+ when COLORTYPE_TRUECOLOR, COLORTYPE_TRUECOLOR_WITH_ALPHA
404
+ @red, @green, @blue = @data.unpack(BKGDAncillaryChunk::LAYOUT_RGB)
405
+ end
406
+ end
407
+
408
+ # チャンクリストへ登録
409
+ Chunk.set(self::TYPE, self)
410
+ end
411
+
241
412
  end
242
413
 
243
414
  end
@@ -246,5 +417,5 @@ end
246
417
 
247
418
 
248
419
  #==============================================================================#
249
- # $Id: chunk.rb,v 753dbf70cab3 2014/05/16 16:13:38 chikuchikugonzalez $
420
+ # $Id: chunk.rb,v a60a21c75463 2014/05/30 17:04:13 chikuchikugonzalez $
250
421
  # vim: set sts=2 ts=2 sw=2 expandtab:
@@ -235,14 +235,35 @@ module Rixmap
235
235
  end
236
236
 
237
237
  # 画像種別による処理
238
+ trns = nil # 透明度チャンクデータ
238
239
  case image.mode
239
240
  when Rixmap::INDEXED
240
241
  ihdr.colortype = COLORTYPE_INDEXED
241
242
 
242
243
  # パレットを設定
243
244
  plte = Chunk::PLTEChunk.new
245
+ alphas = []
246
+ hasalpha = false
244
247
  image.palette.each_with_index do |color, i|
245
248
  plte[i] = [color.red, color.green, color.blue]
249
+ alphas << color.alpha
250
+ if color.alpha < 255
251
+ hasalpha = true
252
+ end
253
+ end
254
+
255
+ if hasalpha
256
+ # 基本的にパレットのαを入れる
257
+ trns = Chunk::TRNSAncillaryChunk.new(ihdr.colortype)
258
+ trns.indexes = alphas
259
+ elsif !image.transparent.nil?
260
+ # 透過インデックス設定の場合
261
+ # ※ 復元できない
262
+ trns = Chunk::TRNSAncillaryChunk.new(ihdr.colortype)
263
+ index = image.transparent.to_i
264
+ indexes = [255] * index
265
+ indexes[index] = 0
266
+ trns.indexes = indexes
246
267
  end
247
268
 
248
269
  # ピクセルを作成
@@ -255,6 +276,11 @@ module Rixmap
255
276
  image.each_line do |line|
256
277
  pixels.concat(filter.filt(line, filter_method).to_str)
257
278
  end
279
+
280
+ unless image.transparent.nil?
281
+ trns = Chunk::TRNSAncillaryChunk.new(ihdr.colortype)
282
+ trns.gray = image.transparent.to_i
283
+ end
258
284
  when Rixmap::GRAYALPHA
259
285
  ihdr.colortype = COLORTYPE_GRAYSCALE_WITH_ALPHA
260
286
  image.each_line do |line|
@@ -265,6 +291,11 @@ module Rixmap
265
291
  image.each_line do |line|
266
292
  pixels.concat(filter.filt(line.to_s('RGB'), filter_method).to_str)
267
293
  end
294
+
295
+ unless image.transparent.nil?
296
+ trns = Chunk::TRNSAncillaryChunk.new(ihdr.colortype)
297
+ trns.value = image.transparent
298
+ end
268
299
  when Rixmap::RGBA
269
300
  ihdr.colortype = COLORTYPE_TRUECOLOR_WITH_ALPHA
270
301
  image.each_line do |line|
@@ -281,11 +312,21 @@ module Rixmap
281
312
  idat = Chunk::IDATChunk.new
282
313
  idat.data = deflated_pixels
283
314
 
284
- # チャンクリスト
315
+ # チャンクリストの作成開始
285
316
  chunks = []
286
317
  chunks << ihdr
287
318
  chunks << plte unless plte.nil?
288
319
  chunks << idat
320
+ chunks << trns unless trns.nil?
321
+
322
+ # 背景色
323
+ unless image.background.nil?
324
+ bkgd = Chunk::BKGDAncillaryChunk.new(ihdr.colortype)
325
+ bkgd.value = image.background
326
+ chunks << bkgd
327
+ end
328
+
329
+ # チャンクリスト構築終了
289
330
  chunks << Chunk::IENDChunk.new
290
331
 
291
332
  # PNGストリームを構築
@@ -340,6 +381,8 @@ module Rixmap
340
381
  warn("Unknown or Not-Implemented Chunk Type: #{chunk_type}")
341
382
  next
342
383
  end
384
+
385
+ # チャンクを作成
343
386
  chunk = Chunk.get(chunk_type).new
344
387
  chunk.data = chunk_data
345
388
 
@@ -361,18 +404,33 @@ module Rixmap
361
404
  # 残りチャンクを処理
362
405
  image_data = ''
363
406
  palette = nil
407
+ bgcolor = nil
408
+ transcolor = nil
364
409
  chunks.each do |chunk|
365
410
  case chunk
366
411
  when Chunk::IDATChunk
367
412
  image_data.concat(chunk.data)
413
+
368
414
  when Chunk::PLTEChunk
369
415
  palette = Rixmap::Palette.new(2 ** image_depth)
370
416
  palette.size.times do |i|
371
417
  palette[i] = chunk[i]
372
418
  end
419
+
373
420
  when Chunk::IENDChunk
374
421
  break
422
+
423
+ when Chunk::BKGDAncillaryChunk
424
+ chunk.colortype = colortype
425
+ chunk.unpack # 中身を更新
426
+ bgcolor = chunk.value
427
+
428
+ when Chunk::TRNSAncillaryChunk
429
+ chunk.colortype = colortype
430
+ chunk.unpack
431
+ transcolor = chunk.value
375
432
  end
433
+
376
434
  end
377
435
 
378
436
  # ピクセルを復元
@@ -382,31 +440,41 @@ module Rixmap
382
440
  image = nil
383
441
  case colortype
384
442
  when COLORTYPE_INDEXED
385
- image = Rixmap::Image.new(Rixmap::INDEXED, image_width, image_height, :palette => palette)
443
+ image = Rixmap::Image.new(Rixmap::INDEXED, image_width, image_height, :palette => palette, :background => bgcolor)
386
444
  filter = AdaptiveFilter.new(image.mode)
387
445
  pixels.each_slice(image_width + 1).each_with_index do |bytes, i|
388
446
  image[i] = filter.recon(bytes)
389
447
  end
448
+
449
+ # 透明度を反映
450
+ unless transcolor.nil?
451
+ transcolor.each_with_index do |alpha, i|
452
+ color = image.palette[i].to_a
453
+ color[3] = alpha
454
+ image.palette[i] = color
455
+ # TODO image.palette[i]の結果をPaletteColorとかにして、各コンポーネント毎に編集できるようにするべきかな
456
+ end
457
+ end
390
458
  when COLORTYPE_GRAYSCALE
391
- image = Rixmap::Image.new(Rixmap::GRAYSCALE, image_width, image_height)
459
+ image = Rixmap::Image.new(Rixmap::GRAYSCALE, image_width, image_height, :background => bgcolor, :transparent => transcolor)
392
460
  filter = AdaptiveFilter.new(image.mode)
393
461
  pixels.each_slice(image_width + 1).each_with_index do |bytes, i|
394
462
  image[i] = filter.recon(bytes)
395
463
  end
396
464
  when COLORTYPE_GRAYSCALE_WITH_ALPHA
397
- image = Rixmap::Image.new(Rixmap::GRAYALPHA, image_width, image_height)
465
+ image = Rixmap::Image.new(Rixmap::GRAYALPHA, image_width, image_height, :background => bgcolor)
398
466
  filter = AdaptiveFilter.new(image.mode)
399
467
  pixels.each_slice((image_width * 2) + 1).each_with_index do |bytes, i|
400
468
  image[i] = filter.recon(bytes)
401
469
  end
402
470
  when COLORTYPE_TRUECOLOR
403
- image = Rixmap::Image.new(Rixmap::RGB, image_width, image_height)
471
+ image = Rixmap::Image.new(Rixmap::RGB, image_width, image_height, :background => bgcolor, :transparent => transcolor)
404
472
  filter = AdaptiveFilter.new(image.mode)
405
473
  pixels.each_slice((image_width * 3) + 1).each_with_index do |bytes, i|
406
474
  image[i] = filter.recon(bytes)
407
475
  end
408
476
  when COLORTYPE_TRUECOLOR_WITH_ALPHA
409
- image = Rixmap::Image.new(Rixmap::RGBA, image_width, image_height)
477
+ image = Rixmap::Image.new(Rixmap::RGBA, image_width, image_height, :background => bgcolor)
410
478
  filter = AdaptiveFilter.new(image.mode)
411
479
  pixels.each_slice((image_width * 4) + 1).each_with_index do |bytes, i|
412
480
  image[i] = filter.recon(bytes)
@@ -427,5 +495,5 @@ end
427
495
 
428
496
 
429
497
  #==============================================================================#
430
- # $Id: imageio.rb,v 753dbf70cab3 2014/05/16 16:13:38 chikuchikugonzalez $
498
+ # $Id: imageio.rb,v a60a21c75463 2014/05/30 17:04:13 chikuchikugonzalez $
431
499
  # vim: set sts=2 ts=2 sw=2 expandtab:
@@ -7,10 +7,10 @@ module Rixmap
7
7
  VERSION_MAJOR = 0
8
8
 
9
9
  # マイナーバージョン番号
10
- VERSION_MINOR = 2
10
+ VERSION_MINOR = 3
11
11
 
12
12
  # バグ修正回数
13
- VERSION_PATCH = 1
13
+ VERSION_PATCH = 0
14
14
 
15
15
  # バージョン番号 (数値表現)
16
16
  VERSION_NUMBER = (VERSION_MAJOR << 16) | (VERSION_MINOR << 8) | VERSION_PATCH
@@ -22,5 +22,5 @@ end
22
22
 
23
23
 
24
24
  #==============================================================================#
25
- # $Id: version.rb,v dd7cf49aa98a 2014/05/17 06:49:55 chikuchikugonzalez $
25
+ # $Id: version.rb,v 3d37b3ca070b 2014/05/17 06:54:52 chikuchikugonzalez $
26
26
  # vim: set sts=2 ts=2 sw=2 expandtab:
data/spec/palette_spec.rb CHANGED
@@ -69,9 +69,27 @@ describe Rixmap::Palette do
69
69
  end
70
70
  end
71
71
  end
72
+
73
+ context "Palette export/import check" do
74
+ before do
75
+ @palette = Rixmap::Palette.new(4)
76
+ @palette[0] = Rixmap::Color.new(255, 0, 0)
77
+ @palette[1] = Rixmap::Color.new(0, 255, 0)
78
+ @palette[2] = Rixmap::Color.new(0, 0, 255)
79
+ @palette[3] = Rixmap::Color.new(0, 0, 0)
80
+ @data = "\xFF\x00\x00\xFF\x00\xFF\x00\xFF\x00\x00\xFF\xFF\x00\x00\x00\xFF".force_encoding(Encoding::BINARY)
81
+ end
82
+
83
+ it "export data match to data" do expect(@palette.export('RGBA')).to eq(@data) end
84
+ it "import binary data" do
85
+ palette = Rixmap::Palette.new(4)
86
+ palette.import!(@data, 'RGBA')
87
+ expect(@palette).to eq(palette)
88
+ end
89
+ end
72
90
  end
73
91
 
74
92
 
75
93
  #==============================================================================#
76
- # $Id: palette_spec.rb,v 36d5b09e38de 2014/03/30 11:13:09 chikuchikugonzalez $
94
+ # $Id: palette_spec.rb,v 6f1b9e3e62b2 2014/05/18 08:46:26 chikuchikugonzalez $
77
95
  # vim: set sts=2 ts=2 sw=2 expandtab:
@@ -29,6 +29,111 @@ namespace Rixmap {
29
29
  ALPHA = 'A', // 透明度
30
30
  };
31
31
 
32
+ /**
33
+ * 各チャンネルデータを一括で扱うための構造体.
34
+ */
35
+ class ChannelByteSet {
36
+ protected: // 非公開メンバ
37
+ std::map<Channel, uint8_t> _data;
38
+
39
+ public: // コンストラクタ
40
+ /**
41
+ * デフォルトコンストラクタ.
42
+ * 全チャンネルを0で初期化します.
43
+ */
44
+ ChannelByteSet() {
45
+ this->clear();
46
+ }
47
+
48
+ /**
49
+ * グレースケール値からチャンネルデータを初期化します.
50
+ *
51
+ * @param [uint8_t] luminance 輝度値
52
+ * @param [uint8_t] alpha 透明度
53
+ */
54
+ ChannelByteSet(uint8_t luminance, uint8_t alpha = 255) {
55
+ this->clear();
56
+ this->setLuminance(luminance);
57
+ this->setAlpha(alpha);
58
+ }
59
+
60
+ /**
61
+ * RGB値からチャンネルデータを初期化します.
62
+ *
63
+ * @param [uint8_t] red 赤要素値
64
+ * @param [uint8_t] green 緑要素値
65
+ * @param [uint8_t] blue 青要素値
66
+ * @param [uint8_t] alpha 透明度
67
+ */
68
+ ChannelByteSet(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255) {
69
+ this->clear();
70
+ this->setRed(red);
71
+ this->setGreen(green);
72
+ this->setBlue(blue);
73
+ this->setAlpha(alpha);
74
+ }
75
+
76
+ /**
77
+ * コピーコンストラクタ
78
+ */
79
+ ChannelByteSet(const ChannelByteSet& bytes) {
80
+ this->clear();
81
+ this->_data = bytes._data;
82
+ }
83
+
84
+ /**
85
+ * デストラクタ
86
+ */
87
+ virtual ~ChannelByteSet() {}
88
+
89
+ public: // 公開プロパティメンバ関数
90
+ inline uint8_t getRed() { return this->_data.at(Channel::RED); }
91
+ inline uint8_t getGreen() { return this->_data.at(Channel::GREEN); }
92
+ inline uint8_t getBlue() { return this->_data.at(Channel::BLUE); }
93
+ inline uint8_t getAlpha() { return this->_data.at(Channel::ALPHA); }
94
+ inline uint8_t getLuminance() { return this->_data.at(Channel::LUMINANCE); }
95
+ inline uint8_t getPalette() { return this->_data.at(Channel::PALETTE); }
96
+
97
+ inline void setRed(uint8_t value) { this->_data[Channel::RED] = value; }
98
+ inline void setGreen(uint8_t value) { this->_data[Channel::GREEN] = value; }
99
+ inline void setBlue(uint8_t value) { this->_data[Channel::BLUE] = value; }
100
+ inline void setAlpha(uint8_t value) { this->_data[Channel::ALPHA] = value; }
101
+ inline void setLuminance(uint8_t value) { this->_data[Channel::LUMINANCE] = value; }
102
+ inline void setPalette(uint8_t value) { this->_data[Channel::PALETTE] = value; }
103
+
104
+ public: // 公開メンバ関数
105
+
106
+ public: // 公開演算子
107
+ inline uint8_t operator[](Channel channel) { return this->_data.at(channel); }
108
+ inline ChannelByteSet& operator=(const ChannelByteSet& bytes) {
109
+ this->_data = bytes._data;
110
+ return *this;
111
+ }
112
+
113
+ inline bool operator==(const ChannelByteSet& bytes) {
114
+ return ( (this->_data.at(Channel::RED) == bytes._data.at(Channel::RED))
115
+ && (this->_data.at(Channel::GREEN) == bytes._data.at(Channel::GREEN))
116
+ && (this->_data.at(Channel::BLUE) == bytes._data.at(Channel::BLUE))
117
+ && (this->_data.at(Channel::ALPHA) == bytes._data.at(Channel::ALPHA))
118
+ && (this->_data.at(Channel::LUMINANCE) == bytes._data.at(Channel::LUMINANCE))
119
+ && (this->_data.at(Channel::PALETTE) == bytes._data.at(Channel::PALETTE))
120
+ );
121
+ }
122
+ inline bool operator!=(const ChannelByteSet& bytes) { return !(*this == bytes); }
123
+
124
+ protected: // 非公開メンバ関数
125
+ /**
126
+ * 各バイトデータを初期化します.
127
+ */
128
+ inline void clear() {
129
+ this->_data[Channel::PALETTE ] = 0;
130
+ this->_data[Channel::LUMINANCE] = 0;
131
+ this->_data[Channel::RED ] = 0;
132
+ this->_data[Channel::GREEN] = 0;
133
+ this->_data[Channel::BLUE ] = 0;
134
+ this->_data[Channel::ALPHA] = 255;
135
+ }
136
+ };
32
137
  }
33
138
 
34
139
  //----------------------------------------------------------------------------//
@@ -38,5 +143,5 @@ namespace Rixmap {
38
143
 
39
144
 
40
145
  //============================================================================//
41
- // $Id: channel.hxx,v 8870c1d9926f 2014/03/18 16:09:35 chikuchikugonzalez $
146
+ // $Id: channel.hxx,v 34aa9654fa22 2014/05/21 14:50:19 chikuchikugonzalez $
42
147
  // vim: set sts=4 ts=4 sw=4 expandtab foldmethod=marker: