本文整理汇总了C++中exiv2::image::AutoPtr::get方法的典型用法代码示例。如果您正苦于以下问题:C++ AutoPtr::get方法的具体用法?C++ AutoPtr::get怎么用?C++ AutoPtr::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类exiv2::image::AutoPtr
的用法示例。
在下文中一共展示了AutoPtr::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
// *****************************************************************************
// Main
int main(int argc, char* const argv[])
{
try {
// Handle command line arguments
Params params;
if (params.getopt(argc, argv)) {
params.usage();
return 1;
}
if (params.help_) {
params.help();
return 2;
}
// Use MemIo to increase test coverage.
Exiv2::BasicIo::AutoPtr fileIo(new Exiv2::FileIo(params.read_));
Exiv2::BasicIo::AutoPtr memIo(new Exiv2::MemIo);
memIo->transfer(*fileIo);
Exiv2::Image::AutoPtr readImg = Exiv2::ImageFactory::open(memIo);
assert(readImg.get() != 0);
readImg->readMetadata();
Exiv2::Image::AutoPtr writeImg = Exiv2::ImageFactory::open(params.write_);
assert(writeImg.get() != 0);
if (params.preserve_) writeImg->readMetadata();
if (params.iptc_) {
writeImg->setIptcData(readImg->iptcData());
}
if (params.exif_) {
writeImg->setExifData(readImg->exifData());
}
if (params.comment_) {
writeImg->setComment(readImg->comment());
}
if (params.xmp_) {
writeImg->setXmpData(readImg->xmpData());
}
try {
writeImg->writeMetadata();
}
catch (const Exiv2::AnyError&) {
std::cerr << params.progname() <<
": Could not write metadata to (" << params.write_ << ")\n";
return 8;
}
return 0;
}
catch (Exiv2::AnyError& e) {
std::cerr << "Caught Exiv2 exception '" << e << "'\n";
return 10;
}
}
示例2: HashExif
bool ExifHasher::HashExif(const std::string& path,
unsigned char* sha1_hash) const {
FD fd;
sys_call_rv(fd, open, path.c_str(), O_RDONLY);
struct stat stat_buf;
sys_call(fstat, fd, &stat_buf);
void* memblock;
sys_call2_rv(NULL, memblock, mmap, NULL, stat_buf.st_size, PROT_READ,
MAP_PRIVATE, fd, 0);
auto bytes = static_cast<const unsigned char*>(memblock);
Exiv2::Image::AutoPtr image;
try {
image = Exiv2::ImageFactory::open(bytes, stat_buf.st_size);
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return false;
}
if (image.get() != 0)
image->readMetadata();
else
std::cerr << "Warning: EXIF not found in: " << path << std::endl;
sys_call(munmap, memblock, stat_buf.st_size);
fd.Close();
if (image.get() == 0)
return false;
const auto& exifData = image->exifData();
if (!exifData.empty()) {
std::ostringstream oss;
auto end = exifData.end();
for (auto i = exifData.begin(); i != end; ++i) {
// std::cerr << i->key() << " (" << i->count() << ")" << ": " <<
// i->value() << std::endl;
oss << i->key() << i->value();
}
const std::string& exif_str = oss.str();
SHA1(reinterpret_cast<const unsigned char*>(exif_str.c_str()),
exif_str.size(), sha1_hash);
return true;
} else {
std::cerr << "Warning: EXIF not found in: " << path << std::endl;
}
return false;
}
示例3: main
int main(int argc, char* const argv[])
try {
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " file\n";
return 1;
}
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(argv[1]);
assert(image.get() != 0);
image->readMetadata();
Exiv2::XmpData xmpData;
Exiv2::copyExifToXmp(image->exifData(), xmpData);
Exiv2::ExifData exifData;
Exiv2::copyXmpToExif(xmpData, exifData);
image->setXmpData(xmpData);
image->setExifData(exifData);
image->writeMetadata();
return 0;
}
catch (Exiv2::AnyError& e) {
std::cout << "Caught Exiv2 exception '" << e << "'\n";
return -1;
}
示例4: write
void write(const std::string& file, Exiv2::ExifData& ed)
{
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file);
assert (image.get() != 0);
image->setExifData(ed);
image->writeMetadata();
}
示例5: getExifFromPath
Exiv2::ExifData getExifFromPath(char* filename) {
qDebug() << "Trying to read EXIF for" << filename;
try {
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(filename);
assert(image.get() != 0);
image->readMetadata();
Exiv2::ExifData &exifData = image->exifData();
if (exifData.empty()) {
std::string error(filename);
error += ": No Exif data found in the file";
//TODO Translate
//throw Exiv2::Error(1, error);
}
return exifData;
} catch (Exiv2::Error& e) {
Exiv2::ExifData exifData;
qCritical() << "Caught Exiv2 exception '" << e.what();
//TODO Translate
return exifData;
}
}
示例6: print
void print(const std::string& file)
{
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file);
assert(image.get() != 0);
image->readMetadata();
Exiv2::ExifData &ed = image->exifData();
Exiv2::ExifData::const_iterator end = ed.end();
for (Exiv2::ExifData::const_iterator i = ed.begin(); i != end; ++i) {
std::cout << std::setw(45) << std::setfill(' ') << std::left
<< i->key() << " "
<< "0x" << std::setw(4) << std::setfill('0') << std::right
<< std::hex << i->tag() << " "
<< std::setw(12) << std::setfill(' ') << std::left
<< i->ifdName() << " "
<< std::setw(9) << std::setfill(' ') << std::left
<< i->typeName() << " "
<< std::dec << std::setw(3)
<< std::setfill(' ') << std::right
<< i->count() << " "
<< std::dec << i->value()
<< "\n";
}
}
示例7: saveExifGps
void ExifReaderWriter::saveExifGps(QString pictureName, double latitude, double longitude, double altitude)
{
qDebug() << "saveExifGps" << pictureName << latitude << longitude << altitude;
Exiv2::Image::AutoPtr image = openExif(pictureName);
if(image.get() == 0)
return;
if(image->exifData().empty())
{
Exiv2::ExifData exifDataTmp;
image->setExifData(exifDataTmp);
}
Exiv2::ExifData &exifData = image->exifData();
writeData(exifData, "Exif.GPSInfo.GPSLatitude", exifLatLonString(latitude));
writeData(exifData, "Exif.GPSInfo.GPSLongitude", exifLatLonString(longitude));
writeData(exifData, "Exif.GPSInfo.GPSLatitudeRef", (latitude<0 ? "S" : "N"));
writeData(exifData, "Exif.GPSInfo.GPSLongitudeRef", (longitude<0 ? "W" : "E"));
if(altitude > -999)
{
writeData(exifData, "Exif.GPSInfo.GPSAltitude", (QString("%1/%2").arg(abs(round(altitude * 1000))).arg(1000)));
writeData(exifData, "Exif.GPSInfo.GPSAltitudeRef", (altitude<0 ? "1" : "0"));
}
image->writeMetadata();
}
示例8: main
int main(int argc, char* const argv[])
try {
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " file\n";
return 1;
}
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(argv[1]);
assert(image.get() != 0);
image->readMetadata();
const std::string& xmpPacket = image->xmpPacket();
if (xmpPacket.empty()) {
std::string error(argv[1]);
error += ": No XMP packet found in the file";
throw Exiv2::Error(1, error);
}
std::cout << xmpPacket << "\n";
return 0;
}
catch (Exiv2::AnyError& e) {
std::cout << "Caught Exiv2 exception '" << e << "'\n";
return -1;
}
示例9: TransferExif
bool ptImageHelper::TransferExif(const QString ASourceFile, const QString ATargetFile)
{
if (ASourceFile == ATargetFile ||
ASourceFile.trimmed().isEmpty() ||
ATargetFile.trimmed().isEmpty())
return false;
try {
if (Exiv2::ImageFactory::getType(ASourceFile.toLocal8Bit().data()) == Exiv2::ImageType::none)
return false;
Exiv2::Image::AutoPtr hSourceImage = Exiv2::ImageFactory::open(ASourceFile.toLocal8Bit().data());
if (!hSourceImage.get()) return false;
hSourceImage->readMetadata();
Exiv2::Image::AutoPtr hTargetImage = Exiv2::ImageFactory::open(ATargetFile.toLocal8Bit().data());
hTargetImage->clearMetadata();
hTargetImage->setMetadata(*hSourceImage);
hTargetImage->writeMetadata();
return true;
} catch (Exiv2::AnyError& Error) {
if (Settings->GetInt("JobMode") == 0) {
ptMessageBox::warning(0 ,"Exiv2 Error","No exif data written!\nCaught Exiv2 exception '" + QString(Error.what()) + "'\n");
} else {
std::cout << "Caught Exiv2 exception '" << Error << "'\n";
}
}
return false;
}
示例10: populateMetaExif
int populateMetaExif(std::string file, std::string plate)
{
try
{
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file);
std::string comment = plate + ' '+ "LOT50"; //Add code to get information about lot
if(!image.get())
{
throw Exiv2::Error(1, "Failed to open image");
}
image->readMetadata();
Exiv2::ExifData &exifData = image->exifData();
exifData["Exif.Photo.UserComment"]= comment;
//std::cout<< "Writing Exiv User Comment "<< exifData["Exif.Image.ImageDescription"] <<"\n";
image->writeMetadata();
} catch (Exiv2::AnyError& e) {
std::cout << "Problem Writing Metadata '" << e << "'\n";
return -1;
}
return 0;
}
示例11: imwrite_tiff
bool imwrite_tiff(matrix<unsigned short> output, string outputfilename,
Exiv2::ExifData exifData)
{
int xsize, ysize;
xsize = output.nc()/3;
ysize = output.nr();
outputfilename = outputfilename + ".tif";
TIFF *out = TIFFOpen(outputfilename.c_str(),"w");
if (!out)
{
cerr << "Can't open file for writing" << endl;
return 1;
}
TIFFSetField(out, TIFFTAG_IMAGEWIDTH, xsize);
TIFFSetField(out, TIFFTAG_IMAGELENGTH, ysize);
TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 3); //RGB
TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 16);
TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); // set the origin of the image.
//Magic below
TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
//End Magic
tsize_t linebytes = 3 * xsize * 2;//Size in bytes of a line
unsigned short *buf = NULL;
buf =(unsigned short *)_TIFFmalloc(linebytes);
for (int j = 0; j < ysize; j++)
{
for(int i = 0; i < xsize; i ++)
{
buf[i*3 ] = output(j,i*3 );
buf[i*3+1] = output(j,i*3+1);
buf[i*3+2] = output(j,i*3+2);
}
if (TIFFWriteScanline(out, buf, j, 0) < 0)
break;
}
(void) TIFFClose(out);
if (buf)
_TIFFfree(buf);
exifData["Exif.Image.Orientation"] = 1;//set all images to unrotated
exifData["Exif.Image.ImageWidth"] = output.nr();
exifData["Exif.Image.ImageLength"] = output.nc()/3;
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(outputfilename.c_str());
assert(image.get() != 0);
image->setExifData(exifData);
//image->writeMetadata();
return 0;
}
示例12: build_dest
// Returns empty string if the destination subdirectory could not be determined
// for the supplied source file.
std::string build_dest(const fs::path &source_file)
{
std::string dest;
Exiv2::Image::AutoPtr image;
try {
image = Exiv2::ImageFactory::open(source_file.string());
image->readMetadata();
}
catch(const Exiv2::AnyError&) {
// No metadata, let things continue to try file info
}
std::vector<PathPart>::iterator iter = g_path_parts.begin();
std::vector<PathPart>::iterator end = g_path_parts.end();
for( ; iter != end; ++iter) {
dest += iter->pre;
std::string result;
const Pattern *pat = iter->pat;
for(unsigned fx = 0; fx < g_run_order.size(); ++fx) {
if(g_run_order[fx] != -1 && pat->funcs[g_run_order[fx]]) {
if(g_run_order[fx] == FILE_SLOT) {
// Always run file operations
result = pat->funcs[g_run_order[fx]](image.get(), source_file);
}
else if(image.get()) {
// No point in running metadata operations without an image
result = pat->funcs[g_run_order[fx]](image.get(), source_file);
}
if(result.length())
break;
}
}
// If we found no data, even for part of pattern, give up and
// return no destination
if(!result.length())
return result;
dest += (result + iter->post);
}
return dest;
}
示例13: RemoveGPSExif
int RemoveGPSExif(const char* File, int NoChangeMtime)
{
struct stat statbuf;
struct stat statbuf2;
struct utimbuf utb;
if (NoChangeMtime)
stat(File, &statbuf);
// Open the file and start reading.
Exiv2::Image::AutoPtr Image;
try {
Image = Exiv2::ImageFactory::open(File);
} catch (Exiv2::Error e) {
DEBUGLOG("Failed to open file %s.\n", File);
return 0;
}
Image->readMetadata();
if (Image.get() == NULL)
{
// It failed if we got here.
DEBUGLOG("Failed to read file %s %s.\n",
File, Exiv2::strError().c_str());
return 0;
}
Exiv2::ExifData &ExifInfo = Image->exifData();
if (ExifInfo.count() == 0)
{
DEBUGLOG("No EXIF tags in file %s.\n", File);
return 0;
}
EraseGpsTags(ExifInfo);
try {
Image->writeMetadata();
} catch (Exiv2::Error e) {
DEBUGLOG("Failed to write to file %s.\n", File);
return 0;
}
if (NoChangeMtime)
{
stat(File, &statbuf2);
utb.actime = statbuf2.st_atime;
utb.modtime = statbuf.st_mtime;
utime(File, &utb);
}
return 1;
}
示例14: loadFromData
bool JpegContent::loadFromData(const QByteArray& data)
{
Exiv2::Image::AutoPtr image;
Exiv2ImageLoader loader;
if (!loader.load(data)) {
qCritical() << "Could not load image with Exiv2, reported error:" << loader.errorMessage();
}
image = loader.popImage();
return loadFromData(data, image.get());
}
示例15: ReadExifDate
char* ReadExifDate(const char* File, int* IncludesGPS)
{
// Open and read the file.
Exiv2::Image::AutoPtr Image;
try {
Image = Exiv2::ImageFactory::open(File);
} catch (Exiv2::Error e) {
DEBUGLOG("Failed to open file %s.\n", File);
return NULL;
}
Image->readMetadata();
if (Image.get() == NULL)
{
DEBUGLOG("Failed to read file %s %s.\n",
File, Exiv2::strError().c_str());
return NULL;
}
Exiv2::ExifData &ExifRead = Image->exifData();
// Read the tag out.
Exiv2::Exifdatum& Tag = ExifRead["Exif.Photo.DateTimeOriginal"];
// Check that the tag is not blank.
std::string Value = Tag.toString();
if (Value.length() == 0)
{
// No date/time stamp.
// Not good.
// Just return - above us will handle it.
return NULL;
}
// Copy the tag and return that.
char* Copy = strdup(Value.c_str());
// Check if we have GPS tags.
Exiv2::Exifdatum& GPSData = ExifRead["Exif.GPSInfo.GPSLatitude"];
if (GPSData.count() < 3)
{
// No valid GPS data.
*IncludesGPS = 0;
} else {
// Seems to include GPS data...
*IncludesGPS = 1;
}
// Now return, passing a pointer to the date string.
return Copy; // It's up to the caller to free this.
}