Class: FreeImage::AbstractSource

Inherits:
Object
  • Object
show all
Defined in:
lib/free-image/sources/abstract_source.rb

Overview

Summary

FreeImage can load images from a variety of files, memory or streams. For additional details please see:

FreeImage::File

Use to load images from files

FreeImage::Memory

Use to load images from byte strings

FreeImage::IO

Use to load images from io streams

Direct Known Subclasses

File, IO, Memory

Defined Under Namespace

Modules: Decoder, Encoder

Instance Method Summary collapse

Instance Method Details

#open(format = nil, flags = 0) ⇒ Object

:nodoc: - This method is documented on subclasses



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/free-image/sources/abstract_source.rb', line 157

def open(format = nil, flags = 0)
  format ||= self.format

  # Do we know the format?
  if format == :unknown
    raise(Error.new(:unknown, "Cannot load :unknown image format"))
  end

  # Can we load the image?
  unless FreeImage.FreeImage_FIFSupportsReading(format)
    raise(Error.new("Cannot load image"))
  end

  ptr = load(format, flags)

  # Make sure we didn't get a null pointer.  This can
  # happen - see test_file for example#test_corrupt_wrong_format
  if ptr.null?
    error = Error.new(:unknown, "Could not load the image")
    raise(error)
  end
  Bitmap.new(ptr, self)
end