Skip to content

Commit

Permalink
Make unknown IFD fields accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
remvee committed Jun 23, 2022
1 parent eb8b8ab commit cdf2543
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
21 changes: 11 additions & 10 deletions lib/exifr/tiff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,10 @@ def inspect # :nodoc:
end

class IFD # :nodoc:
attr_reader :type, :fields, :offset
attr_reader :type, :raw_fields, :fields, :offset

def initialize(data, offset = nil, type = :image)
@data, @offset, @type, @fields = data, offset, type, {}
@data, @offset, @type, @raw_fields, @fields = data, offset, type, {}, {}

pos = offset || @data.readlong(4)
num = @data.readshort(pos)
Expand Down Expand Up @@ -546,15 +546,16 @@ def to_yaml_properties

private
def add_field(field)
return unless tag = TAG_MAPPING[@type][field.tag]
return if @fields[tag]
return if @raw_fields.include?(field.tag) # first encountered value wins
@raw_fields[field.tag] = field.value

if IFD_TAGS.include? tag
@fields[tag] = IFD.new(@data, field.offset, tag)
else
value = ADAPTERS[tag][field.value]
@fields[tag] = value.kind_of?(Array) && value.size == 1 ? value.first : value
end
return unless tag = TAG_MAPPING[@type][field.tag]
@fields[tag] = if IFD_TAGS.include?(tag)
IFD.new(@data, field.offset, tag)
else
value = ADAPTERS[tag][field.value]
value.kind_of?(Array) && value.size == 1 ? value.first : value
end
end
end

Expand Down
4 changes: 4 additions & 0 deletions tests/tiff_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,8 @@ def test_methods_method
assert t.methods(true).include?(:make)
assert ! t.methods(false).include?(:make)
end

def test_unknow_field
assert_equal [1, 1, 1, 1], TIFF.new(f('plain.tif')).first.raw_fields[0x0153] # TIFF Tag SampleFormat
end
end

0 comments on commit cdf2543

Please sign in to comment.