// Load JSON from URL Value loadUrl(const string & url, bool isEscaped) { // Load URL DataSourceRef dataSource = ci::loadUrl(Url(url, isEscaped)); // Read buffer Buffer buffer; try { buffer = dataSource->getBuffer(); } catch (...) { Value value; return value; } size_t dataSize = buffer.getDataSize(); shared_ptr<int_fast8_t> bufferStr(new int_fast8_t[dataSize + 1], checked_array_deleter<int_fast8_t>()); memcpy(bufferStr.get(), buffer.getData(), buffer.getDataSize()); bufferStr.get()[dataSize] = 0; // Convert buffer to string, deserialize and return return deserialize(string(reinterpret_cast<char *>(bufferStr.get()))); }
// TODO: non-local file support? bool FilePlayer::setFile(const DataSourceRef fileSource) { if(fileSource->isFilePath()) { return setFile(fileSource->getFilePath()); } else { return false; } }
HRESULT Shader::setup(DataSourceRef dataSrc, const std::string& entryName) { if (dataSrc && dataSrc->getBuffer().getDataSize() > 0) { CComPtr<ID3DBlob> shaderBytecode; HR( dx11::compileShader(dataSrc->getBuffer(), entryName, getProfileName(), &shaderBytecode) ); HR( doCreateShader(shaderBytecode, &mHandle) ); } return hr; }
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; }
////////////////////////////////////////////////////////////////////////// // GlslProg GlslProg::GlslProg( DataSourceRef vertexShader, DataSourceRef fragmentShader, DataSourceRef geometryShader ) : mObj( shared_ptr<Obj>( new Obj ) ) { mObj->mHandle = glCreateProgram(); loadShader( vertexShader->getBuffer(), GL_VERTEX_SHADER_ARB ); if( fragmentShader ) loadShader( fragmentShader->getBuffer(), GL_FRAGMENT_SHADER_ARB ); if( geometryShader ) loadShader( geometryShader->getBuffer(), GL_GEOMETRY_SHADER_EXT ); link(); }
/////////////////////////////////////////////////////////////////////////////// // 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 ) ); }
void XFont::read(InputSourceRef inputSource) { if (inputSource->isFile()) { ifstream in(inputSource->getFilePath().c_str(), ifstream::binary); readFromStream(in); in.close(); } else { DataSourceRef resource = inputSource->loadDataSource(); Buffer &buffer = resource->getBuffer(); ReadStreamBuffer tmp(buffer); istream in(&tmp); readFromStream(in); } }
/////////////////////////////////////////////////////////////////////////////// // 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(); }
FollowablePath::FollowablePath(InputSourceRef inputSource, int mode) : mode(mode) { if (inputSource->isFile()) { ifstream in(inputSource->getFilePath().c_str(), ifstream::binary); readFromStream(in); in.close(); } else { DataSourceRef resource = inputSource->loadDataSource(); Buffer &buffer = resource->getBuffer(); ReadStreamBuffer tmp(buffer); istream in(&tmp); readFromStream(in); } }
ImageSourceRef loadImage( DataSourceRef dataSource, ImageSource::Options options, string extension ) { #if defined( CINDER_COCOA ) cocoa::SafeNsAutoreleasePool autorelease; #endif if( extension.empty() ) extension = getPathExtension( dataSource->getFilePathHint() ); return ImageIoRegistrar::createSource( dataSource, options, extension ); }
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; }
Dart_Isolate DartTestApp::createIsolateAndSetup( const char* script_uri, const char* main, void* data, char** error ) { DataSourceRef snapshot = loadResource( "snapshot_gen.bin" ); const uint8_t *snapshotData = (const uint8_t *)snapshot->getBuffer().getData(); LOG_V << "Creating isolate " << script_uri << ", " << main << endl; Dart_Isolate isolate = Dart_CreateIsolate( script_uri, main, snapshotData, data, error ); if ( isolate == NULL ) { LOG_E << "Couldn't create isolate: " << *error << endl; return NULL; } LOG_V << "Entering scope" << endl; Dart_EnterScope(); // Set up the library tag handler for this isolate. LOG_V << "Setting up library tag handler" << endl; Dart_Handle result = Dart_SetLibraryTagHandler( libraryTagHandler ); CHECK_RESULT( result ); Dart_ExitScope(); return isolate; }
// static unique_ptr<SourceFile> SourceFile::create( const DataSourceRef &dataSource, size_t sampleRate ) { unique_ptr<SourceFile> result; #if ! defined( CINDER_WINRT ) || ( _MSC_VER > 1800 ) if( dataSource->getFilePathHint().extension().string() == ".ogg" ) #else if( dataSource->getFilePathHint().extension() == ".ogg" ) #endif result.reset( new SourceFileOggVorbis( dataSource, sampleRate ) ); else { #if defined( CINDER_COCOA ) result.reset( new cocoa::SourceFileCoreAudio( dataSource, sampleRate ) ); #elif defined( CINDER_MSW ) result.reset( new msw::SourceFileMediaFoundation( dataSource, sampleRate ) ); #endif } if( result ) result->setupSampleRateConversion(); return result; }
void XmlTree::loadFromDataSource( DataSourceRef dataSource, XmlTree *result, const XmlTree::ParseOptions &parseOptions ) { auto buf = dataSource->getBuffer(); size_t dataSize = buf->getSize(); unique_ptr<char[]> bufString( new char[dataSize+1] ); memcpy( bufString.get(), buf->getData(), buf->getSize() ); bufString.get()[dataSize] = 0; rapidxml::xml_document<> doc; // character type defaults to char if( parseOptions.getParseComments() ) doc.parse<rapidxml::parse_comment_nodes | rapidxml::parse_doctype_node>( bufString.get() ); else doc.parse<rapidxml::parse_doctype_node>( bufString.get() ); parseItem( doc, NULL, result, parseOptions ); result->setNodeType( NODE_DOCUMENT ); // call this after parse - constructor replaces it }
void SplinePath::read(DataSourceRef source) { auto stream = source->createStream(); int newPointsSize; stream->readLittle(&newPointsSize); points.reserve(size() + newPointsSize); // --- Vec2f point; for (int i = 0; i < newPointsSize; i++) { stream->readLittle(&point.x); stream->readLittle(&point.y); add(point); } }
void ConfigDict::loadXML(DataSourceRef source) { XmlTree doc; try { doc = XmlTree(source); } catch(rapidxml::parse_error &e) { LOG_ERROR("ConfigDict::loadXML - couldnt parse XML data ("<< "error: "<< e.what() <<" "<< "file: "<< source->getFilePathHint() << ")"); } XmlTree root = *doc.begin(); for(XmlTree::ConstIter setting = root.begin(); setting != root.end(); ++setting) { string key = setting->getTag(); string value = setting->getValue(); settings.insert(std::pair<string,string>(key, value) ); } }
void TriMesh::read( DataSourceRef dataSource ) { IStreamRef in = dataSource->createStream(); clear(); uint8_t versionNumber; in->read( &versionNumber ); uint32_t numVertices, numNormals, numTexCoords, numIndices; in->readLittle( &numVertices ); in->readLittle( &numNormals ); in->readLittle( &numTexCoords ); in->readLittle( &numIndices ); for( size_t idx = 0; idx < numVertices; ++idx ) { Vec3f v; in->readLittle( &v.x ); in->readLittle( &v.y ); in->readLittle( &v.z ); mVertices.push_back( v ); } for( size_t idx = 0; idx < numNormals; ++idx ) { Vec3f v; in->readLittle( &v.x ); in->readLittle( &v.y ); in->readLittle( &v.z ); mNormals.push_back( v ); } for( size_t idx = 0; idx < numTexCoords; ++idx ) { Vec2f v; in->readLittle( &v.x ); in->readLittle( &v.y ); mTexCoords.push_back( v ); } for( size_t idx = 0; idx < numIndices; ++idx ) { uint32_t v; in->readLittle( &v ); mIndices.push_back( v ); } }
ImageSourcePng::ImageSourcePng( DataSourceRef dataSourceRef, ImageSource::Options /*options*/ ) : ImageSource(), mInfoPtr( 0 ), mPngPtr( 0 ) { mPngPtr = png_create_read_struct( PNG_LIBPNG_VER_STRING, (png_voidp)NULL, NULL, NULL ); if( ! mPngPtr ) { throw ImageSourcePngException( "Could not create png struct." ); } mCiInfoPtr = shared_ptr<ci_png_info>( new ci_png_info ); mCiInfoPtr->srcStreamRef = dataSourceRef->createStream(); png_set_read_fn( mPngPtr, reinterpret_cast<void*>( mCiInfoPtr.get() ), ci_PNG_stream_reader ); mInfoPtr = png_create_info_struct( mPngPtr ); if( ! mInfoPtr ) { png_destroy_read_struct( &mPngPtr, (png_infopp)NULL, (png_infopp)NULL ); mPngPtr = 0; throw ImageSourcePngException( "Could not destroy png read struct." ); } if( ! loadHeader() ) throw ImageSourcePngException( "Could not load png header." ); }
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(); }
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()); }
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(); } }
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 ) + ")" ); } }
/////////////////////////////////////////////////////////////////////////////// // Process the configuration settings. This will set up the recordCopier. // Note: Check HaveConfigurationError() for the result. /////////////////////////////////////////////////////////////////////////////// void GeoLoadCombineAddressRange::ProcessConfiguration() { if (!configChanged) { return; } ::ProcessConfiguration(); // Output record starts out empty outputRecord = new Record; // Make a new record copier recordCopier = new RecordCopier; // Must have an output DataSourceList outputs = GetOutputs(); if (outputs.size() == 0) { ConfigError("Must have at least one output attached"); } // Get references to all inputs. DataSourceRef input = GetFirstInput(); if (input == 0) { ConfigError("Must have at least one input attached"); return; } // Output is always copy of input record schema outputRecord = new Record(*input->GetRecord()); // Copy entire record; this is only very slightly wasteful of CPU. recordCopier->AddRecordTransfers(outputRecord); // Configuration processing. Walk the DataItem hierarchy and // transform that into the data-file, file format, and record layout. DataItemRef tmp; /////////////////////////////////////////////////////////////////////////////// // Specified fields /////////////////////////////////////////////////////////////////////////////// postcodeFieldName = ""; tlidFieldName = ""; leftRightFieldName = ""; fraddrFieldName = ""; toaddrFieldName = ""; tmp = config["ZIP"]; if (tmp != 0) { postcodeFieldName = TsString(*tmp); } if (outputRecord->GetField(postcodeFieldName) == 0) { ConfigError("ZIP field '" + postcodeFieldName + "' does not exist on input record"); } tmp = config["TLID"]; if (tmp != 0) { tlidFieldName = TsString(*tmp); } if (outputRecord->GetField(tlidFieldName) == 0) { ConfigError("TLID field '" + tlidFieldName + "' does not exist on input record"); } tmp = config["LEFTRIGHT"]; if (tmp != 0) { leftRightFieldName = TsString(*tmp); } if (outputRecord->GetField(leftRightFieldName) == 0) { ConfigError("LEFTRIGHT field '" + leftRightFieldName + "' does not exist on input record"); } tmp = config["FRADDR"]; if (tmp != 0) { fraddrFieldName = TsString(*tmp); } if (outputRecord->GetField(fraddrFieldName) == 0) { ConfigError("FRADDR field '" + fraddrFieldName + "' does not exist on input record"); } tmp = config["TOADDR"]; if (tmp != 0) { toaddrFieldName = TsString(*tmp); } if (outputRecord->GetField(toaddrFieldName) == 0) { ConfigError("TOADDR field '" + toaddrFieldName + "' does not exist on input record"); } }
AssimpLoader::AssimpLoader(DataSourceRef dataSource) : mBuffer(dataSource->getBuffer()) { string ext = getPathExtension(dataSource->getFilePath()); load(ext); }
void GeometryShaderApp::loadShader( const std::string &path ) { // ATI/AMD drivers require layout qualifiers, where NVIDIA drivers specifically do not. std::string header; if( isNVIDIA() ) { DataSourceRef headerFile = loadAsset("shaders/header_nvidia.txt"); header = std::string( (char*) headerFile->getBuffer().getData(), headerFile->getBuffer().getDataSize() ); } else { DataSourceRef headerFile = loadAsset("shaders/header_ati.txt"); header = std::string( (char*) headerFile->getBuffer().getData(), headerFile->getBuffer().getDataSize() ); } // Load the geometry shader as a text file into memory and prepend the header DataSourceRef geomFile = loadAsset(path); std::string geom( (char*) geomFile->getBuffer().getData(), geomFile->getBuffer().getDataSize() ); geom = header + geom; // Load vertex and fragments shaders as text files and compile the shader try { DataSourceRef vertFile = loadAsset("shaders/lines.vert"); std::string vert( (char*) vertFile->getBuffer().getData(), vertFile->getBuffer().getDataSize() ); DataSourceRef fragFile = loadAsset("shaders/lines.frag"); std::string frag( (char*) fragFile->getBuffer().getData(), fragFile->getBuffer().getDataSize() ); mShader = gl::GlslProg( vert.c_str(), frag.c_str(), geom.c_str(), GL_LINES_ADJACENCY_EXT, GL_TRIANGLE_STRIP, 7 ); } catch( const std::exception &e ) { console() << "Could not compile shader:" << e.what() << std::endl; } }
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() ); }
ImageSourceFileRadiance::ImageSourceFileRadiance( DataSourceRef dataSourceRef, ImageSource::Options options ) { IStreamRef stream = dataSourceRef->createStream(); loadStream( stream ); }
SourceFileWindowsMedia::SourceFileWindowsMedia( DataSourceRef dataSourceRef ) : Source() { mDataType = DATA_UNKNOWN; mSampleRate = 0; mChannelCount = 0; mBitsPerSample = 0; mBlockAlign = 0; mIsPcm = FALSE; mIsBigEndian = TRUE; mIsInterleaved = FALSE; /*if( dataSourceRef->isFilePath() ) { //TODO: implement } else if ( dataSourceRef->isFilePath() ) { //TODO: implement WindowsMedia network functionallity }else { //have to use buffer //TODO: move current implementation into this }*/ mBuffer = dataSourceRef->getBuffer(); ::HRESULT hr; msw::initializeCom(); //setup readers IWMSyncReader * IWMReaderP = NULL; hr = ::WMCreateSyncReader(0, 0, &IWMReaderP); if( FAILED( hr ) ) { throw SourceFileWindowsMediaExceptionUnsupportedData(); } std::shared_ptr<IWMSyncReader> reader = msw::makeComShared<IWMSyncReader>( IWMReaderP ); //turn data into stream uint32_t dataSize = getLength(); mMemHandle = std::shared_ptr<void>( ::GlobalAlloc( GMEM_MOVEABLE | GMEM_NODISCARD | GMEM_SHARE, dataSize ), GlobalFree ); LPVOID pMem = ::GlobalLock( mMemHandle.get() ); void * data = mBuffer.getData(); ::CopyMemory( pMem, data, dataSize ); ::GlobalUnlock( mMemHandle.get() ); ::IStream* iStreamP; hr = ::CreateStreamOnHGlobal( mMemHandle.get(), FALSE, &iStreamP ); if(FAILED(hr)) { throw SourceFileWindowsMediaExceptionUnsupportedData(); } std::shared_ptr<::IStream> pStream = msw::makeComShared<::IStream>( iStreamP ); hr = reader->OpenStream( pStream.get() ); if( FAILED(hr) ) { throw SourceFileWindowsMediaExceptionUnsupportedData(); } //ensure that there is only one stream in the file DWORD nOutputCount; hr = reader->GetOutputCount( &nOutputCount ); if( FAILED(hr) ) { throw SourceFileWindowsMediaExceptionUnsupportedData(); } //ensure this is audio only if( nOutputCount != 1 ) { throw SourceFileWindowsMediaExceptionUnsupportedData(); } }