// TODO: non-local file support? bool FilePlayer::setFile(const DataSourceRef fileSource) { if(fileSource->isFilePath()) { return setFile(fileSource->getFilePath()); } else { return false; } }
void AssetReloader::load( const fs::path assetPath, string key ) { // console() << "AssetReloader :: loading asset :: " << assetPath << " with key :: " << key << endl; DataSourceRef asset = loadAsset( assetPath ); // console() << asset->getFilePath() << endl; gl::Texture tmp = gl::Texture( loadImage( asset ) ); mLoadedImages[key] = tmp; mKeyList[ asset->getFilePath().c_str() ] = key; }
void SamplePlayerNodeTestApp::setSourceFile( const DataSourceRef &dataSource ) { mSourceFile = audio::load( dataSource, audio::master()->getSampleRate() ); getWindow()->setTitle( dataSource->getFilePath().filename().string() ); CI_LOG_V( "SourceFile info: " ); console() << "samplerate: " << mSourceFile->getSampleRate() << endl; console() << "native samplerate: " << mSourceFile->getSampleRateNative() << endl; console() << "channels: " << mSourceFile->getNumChannels() << endl; console() << "frames: " << mSourceFile->getNumFrames() << endl; console() << "metadata:\n" << mSourceFile->getMetaData() << endl; }
/////////////////////////////////////////////////////////////////////////////// // ImageSourceFileQuartz ImageSourceFileQuartzRef ImageSourceFileQuartz::createFileQuartzRef( DataSourceRef dataSourceRef, ImageSource::Options options ) { std::shared_ptr<CGImageSource> sourceRef; std::shared_ptr<CGImage> imageRef; ::CFStringRef keys[1] = { kCGImageSourceShouldAllowFloat }; ::CFBooleanRef values[1] = { kCFBooleanTrue }; const std::shared_ptr<__CFDictionary> optionsDict( (__CFDictionary*)CFDictionaryCreate( kCFAllocatorDefault, (const void **)&keys, (const void **)&values, 1, NULL, NULL ), cocoa::safeCfRelease ); if( dataSourceRef->isFilePath() ) { ::CFStringRef pathString = cocoa::createCfString( dataSourceRef->getFilePath().string() ); ::CFURLRef urlRef = ::CFURLCreateWithFileSystemPath( kCFAllocatorDefault, pathString, kCFURLPOSIXPathStyle, false ); sourceRef = std::shared_ptr<CGImageSource>( ::CGImageSourceCreateWithURL( urlRef, optionsDict.get() ), cocoa::safeCfRelease ); ::CFRelease( pathString ); ::CFRelease( urlRef ); } else if( dataSourceRef->isUrl() ) { ::CFURLRef urlRef = cocoa::createCfUrl( dataSourceRef->getUrl() ); if( ! urlRef ) throw ImageIoExceptionFailedLoad(); sourceRef = std::shared_ptr<CGImageSource>( ::CGImageSourceCreateWithURL( urlRef, optionsDict.get() ), cocoa::safeCfRelease ); ::CFRelease( urlRef ); } else { // last ditch, we'll use a dataref from the buffer ::CFDataRef dataRef = cocoa::createCfDataRef( dataSourceRef->getBuffer() ); if( ! dataRef ) throw ImageIoExceptionFailedLoad(); sourceRef = std::shared_ptr<CGImageSource>( ::CGImageSourceCreateWithData( dataRef, optionsDict.get() ), cocoa::safeCfRelease ); ::CFRelease( dataRef ); } if( sourceRef ) { imageRef = std::shared_ptr<CGImage>( ::CGImageSourceCreateImageAtIndex( sourceRef.get(), options.getIndex(), optionsDict.get() ), CGImageRelease ); if( ! imageRef ) throw ImageIoExceptionFailedLoad(); } else throw ImageIoExceptionFailedLoad(); const std::shared_ptr<__CFDictionary> imageProperties( (__CFDictionary*)::CGImageSourceCopyProperties( sourceRef.get(), NULL ), ::CFRelease ); const std::shared_ptr<__CFDictionary> imageIndexProperties( (__CFDictionary*)::CGImageSourceCopyPropertiesAtIndex( sourceRef.get(), options.getIndex(), NULL ), ::CFRelease ); return ImageSourceFileQuartzRef( new ImageSourceFileQuartz( imageRef.get(), options, imageProperties, imageIndexProperties ) ); }
/////////////////////////////////////////////////////////////////////////////// // ImageSourceFileQuartz ImageSourceFileQuartzRef ImageSourceFileQuartz::createFileQuartzRef( DataSourceRef dataSourceRef ) { ::CGImageSourceRef sourceRef = NULL; ::CGImageRef imageRef = NULL; ::CFStringRef keys[1] = { kCGImageSourceShouldAllowFloat }; ::CFBooleanRef values[1] = { kCFBooleanTrue }; ::CFDictionaryRef optionsDict = ::CFDictionaryCreate( kCFAllocatorDefault, (const void **)&keys, (const void **)&values, 1, NULL, NULL ); if( dataSourceRef->isFilePath() ) { ::CFStringRef pathString = cocoa::createCfString( dataSourceRef->getFilePath() ); ::CFURLRef urlRef = ::CFURLCreateWithFileSystemPath( kCFAllocatorDefault, pathString, kCFURLPOSIXPathStyle, false ); sourceRef = ::CGImageSourceCreateWithURL( urlRef, optionsDict ); ::CFRelease( pathString ); ::CFRelease( urlRef ); } else if( dataSourceRef->isUrl() ) { ::CFURLRef urlRef = cocoa::createCfUrl( dataSourceRef->getUrl() ); if( ! urlRef ) throw ImageIoExceptionFailedLoad(); sourceRef = ::CGImageSourceCreateWithURL( urlRef, optionsDict ); ::CFRelease( urlRef ); } else { // last ditch, we'll use a dataref from the buffer ::CFDataRef dataRef = cocoa::createCfDataRef( dataSourceRef->getBuffer() ); if( ! dataRef ) throw ImageIoExceptionFailedLoad(); sourceRef = ::CGImageSourceCreateWithData( dataRef, optionsDict ); ::CFRelease( dataRef ); } if( sourceRef ) { imageRef = ::CGImageSourceCreateImageAtIndex( sourceRef, 0, optionsDict ); ::CFRelease( sourceRef ); if( ! imageRef ) throw ImageIoExceptionFailedLoad(); } else throw ImageIoExceptionFailedLoad(); return ImageSourceFileQuartzRef( new ImageSourceFileQuartz( imageRef ) ); }
void DartTestApp::loadScript() { DataSourceRef script = loadAsset( "main.dart" ); const char *scriptPath = script->getFilePath().c_str(); char *error = NULL; mIsolate = createIsolateAndSetup( scriptPath, "main", this, &error ); if( ! mIsolate ) { LOG_E << "could not create isolate: " << error << endl; assert( 0 ); } assert( mIsolate == Dart_CurrentIsolate() ); Dart_EnterScope(); Dart_Handle url = checkError( Dart_NewStringFromCString( scriptPath ) ); string scriptContents = loadString( script ); Dart_Handle source = checkError( Dart_NewStringFromCString( scriptContents.c_str() ) ); checkError( Dart_LoadScript( url, source, 0, 0 ) ); // apparently 'something' must be called before swapping in print, // else she blows up with: parser.cc:4996: error: expected: current_class().is_finalized() invoke( "setup" ); Dart_Handle library = Dart_RootLibrary(); if ( Dart_IsNull( library ) ) { LOG_E << "Unable to find root library" << endl; return; } // load in our custom _printCloser, which maps back to Log Dart_Handle corelib = checkError( Dart_LookupLibrary( Dart_NewStringFromCString( "dart:core" ) ) ); Dart_Handle print = checkError( Dart_GetField( library, Dart_NewStringFromCString( "_printClosure" ) ) ); checkError( Dart_SetField( corelib, Dart_NewStringFromCString( "_printClosure" ), print ) ); checkError( Dart_SetNativeResolver( library, ResolveName ) ); invoke( "main" ); Dart_ExitScope(); Dart_ExitIsolate(); }
void MovieBase::initFromDataSource( DataSourceRef dataSourceRef, const std::string &mimeTypeHint ) { startQuickTime(); if( dataSourceRef->isFilePath() ) { // try to use quicktime's native file handling if possible getObj()->mMovie = openMovieFromPath( dataSourceRef->getFilePath() ); // no need to retain the data source } else if( dataSourceRef->isUrl() ) { // try to use quicktime's native Url handling if possible // Create a loader for this Url and then wait on it MovieLoader loader( dataSourceRef->getUrl() ); loader.waitForLoaded(); getObj()->mMovie = loader.transferMovieHandle(); // no need to retain the data source } else { // we'll need to load from memory; and we'll rer to the data source to make sure it doesn't go away before the movie does Buffer buffer( dataSourceRef->getBuffer() ); getObj()->mMovie = openMovieFromMemory( buffer.getData(), buffer.getDataSize(), dataSourceRef->getFilePathHint(), mimeTypeHint ); getObj()->mDataSource = dataSourceRef; // retain a reference to the dataSource so that it doesn't go away before we do } init(); }
ImageSourceFileTinyExr::ImageSourceFileTinyExr( DataSourceRef dataSource, ImageSource::Options /*options*/ ) { mExrImage.reset( new EXRImage ); const char *error; InitEXRImage( mExrImage.get() ); int status = 0; if( dataSource->isFilePath() ) { status = ParseMultiChannelEXRHeaderFromFile( mExrImage.get(), dataSource->getFilePath().string().c_str(), &error ); if( status != 0 ) throw ImageIoExceptionFailedLoadTinyExr( string( "Failed to parse OpenEXR header; Error message: " ) + error ); status = LoadMultiChannelEXRFromFile( mExrImage.get(), dataSource->getFilePath().string().c_str(), &error ); if( status != 0 ) throw ImageIoExceptionFailedLoadTinyExr( string( "Failed to parse OpenEXR file; Error message: " ) + error ); } else { BufferRef buffer = dataSource->getBuffer(); status = ParseMultiChannelEXRHeaderFromMemory( mExrImage.get(), (const unsigned char*)buffer->getData(), &error ); if( status != 0 ) throw ImageIoExceptionFailedLoadTinyExr( string( "Failed to parse OpenEXR header; Error message: " ) + error ); status = LoadMultiChannelEXRFromMemory( mExrImage.get(), (const unsigned char*)buffer->getData(), &error ); if( status != 0 ) throw ImageIoExceptionFailedLoadTinyExr( string( "Failed to parse OpenEXR file; Error message: " ) + error ); } // verify that the channels are all the same size; currently we don't support variably sized channels int pixelType = mExrImage->pixel_types[0]; for( int c = 1; c < mExrImage->num_channels; ++c ) { if( pixelType != mExrImage->pixel_types[c] ) throw ImageIoExceptionFailedLoadTinyExr( "TinyExr: heterogneous channel data types not supported" ); } switch( pixelType ) { case TINYEXR_PIXELTYPE_HALF: setDataType( ImageIo::FLOAT16 ); break; case TINYEXR_PIXELTYPE_FLOAT: setDataType( ImageIo::FLOAT32 ); break; default: throw ImageIoExceptionFailedLoadTinyExr( "TinyExr: Unknown data type" ); break; } setSize( mExrImage->width, mExrImage->height ); switch( mExrImage->num_channels ) { case 3: setColorModel( ImageIo::CM_RGB ); setChannelOrder( ImageIo::ChannelOrder::RGB ); break; case 4: setColorModel( ImageIo::CM_RGB ); setChannelOrder( ImageIo::ChannelOrder::RGBA ); break; default: throw ImageIoExceptionFailedLoadTinyExr( "TinyExr: Unsupported number of channels (" + to_string( mExrImage->num_channels ) + ")" ); } }
AssimpLoader::AssimpLoader(DataSourceRef dataSource) : mBuffer(dataSource->getBuffer()) { string ext = getPathExtension(dataSource->getFilePath()); load(ext); }
SdkMesh::SdkMesh( DataSourceRef dataSource, bool includeUVs /*= true */ ) :mSdkMesh(std::shared_ptr<CDXUTSDKMesh>(new CDXUTSDKMesh)) { app::console() << dataSource->getFilePath() << std::endl; mSdkMesh->Create(getDevice(), dataSource->getFilePath().c_str()); }
ImageSourceFileWic::ImageSourceFileWic( DataSourceRef dataSourceRef, ImageSource::Options options ) : ImageSource() { ::HRESULT hr = S_OK; // Initialize COM msw::initializeCom(); // Create WIC factory IWICImagingFactory *IWICFactoryP = NULL; hr = ::CoCreateInstance( CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&IWICFactoryP) ); if( ! SUCCEEDED( hr ) ) throw ImageIoExceptionFailedLoad(); std::shared_ptr<IWICImagingFactory> IWICFactory = msw::makeComShared( IWICFactoryP ); // Create a decoder IWICBitmapDecoder *decoderP = NULL; if( dataSourceRef->isFilePath() ) { hr = IWICFactory->CreateDecoderFromFilename( toUtf16( dataSourceRef->getFilePath().string() ).c_str(), // Image to be decoded NULL, // Do not prefer a particular vendor GENERIC_READ, // Desired read access to the file WICDecodeMetadataCacheOnDemand, // Cache metadata when needed &decoderP // Pointer to the decoder ); if( ! SUCCEEDED(hr) ) throw ImageIoExceptionFailedLoad(); } else { // have to use a buffer IWICStream *pIWICStream = NULL; hr = IWICFactory->CreateStream( &pIWICStream ); if( ! SUCCEEDED(hr) ) throw ImageIoExceptionFailedLoad(); std::shared_ptr<IWICStream> stream = msw::makeComShared( pIWICStream ); Buffer buffer = dataSourceRef->getBuffer(); hr = stream->InitializeFromMemory( reinterpret_cast<BYTE*>( buffer.getData() ), buffer.getDataSize() ); if( ! SUCCEEDED(hr) ) throw ImageIoExceptionFailedLoad(); hr = IWICFactory->CreateDecoderFromStream( stream.get(), NULL, WICDecodeMetadataCacheOnDemand, &decoderP ); if( ! SUCCEEDED(hr) ) throw ImageIoExceptionFailedLoad(); } std::shared_ptr<IWICBitmapDecoder> decoder = msw::makeComShared( decoderP ); // Retrieve the 'index' frame of the image from the decoder IWICBitmapFrameDecode *frameP = NULL; hr = decoder->GetFrame( options.getIndex(), &frameP ); if( ! SUCCEEDED(hr) ) throw ImageIoExceptionFailedLoad(); std::shared_ptr<IWICBitmapFrameDecode> frame = msw::makeComShared( frameP ); UINT width = 0, height = 0; frame->GetSize( &width, &height ); mWidth = width; mHeight = height; GUID pixelFormat = { 0 }, convertPixelFormat; frame->GetPixelFormat( &pixelFormat ); bool requiresConversion = processFormat( pixelFormat, &convertPixelFormat ); mRowBytes = mWidth * ImageIo::dataTypeBytes( mDataType ) * channelOrderNumChannels( mChannelOrder ); mData = std::shared_ptr<uint8_t>( new uint8_t[mRowBytes * mHeight], boost::checked_array_delete<uint8_t> ); if( requiresConversion ) { IWICFormatConverter *pIFormatConverter = NULL; hr = IWICFactory->CreateFormatConverter( &pIFormatConverter ); if( ! SUCCEEDED( hr ) ) throw ImageIoExceptionFailedLoad(); std::shared_ptr<IWICFormatConverter> formatConverter = msw::makeComShared( pIFormatConverter ); hr = formatConverter->Initialize( frame.get(), convertPixelFormat, WICBitmapDitherTypeNone, NULL, 0.f, WICBitmapPaletteTypeCustom ); if( ! SUCCEEDED( hr ) ) throw ImageIoExceptionFailedLoad(); hr = formatConverter->CopyPixels( NULL, (UINT)mRowBytes, mRowBytes * mHeight, mData.get() ); } else hr = frame->CopyPixels( NULL, (UINT)mRowBytes, mRowBytes * mHeight, mData.get() ); }
SourceFile::SourceFile( DataSourceRef dataSourceRef ) : Source() { OSStatus err = noErr; AudioFileID aFileRef; if( dataSourceRef->isFilePath() ) { ::CFStringRef pathString = cocoa::createCfString( dataSourceRef->getFilePath() ); ::CFURLRef urlRef = ::CFURLCreateWithFileSystemPath( kCFAllocatorDefault, pathString, kCFURLPOSIXPathStyle, false ); err = AudioFileOpenURL( urlRef, kAudioFileReadPermission/*fsRdPerm*/, 0, &aFileRef ); ::CFRelease( pathString ); ::CFRelease( urlRef ); if( err ) { #if defined(CINDER_MAC) //TODO: find iphone equivalent of fnfErr if( err == fnfErr ) { throw IoExceptionSourceNotFound(); } #endif throw IoExceptionFailedLoad(); } } else if( dataSourceRef->isUrl() ) { ::CFURLRef urlRef = cocoa::createCfUrl( dataSourceRef->getUrl() ); err = AudioFileOpenURL( urlRef, kAudioFileReadPermission/*fsRdPerm*/, 0, &aFileRef ); ::CFRelease( urlRef ); if( err ) { throw IoExceptionFailedLoad(); } } mFileRef = shared_ptr<OpaqueAudioFileID>( aFileRef, AudioFileClose ); //load header info AudioStreamBasicDescription nativeFormatDescription; UInt32 size = sizeof( AudioStreamBasicDescription ); err = AudioFileGetProperty( aFileRef, kAudioFilePropertyDataFormat, &size, &nativeFormatDescription ); if( err ) { throw IoExceptionFailedLoad(); } loadFromCaAudioStreamBasicDescription( this, &nativeFormatDescription ); size = sizeof( uint64_t ); err = AudioFileGetProperty( aFileRef, kAudioFilePropertyAudioDataPacketCount, &size, &mPacketCount ); if( err ) { throw IoExceptionFailedLoad(); } size = sizeof( uint64_t ); err = AudioFileGetProperty( aFileRef, kAudioFilePropertyAudioDataByteCount, &size, &mByteCount ); if( err ) { throw IoExceptionFailedLoad(); } size = sizeof( uint32_t ); err = AudioFileGetProperty( aFileRef, kAudioFilePropertyMaximumPacketSize, &size, &mMaxPacketSize ); if( err ) { throw IoExceptionFailedLoad(); } size = sizeof( double ); err = AudioFileGetProperty( aFileRef, kAudioFilePropertyEstimatedDuration, &size, &mDuration ); if( err ) { throw IoExceptionFailedLoad(); } }