本文整理汇总了C++中DataTargetRef类的典型用法代码示例。如果您正苦于以下问题:C++ DataTargetRef类的具体用法?C++ DataTargetRef怎么用?C++ DataTargetRef使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataTargetRef类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
ImageTargetFileQuartz::ImageTargetFileQuartz( DataTargetRef dataTarget, ImageSourceRef imageSource, ImageTarget::Options options, const std::string &extensionData )
: cocoa::ImageTargetCgImage( imageSource, options )
{
cocoa::SafeCfString uti = cocoa::createSafeCfString( extensionData );
mImageDest = NULL;
if( dataTarget->providesFilePath() ) {
cocoa::SafeCfString pathString = cocoa::createSafeCfString( dataTarget->getFilePath().string() );
const std::shared_ptr<__CFURL> urlRef( (__CFURL*)::CFURLCreateWithFileSystemPath( kCFAllocatorDefault, pathString.get(), kCFURLPOSIXPathStyle, false ), cocoa::safeCfRelease );
mImageDest = ::CGImageDestinationCreateWithURL( urlRef.get(), uti.get(), 1, NULL );
}
else if( dataTarget->providesUrl() ) {
std::shared_ptr<__CFURL> urlRef( (__CFURL*)cocoa::createCfUrl( dataTarget->getUrl() ), cocoa::safeCfRelease );
mImageDest = ::CGImageDestinationCreateWithURL( urlRef.get(), uti.get(), 1, NULL );
}
else { // we'll wrap a cinder::OStream in a CGDataConsumer for output
OStreamRef *ostreamRef = new OStreamRef( dataTarget->getStream() );
::CGDataConsumerCallbacks callbacks;
callbacks.putBytes = cgDataConsumerPutBytes;
callbacks.releaseConsumer = cgDataConsumerRelease;
std::shared_ptr<CGDataConsumer> consumer( ::CGDataConsumerCreate( ostreamRef, &callbacks ), ::CGDataConsumerRelease );
mImageDest = ::CGImageDestinationCreateWithDataConsumer( consumer.get(), uti.get(), 1, NULL );
}
if( ! mImageDest )
throw ImageIoExceptionFailedWrite();
setupImageDestOptions( options );
}
示例2: defined
std::unique_ptr<TargetFile> TargetFile::create( const DataTargetRef &dataTarget, size_t sampleRate, size_t numChannels, SampleType sampleType, const std::string &extension )
{
#if ! defined( CINDER_WINRT ) || ( _MSC_VER > 1800 )
std::string ext = dataTarget->getFilePathHint().extension().string();
#else
std::string ext = dataTarget->getFilePathHint().extension();
#endif
ext = ( ( ! ext.empty() ) && ( ext[0] == '.' ) ) ? ext.substr( 1, string::npos ) : ext;
#if defined( CINDER_COCOA )
return std::unique_ptr<TargetFile>( new cocoa::TargetFileCoreAudio( dataTarget, sampleRate, numChannels, sampleType, ext ) );
#elif defined( CINDER_MSW ) || defined( CINDER_WINRT )
return std::unique_ptr<TargetFile>( new msw::TargetFileMediaFoundation( dataTarget, sampleRate, numChannels, sampleType, ext ) );
#endif
}
示例3: write
void TriMesh::write( DataTargetRef dataTarget ) const
{
OStreamRef out = dataTarget->getStream();
const uint8_t versionNumber = 1;
out->write( versionNumber );
out->writeLittle( static_cast<uint32_t>( mVertices.size() ) );
out->writeLittle( static_cast<uint32_t>( mNormals.size() ) );
out->writeLittle( static_cast<uint32_t>( mTexCoords.size() ) );
out->writeLittle( static_cast<uint32_t>( mIndices.size() ) );
for( vector<Vec3f>::const_iterator it = mVertices.begin(); it != mVertices.end(); ++it ) {
out->writeLittle( it->x ); out->writeLittle( it->y ); out->writeLittle( it->z );
}
for( vector<Vec3f>::const_iterator it = mNormals.begin(); it != mNormals.end(); ++it ) {
out->writeLittle( it->x ); out->writeLittle( it->y ); out->writeLittle( it->z );
}
for( vector<Vec2f>::const_iterator it = mTexCoords.begin(); it != mTexCoords.end(); ++it ) {
out->writeLittle( it->x ); out->writeLittle( it->y );
}
for( vector<size_t>::const_iterator it = mIndices.begin(); it != mIndices.end(); ++it ) {
out->writeLittle( static_cast<uint32_t>( *it) );
}
}
示例4: write
void JsonTree::write( DataTargetRef target, bool createDocument )
{
// Declare output string
string jsonString = "";
try {
// Create JsonCpp data to send to parser
Json::Value value = createNativeDoc( createDocument );
// This routine serializes JsonCpp data and formats it
Json::StyledWriter writer;
jsonString = writer.write( value.toStyledString() );
boost::replace_all( jsonString, "\\n", "\r\n" );
boost::replace_all( jsonString, "\\\"", "\"" );
if( jsonString.length() >= 3 ) {
jsonString = jsonString.substr( 1, boost::trim_copy( jsonString ).length() - 2 );
}
jsonString += "\0";
}
catch ( ... ) {
throw ExcJsonParserError( "Unable to serialize JsonTree." );
}
// Save data to file
OStreamRef os = target->getStream();
os->writeData( jsonString.c_str(), jsonString.length() );
}
示例5: AudioFileExc
TargetFileCoreAudio::TargetFileCoreAudio( const DataTargetRef &dataTarget, size_t sampleRate, size_t numChannels, SampleType sampleType, const std::string &extension )
: TargetFile( dataTarget, sampleRate, numChannels, sampleType )
{
::CFURLRef targetUrl = ci::cocoa::createCfUrl( Url( dataTarget->getFilePath().string() ) );
::AudioFileTypeID fileType = getFileTypeIdFromExtension( extension );
::AudioStreamBasicDescription fileAsbd;
switch( mSampleType ) {
case SampleType::INT_16:
fileAsbd = createInt16Asbd( mSampleRate, mNumChannels, true );
break;
case SampleType::FLOAT_32:
fileAsbd = createFloatAsbd( mSampleRate, mNumChannels, true );
break;
default:
CI_ASSERT_NOT_REACHABLE();
}
::ExtAudioFileRef audioFile;
OSStatus status = ::ExtAudioFileCreateWithURL( targetUrl, fileType, &fileAsbd, nullptr, kAudioFileFlags_EraseFile, &audioFile );
if( status == kAudioFileUnsupportedDataFormatError )
throw AudioFileExc( string( "Extended Audio File Services: Unsupported format error, target file: " ) + dataTarget->getFilePath().string(), (int32_t)status );
else if( status != noErr )
throw AudioFileExc( string( "Extended Audio File Services faild: target file: " ) + dataTarget->getFilePath().string(), (int32_t)status );
::CFRelease( targetUrl );
mExtAudioFile = ExtAudioFilePtr( audioFile );
::AudioStreamBasicDescription clientAsbd = createFloatAsbd( mSampleRate, mNumChannels, false );
status = ::ExtAudioFileSetProperty( mExtAudioFile.get(), kExtAudioFileProperty_ClientDataFormat, sizeof( clientAsbd ), &clientAsbd );
CI_VERIFY( status == noErr );
mBufferList = createNonInterleavedBufferListShallow( mNumChannels );
}
示例6: write
void XmlTree::write( DataTargetRef target, bool createDocument )
{
// this could do with a more efficient implementation
shared_ptr<rapidxml::xml_document<char> > doc = createRapidXmlDoc( createDocument );
OStreamRef os = target->getStream();
std::ostringstream ss;
ss << *doc;
os->writeData( ss.str().c_str(), ss.str().length() );
}
示例7: getPathExtension
std::unique_ptr<TargetFile> TargetFile::create( const DataTargetRef &dataTarget, size_t sampleRate, size_t numChannels, const std::string &extension )
{
std::string ext = ( ! extension.empty() ? extension : getPathExtension( dataTarget->getFilePathHint() ) );
#if defined( CINDER_COCOA )
return std::unique_ptr<TargetFile>( new cocoa::TargetFileCoreAudio( dataTarget, sampleRate, numChannels, ext ) );
#elif defined( CINDER_MSW )
return std::unique_ptr<TargetFile>(); // TODO
// return std::unique_ptr<TargetFile>( new msw::TargetFileMediaFoundation( dataTarget, sampleRate, numChannels, ext ) );
#endif
}
示例8: write
void SplinePath::write(DataTargetRef target)
{
auto stream = target->getStream();
stream->writeLittle(size());
for (auto &point : points)
{
stream->writeLittle(point.x);
stream->writeLittle(point.y);
}
}
示例9: ImageIoExceptionFailedWrite
ImageTargetFileTinyExr::ImageTargetFileTinyExr( DataTargetRef dataTarget, ImageSourceRef imageSource, ImageTarget::Options options, const std::string & /*extensionData*/ )
{
if( ! dataTarget->providesFilePath() ) {
throw ImageIoExceptionFailedWrite( "ImageTargetFileTinyExr only supports writing to files." );
}
mFilePath = dataTarget->getFilePath();
setSize( imageSource->getWidth(), imageSource->getHeight() );
ImageIo::ColorModel cm = options.isColorModelDefault() ? imageSource->getColorModel() : options.getColorModel();
switch( cm ) {
case ImageIo::ColorModel::CM_RGB:
mNumComponents = ( imageSource->hasAlpha() ) ? 4 : 3;
setColorModel( ImageIo::ColorModel::CM_RGB );
setChannelOrder( ( mNumComponents == 3 ) ? ImageIo::ChannelOrder::BGR : ImageIo::ChannelOrder::ABGR );
if( mNumComponents == 3 )
mChannelNames = { "G", "B", "R" };
else
mChannelNames = { "A", "G", "B", "R" };
break;
case ImageIo::ColorModel::CM_GRAY:
mNumComponents = ( imageSource->hasAlpha() ) ? 2 : 1;
setColorModel( ImageIo::ColorModel::CM_GRAY );
setChannelOrder( ( mNumComponents == 2 ) ? ImageIo::ChannelOrder::YA : ImageIo::ChannelOrder::Y );
if( mNumComponents == 2 )
mChannelNames = { "Y", "A" };
else
mChannelNames = { "Y" };
break;
default:
throw ImageIoExceptionIllegalColorModel();
}
// TODO: consider supporting half float and uint types as well
setDataType( ImageIo::DataType::FLOAT32 );
mData.resize( mHeight * imageSource->getWidth() * mNumComponents );
}
示例10: ImageIoExceptionFailedWrite
ImageTargetFileStbImage::ImageTargetFileStbImage( DataTargetRef dataTarget, ImageSourceRef imageSource, ImageTarget::Options options, const std::string &extensionData )
{
if( ! dataTarget->providesFilePath() ) {
throw ImageIoExceptionFailedWrite( "ImageTargetFileStbImage only supports writing to files." );
}
mFilePath = dataTarget->getFilePath();
setSize( imageSource->getWidth(), imageSource->getHeight() );
ImageIo::ColorModel cm = options.isColorModelDefault() ? imageSource->getColorModel() : options.getColorModel();
switch( cm ) {
case ImageIo::ColorModel::CM_RGB:
mNumComponents = ( imageSource->hasAlpha() ) ? 4 : 3;
setColorModel( ImageIo::ColorModel::CM_RGB );
setChannelOrder( ( mNumComponents == 4 ) ? ImageIo::ChannelOrder::RGBA : ImageIo::ChannelOrder::RGB );
break;
case ImageIo::ColorModel::CM_GRAY:
mNumComponents = ( imageSource->hasAlpha() ) ? 2 : 1;
setColorModel( ImageIo::ColorModel::CM_GRAY );
setChannelOrder( ( mNumComponents == 2 ) ? ImageIo::ChannelOrder::YA : ImageIo::ChannelOrder::Y );
break;
default:
throw ImageIoExceptionIllegalColorModel();
}
mExtension = extensionData;
if( mExtension == "hdr" ) { // Radiance files are always float*
setDataType( ImageIo::DataType::FLOAT32 );
mRowBytes = mNumComponents * imageSource->getWidth() * sizeof(float);
}
else {
setDataType( ImageIo::DataType::UINT8 );
mRowBytes = mNumComponents * imageSource->getWidth() * sizeof(float);
}
mData = std::unique_ptr<uint8_t[]>( new uint8_t[mWidth * mRowBytes] );
}
示例11: writeImage
void writeImage( DataTargetRef dataTarget, const ImageSourceRef &imageSource, ImageTarget::Options options, string extension )
{
#if defined( CINDER_COCOA ) // this is necessary to limit the lifetime of the objc-based loader's allocations
cocoa::SafeNsAutoreleasePool autorelease;
#endif
if( extension.empty() )
extension = getPathExtension( dataTarget->getFilePathHint() );
ImageTargetRef imageTarget = ImageIoRegistrar::createTarget( dataTarget, imageSource, options, extension );
if( imageTarget ) {
writeImage( imageTarget, imageSource );
}
else
throw ImageIoExceptionUnknownExtension();
}
示例12: AudioFileExc
TargetFileMediaFoundation::TargetFileMediaFoundation( const DataTargetRef &dataTarget, size_t sampleRate, size_t numChannels, SampleType sampleType, const std::string &extension )
: TargetFile( dataTarget, sampleRate, numChannels, sampleType ), mStreamIndex( 0 )
{
MediaFoundationInitializer::initMediaFoundation();
::IMFSinkWriter *sinkWriter;
HRESULT hr = ::MFCreateSinkWriterFromURL( dataTarget->getFilePath().wstring().c_str(), NULL, NULL, &sinkWriter );
if( hr != S_OK ) {
string errorString = string( "TargetFileMediaFoundation: Failed to create SinkWriter from URL: " ) + dataTarget->getFilePath().string();
if( hr == HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND ) )
errorString += ", file not found.";
throw AudioFileExc( errorString );
}
mSinkWriter = ci::msw::makeComUnique( sinkWriter );
mSampleSize = getBytesPerSample( mSampleType );
const UINT32 bitsPerSample = 8 * mSampleSize;
const WORD blockAlignment = mNumChannels * mSampleSize;
const DWORD averageBytesPerSecond = mSampleRate * blockAlignment;
// Set the output media type.
IMFMediaType *mediaType;
hr = ::MFCreateMediaType( &mediaType );
CI_ASSERT( hr == S_OK );
auto mediaTypeManaged = ci::msw::makeComUnique( mediaType );
hr = mediaType->SetGUID( MF_MT_MAJOR_TYPE, MFMediaType_Audio );
CI_ASSERT( hr == S_OK );
const ::GUID audioFormat = getMfAudioFormat( mSampleType );
hr = mediaType->SetGUID( MF_MT_SUBTYPE, audioFormat );
CI_ASSERT( hr == S_OK );
hr = mediaType->SetUINT32( MF_MT_AUDIO_SAMPLES_PER_SECOND, (UINT32)mSampleRate );
CI_ASSERT( hr == S_OK );
hr = mediaType->SetUINT32( MF_MT_AUDIO_BITS_PER_SAMPLE, bitsPerSample );
CI_ASSERT( hr == S_OK );
hr = mediaType->SetUINT32( MF_MT_AUDIO_BLOCK_ALIGNMENT, blockAlignment );
CI_ASSERT( hr == S_OK );
hr = mediaType->SetUINT32( MF_MT_AUDIO_AVG_BYTES_PER_SECOND, averageBytesPerSecond );
CI_ASSERT( hr == S_OK );
hr = mediaType->SetUINT32( MF_MT_AUDIO_NUM_CHANNELS, (UINT32)mNumChannels );
CI_ASSERT( hr == S_OK );
hr = mediaType->SetUINT32( MF_MT_ALL_SAMPLES_INDEPENDENT, 1 );
CI_ASSERT( hr == S_OK );
hr = mediaType->SetUINT32( MF_MT_FIXED_SIZE_SAMPLES, 1 );
CI_ASSERT( hr == S_OK );
hr = mSinkWriter->AddStream( mediaType, &mStreamIndex );
CI_ASSERT( hr == S_OK );
// Tell the sink writer to start accepting data.
hr = mSinkWriter->BeginWriting();
CI_ASSERT( hr == S_OK );
}