require 'tifffile/version' require "tifffile/tifffile" require "tags" class TiffFile include TiffFileVersion include TiffFileTags alias :valid? :is_valid? alias :is_big_endian? :big_endian? alias :sample_format :sample_format? alias :unset_field :remove_field alias :set :write_matrix alias :get :read_matrix alias :flush! :save alias :save! :save # Get field value def get_field(fname) field = tag fname return nil if field.nil? value = case field.type when :string get_string_field field.id when :ushort get_int_field field.id, 2 when :uint get_int_field field.id, 4 when :double get_float_field field.id, true when :float get_float_field field.id, true else nil end return value if field.map.nil? field.map.has_value?(value) ? field.map.key(value).to_sym : nil end # Set field value def set_field(fname, fvalue) field = tag fname return nil if field.nil? symkey = fname.to_s.to_sym value = (field.map.nil? or not field.map.has_key?(symkey)) ? fvalue : field.map[symkey] case field.type when :string set_string_field field.id, value.to_s when :ushort set_int_field field.id, value.to_i, 2 when :uint set_int_field field.id, value.to_i, 4 when :double set_float_field field.id, value.to_i, true when :float set_float_field field.id, value.to_i, true else nil end end end