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

Linux Cross Reference
Tina5/tina-tools/tinatool/draw/drawTv_picture.c

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

  1 /*********
  2  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  3  * University of Manchester, UK.  All rights reserved.
  4  * 
  5  * Redistribution and use in source and binary forms, with or without modification, 
  6  * are permitted provided that the following conditions are met:
  7  * 
  8  *   . Redistributions of source code must retain the above copyright notice, 
  9  *     this list of conditions and the following disclaimer.
 10  *    
 11  *   . Redistributions in binary form must reproduce the above copyright notice,
 12  *     this list of conditions and the following disclaimer in the documentation 
 13  *     and/or other materials provided with the distribution.
 14  * 
 15  *   . Neither the name of the University of Manchester nor the names of its
 16  *     contributors may be used to endorse or promote products derived from this 
 17  *     software without specific prior written permission.
 18  * 
 19  * 
 20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 30  * POSSIBILITY OF SUCH DAMAGE.
 31  *
 32  **********
 33  *
 34  * Program :    TINA
 35  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/draw/drawTv_picture.c,v $
 36  * Date    :  $Date: 2008/12/02 22:04:19 $
 37  * Version :  $Revision: 1.5 $
 38  * CVS Id  :  $Id: drawTv_picture.c,v 1.5 2008/12/02 22:04:19 paul Exp $
 39  *
 40  * Author  : Legacy TINA
 41  *
 42  * Notes :
 43  *
 44  *********
 45 */
 46 
 47 #if HAVE_CONFIG_H
 48   #include <config.h>
 49 #endif
 50 
 51 #include <stdio.h>
 52 #include <unistd.h>
 53 #include <stdlib.h>
 54 #include <tina/sys/sysDef.h>
 55 #include <tina/sys/sysPro.h>
 56 #include <tina/math/mathDef.h>
 57 #include <tina/math/mathUtil_rand.h>
 58 #include <tinatool/draw/draw_TvDef.h>
 59 #include <tinatool/draw/draw_TvPro.h>
 60 
 61 #include "drawTv_picture.h"
 62 
 63 #ifdef MINGW
 64 static void pause () {}
 65 #endif
 66 
 67 /* EXTERNS */
 68 extern void picture_write();
 69 
 70 /* Tv_picture *tv_screen_get_picture (window system specific) */
 71 extern void *tv_screen_get_picture();
 72 extern void tv_screen_show_picture();
 73 extern void picture_free();
 74 
 75 void   *tv_get_picture(Tv * tv)
 76 {
 77     if (tv == NULL)
 78         return (NULL);
 79     return (tv_screen_get_picture(tv->tv_screen));
 80 }
 81 
 82 void    tv_show_picture(Tv * tv, void *picture)
 83 {
 84     if (tv == NULL)
 85         return;
 86     tv_screen_show_picture(tv->tv_screen, picture);
 87 }
 88 
 89 void    tv_start_movie(Tv * tv)
 90 {
 91     if (tv == NULL)
 92         return;
 93     dd_list_rm(tv->movie, picture_free);
 94     tv->movie = NULL;
 95 }
 96 
 97 void    tv_make_movie(Tv * tv)
 98 {
 99     List *el;
100 
101     if (tv == NULL)
102         return;
103     el = dd_link_alloc((void *) tv_get_picture(tv), 0);
104     tv->movie = dd_list_addtoend(tv->movie, el);
105 }
106 
107 void    tv_show_movie(Tv * tv, int n)
108 {
109     List *ptr;
110     int     i;
111 
112     if (tv == NULL)
113         return;
114     for (i = 0; i < n; ++i)
115         for (ptr = tv->movie; ptr != NULL; ptr = ptr->next)
116           {
117             tv_show_picture(tv, ptr->to);
118             tv_flush(tv);
119             pause();
120           }
121 }
122 
123 
124 void    tv_random_movie(Tv * tv, int n)
125 {
126 /*
127  Timing is critical so all variable length
128  coding is done prior
129 */
130     List  *ptr, *list;
131     int     *randy;
132     int      m, i = 0, frames = 0;
133     int      c = 0, l = 0;
134 
135     if (tv == NULL || tv->movie == NULL)
136       return;
137     for (ptr = tv->movie; ptr != NULL; ptr = ptr->next)
138       frames++;
139 
140     list = (List *)ralloc(frames*sizeof(List));
141     
142     for (ptr = tv->movie; ptr != NULL; ptr = ptr->next)
143       list[i++] = *ptr;
144        
145     randy = (int *)ralloc(n*sizeof(int));
146     for (i = 0; i < n; i++)
147       {           
148         while (c == l)
149           c = rand_int(0, frames);
150         randy[i] = l = c;
151       }
152        
153     i = 0;   
154     while(i < n)
155       {
156         ptr = &(list[(randy[i])]);
157         tv_show_picture(tv, ptr->to);
158         tv_flush(tv);
159         pause();
160         i++;
161       }
162     
163     rfree(list);
164     rfree(randy);
165 }
166 
167 
168 void    tv_loop_movie(Tv * tv, int n)
169 {
170     List *ptr;
171     List *end;
172     int     i;
173 
174     if (tv == NULL || tv->movie == NULL)
175         return;
176     for (i = 0; i < abs(n); ++i)
177     {
178         for (ptr = tv->movie; ptr != NULL; ptr = ptr->next)
179         {
180             tv_show_picture(tv, ptr->to);
181             tv_flush(tv);
182             pause();
183             end = ptr;
184         }
185         if (n > 0)
186         {
187             for (ptr = end; ptr != NULL; ptr = ptr->last)
188             {
189                 tv_show_picture(tv, ptr->to);
190                 tv_flush(tv);
191                 pause();
192             }
193         }
194     }
195 }
196 
197 void    tv_picture_write(Tv * tv, FILE * fp)
198 {
199     void   *picture;
200 
201     if (tv == NULL || tv->tv_screen == NULL || fp == NULL)
202         return;
203 
204     picture = tv_get_picture(tv);
205     picture_write(fp, picture);
206     picture_free(picture);
207 }
208 
209 void   *tv_picture_read(Tv * tv, FILE * fp)
210 {
211     void   *tv_screen_picture_read();
212 
213     if (tv == NULL || tv->tv_screen == NULL || fp == NULL)
214         return (NULL);
215 
216     return (tv_screen_picture_read(tv->tv_screen, fp));
217 }
218 
219 void    tv_movie_write(Tv * tv, char *fname)
220 {
221     FILE   *fp;
222     List *ptr;
223     int     n;
224 
225     if (tv == NULL)
226         return;
227 
228     if ((fp = fopen(fname, "w")) == NULL)
229     {
230         error("tv_movie_write: cannot open file", non_fatal);
231         return;
232     }
233     n = dd_list_length(tv->movie);
234     (void) fwrite((char *) &n, sizeof(int), 1, fp);
235     for (ptr = tv->movie; ptr != NULL; ptr = ptr->next)
236         picture_write(fp, ptr->to);
237     (void) fclose(fp);
238 }
239 
240 void    tv_movie_read(Tv * tv, char *fname)
241 {
242     FILE   *fp;
243     void   *picture;
244     void   *tv_screen_picture_read();   /* Tv_picture* (window system
245                                          * specific) */
246     int     i, n;
247 
248     if (tv == NULL)
249         return;
250     if ((fp = fopen(fname, "r")) == NULL)
251     {
252         error("tv_movie_read: cannot open file", non_fatal);
253         return;
254     }
255     (void) fread((char *) &n, sizeof(int), 1, fp);
256     tv_start_movie(tv);
257     for (i = 0; i < n; i++)
258     {
259         List *el;
260 
261         picture = tv_screen_picture_read(tv->tv_screen, fp);
262         el = dd_link_alloc((void *)picture, 0);
263         tv->movie = dd_list_addtoend(tv->movie, el);
264         tv_show_picture(tv, picture);
265     }
266     (void) fclose(fp);
267 }
268 

~ [ 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.