Module: Rixmap::ImageIO

Defined in:
src/rixmapio.cxx,
lib/rixmap/imageio.rb,
src/rixmapio.cxx

Overview

IO系クラス定義モジュール.

Defined Under Namespace

Classes: BaseImageIO, ImageIOInfo

Constant Summary collapse

MAGIC_BYTES_SIZE =

ファイルフォーマット識別用に読み取るマジックデータサイズ

16

Class Method Summary collapse

Class Method Details

.find(argQuery) ⇒ Rixmap::ImageIO::ImageIOInfo

指定された条件から画像入出力実装情報を探します.

現在対応している条件は以下の通りです.

  • :magic
  • :image
  • :path

複数の条件が指定された場合は、すべてを満たす入出力実装を返します.

Parameters:

  • query (Hash)

    検索条件.

Returns:

See Also:

  • #findall


150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'src/rixmapio.cxx', line 150

static VALUE ImageIO_Find(VALUE klass, VALUE argQuery) {
    // 

.findall(argQuery) ⇒ Array<Rixmap::ImageIO::ImageIOInfo>

指定された条件から画像入出力実装情報を全て探します.

現在対応している条件は以下の通りです.

  • :magic
  • :image
  • :path

複数の条件が指定された場合は、すべてを満たす入出力実装を返します.

Parameters:

  • query (Hash)

    検索条件.

Returns:



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'src/rixmapio.cxx', line 185

static VALUE ImageIO_FindAll(VALUE klass, VALUE argQuery) {
    // 

.get(argName) ⇒ Rixmap::ImageIO::ImageIOInfo

指定した名前に対応する画像入出力実装情報を返します.

Parameters:

  • name (Symbol, String)

    実装名

Returns:



115
116
117
118
119
120
121
122
123
124
125
126
# File 'src/rixmapio.cxx', line 115

static VALUE ImageIO_Get(VALUE klass, VALUE argName) {
    // 

.new(name, *params) ⇒ Object

画像入出力実装のインスタンスを作成します.

Returns 実装クラスインスタンス.

Parameters:

  • name (Symbol, String)

    画像入出力実装名.

  • params (Object...)

    実装クラスのコンストラクタに渡される引数.

Returns:

  • (Object)

    実装クラスインスタンス.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'src/rixmapio.cxx', line 82

static VALUE ImageIO_New(int argc, VALUE* argv, VALUE klass) {
    VALUE argName, argParams;
    rb_scan_args(argc, argv, "1*", &argName, &argParams);

    // 

.open(path, options = {}) ⇒ Rixmap::Image .open(path, format, options = {}) ⇒ Rixmap::Image

Overloads:

  • .open(path, options = {}) ⇒ Rixmap::Image

    ファイルパスから画像を読み込みます.

    Parameters:

    • path (String)

      ファイルパス

    • options (Hash) (defaults to: {})

      読み込み時のオプションパラメータ

    Returns:

  • .open(path, format, options = {}) ⇒ Rixmap::Image

    ファイルパスから指定フォーマットとの画像として読み込みます.

    Parameters:

    • path (String)

      ファイルパス

    • format (Symbol, String)

      ファイルフォーマット

    • options (Hash) (defaults to: {})

      読み込み時のオプションパラメータ

    Returns:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rixmap/imageio.rb', line 24

def self.open(path, *args)
  # 引数をチェック

  format  = nil
  options = {}
  unless args[0].nil?
    if args[0].kind_of?(Hash)
      options = args[0]
    else
      format = args[0]
      if !args[1].nil? && args[1].kind_of?(Hash)
        options = args[1]
      end
    end
  end

  # ImageIOを探索

  info = nil
  if format.nil?
    info = self.find(:path => path)
    if info.nil?
      # パスから判定できない場合はマジックデータから検索

      magic = IO.binread(path, MAGIC_BYTES_SIZE)
      info = self.find(:magic => magic)
    end

    # 見つからない場合は例外を出す

    if info.nil?
      raise NotImplementedError.new("ImageIO Implementation for File is not found: #{path}")
    end
  else
    info = self.get(format)
    if info.nil?
      raise NotImplementedError.new("ImageIO Implementation for #{format} is not found.")
    end
  end

  # 読み込みを実施

  iio = info.imageio.new(options)
  return iio.open(path)
end

.register(name, klass, extensions = []) .register(name, info)

画像入出力実装クラスを登録します.

Overloads:

  • .register(name, klass, extensions = [])

    This method returns an undefined value.

    Parameters:

    • name (Symbol, String)

      画像入出力実装名. :BMP とか.

    • klass (Class)

      画像入出力の実装クラス.

    • extensions (Array<String>) (defaults to: [])

      実装クラスに対応するファイル名拡張子リスト.

  • .register(name, info)

    This method returns an undefined value.

    Parameters:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'src/rixmapio.cxx', line 34

static VALUE ImageIO_Register(int argc, VALUE* argv, VALUE klass) {
    VALUE argName, arg1, arg2;
    rb_scan_args(argc, argv, "21", &argName, &arg1, &arg2);

    // 

.save(path, image, options = {}) .save(path, image, format, options = {})

Overloads:

  • .save(path, image, options = {})

    This method returns an undefined value.

    ファイルパスへ画像を書き込みます.

    Parameters:

    • path (String)

      書き込み先ファイルパス

    • image (Rixmap::Image)

      書き込む画像オブジェクト

    • options (Hash) (defaults to: {})

      オプションパラメータ

  • .save(path, image, format, options = {})

    This method returns an undefined value.

    ファイルパスへ指定されたフォーマットの画像として書き込みます.

    Parameters:

    • path (String)

      書き込み先ファイルパス

    • image (Rixmap::Image)

      書き込む画像オブジェクト

    • format (Symbol, String)

      ファイルフォーマット

    • options (Hash) (defaults to: {})

      オプションパラメータ



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/rixmap/imageio.rb', line 81

def self.save(path, image, *args)
  # パラメータ処理

  format  = nil
  options = {}
  unless args[0].nil?
    if args[0].kind_of?(Hash)
      options = args[0]
    else
      format = args[0]
      if !args[1].nil? && args[1].kind_of?(Hash)
        options = args[1]
      end
    end
  end

  # ImgaeIO探索

  info = nil
  if format.nil?
    info = self.find(:path => path)
    if info.nil?
      raise NotImplementedError.new("ImageIO Implementation for File is not found: #{path}")
    end
  else
    info = self.get(format)
    if info.nil?
      raise NotImplementedError.new("ImageIO Implementation for #{format} is not found.")
    end
  end

  # 書き込み可能かどうかをチェックしつつ書き込み.

  iio = info.imageio.new(options)
  if iio.writable?(image)
    return iio.save(path, image)
  else
    raise NotImplementedError.new("#{iio.class} is not designed for image #{image.inspect}")
  end
end