1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
// =================================================================================================
// Copyright Adobe
// Copyright 2010 Adobe
// All Rights Reserved
//
// NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms
// of the Adobe license agreement accompanying it.
// =================================================================================================
#include <string.h>
#include "public/include/XMP_Environment.h" // ! XMP_Environment.h must be the first included header.
#include "public/include/XMP_Const.h"
#include "XMPFiles/source/FormatSupport/WAVE/DISPMetadata.h"
#include "source/Endian.h"
using namespace IFF_RIFF;
//-----------------------------------------------------------------------------
//
// DISPMetadata::isValidDISP(...)
//
// Purpose: [static] Check if the passed data is a valid DISP chunk. Valid in
// of is it a DISP chunk that XMP should process.
//
//-----------------------------------------------------------------------------
bool DISPMetadata::isValidDISP( const XMP_Uns8* chunkData, XMP_Uns64 size )
{
return ( ( size >= 4 ) && ( LittleEndian::getInstance().getUns32( chunkData ) == 0x0001 ) );
}
//-----------------------------------------------------------------------------
//
// DISPMetadata::DISPMetadata(...)
//
// Purpose: ctor/dtor
//
//-----------------------------------------------------------------------------
DISPMetadata::DISPMetadata()
{
}
DISPMetadata::~DISPMetadata()
{
}
//-----------------------------------------------------------------------------
//
// DISPMetadata::parse(...)
//
// Purpose: Parses the given memory block and creates a data model representation
// The implementation expects that the memory block is the data area of
// the DISP chunk.
// Throws exceptions if parsing is not possible
//
//-----------------------------------------------------------------------------
void DISPMetadata::parse( const XMP_Uns8* chunkData, XMP_Uns64 size )
{
if( DISPMetadata::isValidDISP( chunkData, size ) )
{
this->setValue<std::string>( kTitle, std::string( (char*)&chunkData[4], static_cast<std::string::size_type>(size-4) ) );
this->resetChanges();
}
else
{
XMP_Throw ( "Not a valid DISP chunk", kXMPErr_BadFileFormat );
}
}
//-----------------------------------------------------------------------------
//
// DISPMetadata::serialize(...)
//
// Purpose: Serializes the data model to a memory block.
// The memory block will be the data area of a DISP chunk.
// Throws exceptions if serializing is not possible
//
//-----------------------------------------------------------------------------
XMP_Uns64 DISPMetadata::serialize( XMP_Uns8** outBuffer )
{
XMP_Uns64 size = 0;
if( outBuffer != NULL && this->valueExists( kTitle ) )
{
std::string title = this->getValue<std::string>( kTitle );
size = 4 + title.length(); // at least 4bytes for the type value of the DISP chunk
// [2500563] DISP chunk must be of even length for WAVE,
// as pad byte is not interpreted correctly by third-party tools
if ( size % 2 != 0 )
{
size++;
}
XMP_Uns8* buffer = new XMP_Uns8[static_cast<size_t>(size)];
memset( buffer, 0, static_cast<size_t>(size) );
//
// DISP type
//
buffer[0] = 1;
//
// copy string into buffer
//
memcpy( &buffer[4], title.c_str(), title.length() );
*outBuffer = buffer;
}
else
{
XMP_Throw ( "Invalid buffer", kXMPErr_InternalFailure );
}
return size;
}
//-----------------------------------------------------------------------------
//
// DISPMetadata::isEmptyValue(...)
//
// Purpose: Is the value of the passed ValueObject and its id "empty"?
//
//-----------------------------------------------------------------------------
bool DISPMetadata::isEmptyValue( XMP_Uns32 /*id*/, ValueObject& valueObj )
{
TValueObject<std::string>* strObj = dynamic_cast<TValueObject<std::string>*>(&valueObj);
return ( strObj == NULL || ( strObj != NULL && strObj->getValue().empty() ) );
}
|