Beispiel #1
0
static void	ProcessSttsAtom( char* atomData, qtmovie_t* qtmovie )
{
	unsigned int loop;
	unsigned int numEntries = ReadUnsignedInt( &atomData[ 4 ] );
	qtmovie->res->num_time_to_samples = numEntries;
	qtmovie->res->time_to_sample = malloc( numEntries * sizeof( *qtmovie->res->time_to_sample ) );

	for ( loop = 0; loop < numEntries; loop++ )
	{	
		qtmovie->res->time_to_sample[ loop ].sample_count		= ReadUnsignedInt( &atomData[ 8 + ( 8 * loop ) + 0 ] );
		qtmovie->res->time_to_sample[ loop ].sample_duration	= ReadUnsignedInt( &atomData[ 8 + ( 8 * loop ) + 4 ] );
	}
}
Beispiel #2
0
Node<real>* SceneImporter<real>::ReadSphere( std::istream& stream, const std::string& name )
{
	Sphere<real>* sphere = new Sphere<real>;
	sphere->SetName( name );

	ReadGeometryHeader( stream, sphere ); ReadNextExactToken( stream, "," );

	real radius = ReadReal( stream ); ReadNextExactToken( stream, "," );
	real latitudeSubdivisions = ReadUnsignedInt( stream ); ReadNextExactToken( stream, "," );
	real longitudeSubdivisions = ReadUnsignedInt( stream );
	sphere->SetSizes( radius, latitudeSubdivisions, longitudeSubdivisions );

	return sphere;
}
Beispiel #3
0
static void ProcessStszAtom( char* atomData, qtmovie_t* qtmovie )
{
	unsigned int loop;
	unsigned int numEntries;
	if ( ReadUnsignedInt( &atomData[ 4 ] ) == 0 )
	{
		numEntries = ReadUnsignedInt( &atomData[ 8 ] );
		qtmovie->res->num_sample_byte_sizes = numEntries;	
		qtmovie->res->sample_byte_size = malloc( numEntries * sizeof( *qtmovie->res->sample_byte_size ) );
	
		for ( loop = 0; loop < numEntries; loop++ )
		{
			qtmovie->res->sample_byte_size[ loop ] = ReadUnsignedInt( &atomData[ 12 + ( 4 * loop ) ] );
		}
	}
}
Beispiel #4
0
unsigned int Reader::ReadUnsignedIntOrDie(void) {
  unsigned int u;
  if (! ReadUnsignedInt(&u)) {
    fprintf(stderr, "Couldn't read unsigned int\n");
    fprintf(stderr, "File: %s\n", filename_.c_str());
    fprintf(stderr, "Byte pos: %lli\n", byte_pos_);
    exit(-1);
  }
  return u;
}
std::string BinaryFile::ReadLongString()
{
    unsigned length;
    length = ReadUnsignedInt();
    auto* tmp = new char[length];
    ReadRawData(tmp, length);
    std::string str = tmp;
    delete[] tmp;
    return str;
}
Beispiel #6
0
static void	ProcessFtypAtom( char* atomData, qtmovie_t* qtmovie )
{
	unsigned int	type = ReadUnsignedInt( atomData );

	if ( type == MAKE_ATOM_NAME( 'M', '4', 'A', ' ' ) )
		g_IsM4AFile = 1;
	else
	{
		// Not an M4A file, so time to stop.. 
		g_StopParsing = 1;
	}
}
Beispiel #7
0
static void	ProcessStsdAtom( char* atomData, qtmovie_t* qtmovie )
{	
	unsigned int entrySize;
	unsigned int numEntries = ReadUnsignedInt( &atomData[ 4 ] );

	// According to original source, we only expect one entry in sample description atom
	if ( numEntries != 1 )
		return;
	
	// The size of the entry is...?
	entrySize = ReadUnsignedInt( &atomData[ 8 ] );
	qtmovie->res->format = ReadUnsignedInt( &atomData[ 12 ] );

	if ( qtmovie->res->format == MAKE_ATOM_NAME( 'a', 'l', 'a', 'c' ) )
	{
		g_IsAppleLossless = 1;

		qtmovie->res->num_channels	= ReadUnsignedShort( &atomData[ 32 ] );
		qtmovie->res->sample_size	= ReadUnsignedShort( &atomData[ 34 ] );
		qtmovie->res->sample_rate	= ReadUnsignedShort( &atomData[ 40 ] );

		// 36 is the bytes for prior to codec data for this entry.
		// 12 is the additional size of our atom header (the 3 uint writes)
		// 8 is for padding, as the original code is a bit paranoid..
		qtmovie->res->codecdata_len = ( entrySize - 36 ) + 12 + 8;
		qtmovie->res->codecdata = malloc( qtmovie->res->codecdata_len );
		memset( qtmovie->res->codecdata, 0, qtmovie->res->codecdata_len );
		
		( ( unsigned int* )qtmovie->res->codecdata )[0] = 0x0c000000;
		( ( unsigned int* )qtmovie->res->codecdata )[1] = MAKE_ATOM_NAME( 'a', 'm', 'r', 'f' );
		( ( unsigned int* )qtmovie->res->codecdata )[2] = MAKE_ATOM_NAME( 'c', 'a', 'l', 'a' );
		memcpy( ( ( char* )qtmovie->res->codecdata ) + 12, &atomData[ 44 ], qtmovie->res->codecdata_len - 8 );
	}
	else
	{
		// Not an apple lossless file.. not interested.
		g_StopParsing = 1;
	}
}
Beispiel #8
0
Node<real>* SceneImporter<real>::ReadCylinder( std::istream& stream, const std::string& name )
{
	Cylinder<real>* cylinder = new Cylinder<real>;
	cylinder->SetName( name );

	ReadGeometryHeader( stream, cylinder ); ReadNextExactToken( stream, "," );

	real height = ReadReal( stream ); ReadNextExactToken( stream, "," );
	real radius = ReadReal( stream ); ReadNextExactToken( stream, "," );
	real radiusSubdivisions = ReadUnsignedInt( stream );
	cylinder->SetSizes( height, radius, radiusSubdivisions );

	return cylinder;
}
Beispiel #9
0
static void ParseAtom( int startOffset, int stopOffset, qtmovie_t* qtmovie )
{
  long			currentOffset;

  int			containerAtom;
  int			atomSize;
  unsigned int	atomName;
  char			atomHeader[ 10 ];

  if ( g_StopParsing )
	return;

  currentOffset = startOffset;
  while ( currentOffset < stopOffset)
  {
    // Seek to the atom header
    stream_seek( qtmovie->stream, currentOffset, SEEK_SET );

	memset( atomHeader, 0, 10 );

    // Read it in.. we only want the atom name & size..	they're always there..
    stream_read( qtmovie->stream, 8, atomHeader );

    // Now pull out the bits we need..
    atomSize = ReadUnsignedInt( &atomHeader[ 0 ] );
    atomName = ReadUnsignedInt( &atomHeader[ 4 ] );

    // See if it's a container atom.. if it is, then recursively call ParseAtom on it...
    for ( containerAtom = 0; containerAtom < ( sizeof( g_ContainerAtoms ) / sizeof( unsigned int ) ); containerAtom++ )
    {
      if ( atomName == g_ContainerAtoms[ containerAtom ] )
      {
        ParseAtom( stream_tell( qtmovie->stream ), currentOffset + atomSize, qtmovie );
        break;
      }
    }

	if ( atomName == g_FtypAtomName )
	{
		void* pAtomData = GetAtomData( qtmovie, atomSize );
		ProcessFtypAtom( pAtomData, qtmovie );
		FreeAtomData( pAtomData );
	}
	else
	if ( atomName == g_StsdAtomName )
	{
		void* pAtomData = GetAtomData( qtmovie, atomSize );
		ProcessStsdAtom( pAtomData, qtmovie );
		FreeAtomData( pAtomData );
	}
	else
	if ( atomName == g_SttsAtomName )
	{
		void* pAtomData = GetAtomData( qtmovie, atomSize );
		ProcessSttsAtom( pAtomData, qtmovie );
		FreeAtomData( pAtomData );
	}
	else
	if ( atomName == g_StszAtomName )
	{
		void* pAtomData = GetAtomData( qtmovie, atomSize );
		ProcessStszAtom( pAtomData, qtmovie );
		FreeAtomData( pAtomData );
	}
	else
	if ( atomName == g_MdatAtomName )
	{
		g_FoundMdatAtom = 1;
		g_StopParsing = 1;
	}

    // If we've got a zero sized atom, then it's all over.. force the offset to trigger a stop.
    if ( atomSize == 0 )
      currentOffset = stopOffset;
    else
      currentOffset += atomSize;	
  }

  // Everything seems to have gone ok...
  return;
}
Beispiel #10
0
/******************************************************************************
 * read the input file
 * parse each section as it occurs
 * load the data into the coaster variables
 * see COASTER.FORMAT.README.txt for details
 *****************************************************************************/
int ReadInputFile()
{
	char SECTION[BUFSIZ/2];
	int i, sectionOK;

	SkipComment();
	while(!feof(file))
	{
		if (!ReadSectionName(SECTION,BUFSIZ/2))
		{
			PrintError("Section SECTION expected");
			return 0;
		}
		// read each section and parse it
		sectionOK = 0;
		if (!strcmp(SECTION,"trackcontrolpoints"))
		{
			sectionOK = 1;
			if (!SkipNewline()) return 0;
			if (!ReadUnsignedInt(&nbPointControl)) return 0;
			
			pPointControl = (point*)malloc(nbPointControl*2*sizeof(point));
			for(i=0; i<nbPointControl; i++)
			{
				if (!SkipNewline()) return 0;
				if (!ReadPoint(&pPointControl[i*2])) return 0;
				if (!ReadSeparator()) return 0;
				if (!ReadPoint(&pPointControl[i*2+1])) return 0;
			}
		}
		if (!strcmp(SECTION,"supportscoordinate"))
		{
			sectionOK = 1;
			if (!SkipNewline()) return 0;
			if (!ReadUnsignedInt(&nbColumnCoord)) return 0;
			pColumnCoordinate = (int*)malloc(nbColumnCoord*sizeof(int));
			for(i=0; i<nbColumnCoord; i++)
			{
				if (!SkipNewline()) return 0;
				if (!ReadUnsignedInt(&pColumnCoordinate[i])) return 0;
			}
		}
		if (!strcmp(SECTION,"platform"))
		{
			sectionOK = 1;
			if (!SkipNewline()) return 0;
			if (!ReadPoint(&metalPosition)) return 0;
			if (!SkipNewline()) return 0;
			if (!ReadFloat(&metalLength))
			{
				PrintError("Number expected");
				return 0;
			}
			if (!SkipNewline()) return 0;
			if (!ReadFloat(&metalAngle))
			{
				PrintError("Number expected");
				return 0;
			}
		}
		if (!strcmp(SECTION,"trees"))
		{
			sectionOK = 1;
			if (!SkipNewline()) return 0;
			if (!ReadUnsignedInt(&nbTree)) return 0;
			pTree = (point*)malloc(nbTree*sizeof(point));
			for(i=0; i<nbTree; i++)
			{
				if (!SkipNewline()) return 0;
				if (!ReadPoint(&pTree[i])) return 0;
				pTree[i].z = -0.001f;
			}
		}
		if (!strcmp(SECTION,"startsegment"))
		{
			sectionOK = 1;
			if (!SkipNewline()) return 0;
			if (!ReadSignedInt(&startSegment)) return 0;
		}
		if (!strcmp(SECTION,"brakesegment"))
		{
			sectionOK = 1;
			if (!SkipNewline()) return 0;
			if (!ReadSignedInt(&brakeSegment)) return 0;
		}
		if (!strcmp(SECTION,"segmentlength"))
		{
			sectionOK = 1;
			if (!SkipNewline()) return 0;
			if (!ReadFloat(&avgSegmentLength))
			{
				PrintError("Number expected");
				return 0;
			}
		}
		if (!strcmp(SECTION,"bankfactor"))
		{
			sectionOK = 1;
			if (!SkipNewline()) return 0;
			if (!ReadFloat(&twistFactor))
			{
				PrintError("Number expected");
				return 0;
			}
		}
		if (!sectionOK) PrintError("Unknown section \"%s\"",SECTION);
		// don't print an error if there is no new line at the end of the file, 
		// don't directly call skipnewline
		i = line_number;
		SkipComment();
		if ((line_number - i == 0) && !feof(file)) PrintError("Newline expected");
	}
	return 1;
}