~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/tv/tv_picture.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)
  2 **/
  3 #include <stdio.h>
  4 #include <unistd.h>
  5 #include <tina/sys.h>
  6 #include <tina/sysfuncs.h>
  7 #include <tina/math.h>
  8 #include <tina/tv.h>
  9 #include <tina/tvfuncs.h>
 10 
 11 /* EXTERNS */
 12 extern void picture_write();
 13 
 14 /* Tv_picture *tv_screen_get_picture (window system specific) */
 15 extern void *tv_screen_get_picture();
 16 extern void tv_screen_show_picture();
 17 extern void picture_free();
 18 
 19 void   *tv_get_picture(Tv * tv)
 20 {
 21     if (tv == NULL)
 22         return (NULL);
 23     return (tv_screen_get_picture(tv->tv_screen));
 24 }
 25 
 26 void    tv_show_picture(Tv * tv, void *picture)
 27 {
 28     if (tv == NULL)
 29         return;
 30     tv_screen_show_picture(tv->tv_screen, picture);
 31 }
 32 
 33 void    tv_start_movie(Tv * tv)
 34 {
 35     if (tv == NULL)
 36         return;
 37     dd_list_rm(tv->movie, picture_free);
 38     tv->movie = NULL;
 39 }
 40 
 41 void    tv_make_movie(Tv * tv)
 42 {
 43     List *el;
 44 
 45     if (tv == NULL)
 46         return;
 47     el = dd_link_alloc((void *) tv_get_picture(tv), (int)NULL);
 48     tv->movie = dd_list_addtoend(tv->movie, el);
 49 }
 50 
 51 void    tv_show_movie(Tv * tv, int n)
 52 {
 53     List *ptr;
 54     int     i;
 55 
 56     if (tv == NULL)
 57         return;
 58     for (i = 0; i < n; ++i)
 59         for (ptr = tv->movie; ptr != NULL; ptr = ptr->next)
 60           {
 61             tv_show_picture(tv, ptr->to);
 62             tv_flush(tv);
 63             pause();
 64           }
 65 }
 66 
 67 
 68 void    tv_random_movie(Tv * tv, int n)
 69 {
 70 /*
 71  Timing is critical so all variable length
 72  coding is done prior
 73 */
 74     List  *ptr, *list;
 75     int     *randy;
 76     int      m, i = 0, frames = 0;
 77     int      c = 0, l = 0;
 78 
 79     if (tv == NULL || tv->movie == NULL)
 80       return;
 81     for (ptr = tv->movie; ptr != NULL; ptr = ptr->next)
 82       frames++;
 83 
 84     list = (List *)ralloc(frames*sizeof(List));
 85     
 86     for (ptr = tv->movie; ptr != NULL; ptr = ptr->next)
 87       list[i++] = *ptr;
 88        
 89     randy = (int *)ralloc(n*sizeof(int));
 90     for (i = 0; i < n; i++)
 91       {           
 92         while (c == l)
 93           c = rand_int(0, frames);
 94         randy[i] = l = c;
 95       }
 96        
 97     i = 0;   
 98     while(i < n)
 99       {
100         ptr = &(list[(randy[i])]);
101         tv_show_picture(tv, ptr->to);
102         tv_flush(tv);
103         pause();
104         i++;
105       }
106     
107     rfree(list);
108     rfree(randy);
109 }
110 
111 
112 void    tv_loop_movie(Tv * tv, int n)
113 {
114     List *ptr;
115     List *end;
116     int     i;
117 
118     if (tv == NULL || tv->movie == NULL)
119         return;
120     for (i = 0; i < abs(n); ++i)
121     {
122         for (ptr = tv->movie; ptr != NULL; ptr = ptr->next)
123         {
124             tv_show_picture(tv, ptr->to);
125             tv_flush(tv);
126             pause();
127             end = ptr;
128         }
129         if (n > 0)
130         {
131             for (ptr = end; ptr != NULL; ptr = ptr->last)
132             {
133                 tv_show_picture(tv, ptr->to);
134                 tv_flush(tv);
135                 pause();
136             }
137         }
138     }
139 }
140 
141 void    tv_picture_write(Tv * tv, FILE * fp)
142 {
143     void   *picture;
144 
145     if (tv == NULL || tv->tv_screen == NULL || fp == NULL)
146         return;
147 
148     picture = tv_get_picture(tv);
149     picture_write(fp, picture);
150     picture_free(picture);
151 }
152 
153 void   *tv_picture_read(Tv * tv, FILE * fp)
154 {
155     void   *tv_screen_picture_read();
156 
157     if (tv == NULL || tv->tv_screen == NULL || fp == NULL)
158         return (NULL);
159 
160     return (tv_screen_picture_read(tv->tv_screen, fp));
161 }
162 
163 void    tv_movie_write(Tv * tv, char *fname)
164 {
165     FILE   *fp;
166     List *ptr;
167     int     n;
168 
169     if (tv == NULL)
170         return;
171 
172     if ((fp = fopen(fname, "w")) == NULL)
173     {
174         error("tv_movie_write: cannot open file", non_fatal);
175         return;
176     }
177     n = dd_list_length(tv->movie);
178     (void) fwrite((char *) &n, sizeof(int), 1, fp);
179     for (ptr = tv->movie; ptr != NULL; ptr = ptr->next)
180         picture_write(fp, ptr->to);
181     (void) fclose(fp);
182 }
183 
184 void    tv_movie_read(Tv * tv, char *fname)
185 {
186     FILE   *fp;
187     void   *picture;
188     void   *tv_screen_picture_read();   /* Tv_picture* (window system
189                                          * specific) */
190     int     i, n;
191 
192     if (tv == NULL)
193         return;
194     if ((fp = fopen(fname, "r")) == NULL)
195     {
196         error("tv_movie_read: cannot open file", non_fatal);
197         return;
198     }
199     (void) fread((char *) &n, sizeof(int), 1, fp);
200     tv_start_movie(tv);
201     for (i = 0; i < n; i++)
202     {
203         List *el;
204 
205         picture = tv_screen_picture_read(tv->tv_screen, fp);
206         el = dd_link_alloc((void *)picture, (int)NULL);
207         tv->movie = dd_list_addtoend(tv->movie, el);
208         tv_show_picture(tv, picture);
209     }
210     (void) fclose(fp);
211 }
212 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.