Class: Exif::Nikon2

Inherits:
Object
  • Object
show all
Defined in:
lib/exifparser/makernote/nikon2.rb

Instance Method Summary collapse

Constructor Details

#initialize(fin, tiff_origin, dataPos, byteOrder_module) ⇒ Nikon2

Returns a new instance of Nikon2.



504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
# File 'lib/exifparser/makernote/nikon2.rb', line 504

def initialize(fin, tiff_origin, dataPos, byteOrder_module)
  @fin = fin
  @tiffHeader0 = tiff_origin
  @dataPos = dataPos
  @nikonOffset = 0

  @fin.pos = dataPos
  magic = fin_read_n(6)

  if magic == "Nikon\000"
    @nikonOffset = 18   # D100, E5700, etc..
    fin_read_n(4)
    @tiffHeader0 = @fin.pos
    bo = @fin.read(2)
    case bo
    when "MM"
      byteOrder_module = Utils::Decode::Motorola
    when "II"
      byteOrder_module = Utils::Decode::Intel
    else
      raise RuntimeError, "Unknown byte order"
    end
  end
  @byteOrder_module = byteOrder_module
  self.extend @byteOrder_module
end

Instance Method Details

#scan_IFDObject



531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
# File 'lib/exifparser/makernote/nikon2.rb', line 531

def scan_IFD
  #
  # Nikon D1 series MakerNote starts from 0 byte from the origin.
  #
  @fin.pos = @dataPos + @nikonOffset

  #
  # get the number of tags
  #
  num_dirs = decode_ushort(fin_read_n(2))
  
  #
  # now scan them
  #
  1.upto(num_dirs) {
    curpos_tag = @fin.pos
    tag = parseTagID(fin_read_n(2))
    tagclass = Tag.find(tag.hex, Tag::Nikon2IFDTable)
    unit, formatter = Tag::Format::Unit[decode_ushort(fin_read_n(2))]
    count = decode_ulong(fin_read_n(4))
    tagdata = fin_read_n(4)
    obj = tagclass.new(tag, "MakerNote", count)
    obj.extend formatter, @byteOrder_module
    obj.pos = curpos_tag
    if unit * count > 4
      curpos = @fin.pos
      begin 
        @fin.pos = @tiffHeader0 + decode_ulong(tagdata)
        obj.dataPos = @fin.pos
        obj.data = fin_read_n(unit*count)
      ensure
        @fin.pos = curpos
      end
    else
      obj.dataPos = @fin.pos - 4
      obj.data = tagdata
    end
    obj.processData
    yield obj
  }
end