From 19ca69692093a43e2d21e71b1f2dfd7615ebc829 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Tue, 15 Jul 2003 09:51:40 +0000 Subject: movie handling --- Movie.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----------- Movie.h | 14 ++++++++++-- X11.c | 3 +-- 3 files changed, 81 insertions(+), 17 deletions(-) diff --git a/Movie.c b/Movie.c index b9e9bab..44a15e9 100755 --- a/Movie.c +++ b/Movie.c @@ -1,10 +1,15 @@ #include +#include +#include +#include "Movie.h" + +#ifndef NULL + #define NULL ((void*)0) +#endif struct Frame; -struct Movie; typedef struct Frame Frame; -typedef struct Movie Movie; struct Frame { unsigned long *framedata; @@ -13,23 +18,25 @@ struct Frame { struct Movie { Frame *Movie; + Frame *current; Movie *next; int rate; time_t starttime; }; -static Movie *movie_list; +static Movie movie_list = { NULL, NULL, NULL, 0, 0}; static Movie *current; +static int MoviePoints; void Movie_init( int points ) { - movie_list = (Movie*)0; - current = (Movie*)0; + MoviePoints = points; + current = NULL; } void Movie_destroy( void ) { - Movie *tmp = movie_list; + Movie *tmp = movie_list.next; - current = (Movie*)0; + current = NULL; while( tmp ) { Movie *next = tmp->next; Movie_unloadmovie( tmp ); @@ -38,20 +45,68 @@ void Movie_destroy( void ) { } Movie *Movie_loadmovie( char *filename ) { + FILE *infile = fopen( filename, "r" ); + Movie *movie = NULL; + Frame **loaded = NULL; + int points, frames, i; + + if( infile == NULL ) return NULL; + + if( ( fscanf( infile, "%d\n", &points ) != 1 ) || + ( MoviePoints != points ) || + ( fscanf( infile, "%d\n", &frames ) != 1 ) || + ( ( movie = malloc( sizeof( Movie ) ) ) == NULL ) || + ( fscanf( infile, "%d\n", &movie->rate ) != 1 ) ) + goto error; + + loaded = &movie->Movie; + + while( frames-- > 0 ) { + if( + ( ( *loaded = malloc( sizeof( Frame ) ) ) == NULL ) || + ( ( (*loaded)->framedata = malloc( points * points * points * sizeof( unsigned long ) ) ) == NULL ) + ) + goto error; + + for( i = 0; i < points * points * points; ++i ) { + if( fscanf( infile, "%d%d%d", ((char *)((*loaded)->framedata)), + ((char *)((*loaded)->framedata))+1, + ((char *)((*loaded)->framedata))+2 ) + != 3 ) + goto error; + } + loaded = &((*loaded)->next); + } + error: + if( loaded ) + (*loaded)->next = NULL; + if( movie ) + Movie_unloadmovie( movie ); + movie = NULL; + success: + fclose( infile ); + return movie; } void Movie_unloadmovie( Movie *movie ) { - Movie *tmp = movie_list; + Movie *tmp = &movie_list; if( current == movie ) - current = (Movie*)0; + current = NULL; - while( tmp && ( tmp != movie )) + while( tmp && ( tmp->next != movie )) tmp = tmp->next; - if( tmp) { - - free( tmp ); + if( tmp->next) { + Frame *frame = tmp->next->Movie; + while( frame != NULL ) { + Frame *next = frame->next; + free( frame ); + frame = next; + } + + tmp->next = tmp->next->next; + free( tmp->next ); } } diff --git a/Movie.h b/Movie.h index 3b2feba..576f618 100755 --- a/Movie.h +++ b/Movie.h @@ -1,7 +1,8 @@ /* Opaque reference to Movie in Movie library */ -typedef void* Movie; +struct Movie; +typedef struct Movie Movie; /* Initialise Movie handler - points is number of balls @@ -15,7 +16,16 @@ void Movie_destroy( void ); /* Load one movie from File - filename pointer to file containing Movie - - returns handle to the Movie + - returns handle to the Movie or NULL + on error + +File format is: + %d\n number of points for Cube + %d\n number of frames + %d\n frame rate + foreach frame + foreach point * point * point + %d%d%d RGB of pixel */ Movie *Movie_loadmovie( char *filename ); diff --git a/X11.c b/X11.c index de552fe..887eef9 100755 --- a/X11.c +++ b/X11.c @@ -96,7 +96,7 @@ int main(int argc, char **argv) { signal( SIGINT, handle_signal ); signal( SIGALRM, handle_signal ); - Vector_init( 8, 300); + Vector_init( 5, 300); #ifdef ENABLE_X11_SHARED_MEMORY_PIXMAPS shminfo = malloc( sizeof( shminfo )); @@ -244,7 +244,6 @@ int main(int argc, char **argv) { } default: - printf( "Uncatched event!" ); break; } if( shallredraw == 1 ) { -- cgit v1.2.3