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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68d917985e256067776c2d3b2f43bfda3444e235
4
- data.tar.gz: ea89aa3ffc196d656afaebdb5dd499b4964c2db5
3
+ metadata.gz: bb9119689e5f3a45937bfa2242b9a349cc1a9b4e
4
+ data.tar.gz: 156039457cc38eb8528d860c947fcfa8234d71f3
5
5
  SHA512:
6
- metadata.gz: 66ec63d02d19613561de02e14d9b3a9e669c0011008a58550344deb93e48daa5db8b8cea1c6b78554968a774233ab9302a0ff8636ac85e263826d19ef3a03524
7
- data.tar.gz: 3da6eedc56945bdd2ffe1a343498f87c828171f34d9619366b99c063860ca0aa98aa9ae66f8758aa1614eeee4cbbcd60eb3b6a7d2a1887ed5916dc43e501218c
6
+ metadata.gz: da28e74d6f01ef8cd2479f1b92a4b48037249471284e07184b908ad4cd7ac9443ba8586ae96c2a1c628257cc498c617f9da6239f9dc619656b9f04852cd42007
7
+ data.tar.gz: 5e01aa8f1b4389de32491c8596366213e14d7b8aaad1234fa3ade341375a67ee1bc7cf9a03fedb463782ea8c801f5016603bd09cab65bf954c69d66d7ce957a7
data/Rakefile CHANGED
@@ -101,7 +101,7 @@ end
101
101
  #------------------------------------------------------------------------------#
102
102
  if defined?(YARD::Rake::YardocTask)
103
103
  YARD::Rake::YardocTask.new do |yd|
104
- yd.files = FileList['src/**/*.{c,cpp,cxx}']
104
+ yd.files = FileList['src/*.{c,cpp,cxx}']
105
105
  yd.files += FileList['lib/**/*.rb']
106
106
  yd.options << '--markup=markdown'
107
107
  yd.options << '--private'
@@ -152,5 +152,5 @@ end
152
152
 
153
153
 
154
154
  #==============================================================================#
155
- # $Id: Rakefile,v f933bbbed93e 2014/04/21 14:36:01 chikuchikugonzalez $
155
+ # $Id: Rakefile,v 753dbf70cab3 2014/05/16 16:13:38 chikuchikugonzalez $
156
156
  # vim: set sts=2 ts=2 sw=2 expandtab:
@@ -31,6 +31,17 @@ module Rixmap
31
31
  return @chunks[name]
32
32
  end
33
33
 
34
+ # チャンクタイプに対応する実装クラスが存在するかを返します.
35
+ #
36
+ # @param [String] name チャンクタイプ名
37
+ # @return [Boolean] チャンク実装クラスがある場合はtrue.
38
+ def self.has?(name)
39
+ unless defined?(@chunks)
40
+ @chunks = Hash.new
41
+ end
42
+ return @chunks.has_key?(name)
43
+ end
44
+
34
45
  # PNGチャンクベースクラス
35
46
  class BaseChunk
36
47
  # チャンクを初期化します.
@@ -235,5 +246,5 @@ end
235
246
 
236
247
 
237
248
  #==============================================================================#
238
- # $Id: chunk.rb,v 57b1fb2cd6a6 2014/04/20 12:21:27 chikuchikugonzalez $
249
+ # $Id: chunk.rb,v 753dbf70cab3 2014/05/16 16:13:38 chikuchikugonzalez $
239
250
  # vim: set sts=2 ts=2 sw=2 expandtab:
@@ -334,6 +334,12 @@ module Rixmap
334
334
  end
335
335
  offset += (chunk_size + 8)
336
336
 
337
+ # チャンクがあるかをチェック
338
+ unless Chunk.has?(chunk_type)
339
+ # ないので警告出して次へ
340
+ warn("Unknown or Not-Implemented Chunk Type: #{chunk_type}")
341
+ next
342
+ end
337
343
  chunk = Chunk.get(chunk_type).new
338
344
  chunk.data = chunk_data
339
345
 
@@ -421,5 +427,5 @@ end
421
427
 
422
428
 
423
429
  #==============================================================================#
424
- # $Id: imageio.rb,v f933bbbed93e 2014/04/21 14:36:01 chikuchikugonzalez $
430
+ # $Id: imageio.rb,v 753dbf70cab3 2014/05/16 16:13:38 chikuchikugonzalez $
425
431
  # vim: set sts=2 ts=2 sw=2 expandtab:
@@ -88,7 +88,7 @@ module Rixmap
88
88
  # @param [String] magic 先頭バイトデータ
89
89
  # @return [Boolean] XPM1形式で読み込める場合はtrue
90
90
  def self.readable?(magic)
91
- if MAGIC_XPM1_PATTERN.match(magci)
91
+ if MAGIC_XPM1_PATTERN.match(magic)
92
92
  return true
93
93
  else
94
94
  return false
@@ -225,7 +225,7 @@ module Rixmap
225
225
  # @param [String] magic 先頭バイトデータ
226
226
  # @return [Boolean] XPM2形式で読み込める場合はtrue
227
227
  def self.readable?(magic)
228
- if MAGIC_XPM2_PATTERN.match(magci)
228
+ if MAGIC_XPM2_PATTERN.match(magic)
229
229
  return true
230
230
  else
231
231
  return false
@@ -442,5 +442,5 @@ end
442
442
 
443
443
 
444
444
  #==============================================================================#
445
- # $Id: xpm.rb,v 57b1fb2cd6a6 2014/04/20 12:21:27 chikuchikugonzalez $
445
+ # $Id: xpm.rb,v 753dbf70cab3 2014/05/16 16:13:38 chikuchikugonzalez $
446
446
  # vim: set sts=2 ts=2 sw=2 expandtab:
@@ -0,0 +1,231 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ #
4
+ module Rixmap
5
+ class Image
6
+
7
+ # 指定サイズに画像サイズを変更します.
8
+ #
9
+ # ピクセルは拡縮されないことに注意してください.
10
+ # あくまで、画像自体のサイズ変更を目的としています.
11
+ #
12
+ # @param [Integer] width 新しい横幅
13
+ # @param [Integer] height 新しい高さ
14
+ # @param [Symbol] anchor 基準点をシンボルで指定します. 指定されない場合は左上を基準にします.
15
+ # 使用できるシンボルは以下の通りです.
16
+ #
17
+ # - :n, :north
18
+ # - 中央上部を基準にします.
19
+ # - :nw, :northwest
20
+ # - 左上を基準にします (デフォルト)
21
+ # - :ne, :northeast
22
+ # - 右上を基準にします
23
+ # - :w, :west
24
+ # - 左側中央を基準にします.
25
+ # - :e, :east
26
+ # - 右側中央を基準にします.
27
+ # - :s, :south
28
+ # - 中央下部を基準にします.
29
+ # - :sw, :southwest
30
+ # - 左下を基準にします.
31
+ # - :se, :southeast
32
+ # - 右下を基準にします.
33
+ # - :c, :center
34
+ # - 中心を基準にします.
35
+ #
36
+ # @return [Rixmap::Image] サイズ変更された画像.
37
+ # @see #crop
38
+ def resize(width, height, anchor=nil)
39
+ left, top, right, bottom = get_bounds(width, height, anchor)
40
+ return self.crop(left, top, right, bottom)
41
+ end
42
+
43
+ # 画像サイズを破壊的に変更します.
44
+ #
45
+ # @param [Integer] width 新しい横幅
46
+ # @param [Integer] height 新しい高さ
47
+ # @param [Symbol] anchor 基準点をシンボルで指定します. 指定されない場合は左上を基準にします.
48
+ # @return [Rixmnap::Image] selfを返します.
49
+ # @see #crop!
50
+ # @see #resize
51
+ def resize!(width, height, anchor=nil)
52
+ left, top, right, bottom = get_bounds(width, height, anchor)
53
+ return self.crop!(left, top, right, bottom)
54
+ end
55
+
56
+ # 画像を拡大または縮小します.
57
+ #
58
+ # @overload scale(scale)
59
+ # 縦と横方向を同じ倍率で拡大または縮小します.
60
+ # @param [Float] scale 拡大率.
61
+ # @return [Rixmap::Image] 拡縮処理後の画像
62
+ #
63
+ # @overload scale(xscale, yscale)
64
+ # 縦と横にそれぞれ拡大率を指定して拡大または縮小を行います.
65
+ # @param [Float] xscale 横方向倍率
66
+ # @param [Float] yscale 縦方向倍率
67
+ # @return [Rixmap::Image] 拡縮処理後の画像
68
+ def scale(*args)
69
+ xscale = 1.0
70
+ yscale = 1.0
71
+
72
+ case args.size
73
+ when 1
74
+ xscale = args[0].to_f
75
+ yscale = args[0].to_f
76
+ when 2
77
+ xscale = args[0].to_f
78
+ yscale = args[1].to_f
79
+ else
80
+ raise ArgumentError.new("wrong number of arguments (#{args.size} for 1..2)")
81
+ end
82
+
83
+ deformer = Rixmap::Deformer::AffineDeformer.new
84
+ deformer.matrix.scale = [xscale, yscale]
85
+
86
+ return self.deform(deformer, true)
87
+ end
88
+
89
+ # 画像を破壊的に拡大または縮小します.
90
+ #
91
+ # @overload scale(scale)
92
+ # 縦と横方向を同じ倍率で拡大または縮小します.
93
+ # @param [Float] scale 拡大率.
94
+ # @return [Rixmap::Image] selfを返します.
95
+ #
96
+ # @overload scale(xscale, yscale)
97
+ # 縦と横にそれぞれ拡大率を指定して拡大または縮小を行います.
98
+ # @param [Float] xscale 横方向倍率
99
+ # @param [Float] yscale 縦方向倍率
100
+ # @return [Rixmap::Image] selfを返します.
101
+ def scale!(*args)
102
+ xscale = 1.0
103
+ yscale = 1.0
104
+
105
+ case args.size
106
+ when 1
107
+ xscale = args[0].to_f
108
+ yscale = args[0].to_f
109
+ when 2
110
+ xscale = args[0].to_f
111
+ yscale = args[1].to_f
112
+ else
113
+ raise ArgumentError.new("wrong number of arguments (#{args.size} for 1..2)")
114
+ end
115
+
116
+ deformer = Rixmap::Deformer::AffineDeformer.new
117
+ deformer.matrix.scale = [xscale, yscale]
118
+
119
+ return self.deform!(deformer, true)
120
+ end
121
+
122
+ # 画像を回転させます.
123
+ #
124
+ # @param [Float] angle 回転角度 (ラジアン)
125
+ # @return [Rixmap::Image] 回転させた画像
126
+ def rotate(angle)
127
+ deformer = Rixmap::Deformer::AffineDeformer.new
128
+ deformer.matrix.angle = angle
129
+ deformer.interpolator = Rixmap::Deformer::IPO_BICUBIC
130
+ return self.deform(deformer, true)
131
+ end
132
+
133
+ # 画像を破壊的に回転させます.
134
+ #
135
+ # @param [Float] angle 回転角度 (ラジアン)
136
+ # @return [Rixmap::Image] selfを返します.
137
+ def rotate!(angle)
138
+ deformer = Rixmap::Deformer::AffineDeformer.new
139
+ deformer.matrix.angle = angle
140
+ deformer.interpolator = Rixmap::Deformer::IPO_BICUBIC
141
+ return self.deform!(deformer, true)
142
+ end
143
+
144
+ # {#resize}用に`anchor`から[left, top, right, bottom]形式の配列を作成します.
145
+ #
146
+ # @param [Integer] width 領域の幅
147
+ # @param [Integer] height 領域の高さ
148
+ # @param [Symbol] anchor 画像に対する基準点
149
+ # @return [Array<Integer>] 基準点から計算された `width x height` 領域の座標配列
150
+ def get_bounds(width, height, anchor)
151
+ left = 0
152
+ top = 0
153
+ right = 0
154
+ bottom = 0
155
+
156
+ if anchor.nil?
157
+ anchor = :nw
158
+ else
159
+ anchor = anchor.to_s.downcase.to_sym
160
+ end
161
+
162
+ case anchor
163
+ when :n, :north
164
+ left = (self.width / 2.0 - width / 2.0).floor
165
+ right = left + width - 1
166
+ top = 0
167
+ bottom = height - 1
168
+
169
+ when :nw, :northwest
170
+ left = 0
171
+ top = 0
172
+ right = width - 1
173
+ bottom = height - 1
174
+
175
+ when :ne, :northeast
176
+ left = self.width - width
177
+ top = 0
178
+ right = self.width - 1
179
+ bottom = height - 1
180
+
181
+ when :w, :west
182
+ left = 0
183
+ top = (self.height / 2.0 - height / 2.0).floor
184
+ right = width - 1
185
+ bottom = top + height - 1
186
+
187
+ when :c, :center
188
+ left = (self.width / 2.0 - width / 2.0).floor
189
+ top = (self.height / 2.0 - height / 2.0).floor
190
+ right = left + width - 1
191
+ bottom = top + height - 1
192
+
193
+ when :e, :east
194
+ left = self.width - width
195
+ top = (self.height / 2.0 - height / 2.0).floor
196
+ right = self.width - 1
197
+ bottom = top + height - 1
198
+
199
+ when :s, :south
200
+ left = (self.width / 2.0 - width / 2.0).floor
201
+ top = (self.height - height)
202
+ right = left + width - 1
203
+ bottom = self.height - 1
204
+
205
+ when :sw, :southwest
206
+ left = 0
207
+ top = (self.height - height)
208
+ right = width - 1
209
+ bottom = self.height - 1
210
+
211
+ when :se, :southeast
212
+ left = self.width - width
213
+ top = self.height - height
214
+ right = self.width - 1
215
+ bottom = self.height - 1
216
+
217
+ else
218
+ raise ArgumentError.new("Unsupported Resize-Anchor: #{anchor}")
219
+ end
220
+
221
+ return [left, top, right, bottom]
222
+ end
223
+ private :get_bounds
224
+
225
+ end
226
+ end
227
+
228
+
229
+ #==============================================================================#
230
+ # $Id: image.rb,v 753dbf70cab3 2014/05/16 16:13:38 chikuchikugonzalez $
231
+ # vim: set sts=2 ts=2 sw=2 expandtab:
@@ -0,0 +1,125 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ #
4
+ module Rixmap
5
+ module ImageIO
6
+
7
+ # ファイルフォーマット識別用に読み取るマジックデータサイズ
8
+ MAGIC_BYTES_SIZE = 16
9
+
10
+ # @overload open(path, options={})
11
+ # ファイルパスから画像を読み込みます.
12
+ #
13
+ # @param [String] path ファイルパス
14
+ # @param [Hash] options 読み込み時のオプションパラメータ
15
+ # @return [Rixmap::Image] 読み込まれた画像オブジェクト
16
+ #
17
+ # @overload open(path, format, options={})
18
+ # ファイルパスから指定フォーマットとの画像として読み込みます.
19
+ #
20
+ # @param [String] path ファイルパス
21
+ # @param [Symbol,String] format ファイルフォーマット
22
+ # @param [Hash] options 読み込み時のオプションパラメータ
23
+ # @return [Rixmap::Image] 読み込まれた画像オブジェクト
24
+ def self.open(path, *args)
25
+ # 引数をチェック
26
+ format = nil
27
+ options = {}
28
+ unless args[0].nil?
29
+ if args[0].kind_of?(Hash)
30
+ options = args[0]
31
+ else
32
+ format = args[0]
33
+ if !args[1].nil? && args[1].kind_of?(Hash)
34
+ options = args[1]
35
+ end
36
+ end
37
+ end
38
+
39
+ # ImageIOを探索
40
+ info = nil
41
+ if format.nil?
42
+ info = self.find(:path => path)
43
+ if info.nil?
44
+ # パスから判定できない場合はマジックデータから検索
45
+ magic = IO.binread(path, MAGIC_BYTES_SIZE)
46
+ info = self.find(:magic => magic)
47
+ end
48
+
49
+ # 見つからない場合は例外を出す
50
+ if info.nil?
51
+ raise NotImplementedError.new("ImageIO Implementation for File is not found: #{path}")
52
+ end
53
+ else
54
+ info = self.get(format)
55
+ if info.nil?
56
+ raise NotImplementedError.new("ImageIO Implementation for #{format} is not found.")
57
+ end
58
+ end
59
+
60
+ # 読み込みを実施
61
+ iio = info.imageio.new(options)
62
+ return iio.open(path)
63
+ end
64
+
65
+ # @overload save(path, image, options={})
66
+ # ファイルパスへ画像を書き込みます.
67
+ #
68
+ # @param [String] path 書き込み先ファイルパス
69
+ # @param [Rixmap::Image] image 書き込む画像オブジェクト
70
+ # @param [Hash] options オプションパラメータ
71
+ # @return [void]
72
+ #
73
+ # @overload save(path, image, format, options={})
74
+ # ファイルパスへ指定されたフォーマットの画像として書き込みます.
75
+ #
76
+ # @param [String] path 書き込み先ファイルパス
77
+ # @param [Rixmap::Image] image 書き込む画像オブジェクト
78
+ # @param [Symbol,String] format ファイルフォーマット
79
+ # @param [Hash] options オプションパラメータ
80
+ # @return [void]
81
+ def self.save(path, image, *args)
82
+ # パラメータ処理
83
+ format = nil
84
+ options = {}
85
+ unless args[0].nil?
86
+ if args[0].kind_of?(Hash)
87
+ options = args[0]
88
+ else
89
+ format = args[0]
90
+ if !args[1].nil? && args[1].kind_of?(Hash)
91
+ options = args[1]
92
+ end
93
+ end
94
+ end
95
+
96
+ # ImgaeIO探索
97
+ info = nil
98
+ if format.nil?
99
+ info = self.find(:path => path)
100
+ if info.nil?
101
+ raise NotImplementedError.new("ImageIO Implementation for File is not found: #{path}")
102
+ end
103
+ else
104
+ info = self.get(format)
105
+ if info.nil?
106
+ raise NotImplementedError.new("ImageIO Implementation for #{format} is not found.")
107
+ end
108
+ end
109
+
110
+ # 書き込み可能かどうかをチェックしつつ書き込み.
111
+ iio = info.imageio.new(options)
112
+ if iio.writable?(image)
113
+ return iio.save(path, image)
114
+ else
115
+ raise NotImplementedError.new("#{iio.class} is not designed for image #{image.inspect}")
116
+ end
117
+ end
118
+
119
+ end
120
+ end
121
+
122
+
123
+ #==============================================================================#
124
+ # $Id: imageio.rb,v 753dbf70cab3 2014/05/16 16:13:38 chikuchikugonzalez $
125
+ # vim: set sts=2 ts=2 sw=2 expandtab:
@@ -7,20 +7,20 @@ module Rixmap
7
7
  VERSION_MAJOR = 0
8
8
 
9
9
  # マイナーバージョン番号
10
- VERSION_MINOR = 1
10
+ VERSION_MINOR = 2
11
11
 
12
- # リビジョン番号のようなもの
13
- VERSION_TEENY = 1
12
+ # バグ修正回数
13
+ VERSION_PATCH = 0
14
14
 
15
15
  # バージョン番号 (数値表現)
16
- VERSION_NUMBER = (VERSION_MAJOR << 16) | (VERSION_MINOR << 8) | VERSION_TEENY
16
+ VERSION_NUMBER = (VERSION_MAJOR << 16) | (VERSION_MINOR << 8) | VERSION_PATCH
17
17
 
18
18
  # バージョン番号 (文字列)
19
- VERSION = "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_TEENY}"
19
+ VERSION = "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_PATCH}"
20
20
 
21
21
  end
22
22
 
23
23
 
24
24
  #==============================================================================#
25
- # $Id: version.rb,v f933bbbed93e 2014/04/21 14:36:01 chikuchikugonzalez $
25
+ # $Id: version.rb,v 753dbf70cab3 2014/05/16 16:13:38 chikuchikugonzalez $
26
26
  # vim: set sts=2 ts=2 sw=2 expandtab:
data/lib/rixmap.rb CHANGED
@@ -15,10 +15,12 @@ require_relative "#{RUBY_PLATFORM}/rixmap"
15
15
 
16
16
  # 3. Ruby実装を読み込み
17
17
  require_relative 'rixmap/format'
18
+ require_relative 'rixmap/image'
19
+ require_relative 'rixmap/imageio'
18
20
 
19
21
  # 4. その他
20
22
 
21
23
 
22
24
  #==============================================================================#
23
- # $Id: rixmap.rb,v 57b1fb2cd6a6 2014/04/20 12:21:27 chikuchikugonzalez $
25
+ # $Id: rixmap.rb,v 753dbf70cab3 2014/05/16 16:13:38 chikuchikugonzalez $
24
26
  # vim: set sts=2 ts=2 sw=2 expandtab:
@@ -16,13 +16,20 @@
16
16
  #include <cctype>
17
17
  #include <cfloat>
18
18
  #if REQUIRE_MATH_H
19
- # include <math.h>
19
+ # include <math.h>
20
20
  #endif
21
21
  #include <ruby.h>
22
22
  #include <ruby/encoding.h>
23
23
  #include "../chollas/raser.hxx"
24
24
  #include "../chollas/utilities.hxx"
25
25
 
26
+ /**
27
+ * C++11用キーワードの定義
28
+ */
29
+ #if __cplusplus < 201103L
30
+ # define override
31
+ #endif
32
+
26
33
  /**
27
34
  * Ruby側で提供していてほしいけど提供してないのでこっちで定義する
28
35
  */
@@ -54,5 +61,5 @@ namespace Rixmap {
54
61
 
55
62
 
56
63
  //============================================================================//
57
- // $Id: common.hxx,v 66c8edefa6c0 2014/04/20 14:22:54 chikuchikugonzalez $
64
+ // $Id: common.hxx,v 753dbf70cab3 2014/05/16 16:13:38 chikuchikugonzalez $
58
65
  // vim: set sts=4 ts=4 sw=4 expandtab foldmethod=marker: