示例#1
0
文件: RIFF.cpp 项目: hfiguiere/exempi
// parsing creation
Chunk::Chunk( ContainerChunk* parent_, RIFF_MetaHandler* handler, bool skip, ChunkType c )
{
	chunkType = c; // base class assumption
	this->parent = parent_;
	this->oldSize = 0;
	this->hasChange = false; // [2414649] valid assumption at creation time

	XMP_IO* file = handler->parent->ioRef;

	this->oldPos = file->Offset();
	this->id = XIO::ReadUns32_LE( file );
	this->oldSize = XIO::ReadUns32_LE( file );
	this->oldSize += 8;

	// Make sure the size is within expected bounds.
	XMP_Int64 chunkEnd = this->oldPos + this->oldSize;
	XMP_Int64 chunkLimit = handler->oldFileSize;
	if ( parent_ != 0 ) chunkLimit = parent_->oldPos + parent_->oldSize;
	if ( chunkEnd > chunkLimit ) {
		bool isUpdate = XMP_OptionIsSet ( handler->parent->openFlags, kXMPFiles_OpenForUpdate );
		bool repairFile = XMP_OptionIsSet ( handler->parent->openFlags, kXMPFiles_OpenRepairFile );
		if ( (! isUpdate) || (repairFile && (parent_ == 0)) ) {
			this->oldSize = chunkLimit - this->oldPos;
		} else {
			XMP_Throw ( "Bad RIFF chunk size", kXMPErr_BadFileFormat );
		}
	}

	this->newSize = this->oldSize;
	this->needSizeFix = false;

	if ( skip ) file->Seek ( (this->oldSize - 8), kXMP_SeekFromCurrent );

	// "good parenting", essential for latter destruction.
	if ( this->parent != NULL )
	{
		this->parent->children.push_back( this );
		if( this->chunkType == chunk_VALUE )
			this->parent->childmap.insert( std::make_pair( this->id, (ValueChunk*) this ) );
	}
}
示例#2
0
void ImportJTPtoXMP ( XMP_FileFormat		srcFormat,
					  RecJTP_LegacyPriority lastLegacy,
					  TIFF_Manager *        tiff,	// ! Need for UserComment and RelatedSoundFile hack.
					  const PSIR_Manager &  psir,
					  IPTC_Manager *        iptc,	// ! Need to call UpdateDataSets.
					  SXMPMeta *			xmp,
					  XMP_OptionBits		options /* = 0 */ )
{
	bool haveXMP  = XMP_OptionIsSet ( options, k2XMP_FileHadXMP );
	bool haveIPTC = XMP_OptionIsSet ( options, k2XMP_FileHadIPTC );
	bool haveExif = XMP_OptionIsSet ( options, k2XMP_FileHadExif );
	
	int iptcDigestState = kDigestMatches;	// Default is to do no imports.
	int tiffDigestState = kDigestMatches;
	int exifDigestState = kDigestMatches;

	if ( ! haveXMP ) {
	
		// If there is no XMP then what we have differs.
		if ( haveIPTC) iptcDigestState = kDigestDiffers;
		if ( haveExif ) tiffDigestState = exifDigestState = kDigestDiffers;
	
	} else {

		// If there is XMP then check the digests for what we have. No legacy at all means the XMP
		// is OK, and the CheckXyzDigest routines return true when there is no digest. This matches
		// Photoshop, and avoids importing when an app adds XMP but does not export to the legacy or
		// write a digest.

		if ( haveIPTC ) iptcDigestState = ReconcileUtils::CheckIPTCDigest ( iptc, psir );
		if ( iptcDigestState == kDigestMissing ) {
			// *** Temporary hack to approximate Photoshop's behavior. Need fully documented policies!
			tiffDigestState = exifDigestState = kDigestMissing;
		} else if ( haveExif ) {
			tiffDigestState = ReconcileUtils::CheckTIFFDigest ( *tiff, *xmp );
			exifDigestState = ReconcileUtils::CheckExifDigest ( *tiff, *xmp );	// ! Yes, the Exif is in the TIFF stream.
		}

	}
	
	if ( lastLegacy > kLegacyJTP_TIFF_IPTC ) {
		XMP_Throw ( "Invalid JTP legacy priority", kXMPErr_InternalFailure );
	}

	// A TIFF file with tags 270, 315, or 33432 is currently the only case where the IPTC is less
	// important than the TIFF/Exif. If there is no IPTC or no TIFF/Exif then the order does not
	// matter. The order only affects collisions between those 3 TIFF tags and their IPTC counterparts.
	
	if ( lastLegacy == kLegacyJTP_TIFF_TIFF_Tags ) {

		if ( iptcDigestState != kDigestMatches ) {
			ReconcileUtils::ImportIPTC ( *iptc, xmp, iptcDigestState );
			ReconcileUtils::ImportPSIR ( psir, xmp, iptcDigestState );
		}
		if ( tiffDigestState != kDigestMatches ) ReconcileUtils::ImportTIFF ( *tiff, xmp, tiffDigestState, srcFormat );
		if ( exifDigestState != kDigestMatches ) ReconcileUtils::ImportExif ( *tiff, xmp, exifDigestState );

	} else {

		if ( tiffDigestState != kDigestMatches ) ReconcileUtils::ImportTIFF ( *tiff, xmp, tiffDigestState, srcFormat );
		if ( exifDigestState != kDigestMatches ) ReconcileUtils::ImportExif ( *tiff, xmp, exifDigestState );
		if ( iptcDigestState != kDigestMatches ) {
			ReconcileUtils::ImportIPTC ( *iptc, xmp, iptcDigestState );
			ReconcileUtils::ImportPSIR ( psir, xmp, iptcDigestState );
		}

	}
	
	// ! Older versions of Photoshop did not import the UserComment or RelatedSoundFile tags. Note
	// ! whether the initial XMP has these tags. Don't delete them from the TIFF when saving unless
	// ! they were in the XMP to begin with. Can't do this in ReconcileUtils::ImportExif, that is
	// ! only called when the Exif is newer than the XMP.
	
	tiff->xmpHadUserComment = xmp->DoesPropertyExist ( kXMP_NS_EXIF, "UserComment" );
	tiff->xmpHadRelatedSoundFile = xmp->DoesPropertyExist ( kXMP_NS_EXIF, "RelatedSoundFile" );

}	// ImportJTPtoXMP