Class: Exif::Tag::Base

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

Overview

The base class that specifies common operations for tag data. All the tag classes are derived from this, and client code shoude use the public methods as interface.

Direct Known Subclasses

Exif::ApertureValue, Exif::BrightnessValue, Exif::CFAPattern, Exif::ColorSpace, Exif::ComponentsConfiguration, Exif::CompressedBitsPerPixel, Exif::Contrast, Exif::CustomRendered, Exif::DateTimeDigitized, Exif::DateTimeOriginal, Exif::DeviceSettingDescription, Exif::DigitalZoomRatio, Exif::ExifVersion, Exif::ExposureBiasValue, Exif::ExposureIndex, Exif::ExposureMode, Exif::ExposureProgram, Exif::ExposureTime, Exif::FNumber, Exif::FileSource, Exif::Flash, Exif::FlashEnergy, Exif::FlashPixVersion, Exif::FocalLength, Exif::FocalLengthIn35mmFilm, Exif::FocalPlaneResolutionUnit, Exif::FocalPlaneXResolution, Exif::FocalPlaneYResolution, Exif::GainControl, Exif::ISOSpeedRatings, Exif::ImageUniqueID, Exif::LensMake, Exif::LensModel, Exif::LightSource, Exif::MakerNote, Exif::MaxApertureValue, Exif::MeteringMode, Exif::OECF, Exif::PixelXDimension, Exif::PixelYDimension, Exif::RelatedSoundFile, Exif::Saturation, Exif::SceneCaptureType, Exif::SceneType, Exif::SensingMethod, Exif::Sharpness, Exif::ShutterSpeedValue, Exif::SpatialFrequencyResponse, Exif::SpectralSensitivity, Exif::SubjectArea, Exif::SubjectDistance, Exif::SubjectDistanceRange, Exif::SubjectLocation, Exif::SubsecTime, Exif::SubsecTimeDigitized, Exif::SubsecTimeOriginal, Exif::UserComment, Exif::WhiteBalance, ExifIFDPointer, GPS::GPSAltitude, GPS::GPSAltitudeRef, GPS::GPSAreaInformation, GPS::GPSDOP, GPS::GPSDateStamp, GPS::GPSDestBearing, GPS::GPSDestBearingRef, GPS::GPSDestDistance, GPS::GPSDestDistanceRef, GPS::GPSDestLatitude, GPS::GPSDestLatitudeRef, GPS::GPSDestLongitude, GPS::GPSDestLongitudeRef, GPS::GPSDifferential, GPS::GPSImgDirection, GPS::GPSImgDirectionRef, GPS::GPSLatitude, GPS::GPSLatitudeRef, GPS::GPSLongitude, GPS::GPSLongitudeRef, GPS::GPSMapDatum, GPS::GPSMeasureMode, GPS::GPSProcessingMethod, GPS::GPSSatelites, GPS::GPSSpeed, GPS::GPSSpeedRef, GPS::GPSStatus, GPS::GPSTimeStamp, GPS::GPSTrack, GPS::GPSTrackRef, GPS::GPSVersionID, GPSIFDPointer, Interoperability::InteroperabilityIndex, Interoperability::InteroperabilityVersion, Interoperability::RelatedImageLength, Interoperability::RelatedImageWidth, InteroperabilityIFDPointer, MakerNote::AFFocusPosition, MakerNote::AF_Mode, MakerNote::AF_Setting, MakerNote::ActiveD_Lighting, MakerNote::Adapter, MakerNote::AutoBracket, MakerNote::AutoExposureWarning, MakerNote::BlurWarning, MakerNote::CCDSensitivity, MakerNote::CameraColorMode, MakerNote::CameraID, MakerNote::CameraSerialNumber, MakerNote::Color, MakerNote::ColorControl, MakerNote::ColorMode, MakerNote::ColorSpace, MakerNote::Cont_Bracket, MakerNote::Contrast, MakerNote::Converter, MakerNote::CustomFunctions, MakerNote::DataDump, MakerNote::DataVersion, MakerNote::DigiZoom, MakerNote::DigitalZoom, MakerNote::DriveMode, MakerNote::ExposureBias, MakerNote::ExposureDifference, MakerNote::ExposureMode, MakerNote::Firmware, MakerNote::FirmwareVersion, MakerNote::FlashMode, MakerNote::FlashSetting, MakerNote::FlashStrength, MakerNote::FocalLength, MakerNote::Focus, MakerNote::FocusMode, MakerNote::FocusWarning, MakerNote::FocusingMode, MakerNote::HighLight, MakerNote::ISOSelection, MakerNote::ImageAdjustment, MakerNote::ImageNumber, MakerNote::ImageOptimization, MakerNote::ImageQuality, MakerNote::ImageSharpening, MakerNote::ImageSize, MakerNote::ImageType, MakerNote::JpegQual, MakerNote::LensSpecification, MakerNote::LensType, MakerNote::LightSource, MakerNote::LongtimeExposureNR, MakerNote::Macro, MakerNote::ManualForcusDistance, MakerNote::MeteringMode, MakerNote::NikonBase, MakerNote::OwnerName, MakerNote::PictInfo, MakerNote::PictureControl, MakerNote::PictureMode, MakerNote::ProgramShift, MakerNote::Quality, MakerNote::Saturation, MakerNote::SceneMode, MakerNote::SettingMode, MakerNote::Shadow, MakerNote::Sharpness, MakerNote::SharpnessBias, MakerNote::SigmaSoftware, MakerNote::SlowSync, MakerNote::SoftwareRelease, MakerNote::SonyAFIlluminator, MakerNote::SonyAFMode, MakerNote::SonyAntiBlur, MakerNote::SonyAutoHDR, MakerNote::SonyCameraSettings, MakerNote::SonyColorCompensationFilter, MakerNote::SonyColorMode, MakerNote::SonyColorTemperature, MakerNote::SonyContrast, MakerNote::SonyDynamicRangeOptimizer, MakerNote::SonyDynamicRangeOptimizer2, MakerNote::SonyExposureMode, MakerNote::SonyFileFormat, MakerNote::SonyFlashExposureComp, MakerNote::SonyFlashLevel, MakerNote::SonyFocusMode, MakerNote::SonyFullImageSize, MakerNote::SonyImageStabilization, MakerNote::SonyIntelligentAuto, MakerNote::SonyJPEGQuality, MakerNote::SonyLensID, MakerNote::SonyLongExposureNoiseReduction, MakerNote::SonyMacro, MakerNote::SonyModelID, MakerNote::SonyMultiBurstImageHeight, MakerNote::SonyMultiBurstImageWidth, MakerNote::SonyMultiBurstMode, MakerNote::SonyPanorama, MakerNote::SonyPreviewImage, MakerNote::SonyPreviewImageSize, MakerNote::SonyPrintIM, MakerNote::SonyQuality, MakerNote::SonyReleaseMode, MakerNote::SonySaturation, MakerNote::SonySceneMode, MakerNote::SonySequenceNumber, MakerNote::SonyShotInfo, MakerNote::SonyTeleconverter, MakerNote::SonyWhiteBalance, MakerNote::SonyWhiteBalance2, MakerNote::SonyWhiteBalanceFineTune, MakerNote::SonyZoneMatching, MakerNote::SpecialMode, MakerNote::SpeedlightBias, MakerNote::SpeedlightMode, MakerNote::Tag0x0001, MakerNote::Tag0x0003, MakerNote::Tag0x0004, MakerNote::Tone, MakerNote::ToneCompensation, MakerNote::Version, MakerNote::White, MakerNote::WhiteBalance, MakerNote::White_Balance, MakerNote::Whitebalance, MakerNote::X3FillLight, TIFF::Artist, TIFF::BitsPerSample, TIFF::Compression, TIFF::Copyright, TIFF::DateTime, TIFF::ImageDescription, TIFF::ImageLength, TIFF::ImageWidth, TIFF::JpegInterchangeFormat, TIFF::JpegInterchangeFormatLength, TIFF::Make, TIFF::Model, TIFF::Orientation, TIFF::PhotometricInterpretation, TIFF::PlanarConfiguration, TIFF::PrimaryChromaticities, TIFF::ReferenceBlackWhite, TIFF::ResolutionUnit, TIFF::RowsPerStrip, TIFF::SamplesPerPixel, TIFF::Software, TIFF::StripByteCounts, TIFF::StripOffsets, TIFF::TransferFunction, TIFF::WhitePoint, TIFF::XResolution, TIFF::YCbCrCoefficients, TIFF::YCbCrPositioning, TIFF::YCbCrSubSampling, TIFF::YResolution, Unknown

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tagID, ifdname, count) ⇒ Base

the argument ‘byteorder’ is either :intel or :motorola. this is used when packing @data given after initialized.



208
209
210
211
212
213
214
215
216
# File 'lib/exifparser/tag.rb', line 208

def initialize(tagID, ifdname, count)
  @tagID = tagID
  @IFD = ifdname
  @count = count
  @data = nil
  @formatted = nil
  @pos = nil
  @dataPos = nil
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



219
220
221
# File 'lib/exifparser/tag.rb', line 219

def count
  @count
end

#data=(value) ⇒ Object (writeonly)

Sets the attribute data

Parameters:

  • value

    the value to set the attribute data to.



217
218
219
# File 'lib/exifparser/tag.rb', line 217

def data=(value)
  @data = value
end

#dataPosObject

Returns the value of attribute dataPos.



218
219
220
# File 'lib/exifparser/tag.rb', line 218

def dataPos
  @dataPos
end

#IFDObject (readonly)

Returns the value of attribute IFD.



219
220
221
# File 'lib/exifparser/tag.rb', line 219

def IFD
  @IFD
end

#posObject

Returns the value of attribute pos.



218
219
220
# File 'lib/exifparser/tag.rb', line 218

def pos
  @pos
end

#tagIDObject (readonly)

Returns the value of attribute tagID.



219
220
221
# File 'lib/exifparser/tag.rb', line 219

def tagID
  @tagID
end

Instance Method Details

#formatExposureTime(ss) ⇒ Object

format exposure time



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/exifparser/tag.rb', line 276

def formatExposureTime(ss)
  rss = 1.0/ss
  if (rss >= 3.0)
    str = "1/%.0f"%[rss]
  elsif (3.0 > rss && rss > 1.0)
    str = "1/%.1f"%[rss]
  elsif (ss == 1.0)
    str = "1.0"
  elsif (3.0 > ss && ss > 1.0)
    str = "%.1f"%[ss]
  else
    str = "%.0f"%[ss]
  end
  "#{str}sec."
end

#formatFNumber(f) ⇒ Object

format f number



295
296
297
298
299
300
301
302
# File 'lib/exifparser/tag.rb', line 295

def formatFNumber(f)
  if (f.abs < 10.0)
    str = "%.1f"%[f]
  else
    str = "%.0f"%[f]
  end
  "F#{str}"
end

#formatFocalLength(f) ⇒ Object

format focal length



264
265
266
267
268
269
270
271
# File 'lib/exifparser/tag.rb', line 264

def formatFocalLength(f)
  if (f.abs < 10.0)
    str = "%.1f"%[f]
  else
    str = "%.0f"%[f]
  end
  "#{str}mm"
end

#formatLatLon(f) ⇒ Object

format Latitude and Longitude



307
308
309
310
311
312
313
# File 'lib/exifparser/tag.rb', line 307

def formatLatLon(f)
  if f[2].to_f == 0.0
    sprintf("%d deg %.2f'",f[0],f[1])
  else
    sprintf("%d deg %d' %.2f\"",f[0],f[1],f[2])
  end
end

#inspectObject



317
318
319
# File 'lib/exifparser/tag.rb', line 317

def inspect
  sprintf("#<%s ID=0x%04x, IFD=\"%s\" Name=\"%s\", Format=\"%s\", Count=\"%d\", Value=\"%s\">", self.class, @tagID, @IFD, self.name, self.format, self.count, self.value)
end

#nameObject

return tag’s name



257
258
259
# File 'lib/exifparser/tag.rb', line 257

def name
  self.class.to_s.split("::")[-1]
end

#processDataObject



221
222
223
# File 'lib/exifparser/tag.rb', line 221

def processData
  @formatted = _formatData(@data)
end

#to_sObject

String representation of tag’s value this is the default method that simply sends Object#to_s to @formatted. Subclasses may override this so that it returns more human-readable form.



239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/exifparser/tag.rb', line 239

def to_s
  if self.is_a? Formatter::Undefined
    length = @formatted.length
    data = length > 8 ? @formatted[0, 8] : @formatted
    ret = ""
    data.each do |dat|
      ret += sprintf("%02X ", dat)
    end
    ret += %Q[...(#{length} bytes)] if length > data.length
    return ret
  else
    @formatted.to_s
  end
end

#valueObject

return tag’s value: simply returns @formatted as it is.



228
229
230
# File 'lib/exifparser/tag.rb', line 228

def value
  @formatted
end