示例#1
0
Image::AutoPtr ImageFactory::open(const std::string& path)
{
    BasicIo::AutoPtr io(new FileIo(path));
    Image::AutoPtr image = open(io); // may throw
    if (image.get() == 0) throw Error(11, path);
    return image;
}
示例#2
0
time_t readImageTime(std::string path,std::string* pS=NULL)
{
    using namespace Exiv2;

    time_t       result       = 0 ;
	static std::map<std::string,time_t> cache;
	if ( cache.count(path) == 1 ) return cache[path];

    const char* dateStrings[] =
    { "Exif.Photo.DateTimeOriginal"
    , "Exif.Photo.DateTimeDigitized"
    , "Exif.Image.DateTime"
    , NULL
    };
    const char* ds            = dateStrings[0] ;

    while ( !result && ds++  ) {
        try {
            Image::AutoPtr image = ImageFactory::open(path);
            if ( image.get() ) {
                image->readMetadata();
                ExifData &exifData = image->exifData();
            //  printf("%s => %s\n",(ds-1), exifData[ds-1].toString().c_str());
                result = parseTime(exifData[ds-1].toString().c_str(),true);
                if ( result && pS ) *pS = exifData[ds-1].toString();
            }
        } catch ( ... ) {};
    }
	if ( result ) cache[path] = result;
    return result ;
}
示例#3
0
Image::AutoPtr ImageFactory::create(int type)
{
    BasicIo::AutoPtr io(new MemIo);
    Image::AutoPtr image = create(type, io);
    if (image.get() == 0) throw Error(13, type);
    return image;
}
示例#4
0
Image::AutoPtr ImageFactory::open(const byte* data, long size)
{
    BasicIo::AutoPtr io(new MemIo(data, size));
    Image::AutoPtr image = open(io); // may throw
    if (image.get() == 0) throw Error(12);
    return image;
}
示例#5
0
// *****************************************************************************
// Main
int main(int argc, char* const argv[])
{
    try {

        if (argc != 2) {
            std::cout << "Usage: " << argv[0] << " image\n";
            std::cout << "Commands read from stdin.\n";
            return 1;
        }

        Image::AutoPtr image = ImageFactory::open(argv[1]);
        assert (image.get() != 0);
        image->readMetadata();

        // Process commands
        std::string line;
        int num = 0;
        std::getline(std::cin, line);
        while (line.length() && processLine(line, ++num, image->iptcData())) {
            std::getline(std::cin, line);
        }

        // Save any changes
        image->writeMetadata();

        return 0;
    }
    catch (AnyError& e) {
        std::cout << "Caught Exiv2 exception '" << e << "'\n";
        return -1;
    }
}
示例#6
0
Image::AutoPtr ImageFactory::create(int type,
                                    const std::string& path)
{
    std::auto_ptr<FileIo> fileIo(new FileIo(path));
    // Create or overwrite the file, then close it
    if (fileIo->open("w+b") != 0) {
        throw Error(10, path, "w+b", strError());
    }
    fileIo->close();
    BasicIo::AutoPtr io(fileIo);
    Image::AutoPtr image = create(type, io);
    if (image.get() == 0) throw Error(13, type);
    return image;
}
示例#7
0
文件: iptc.cpp 项目: obklar/exiv2
    int IptcData::erase(const std::string& path) const
    {
        if (!fileExists(path, true)) return -1;
        Image::AutoPtr image = ImageFactory::instance().open(path);
        if (image.get() == 0) return -2;

        // Read all metadata then erase only Iptc data
        int rc = image->readMetadata();
        if (rc == 0) {
            image->clearIptcData();
            rc = image->writeMetadata();
        }
        return rc;
    } // IptcData::erase
示例#8
0
bool readImage(const char* path,Options& /* options */)
{
    using namespace Exiv2;
    bool bResult = false ;

    try {
        Image::AutoPtr image = ImageFactory::open(path);
        if ( image.get() ) {
            image->readMetadata();
            ExifData &exifData = image->exifData();
            bResult = !exifData.empty();
        }
    } catch ( ... ) {};
    return bResult ;
}
示例#9
0
文件: iptc.cpp 项目: obklar/exiv2
    int IptcData::write(const std::string& path) 
    {
        // Remove the Iptc section from the file if there is no metadata 
        if (count() == 0) return erase(path);

        if (!fileExists(path, true)) return -1;
        Image::AutoPtr image = ImageFactory::instance().open(path);
        if (image.get() == 0) return -2;

        DataBuf buf(copy());

        // Read all metadata to preserve non-Iptc data
        int rc = image->readMetadata();
        if (rc == 0) {
            image->setIptcData(buf.pData_, buf.size_);
            rc = image->writeMetadata();
        }
        return rc;
    } // IptcData::write
示例#10
0
文件: iptc.cpp 项目: obklar/exiv2
 int IptcData::read(const std::string& path)
 {
     if (!fileExists(path, true)) return -1;
     Image::AutoPtr image = ImageFactory::instance().open(path);
     if (image.get() == 0) {
         // We don't know this type of file
         return -2;
     }
     
     int rc = image->readMetadata();
     if (rc == 0) {
         if (image->sizeIptcData() > 0) {
             rc = read(image->iptcData(), image->sizeIptcData());
         }
         else {
             rc = 3;
         }
     }
     return rc;
 }
示例#11
0
    void Rw2Image::readMetadata()
    {
#ifdef DEBUG
        std::cerr << "Reading RW2 file " << io_->path() << "\n";
#endif
        if (io_->open() != 0) {
            throw Error(9, io_->path(), strError());
        }
        IoCloser closer(*io_);
        // Ensure that this is the correct image type
        if (!isRw2Type(*io_, false)) {
            if (io_->error() || io_->eof()) throw Error(14);
            throw Error(3, "RW2");
        }
        clearMetadata();
        std::ofstream devnull;
        printStructure(devnull, kpsRecursive, 0);
        ByteOrder bo = Rw2Parser::decode(exifData_,
                                         iptcData_,
                                         xmpData_,
                                         io_->mmap(),
                                         io_->size());
        setByteOrder(bo);

        // A lot more metadata is hidden in the embedded preview image
        // Todo: This should go into the Rw2Parser, but for that it needs the Image
        PreviewManager loader(*this);
        PreviewPropertiesList list = loader.getPreviewProperties();
        // Todo: What if there are more preview images?
        if (list.size() > 1) {
#ifndef SUPPRESS_WARNINGS
            EXV_WARNING << "RW2 image contains more than one preview. None used.\n";
#endif
        }
        if (list.size() != 1) return;
        ExifData exifData;
        PreviewImage preview = loader.getPreviewImage(*list.begin());
        Image::AutoPtr image = ImageFactory::open(preview.pData(), preview.size());
        if (image.get() == 0) {
#ifndef SUPPRESS_WARNINGS
            EXV_WARNING << "Failed to open RW2 preview image.\n";
#endif
            return;
        }
        image->readMetadata();
        ExifData& prevData = image->exifData();
        if (!prevData.empty()) {
            // Filter duplicate tags
            for (ExifData::const_iterator pos = exifData_.begin(); pos != exifData_.end(); ++pos) {
                if (pos->ifdId() == panaRawId) continue;
                ExifData::iterator dup = prevData.findKey(ExifKey(pos->key()));
                if (dup != prevData.end()) {
#ifdef DEBUG
                    std::cerr << "Filtering duplicate tag " << pos->key()
                              << " (values '" << pos->value()
                              << "' and '" << dup->value() << "')\n";
#endif
                    prevData.erase(dup);
                }
            }
        }
        // Remove tags not applicable for raw images
        static const char* filteredTags[] = {
            "Exif.Photo.ComponentsConfiguration",
            "Exif.Photo.CompressedBitsPerPixel",
            "Exif.Panasonic.ColorEffect",
            "Exif.Panasonic.Contrast",
            "Exif.Panasonic.NoiseReduction",
            "Exif.Panasonic.ColorMode",
            "Exif.Panasonic.OpticalZoomMode",
            "Exif.Panasonic.Contrast",
            "Exif.Panasonic.Saturation",
            "Exif.Panasonic.Sharpness",
            "Exif.Panasonic.FilmMode",
            "Exif.Panasonic.SceneMode",
            "Exif.Panasonic.WBRedLevel",
            "Exif.Panasonic.WBGreenLevel",
            "Exif.Panasonic.WBBlueLevel",
            "Exif.Photo.ColorSpace",
            "Exif.Photo.PixelXDimension",
            "Exif.Photo.PixelYDimension",
            "Exif.Photo.SceneType",
            "Exif.Photo.CustomRendered",
            "Exif.Photo.DigitalZoomRatio",
            "Exif.Photo.SceneCaptureType",
            "Exif.Photo.GainControl",
            "Exif.Photo.Contrast",
            "Exif.Photo.Saturation",
            "Exif.Photo.Sharpness",
            "Exif.Image.PrintImageMatching",
            "Exif.Image.YCbCrPositioning"
        };
        for (unsigned int i = 0; i < EXV_COUNTOF(filteredTags); ++i) {
            ExifData::iterator pos = prevData.findKey(ExifKey(filteredTags[i]));
            if (pos != prevData.end()) {
#ifdef DEBUG
                std::cerr << "Exif tag " << pos->key() << " removed\n";
#endif
                prevData.erase(pos);
            }
        }

        // Add the remaining tags
        for (ExifData::const_iterator pos = prevData.begin(); pos != prevData.end(); ++pos) {
            exifData_.add(*pos);
        }

    } // Rw2Image::readMetadata