Class: Tiff::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/tiff/image.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, mode) ⇒ Image

Returns a new instance of Image.



10
11
12
13
14
15
# File 'lib/tiff/image.rb', line 10

def initialize(path, mode)
  @path = path
  @mode = mode

  @fd = Bindings::open path, mode
end

Instance Attribute Details

#fdObject (readonly)

The file descriptor. This is an FFI::Pointer to the opened TIFF file.



8
9
10
# File 'lib/tiff/image.rb', line 8

def fd
  @fd
end

#modeObject (readonly)

Returns the value of attribute mode.



5
6
7
# File 'lib/tiff/image.rb', line 5

def mode
  @mode
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/tiff/image.rb', line 5

def path
  @path
end

Class Method Details

.open(path, mode) ⇒ Object

Initializes a new image. If a block is provided, the image is yielded and automatically closed.



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/tiff/image.rb', line 75

def open(path, mode)
  new(path, mode).tap do |image|
    if block_given?
      begin
        yield image
      ensure
        image.close
      end
    end
  end
end

Instance Method Details

#bits_per_sample=(bits_per_sample) ⇒ Object

Sets the image’s bits_per_sample



57
58
59
# File 'lib/tiff/image.rb', line 57

def bits_per_sample=(bits_per_sample)
  set_field :bits_per_sample, bits_per_sample
end

#closeObject



17
18
19
# File 'lib/tiff/image.rb', line 17

def close
  Bindings::close fd
end

#compression=(compresion) ⇒ Object

Sets the image’s compression



62
63
64
# File 'lib/tiff/image.rb', line 62

def compression=(compresion)
  set_field :compression, compresion
end

#data=(data) ⇒ Object

Writes raw data to the image.



22
23
24
# File 'lib/tiff/image.rb', line 22

def data=(data)
  Bindings::write_raw_strip fd, 0, data, data.length
end

#get_field(name) ⇒ Object

Gets a field from the image, using the list of tags in # ‘Tiff::Bindings.tags`



35
36
37
38
39
40
41
42
43
44
# File 'lib/tiff/image.rb', line 35

def get_field(name)
  tag = Bindings::tags[name]
  pointer = FFI::MemoryPointer.new tag.type
  result = Bindings::get_field fd, tag.id, :pointer, pointer
  if result == 1
    tag.deserialize pointer
  else
    nil
  end
end

#height=(height) ⇒ Object

Sets the image’s height



52
53
54
# File 'lib/tiff/image.rb', line 52

def height=(height)
  set_field :height, height
end

#photometric=(compresion) ⇒ Object

Sets the image’s photometric



67
68
69
# File 'lib/tiff/image.rb', line 67

def photometric=(compresion)
  set_field :photometric, compresion
end

#set_field(name, value) ⇒ Object

Sets a field on the image, using the list of tags in ‘Tiff::Bindings.tags`



28
29
30
31
# File 'lib/tiff/image.rb', line 28

def set_field(name, value)
  tag = Bindings::tags[name]
  Bindings::set_field fd, tag.id, tag.type, tag.serialize(value)
end

#width=(width) ⇒ Object

Sets the image’s width



47
48
49
# File 'lib/tiff/image.rb', line 47

def width=(width)
  set_field :width, width
end