rixmap 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +2 -2
- data/lib/rixmap/format/png/chunk.rb +12 -1
- data/lib/rixmap/format/png/imageio.rb +7 -1
- data/lib/rixmap/format/xpm.rb +3 -3
- data/lib/rixmap/image.rb +231 -0
- data/lib/rixmap/imageio.rb +125 -0
- data/lib/rixmap/version.rb +6 -6
- data/lib/rixmap.rb +3 -1
- data/src/rixmap/common.hxx +9 -2
- data/src/rixmap/converter.hxx +348 -0
- data/src/rixmap/deformer.hxx +325 -0
- data/src/rixmap/helper.hxx +347 -0
- data/src/rixmap/image.hxx +284 -39
- data/src/rixmap/interpolator.hxx +226 -0
- data/src/rixmap/palette.hxx +14 -2
- data/src/rixmap/quantizer.hxx +385 -0
- data/src/rixmap.hxx +4 -1
- data/src/rixmapcore.cxx +668 -272
- data/src/rixmapcore.hxx +8 -1
- data/src/rixmapdeformation.cxx +687 -0
- data/src/rixmapdeformation.hxx +30 -0
- data/src/rixmapio.cxx +93 -56
- data/src/rixmapmain.cxx +3 -1
- data/test/test_clone.rb +15 -0
- data/test/test_deformer.rb +46 -0
- data/test/test_quantize.rb +4 -0
- data/test/test_resize_cutter.rb +27 -0
- metadata +16 -2
@@ -0,0 +1,30 @@
|
|
1
|
+
// -*- coding: utf-8 -*-
|
2
|
+
/**
|
3
|
+
* Rixmap変形処理実装用ヘッダ
|
4
|
+
*/
|
5
|
+
#pragma once
|
6
|
+
#include "rixmap.hxx"
|
7
|
+
#include "rixmapcore.hxx"
|
8
|
+
|
9
|
+
//----------------------------------------------------------------------------//
|
10
|
+
// グローバル変数宣言
|
11
|
+
//----------------------------------------------------------------------------//
|
12
|
+
extern VALUE mRixmapDeformer;
|
13
|
+
extern VALUE cRixmapBaseDeformer;
|
14
|
+
extern VALUE cRixmapAffineDeformer;
|
15
|
+
extern VALUE cRixmapAffineMatrix;
|
16
|
+
|
17
|
+
//extern VALUE cRixmapAffinePoint;
|
18
|
+
//extern VALUE cRixmapAffineCenter;
|
19
|
+
//extern VALUE cRixmapAffineScale;
|
20
|
+
//extern VALUE cRixmapAffineTranslation;
|
21
|
+
|
22
|
+
//----------------------------------------------------------------------------//
|
23
|
+
// コアAPI関数プロトタイプ
|
24
|
+
//----------------------------------------------------------------------------//
|
25
|
+
extern void RixmapDeformation_Init();
|
26
|
+
|
27
|
+
|
28
|
+
//============================================================================//
|
29
|
+
// $Id: rixmapdeformation.hxx,v 753dbf70cab3 2014/05/16 16:13:38 chikuchikugonzalez $
|
30
|
+
// vim: set sts=4 ts=4 sw=4 expandtab foldmethod=marker:
|
data/src/rixmapio.cxx
CHANGED
@@ -126,84 +126,119 @@ static VALUE ImageIO_Get(VALUE klass, VALUE argName) {
|
|
126
126
|
}
|
127
127
|
|
128
128
|
/**
|
129
|
-
*
|
129
|
+
* 指定された条件から画像入出力実装情報を探します.
|
130
130
|
*
|
131
|
-
*
|
132
|
-
*
|
133
|
-
*
|
131
|
+
* 現在対応している条件は以下の通りです.
|
132
|
+
*
|
133
|
+
* - `:magic`
|
134
|
+
* - `:image`
|
135
|
+
* - `:path`
|
136
|
+
*
|
137
|
+
* 複数の条件が指定された場合は、すべてを満たす入出力実装を返します.
|
138
|
+
*
|
139
|
+
* @param [Hash] query 検索条件.
|
140
|
+
* @option query [String] :magic 画像のマジックデータ.
|
141
|
+
* 指定された場合は、このマジックデータを持つ画像を読み込める
|
142
|
+
* 入出力実装を返します.
|
143
|
+
* @option query [Rixmap::Image] :image 画像オブジェクト.
|
144
|
+
* この画像オブジェクトを書き込むことができる入出力実装を返します.
|
145
|
+
* @option query [String] :path ファイルパス. このファイルパスにマッチする拡張子情報を持っている
|
146
|
+
* 入出力実装を返します.
|
147
|
+
* @return [Rixmap::ImageIO::ImageIOInfo] 入出力実装情報. 見つからない場合はnil
|
148
|
+
* @see #findall
|
134
149
|
*/
|
135
|
-
static VALUE ImageIO_Find(VALUE klass, VALUE
|
136
|
-
//
|
137
|
-
VALUE
|
138
|
-
|
139
|
-
//
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
long nkey = RARRAY_LEN(allKeys);
|
147
|
-
for (long i = 0; i < nkey; i++) {
|
148
|
-
VALUE tblKey = rb_ary_entry(allKeys, i);
|
149
|
-
VALUE tblVal = rb_hash_lookup(registry, tblKey);
|
150
|
-
|
151
|
-
if (!NIL_P(tblVal) && RTEST(rb_obj_is_kind_of(tblVal, cRixmapImageIOInfo))) {
|
152
|
-
VALUE iioInfo = tblVal; // 変数名だけ変えておく
|
153
|
-
|
154
|
-
// 拡張子をチェック
|
155
|
-
if (RTEST(rb_funcall(iioInfo, rb_intern("match?"), 1, strFileName))) {
|
156
|
-
// TODO 複数のフォーマットで同じ拡張子に対応している場合
|
157
|
-
return iioInfo;
|
158
|
-
}
|
159
|
-
} else {
|
160
|
-
// TODO warningぐらい出しておく?
|
161
|
-
}
|
150
|
+
static VALUE ImageIO_Find(VALUE klass, VALUE argQuery) {
|
151
|
+
// すべて検索
|
152
|
+
VALUE infos = rb_funcall(klass, rb_intern("findall"), 1, argQuery);
|
153
|
+
|
154
|
+
// 空配列かどうか.
|
155
|
+
if (RARRAY_LEN(infos) > 0) {
|
156
|
+
// 空でないので、先頭を返す.
|
157
|
+
return rb_ary_entry(infos, 0);
|
158
|
+
} else {
|
159
|
+
// 空=見つからなった
|
160
|
+
return Qnil;
|
162
161
|
}
|
163
|
-
|
164
|
-
// 見つからなかったらnil
|
165
|
-
return Qnil;
|
166
162
|
}
|
167
163
|
|
168
164
|
/**
|
169
|
-
*
|
165
|
+
* 指定された条件から画像入出力実装情報を全て探します.
|
170
166
|
*
|
171
|
-
*
|
172
|
-
*
|
173
|
-
*
|
167
|
+
* 現在対応している条件は以下の通りです.
|
168
|
+
*
|
169
|
+
* - `:magic`
|
170
|
+
* - `:image`
|
171
|
+
* - `:path`
|
172
|
+
*
|
173
|
+
* 複数の条件が指定された場合は、すべてを満たす入出力実装を返します.
|
174
|
+
*
|
175
|
+
* @param [Hash] query 検索条件.
|
176
|
+
* @option query [String] :magic 画像のマジックデータ.
|
177
|
+
* 指定された場合は、このマジックデータを持つ画像を読み込める
|
178
|
+
* 入出力実装を返します.
|
179
|
+
* @option query [Rixmap::Image] :image 画像オブジェクト.
|
180
|
+
* この画像オブジェクトを書き込むことができる入出力実装を返します.
|
181
|
+
* @option query [String] :path ファイルパス. このファイルパスにマッチする拡張子情報を持っている
|
182
|
+
* 入出力実装を返します.
|
183
|
+
* @return [Array<Rixmap::ImageIO::ImageIOInfo>] 見つかった入出力実装情報の配列. 見つからない場合は空配列です
|
174
184
|
*/
|
175
|
-
static VALUE ImageIO_FindAll(VALUE klass, VALUE
|
176
|
-
//
|
177
|
-
VALUE
|
185
|
+
static VALUE ImageIO_FindAll(VALUE klass, VALUE argQuery) {
|
186
|
+
// 条件を分解
|
187
|
+
VALUE condMagic = rb_hash_lookup(argQuery, ID2SYM(rb_intern("magic")));
|
188
|
+
VALUE condImage = rb_hash_lookup(argQuery, ID2SYM(rb_intern("image")));
|
189
|
+
VALUE condPath = rb_hash_lookup(argQuery, ID2SYM(rb_intern("path")));
|
190
|
+
|
191
|
+
// 条件が一つ以上あるか
|
192
|
+
if (NIL_P(condMagic) && NIL_P(condImage) && NIL_P(condPath)) {
|
193
|
+
rb_raise(rb_eArgError, "empty query is not supported. :magic, :image or :path is needed");
|
194
|
+
}
|
178
195
|
|
179
196
|
// レジストリ
|
180
197
|
VALUE registry = rb_iv_get(klass, "@registry");
|
181
198
|
|
182
|
-
//
|
199
|
+
// キーリスト
|
183
200
|
VALUE allKeys = rb_funcall(registry, rb_intern("keys"), 0);
|
184
201
|
|
185
|
-
//
|
186
|
-
VALUE
|
202
|
+
// 配列オブジェクトを確保
|
203
|
+
VALUE iioInfoList = rb_ary_new();
|
204
|
+
|
205
|
+
// 各キーについて処理
|
187
206
|
long nkey = RARRAY_LEN(allKeys);
|
188
207
|
for (long i = 0; i < nkey; i++) {
|
189
208
|
VALUE tblKey = rb_ary_entry(allKeys, i);
|
190
209
|
VALUE tblVal = rb_hash_lookup(registry, tblKey);
|
191
210
|
|
192
|
-
|
193
|
-
|
211
|
+
// 値を調べる
|
212
|
+
if (NIL_P(tblVal) || !RTEST(rb_obj_is_kind_of(tblVal, cRixmapImageIOInfo))) {
|
213
|
+
// TODO 警告表示
|
214
|
+
continue;
|
215
|
+
}
|
216
|
+
|
217
|
+
// 一応
|
218
|
+
VALUE iioInfo = tblVal;
|
219
|
+
VALUE iioKlass = rb_iv_get(iioInfo, "@imageio");
|
194
220
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
}
|
200
|
-
} else {
|
201
|
-
// TODO warningぐらい出しておく?
|
221
|
+
// 条件でチェック
|
222
|
+
if (!NIL_P(condMagic) && !RTEST(rb_funcall(iioKlass, rb_intern("readable?"), 1, condMagic))) {
|
223
|
+
// 読み込めない
|
224
|
+
continue;
|
202
225
|
}
|
226
|
+
if (!NIL_P(condImage) && !RTEST(rb_funcall(iioKlass, rb_intern("writable?"), 1, condImage))) {
|
227
|
+
// 書き込めない
|
228
|
+
continue;
|
229
|
+
}
|
230
|
+
if (!NIL_P(condPath) && !RTEST(rb_funcall(iioInfo, rb_intern("match?"), 1, condPath))) {
|
231
|
+
// 対応している拡張子ではない
|
232
|
+
continue;
|
233
|
+
}
|
234
|
+
|
235
|
+
// 全部通過
|
236
|
+
rb_ary_push(iioInfoList, iioInfo);
|
203
237
|
}
|
204
238
|
|
205
|
-
//
|
206
|
-
|
239
|
+
// 見つかったものをすべて返す.
|
240
|
+
// ※ 見つからなかった場合は空配列
|
241
|
+
return iioInfoList;
|
207
242
|
}
|
208
243
|
/* }}} */
|
209
244
|
/* Rixmap::ImageIO::ImageIOInfo {{{ */
|
@@ -605,6 +640,8 @@ void RixmapIO_Init() {
|
|
605
640
|
rb_define_method(cRixmapBaseImageIO, "write", RUBY_METHOD_FUNC(BaseImageIO_write), -1);
|
606
641
|
rb_define_method(cRixmapBaseImageIO, "open", RUBY_METHOD_FUNC(BaseImageIO_open), -1);
|
607
642
|
rb_define_method(cRixmapBaseImageIO, "read", RUBY_METHOD_FUNC(BaseImageIO_read), -1);
|
643
|
+
rb_alias(cRixmapBaseImageIO, rb_intern("load"), rb_intern("decode"));
|
644
|
+
rb_alias(cRixmapBaseImageIO, rb_intern("dump"), rb_intern("encode"));
|
608
645
|
|
609
646
|
/**
|
610
647
|
* Document-module: Rixmap::Format
|
@@ -648,5 +685,5 @@ void RixmapIO_RegisterImageIO(const char* name, volatile VALUE klass, int num, .
|
|
648
685
|
|
649
686
|
|
650
687
|
//============================================================================//
|
651
|
-
// $Id: rixmapio.cxx,v
|
688
|
+
// $Id: rixmapio.cxx,v 753dbf70cab3 2014/05/16 16:13:38 chikuchikugonzalez $
|
652
689
|
// vim: set sts=4 ts=4 sw=4 expandtab foldmethod=marker:
|
data/src/rixmapmain.cxx
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
#include <ruby.h>
|
9
9
|
#include "rixmapcore.hxx"
|
10
10
|
#include "rixmapio.hxx"
|
11
|
+
#include "rixmapdeformation.hxx"
|
11
12
|
|
12
13
|
/**
|
13
14
|
* Rixmapエントリポイント
|
@@ -16,9 +17,10 @@ extern "C" void Init_rixmap(void) {
|
|
16
17
|
// 初期化処理実行
|
17
18
|
RixmapCore_Init();
|
18
19
|
RixmapIO_Init();
|
20
|
+
RixmapDeformation_Init();
|
19
21
|
}
|
20
22
|
|
21
23
|
|
22
24
|
//============================================================================//
|
23
|
-
// $Id: rixmapmain.cxx,v
|
25
|
+
// $Id: rixmapmain.cxx,v 753dbf70cab3 2014/05/16 16:13:38 chikuchikugonzalez $
|
24
26
|
// vim: set sts=4 ts=4 sw=4 expandtab foldmethod=marker:
|
data/test/test_clone.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require_relative '../lib/rixmap'
|
3
|
+
require_relative '../lib/rixmap/format/bmp'
|
4
|
+
|
5
|
+
iio = Rixmap::ImageIO.new(:BMP)
|
6
|
+
img1 = iio.open('rgba.bmp')
|
7
|
+
img2 = img1.clone
|
8
|
+
|
9
|
+
p img1 == img2
|
10
|
+
iio.save('cloned.bmp', img2)
|
11
|
+
|
12
|
+
|
13
|
+
#==============================================================================#
|
14
|
+
# $Id$
|
15
|
+
# vim: set sts=2 ts=2 sw=2 expandtab:
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require_relative '../lib/rixmap'
|
2
|
+
|
3
|
+
base = Rixmap::ImageIO.open('square.bmp')
|
4
|
+
deformer = Rixmap::Deformer::AffineDeformer.new
|
5
|
+
|
6
|
+
# 拡縮
|
7
|
+
deformer.matrix.angle = 0.0
|
8
|
+
deformer.matrix.scale = [2.0, 2.0]
|
9
|
+
scaled1 = deformer.deform(base, false)
|
10
|
+
scaled2 = deformer.deform(base, true)
|
11
|
+
Rixmap::ImageIO.save('square-scaled1.bmp', scaled1)
|
12
|
+
Rixmap::ImageIO.save('square-scaled2.bmp', scaled2)
|
13
|
+
|
14
|
+
# 回転
|
15
|
+
deformer.matrix.scale = [1.2, 1.2]
|
16
|
+
deformer.matrix.angle = (45 * Math::PI / 180.0)
|
17
|
+
deformer.matrix.center = [base.width / 2.0, base.height / 2.0]
|
18
|
+
#deformer.interpolator = :bicubic #Rixmap::Deformer::IPO_BICUBIC
|
19
|
+
rotated1 = base.deform(deformer, false)
|
20
|
+
rotated2 = base.deform(deformer, true)
|
21
|
+
Rixmap::ImageIO.save('square-rotated1.bmp', rotated1)
|
22
|
+
Rixmap::ImageIO.save('square-rotated2.bmp', rotated2)
|
23
|
+
|
24
|
+
# 剪断
|
25
|
+
deformer.matrix.skew = :horizontal
|
26
|
+
deformer.matrix.scale = [1.0, 1.0]
|
27
|
+
deformer.matrix.angle = (30 * Math::PI / 180.0)
|
28
|
+
deformer.interpolator = :none
|
29
|
+
skew1 = deformer.deform(base, true)
|
30
|
+
|
31
|
+
deformer.matrix.skew = :vertical
|
32
|
+
skew2 = deformer.deform(base, true)
|
33
|
+
|
34
|
+
deformer.matrix.skew = :both
|
35
|
+
skew3 = deformer.deform(base, true)
|
36
|
+
|
37
|
+
Rixmap::ImageIO.save('square-skew1.bmp', skew1)
|
38
|
+
Rixmap::ImageIO.save('square-skew2.bmp', skew2)
|
39
|
+
Rixmap::ImageIO.save('square-skew3.bmp', skew3)
|
40
|
+
|
41
|
+
# 平行移動
|
42
|
+
deformer.matrix.angle = 0
|
43
|
+
deformer.matrix.trans = [128, -256]
|
44
|
+
deformer.matrix.skew = :none
|
45
|
+
trans1 = deformer.deform(base, false)
|
46
|
+
Rixmap::ImageIO.save('square-trans1.bmp', trans1)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require_relative '../lib/rixmap'
|
3
|
+
|
4
|
+
base = Rixmap::ImageIO.open('square.bmp')
|
5
|
+
|
6
|
+
# 分割
|
7
|
+
anchors = [:nw, :n, :ne, :w, :c, :e, :sw, :s, :se]
|
8
|
+
sizes = [
|
9
|
+
[290, 290],
|
10
|
+
[290, 290],
|
11
|
+
[290, 290],
|
12
|
+
[290, 290],
|
13
|
+
[290, 290],
|
14
|
+
[290, 290],
|
15
|
+
[290, 291],
|
16
|
+
[290, 291],
|
17
|
+
[290, 291],
|
18
|
+
]
|
19
|
+
anchors.each_with_index do |anchor, i|
|
20
|
+
img = base.resize(*sizes[i], anchor)
|
21
|
+
Rixmap::ImageIO.save("part#{i}.bmp", img)
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
#==============================================================================#
|
26
|
+
# $Id: test_bmp.rb,v a43e566390cb 2014/04/16 16:03:22 chikuchikugonzalez $
|
27
|
+
# vim: set sts=2 ts=2 sw=2 expandtab:
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rixmap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- chikuchikugonzalez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|
@@ -66,24 +66,32 @@ extensions:
|
|
66
66
|
- src/extconf.rb
|
67
67
|
extra_rdoc_files:
|
68
68
|
- src/rixmapcore.cxx
|
69
|
+
- src/rixmapdeformation.cxx
|
69
70
|
- src/rixmapio.cxx
|
70
71
|
- src/rixmapmain.cxx
|
71
72
|
- README.markdown
|
72
73
|
- LICENSE.txt
|
73
74
|
files:
|
74
75
|
- src/rixmapcore.cxx
|
76
|
+
- src/rixmapdeformation.cxx
|
75
77
|
- src/rixmapio.cxx
|
76
78
|
- src/rixmapmain.cxx
|
77
79
|
- src/rixmap.hxx
|
78
80
|
- src/rixmapcore.hxx
|
81
|
+
- src/rixmapdeformation.hxx
|
79
82
|
- src/rixmapio.hxx
|
80
83
|
- src/rixmap/binary.hxx
|
81
84
|
- src/rixmap/channel.hxx
|
82
85
|
- src/rixmap/color.hxx
|
83
86
|
- src/rixmap/common.hxx
|
87
|
+
- src/rixmap/converter.hxx
|
88
|
+
- src/rixmap/deformer.hxx
|
89
|
+
- src/rixmap/helper.hxx
|
84
90
|
- src/rixmap/image.hxx
|
91
|
+
- src/rixmap/interpolator.hxx
|
85
92
|
- src/rixmap/mode.hxx
|
86
93
|
- src/rixmap/palette.hxx
|
94
|
+
- src/rixmap/quantizer.hxx
|
87
95
|
- src/chollas/LICENSE.txt
|
88
96
|
- src/chollas/README.md
|
89
97
|
- src/chollas/alloc.hxx
|
@@ -97,11 +105,17 @@ files:
|
|
97
105
|
- lib/rixmap/format/png.rb
|
98
106
|
- lib/rixmap/format/xpm.rb
|
99
107
|
- lib/rixmap/format.rb
|
108
|
+
- lib/rixmap/image.rb
|
109
|
+
- lib/rixmap/imageio.rb
|
100
110
|
- lib/rixmap/version.rb
|
101
111
|
- lib/rixmap.rb
|
102
112
|
- test/test_bmp.rb
|
113
|
+
- test/test_clone.rb
|
114
|
+
- test/test_deformer.rb
|
103
115
|
- test/test_pcx.rb
|
104
116
|
- test/test_png.rb
|
117
|
+
- test/test_quantize.rb
|
118
|
+
- test/test_resize_cutter.rb
|
105
119
|
- test/test_xpm.rb
|
106
120
|
- spec/binary_spec.rb
|
107
121
|
- spec/color_spec.rb
|