Esempio n. 1
0
 const double getExiv2ValueDouble(Exiv2::ExifData& exifData, Exiv2::ExifData::const_iterator it)
 {
     if(it!=exifData.end() && it->count())
     {
         return it->toFloat();
     }
     return 0;
 };
Esempio n. 2
0
void ImageResolution::readexiv(char const *fn) {
  Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fn);
  if (!image.get())
    return;

  image->readMetadata();
  Exiv2::ExifData &exifData = image->exifData();
  if (exifData.empty())
    return;

  Exiv2::ExifData::const_iterator end = exifData.end();
  bool havex = false;
  bool havey = false;
  bool haveunit = false;
  int unit;
  for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i) {
    if (ok_)
      break;
    if (i->tag()==0x011a) {
      // X Resolution
      x_ = i->toFloat();
      havex = true;
    } else if (i->tag()==0x011b) {
      // Y Resolution
      y_ = i->toFloat();
      havey = true;
    } else if (i->tag()==0x0128) {
      unit = i->toLong();
    }
    ok_ = havex && havey && haveunit;
  }
  if (haveunit) {
    if (unit==3) {
      x_ *= 2.54;
      y_ *= 2.54;
    }
  }
  ok_ = havex && havey;
}
Esempio n. 3
0
QVariantMap QgsExifTools::readTags( const QString &imagePath )
{
  std::unique_ptr< Exiv2::Image > image( Exiv2::ImageFactory::open( imagePath.toStdString() ) );
  if ( !image )
    return QVariantMap();

  image->readMetadata();
  Exiv2::ExifData &exifData = image->exifData();
  if ( exifData.empty() )
  {
    return QVariantMap();
  }

  QVariantMap res;
  Exiv2::ExifData::const_iterator end = exifData.end();
  for ( Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i )
  {
    const QString key = QString::fromStdString( i->key() );
    QVariant val;
    switch ( i->typeId() )
    {
      case Exiv2::asciiString:
      case Exiv2::string:
      case Exiv2::comment:
      case Exiv2::directory:
      case Exiv2::xmpText:
        val = QString::fromStdString( i->toString() );
        break;

      case Exiv2::unsignedLong:
      case Exiv2::signedLong:
        val = QVariant::fromValue( i->toLong() );
        break;

      case Exiv2::tiffDouble:
      case Exiv2::tiffFloat:
        val = QVariant::fromValue( i->toFloat() );
        break;

      case Exiv2::unsignedShort:
      case Exiv2::signedShort:
        val = QVariant::fromValue( static_cast< int >( i->toLong() ) );
        break;

      case Exiv2::unsignedRational:
      case Exiv2::signedRational:
      case Exiv2::unsignedByte:
      case Exiv2::signedByte:
      case Exiv2::undefined:
      case Exiv2::tiffIfd:
      case Exiv2::date:
      case Exiv2::time:
      case Exiv2::xmpAlt:
      case Exiv2::xmpBag:
      case Exiv2::xmpSeq:
      case Exiv2::langAlt:
      case Exiv2::invalidTypeId:
      case Exiv2::lastTypeId:
        val = QString::fromStdString( i->toString() );
        break;

    }

    res.insert( key, val );
  }
  return res;
}
Esempio n. 4
0
void exif_data::from_file(const std::string& filename)
{
    reset();
    try
    {
        Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(filename);
        image->readMetadata();
        Exiv2::ExifData &exif_data = image->exifData();

        // if data is empty
        if (exif_data.empty()) return;

        // Exiv2 iterator in read-only
        Exiv2::ExifData::const_iterator it = exif_data.end();
        if ((it = exif_data.findKey(Exiv2::ExifKey("Exif.Photo.ExposureTime"))) != exif_data.end())
        {
            exposure_time_ = it->toFloat();
        }
        else if ((it = exif_data.findKey(Exiv2::ExifKey("Exif.Photo.ShutterSpeedValue"))) != exif_data.end())
        {
            long num = 1;
            long div = 1;
            float tmp = std::exp(std::log(2.0f) * it->toFloat());
            if (tmp > 1)
            {
                div = static_cast<long>(tmp + 0.5f);
            }
            else
            {
                num = static_cast<long>(1.0f/tmp + 0.5f);
            }
            exposure_time_ = static_cast<float>(num)/div;
        }


        if ((it = exif_data.findKey(Exiv2::ExifKey("Exif.Photo.FNumber"))) != exif_data.end())
        {
            f_number_ = it->toFloat();
        }
        else if ((it = exif_data.findKey(Exiv2::ExifKey("Exif.Photo.ApertureValue"))) != exif_data.end())
        {
            f_number_ = static_cast<float>(expf(logf(2.0f) * it->toFloat() / 2.f));
        }
        // some cameras/lens DO print the fnum but with value 0, and this is not allowed for ev computation purposes.
        if (f_number_ == 0.0f)
        {
            f_number_ = INVALID_VALUE;
        }

        //if iso is found use that value, otherwise assume a value of iso=100. (again, some cameras do not print iso in exif).
        if ((it = exif_data.findKey(Exiv2::ExifKey("Exif.Photo.ISOSpeedRatings"))) != exif_data.end())
        {
            iso_speed_ = it->toFloat();
        }

        if ((it = exif_data.findKey(Exiv2::ExifKey("Exif.Photo.ExposureBiasValue"))) != exif_data.end())
        {
            ev_compensation_ = it->toFloat();
        }
    }
    catch (Exiv2::AnyError& e)
    {
        return;
    }
}