rixmap 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +3 -1
- data/lib/rixmap/format/bmp.rb +4 -1
- data/lib/rixmap/format/png/chunk.rb +178 -7
- data/lib/rixmap/format/png/imageio.rb +75 -7
- data/lib/rixmap/version.rb +3 -3
- data/spec/palette_spec.rb +19 -1
- data/src/rixmap/channel.hxx +106 -1
- data/src/rixmap/color.hxx +84 -14
- data/src/rixmap/image.hxx +205 -25
- data/src/rixmap/interpolator.hxx +29 -12
- data/src/rixmapcore.cxx +275 -210
- data/src/rixmapdeformation.cxx +4 -82
- data/src/rixmaphelper.cxx +501 -0
- data/src/rixmaphelper.hxx +82 -0
- data/src/rixmappool.cxx +65 -0
- data/src/rixmappool.hxx +69 -0
- data/test/test_png.rb +18 -5
- metadata +8 -3
- data/src/rixmap/helper.hxx +0 -347
data/src/rixmap/color.hxx
CHANGED
@@ -51,9 +51,17 @@ namespace Rixmap {
|
|
51
51
|
|
52
52
|
public: // プロパティメンバ関数
|
53
53
|
inline uint8_t getRed() const { return this->_red; }
|
54
|
+
inline void setRed(uint8_t value) { this->_red = value; }
|
55
|
+
|
54
56
|
inline uint8_t getGreen() const { return this->_green; }
|
57
|
+
inline void setGreen(uint8_t value) { this->_green = value; }
|
58
|
+
|
55
59
|
inline uint8_t getBlue() const { return this->_blue; }
|
60
|
+
inline void setBlue(uint8_t value) { this->_blue = value; }
|
61
|
+
|
56
62
|
inline uint8_t getAlpha() const { return this->_alpha; }
|
63
|
+
inline void setAlpha(uint8_t value) { this->_alpha = value; }
|
64
|
+
|
57
65
|
inline uint32_t getValue() const { return this->_value; }
|
58
66
|
|
59
67
|
public: // メンバ関数
|
@@ -64,6 +72,12 @@ namespace Rixmap {
|
|
64
72
|
return ROUND2BYTE(lround((r + g + b) / 3.0));
|
65
73
|
}
|
66
74
|
|
75
|
+
inline void setLuminance(uint8_t value) {
|
76
|
+
this->_red = value;
|
77
|
+
this->_green = value;
|
78
|
+
this->_blue = value;
|
79
|
+
}
|
80
|
+
|
67
81
|
/**
|
68
82
|
* 指定した色との距離を計算します.
|
69
83
|
* 現在の実装では透明度を無視しています.
|
@@ -77,19 +91,10 @@ namespace Rixmap {
|
|
77
91
|
return sqrt((dr + dg + db));
|
78
92
|
}
|
79
93
|
|
80
|
-
public: // 演算子オーバーロード
|
81
94
|
/**
|
82
|
-
*
|
95
|
+
* 配列のようにインデックスアクセス
|
83
96
|
*/
|
84
|
-
inline
|
85
|
-
this->_value = c._value;
|
86
|
-
return *this;
|
87
|
-
}
|
88
|
-
|
89
|
-
/**
|
90
|
-
* 配列アクセス
|
91
|
-
*/
|
92
|
-
inline uint8_t operator[](size_t offset) const {
|
97
|
+
inline uint8_t get(size_t offset) const {
|
93
98
|
switch (offset) {
|
94
99
|
case 0: return this->_red;
|
95
100
|
case 1: return this->_green;
|
@@ -101,9 +106,9 @@ namespace Rixmap {
|
|
101
106
|
}
|
102
107
|
|
103
108
|
/**
|
104
|
-
*
|
109
|
+
* チャンネルアクセス
|
105
110
|
*/
|
106
|
-
inline uint8_t
|
111
|
+
inline uint8_t get(Channel channel) const {
|
107
112
|
switch (channel) {
|
108
113
|
case Channel::RED: return this->_red;
|
109
114
|
case Channel::GREEN: return this->_green;
|
@@ -114,6 +119,71 @@ namespace Rixmap {
|
|
114
119
|
}
|
115
120
|
}
|
116
121
|
|
122
|
+
/**
|
123
|
+
* 配列のようにインデックスで更新
|
124
|
+
*/
|
125
|
+
inline void set(size_t offset, uint8_t value) {
|
126
|
+
switch (offset) {
|
127
|
+
case 0:
|
128
|
+
this->_red = value;
|
129
|
+
break;
|
130
|
+
case 1:
|
131
|
+
this->_green = value;
|
132
|
+
break;
|
133
|
+
case 2:
|
134
|
+
this->_blue = value;
|
135
|
+
break;
|
136
|
+
case 3:
|
137
|
+
this->_alpha = value;
|
138
|
+
break;
|
139
|
+
default:
|
140
|
+
// 何もできねぇ
|
141
|
+
break;
|
142
|
+
}
|
143
|
+
}
|
144
|
+
|
145
|
+
/**
|
146
|
+
* チャンネルで更新
|
147
|
+
*/
|
148
|
+
inline void set(Channel channel, uint8_t value) {
|
149
|
+
switch (channel) {
|
150
|
+
case Channel::RED:
|
151
|
+
this->_red = value;
|
152
|
+
break;
|
153
|
+
case Channel::GREEN:
|
154
|
+
this->_green = value;
|
155
|
+
break;
|
156
|
+
case Channel::BLUE:
|
157
|
+
this->_blue = value;
|
158
|
+
break;
|
159
|
+
case Channel::ALPHA:
|
160
|
+
this->_alpha = value;
|
161
|
+
break;
|
162
|
+
default:
|
163
|
+
// 何もできねぇ
|
164
|
+
break;
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
public: // 演算子オーバーロード
|
169
|
+
/**
|
170
|
+
* 代入演算子定義
|
171
|
+
*/
|
172
|
+
inline Color& operator=(const Color& c) {
|
173
|
+
this->_value = c._value;
|
174
|
+
return *this;
|
175
|
+
}
|
176
|
+
|
177
|
+
/**
|
178
|
+
* 配列アクセス
|
179
|
+
*/
|
180
|
+
inline uint8_t operator[](size_t offset) const { return this->get(offset); }
|
181
|
+
|
182
|
+
/**
|
183
|
+
* 配列アクセス with Channel
|
184
|
+
*/
|
185
|
+
inline uint8_t operator[](Channel channel) const { return this->get(channel); }
|
186
|
+
|
117
187
|
/**
|
118
188
|
* 等値比較演算子
|
119
189
|
*/
|
@@ -218,5 +288,5 @@ namespace Rixmap {
|
|
218
288
|
|
219
289
|
|
220
290
|
//============================================================================//
|
221
|
-
// $Id: color.hxx,v
|
291
|
+
// $Id: color.hxx,v 7ded24c516db 2014/05/18 08:28:38 chikuchikugonzalez $
|
222
292
|
// vim: set sts=4 ts=4 sw=4 expandtab foldmethod=marker:
|
data/src/rixmap/image.hxx
CHANGED
@@ -20,6 +20,102 @@ namespace Rixmap {
|
|
20
20
|
DIAGONAL = 0x03
|
21
21
|
};
|
22
22
|
|
23
|
+
/**
|
24
|
+
* 画像背景色データ.
|
25
|
+
*/
|
26
|
+
class BackgroundColor {
|
27
|
+
private: // 非公開メンバ
|
28
|
+
std::map<Channel, uint8_t> _data;
|
29
|
+
bool _disabled;
|
30
|
+
|
31
|
+
public: // コンストラクタ
|
32
|
+
BackgroundColor() : _disabled(true) {
|
33
|
+
this->clear();
|
34
|
+
}
|
35
|
+
|
36
|
+
BackgroundColor(uint8_t l, uint8_t a = 255) : _disabled(true) {
|
37
|
+
this->clear();
|
38
|
+
this->_data[Channel::LUMINANCE] = l;
|
39
|
+
this->_data[Channel::ALPHA ] = a;
|
40
|
+
}
|
41
|
+
|
42
|
+
BackgroundColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) : _disabled(true) {
|
43
|
+
this->clear();
|
44
|
+
this->_data[Channel::RED ] = r;
|
45
|
+
this->_data[Channel::GREEN] = g;
|
46
|
+
this->_data[Channel::BLUE ] = b;
|
47
|
+
this->_data[Channel::ALPHA] = a;
|
48
|
+
}
|
49
|
+
|
50
|
+
BackgroundColor(const BackgroundColor& bg) {
|
51
|
+
this->clear();
|
52
|
+
this->_data = bg._data;
|
53
|
+
this->_disabled = bg._disabled;
|
54
|
+
}
|
55
|
+
|
56
|
+
public: // 公開メンバ関数
|
57
|
+
inline uint8_t getRed() { return this->_data.at(Channel::RED); }
|
58
|
+
inline uint8_t getRed() const { return this->_data.at(Channel::RED); }
|
59
|
+
inline void setRed(uint8_t value) { this->_data[Channel::RED] = value; }
|
60
|
+
|
61
|
+
inline uint8_t getGreen() { return this->_data.at(Channel::GREEN); }
|
62
|
+
inline uint8_t getGreen() const { return this->_data.at(Channel::GREEN); }
|
63
|
+
inline void setGreen(uint8_t value) { this->_data[Channel::GREEN] = value; }
|
64
|
+
|
65
|
+
inline uint8_t getBlue() { return this->_data.at(Channel::BLUE); }
|
66
|
+
inline uint8_t getBlue() const { return this->_data.at(Channel::BLUE); }
|
67
|
+
inline void setBlue(uint8_t value) { this->_data[Channel::BLUE] = value; }
|
68
|
+
|
69
|
+
inline uint8_t getAlpha() { return this->_data.at(Channel::ALPHA); }
|
70
|
+
inline uint8_t getAlpha() const { return this->_data.at(Channel::ALPHA); }
|
71
|
+
inline void setAlpha(uint8_t value) { this->_data[Channel::ALPHA] = value; }
|
72
|
+
|
73
|
+
inline uint8_t getLuminance() { return this->_data.at(Channel::LUMINANCE); }
|
74
|
+
inline uint8_t getLuminance() const { return this->_data.at(Channel::LUMINANCE); }
|
75
|
+
inline void setLuminance(uint8_t value) { this->_data[Channel::LUMINANCE] = value; }
|
76
|
+
|
77
|
+
inline uint8_t getPalette() { return this->_data.at(Channel::PALETTE); }
|
78
|
+
inline uint8_t getPalette() const { return this->_data.at(Channel::PALETTE); }
|
79
|
+
inline void setPalette(uint8_t value) { this->_data[Channel::PALETTE] = value; }
|
80
|
+
|
81
|
+
inline bool isEnabled() const { return !(this->_disabled); }
|
82
|
+
inline bool isDisabled() const { return this->_disabled; }
|
83
|
+
inline void enable() { this->_disabled = false; }
|
84
|
+
inline void disable() { this->_disabled = true; }
|
85
|
+
|
86
|
+
public: // 演算子オーバーロード
|
87
|
+
inline const uint8_t& operator[](Channel channel) const { return this->_data.at(channel); }
|
88
|
+
inline uint8_t& operator[](Channel channel) { return this->_data.at(channel); }
|
89
|
+
|
90
|
+
inline bool operator==(const BackgroundColor& bg) const {
|
91
|
+
return ( (this->_data.at(Channel::RED) == bg._data.at(Channel::RED))
|
92
|
+
&& (this->_data.at(Channel::GREEN) == bg._data.at(Channel::GREEN))
|
93
|
+
&& (this->_data.at(Channel::BLUE) == bg._data.at(Channel::BLUE))
|
94
|
+
&& (this->_data.at(Channel::ALPHA) == bg._data.at(Channel::ALPHA))
|
95
|
+
&& (this->_data.at(Channel::LUMINANCE) == bg._data.at(Channel::LUMINANCE))
|
96
|
+
&& (this->_data.at(Channel::PALETTE) == bg._data.at(Channel::PALETTE))
|
97
|
+
&& (this->_disabled == bg._disabled)
|
98
|
+
);
|
99
|
+
}
|
100
|
+
inline bool operator!=(const BackgroundColor& bg) const { return !((*this) == bg); }
|
101
|
+
|
102
|
+
inline BackgroundColor& operator=(const BackgroundColor& base) {
|
103
|
+
this->_data = base._data;
|
104
|
+
this->_disabled = base._disabled;
|
105
|
+
return *this;
|
106
|
+
}
|
107
|
+
|
108
|
+
private: // 非公開メンバ関数
|
109
|
+
inline void clear() {
|
110
|
+
this->_data[Channel::PALETTE ] = 0;
|
111
|
+
this->_data[Channel::LUMINANCE] = 0;
|
112
|
+
this->_data[Channel::RED ] = 0;
|
113
|
+
this->_data[Channel::GREEN] = 0;
|
114
|
+
this->_data[Channel::BLUE ] = 0;
|
115
|
+
this->_data[Channel::ALPHA] = 255;
|
116
|
+
}
|
117
|
+
};
|
118
|
+
|
23
119
|
/**
|
24
120
|
* Ruby用画像情報クラスデータ
|
25
121
|
*/
|
@@ -59,16 +155,24 @@ namespace Rixmap {
|
|
59
155
|
* @param [int32_t] width 画像の横幅
|
60
156
|
* @param [int32_t] height 画像の高さ
|
61
157
|
* @param [bool] cleared 初期化するかのフラグ (default=true)
|
158
|
+
* @param [BackgroundColor*] bg 背景色
|
62
159
|
*/
|
63
|
-
static void AllocatePixels(Pixels& pixels, const ChannelArray& channels, int32_t width, int32_t height, bool cleared = true) {
|
160
|
+
static void AllocatePixels(Pixels& pixels, const ChannelArray& channels, int32_t width, int32_t height, bool cleared = true, const BackgroundColor* bg = NULL) {
|
64
161
|
// メモリ不足時に投げる例外オブジェクト
|
65
162
|
static std::bad_alloc excNoMemory;
|
163
|
+
static BackgroundColor defaultBG;
|
164
|
+
|
165
|
+
// 背景色へのポインタ
|
166
|
+
const BackgroundColor* bgColor = ((bg != NULL) && bg->isEnabled()) ? bg : &defaultBG;
|
66
167
|
|
67
168
|
// 確保処理
|
68
169
|
try {
|
69
170
|
for (auto it = channels.begin(); it != channels.end(); it++) {
|
70
171
|
Channel channel = *it;
|
71
172
|
|
173
|
+
// 背景色
|
174
|
+
uint8_t bgByte = (*bgColor)[channel];
|
175
|
+
|
72
176
|
// NULLポインタで初期化
|
73
177
|
// TODO ところでこれ、nullptrのほうがいいんですかね
|
74
178
|
pixels[channel] = NULL;
|
@@ -93,12 +197,14 @@ namespace Rixmap {
|
|
93
197
|
plane[h] = line;
|
94
198
|
|
95
199
|
// 初期化する
|
200
|
+
// TODO 初期カラーを設定できるようにする
|
96
201
|
if (cleared) {
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
202
|
+
std::memset(&(line[0]), bgByte, sizeof(uint8_t) * width);
|
203
|
+
//if (channel == Channel::ALPHA) {
|
204
|
+
// std::memset(&(line[0]), 255, sizeof(uint8_t) * width);
|
205
|
+
//} else {
|
206
|
+
// std::memset(&(line[0]), 0, sizeof(uint8_t) * width);
|
207
|
+
//}
|
102
208
|
}
|
103
209
|
}
|
104
210
|
}
|
@@ -123,25 +229,35 @@ namespace Rixmap {
|
|
123
229
|
Pixels _data;
|
124
230
|
VALUE _palette;
|
125
231
|
|
232
|
+
// 補助データ
|
233
|
+
//VALUE _background; // 背景色
|
234
|
+
//VALUE _transparent; // 透過設定
|
235
|
+
|
236
|
+
// 構造体スタイル
|
237
|
+
BackgroundColor _background;
|
238
|
+
BackgroundColor _transparent;
|
239
|
+
|
126
240
|
public: // コンストラクタ
|
127
241
|
/**
|
128
242
|
* デフォルトコンストラクタ
|
129
243
|
*/
|
130
|
-
ImageData() : _mode(Mode::NONE), _width(0), _height(0), _ready(false), _palette(Qnil) {}
|
244
|
+
ImageData() : _mode(Mode::NONE), _width(0), _height(0), _ready(false), _palette(Qnil), _background(), _transparent() {}
|
131
245
|
|
132
246
|
/**
|
133
247
|
* 一応初期データつき
|
134
248
|
*/
|
135
|
-
ImageData(Mode mode, int32_t width, int32_t height) : _mode(Mode::NONE), _width(0), _height(0), _ready(false), _palette(Qnil) {
|
249
|
+
ImageData(Mode mode, int32_t width, int32_t height) : _mode(Mode::NONE), _width(0), _height(0), _ready(false), _palette(Qnil), _background(), _transparent() {
|
136
250
|
this->init(mode, width, height);
|
137
251
|
}
|
138
252
|
|
139
253
|
/**
|
140
254
|
* コピーコンストラクタ
|
141
255
|
*/
|
142
|
-
ImageData(const ImageData& image) : _mode(Mode::NONE), _width(0), _height(0), _ready(false), _palette(Qnil) {
|
256
|
+
ImageData(const ImageData& image) : _mode(Mode::NONE), _width(0), _height(0), _ready(false), _palette(Qnil), _background(), _transparent() {
|
257
|
+
this->_palette = image._palette;
|
258
|
+
this->_background = image._background;
|
259
|
+
this->_transparent = image._transparent;
|
143
260
|
this->init(image.getMode(), image._width, image._height);
|
144
|
-
this->_palette = image._palette;
|
145
261
|
|
146
262
|
// ピクセルの複製
|
147
263
|
const ChannelArray& channels = image._mode.getChannels();
|
@@ -161,9 +277,11 @@ namespace Rixmap {
|
|
161
277
|
* ベース画像ののサイズを変更した新しい画像を作成する、部分コピーコンストラクタ.
|
162
278
|
* ピクセルデータは複製されません.
|
163
279
|
*/
|
164
|
-
ImageData(const ImageData& image, int32_t width, int32_t height) : _mode(Mode::NONE), _width(0), _height(0), _ready(false), _palette(Qnil) {
|
280
|
+
ImageData(const ImageData& image, int32_t width, int32_t height) : _mode(Mode::NONE), _width(0), _height(0), _ready(false), _palette(Qnil), _background(), _transparent() {
|
281
|
+
this->_palette = image._palette;
|
282
|
+
this->_background = image._background;
|
283
|
+
this->_transparent = image._transparent;
|
165
284
|
this->init(image.getMode(), width, height);
|
166
|
-
this->_palette = image._palette;
|
167
285
|
}
|
168
286
|
|
169
287
|
/**
|
@@ -185,7 +303,7 @@ namespace Rixmap {
|
|
185
303
|
* 画像形式情報を取得します.
|
186
304
|
*/
|
187
305
|
inline const ModeInfo& getModeInfo() const { return this->_mode; }
|
188
|
-
inline
|
306
|
+
inline ModeInfo& getModeInfo() { return this->_mode; }
|
189
307
|
|
190
308
|
/**
|
191
309
|
* 横幅を取得します.
|
@@ -228,6 +346,14 @@ namespace Rixmap {
|
|
228
346
|
this->_palette = obj;
|
229
347
|
}
|
230
348
|
|
349
|
+
inline const BackgroundColor& getBackground() const { return this->_background; }
|
350
|
+
inline BackgroundColor& getBackground() { return this->_background; }
|
351
|
+
inline void setBackground(const BackgroundColor& bg) { this->_background = bg; }
|
352
|
+
|
353
|
+
inline const BackgroundColor& getTransparent() const { return this->_transparent; }
|
354
|
+
inline BackgroundColor& getTransparent() { return this->_transparent; }
|
355
|
+
inline void setTransparent(const BackgroundColor& bg) { this->_transparent = bg; }
|
356
|
+
|
231
357
|
public: // 公開メンバ関数
|
232
358
|
/**
|
233
359
|
* 指定座標が画像範囲内かどうかを返します.
|
@@ -340,7 +466,27 @@ namespace Rixmap {
|
|
340
466
|
err << "point [" << x << ", " << y << "] is out of image";
|
341
467
|
throw std::out_of_range(err.str());
|
342
468
|
} else {
|
343
|
-
|
469
|
+
if (this->_background.isEnabled()) {
|
470
|
+
switch (this->_mode.getMode()) {
|
471
|
+
case Mode::INDEXED:
|
472
|
+
return this->getPaletteData()->get(this->_background.getPalette());
|
473
|
+
break;
|
474
|
+
|
475
|
+
case Mode::GRAYSCALE:
|
476
|
+
case Mode::GRAYALPHA:
|
477
|
+
{
|
478
|
+
uint8_t l = this->_background.getLuminance();
|
479
|
+
return Color(l, l, l);
|
480
|
+
}
|
481
|
+
break;
|
482
|
+
|
483
|
+
default:
|
484
|
+
return Color(this->_background.getRed(), this->_background.getGreen(), this->_background.getBlue());
|
485
|
+
break;
|
486
|
+
}
|
487
|
+
} else {
|
488
|
+
return Color(0, 0, 0);
|
489
|
+
}
|
344
490
|
}
|
345
491
|
}
|
346
492
|
}
|
@@ -367,7 +513,7 @@ namespace Rixmap {
|
|
367
513
|
const ChannelArray& channels = info.getChannels();
|
368
514
|
|
369
515
|
// ピクセルデータを確保
|
370
|
-
ImageData::AllocatePixels(this->_data, channels, width, height, true);
|
516
|
+
ImageData::AllocatePixels(this->_data, channels, width, height, true, &(this->_background));
|
371
517
|
|
372
518
|
// その他プロパティを初期化
|
373
519
|
this->_mode = info;
|
@@ -384,14 +530,14 @@ namespace Rixmap {
|
|
384
530
|
rb_gc_mark_maybe(this->_palette);
|
385
531
|
}
|
386
532
|
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
inline VALUE getMetadata() const {
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
}
|
533
|
+
///**
|
534
|
+
// * 必須ではないオブジェクトのハッシュを返します.
|
535
|
+
// */
|
536
|
+
//inline VALUE getMetadata() const {
|
537
|
+
// VALUE metadata = rb_hash_new();
|
538
|
+
// rb_hash_aset(metadata, ID2SYM(rb_intern("palette")), this->_palette);
|
539
|
+
// return metadata;
|
540
|
+
//}
|
395
541
|
|
396
542
|
/**
|
397
543
|
* 画像の反転処理を行います.
|
@@ -440,6 +586,30 @@ namespace Rixmap {
|
|
440
586
|
}
|
441
587
|
}
|
442
588
|
|
589
|
+
/**
|
590
|
+
* 背景色で画像を塗りつぶします.
|
591
|
+
*/
|
592
|
+
void clear() {
|
593
|
+
// TODO AllocatePixelsと共通化したいよねぇ
|
594
|
+
static BackgroundColor _default;
|
595
|
+
|
596
|
+
// 背景色
|
597
|
+
BackgroundColor* bg = (this->_background.isEnabled()) ? &(this->_background) : &_default;
|
598
|
+
|
599
|
+
// チャンネル毎に処理
|
600
|
+
const ChannelArray& channels = this->_mode.getChannels();
|
601
|
+
for (auto it = channels.begin(); it != channels.end(); it++) {
|
602
|
+
Channel channel = *it;
|
603
|
+
uint8_t byte = (*bg)[channel];
|
604
|
+
uint8_t** plane = this->get(channel);
|
605
|
+
|
606
|
+
for (int32_t h = 0; h < this->_height; h++) {
|
607
|
+
uint8_t* line = plane[h];
|
608
|
+
std::memset(&(line[0]), byte, sizeof(uint8_t) * this->_width);
|
609
|
+
}
|
610
|
+
}
|
611
|
+
}
|
612
|
+
|
443
613
|
public: // 演算子オーバーロード
|
444
614
|
bool operator==(const ImageData& data) const {
|
445
615
|
if (this->_ready && data._ready && (this->_mode == data._mode) && (this->_width == data._width) && (this->_height == data._height)) {
|
@@ -448,6 +618,12 @@ namespace Rixmap {
|
|
448
618
|
return false;
|
449
619
|
}
|
450
620
|
}
|
621
|
+
if (this->_background != data._background) {
|
622
|
+
return false;
|
623
|
+
}
|
624
|
+
if (this->_transparent != data._transparent) {
|
625
|
+
return false;
|
626
|
+
}
|
451
627
|
|
452
628
|
// ピクセルを比較
|
453
629
|
const ChannelArray& channels = this->_mode.getChannels();
|
@@ -481,7 +657,7 @@ namespace Rixmap {
|
|
481
657
|
|
482
658
|
// ピクセルデータは新しく確保 (破壊防止)
|
483
659
|
std::map<Channel, uint8_t**> pixels;
|
484
|
-
ImageData::AllocatePixels(pixels, channels, base._width, base._height, false);
|
660
|
+
ImageData::AllocatePixels(pixels, channels, base._width, base._height, false, NULL);
|
485
661
|
|
486
662
|
// ピクセルデータを複製
|
487
663
|
for (auto it = channels.begin(); it != channels.end(); it++) {
|
@@ -506,6 +682,10 @@ namespace Rixmap {
|
|
506
682
|
// パレットは参照
|
507
683
|
this->_palette = base._palette;
|
508
684
|
|
685
|
+
// 背景色とかを複製
|
686
|
+
this->_background = base._background;
|
687
|
+
this->_transparent = base._transparent;
|
688
|
+
|
509
689
|
// 準備完了
|
510
690
|
this->_ready = true;
|
511
691
|
|
@@ -612,5 +792,5 @@ namespace Rixmap {
|
|
612
792
|
|
613
793
|
|
614
794
|
//============================================================================//
|
615
|
-
// $Id: image.hxx,v
|
795
|
+
// $Id: image.hxx,v 5590f3c64493 2014/05/31 14:59:34 chikuchikugonzalez $
|
616
796
|
// vim: set sts=4 ts=4 sw=4 expandtab foldmethod=marker:
|
data/src/rixmap/interpolator.hxx
CHANGED
@@ -26,12 +26,13 @@ namespace Rixmap {
|
|
26
26
|
protected:
|
27
27
|
ImageData* _base; // 元画像
|
28
28
|
ModeInfo* _mode; // 元画像形式
|
29
|
+
BackgroundColor* _bg; // 元画像背景色
|
29
30
|
|
30
31
|
// 補間処理キャッシュ
|
31
32
|
std::map<Channel, uint8_t> _pixel;
|
32
33
|
|
33
34
|
public:
|
34
|
-
Interpolator(ImageData* base) : _base(base), _mode(&(_base->getModeInfo())) {
|
35
|
+
Interpolator(ImageData* base) : _base(base), _mode(&(_base->getModeInfo())), _bg(&(base->getBackground())) {
|
35
36
|
this->reset();
|
36
37
|
}
|
37
38
|
|
@@ -54,15 +55,29 @@ namespace Rixmap {
|
|
54
55
|
virtual uint8_t get(Channel channel) { return this->_pixel.at(channel); }
|
55
56
|
|
56
57
|
protected: // 非公開メンバ
|
58
|
+
inline uint8_t getBG(Channel channel) {
|
59
|
+
if (this->_bg != NULL && this->_bg->isEnabled()) {
|
60
|
+
return (*(this->_bg))[channel];
|
61
|
+
} else {
|
62
|
+
if (channel == Channel::ALPHA) {
|
63
|
+
return 255;
|
64
|
+
} else {
|
65
|
+
return 0;
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
57
70
|
virtual void reset() {
|
58
71
|
const ChannelArray& channels = this->_mode->getChannels();
|
59
72
|
for (auto it = channels.begin(); it != channels.end(); it++) {
|
60
73
|
Channel channel = *it;
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
74
|
+
//uint8_t byte = (*(this->_bg))[channel]; // TODO NULLになっちゃってた場合の対処
|
75
|
+
uint8_t byte = this->getBG(channel);
|
76
|
+
//uint8_t byte = 0;
|
77
|
+
//if (channel == Channel::ALPHA) {
|
78
|
+
// byte = 255;
|
79
|
+
//}
|
80
|
+
this->_pixel[channel] = byte;
|
66
81
|
}
|
67
82
|
}
|
68
83
|
};
|
@@ -210,11 +225,13 @@ namespace Rixmap {
|
|
210
225
|
const ChannelArray& channels = this->_preferredMode.getChannels();
|
211
226
|
for (auto it = channels.begin(); it != channels.end(); it++) {
|
212
227
|
Channel channel = *it;
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
228
|
+
//uint8_t byte = (*(this->_bg))[channel]; // TODO NULLになっちゃってた場合の対処
|
229
|
+
uint8_t byte = this->getBG(channel);
|
230
|
+
//uint8_t byte = 0;
|
231
|
+
//if (channel == Channel::ALPHA) {
|
232
|
+
// byte = 255;
|
233
|
+
//}
|
234
|
+
this->_pixel[channel] = byte;
|
218
235
|
}
|
219
236
|
}
|
220
237
|
};
|
@@ -222,5 +239,5 @@ namespace Rixmap {
|
|
222
239
|
|
223
240
|
|
224
241
|
//============================================================================//
|
225
|
-
// $Id: interpolator.hxx,v
|
242
|
+
// $Id: interpolator.hxx,v f55202a19a4a 2014/05/31 13:04:07 chikuchikugonzalez $
|
226
243
|
// vim: set sts=4 ts=4 sw=4 expandtab foldmethod=marker:
|