void ImageSourceFileRadiance::loadStream( IStreamRef stream )
{
	setDataType( ImageIo::FLOAT32 );
	setColorModel( ImageIo::CM_RGB );
	setChannelOrder( ImageIo::RGB );

	char str[200];
	stream->readData( str, 10 );
	if( memcmp( str, "#?RADIANCE", 10 ) )
		throw ImageSourceFileRadianceException( "Invalid header" );

	stream->seekRelative( 1 );

	char cmd[200];
	int i = 0;
	char c = 0, oldc;
	while( true ) {
		oldc = c;
		stream->read( &c );
		if( c == 0xa && oldc == 0xa )
			break;
		cmd[i++] = c;
	}

	char resolution[200];
	i = 0;
	while( true ) {
		stream->read( &c );
		resolution[i++] = c;
		if( c == 0xa )
			break;
	}

	int width, height;
#if defined( CINDER_WINRT )
	if( ! sscanf_s( resolution, "-Y %d +X %d", &height, &width ) )
#else
	if( ! sscanf( resolution, "-Y %d +X %d", &height, &width ) )
#endif
		throw ImageSourceFileRadianceException( "Unable to parse size" );
	setSize( width, height );

	mRgbData = std::unique_ptr<float[]>( new float[width * height * 3] );
	std::unique_ptr<RgbePixel[]> scanline( new RgbePixel[width] );

	// convert image
	float *cols = mRgbData.get();
	for( int y = height - 1; y >= 0; y-- ) {
		if( ! decrunchScanline( scanline.get(), width, stream.get() ) )
			break;
		workOnRgbeScanline( scanline.get(), width, cols );
		cols += width * 3;
	}
}
Esempio n. 2
0
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 );
	}
}