Class: EXIFR::TIFF::Field
- Inherits:
-
Object
- Object
- EXIFR::TIFF::Field
- Defined in:
- lib/exifr/tiff.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(data, pos) ⇒ Field
constructor
A new instance of Field.
Constructor Details
#initialize(data, pos) ⇒ Field
Returns a new instance of Field.
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 |
# File 'lib/exifr/tiff.rb', line 565 def initialize(data, pos) @tag, count, @offset = data.readshort(pos), data.readlong(pos + 4), data.readlong(pos + 8) @type = data.readshort(pos + 2) case @type when 1 # byte len, pack = count, proc { |d| d } when 6 # signed byte len, pack = count, proc { |d| sign_byte(d) } when 2 # ascii len, pack = count, proc { |d| d.unpack('Z*') } when 3 # short len, pack = count * 2, proc { |d| d.unpack(data.short + '*') } when 8 # signed short len, pack = count * 2, proc { |d| d.unpack(data.short + '*').map{|n| sign_short(n)} } when 4 # long len, pack = count * 4, proc { |d| d.unpack(data.long + '*') } when 9 # signed long len, pack = count * 4, proc { |d| d.unpack(data.long + '*').map{|n| sign_long(n)} } when 7 # undefined # UserComment if @tag == 0x9286 len, pack = count, proc { |d| d.strip } len -= 8 # reduce to account for first 8 bytes start = len > 4 ? @offset + 8 : (pos + 8) # UserComment first 8-bytes is char code @value = [pack[data[start..(start + len - 1)]]].flatten end when 5 # unsigned rational len, pack = count * 8, proc do |d| rationals = [] d.unpack(data.long + '*').each_slice(2) do |f| rationals << rational(*f) end rationals end when 10 # signed rational len, pack = count * 8, proc do |d| rationals = [] d.unpack(data.long + '*').map{|n| sign_long(n)}.each_slice(2) do |f| rationals << rational(*f) end rationals end when 11 # float len, pack = count * 4, proc { |d| d.unpack(data.float + '*') } when 12 # double len, pack = count * 8, proc { |d| d.unpack(data.double + '*') } else return end if len && pack && @type != 7 start = len > 4 ? @offset : (pos + 8) d = data[start..(start + len - 1)] @value = d && [pack[d]].flatten end end |
Instance Attribute Details
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
563 564 565 |
# File 'lib/exifr/tiff.rb', line 563 def offset @offset end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
563 564 565 |
# File 'lib/exifr/tiff.rb', line 563 def tag @tag end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
563 564 565 |
# File 'lib/exifr/tiff.rb', line 563 def value @value end |