home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume4 / 8to1 / scload.c < prev   
Encoding:
C/C++ Source or Header  |  1989-02-03  |  6.3 KB  |  237 lines

  1. /* Compile: cc -g -o scload scload.c -lpixrect */
  2.  
  3. /**************************************************************************
  4.    The program "scload" is like Sun's "screenload" program, but more
  5.    entertaining, and actually better than screenload.
  6.  
  7.    Copyright (c) 1988 by Raymond Kreisel
  8.    7/1/88 @ Suny Stony Brook
  9.  
  10.    This program may be redistributed without fee as long as this copyright
  11.    notice is intact.
  12.  
  13. ==> PLEASE send comments and bug reports to one of the following addresses:
  14.  
  15.        Ray Kreisel
  16.        CS Dept., SUNY at Stony Brook, Stony Brook NY 11794
  17.  
  18.        UUCP: {allegra, philabs, pyramid, research}!sbcs!rayk   
  19.        ARPA-Internet: rayk@sbcs.sunysb.edu            
  20.        CSnet: rayk@suny-sb
  21.        (If nobody is home at any of the above addresses try:
  22.         S72QKRE@TOWSONVX.BITNET                    )
  23.  
  24.  "If I get home before daylight, I just might get some sleep tonight...."
  25.  
  26. **************************************************************************/
  27. #include <pixrect/pixrect_hs.h>
  28. #include <stdio.h>
  29. #include <sys/time.h>
  30. #include <sys/types.h>
  31. #include <sys/stat.h>
  32.  
  33.  
  34. int time_rand()
  35. {
  36.  struct tm *localtime(), *nowtime;
  37.  long inttime;
  38.  
  39.  inttime = time();
  40.  nowtime = localtime(&inttime);
  41.  return((int)((nowtime->tm_sec)));
  42. }
  43.  
  44.  
  45. main(argc,argv) int argc; char *argv[];
  46. {
  47. int i, my_fb = 0;
  48. char *fb, *strcpy();
  49.  
  50.    if (argc == 1) {
  51.        fprintf(stderr,"Usage: scload [-f frame_buffer] filename\n");
  52.     exit(1);
  53.    }
  54.  
  55.    if ((argv[1][0] == '-') && (argv[1][1] == 'f')) {
  56.     if (argc < 4) {
  57.            fprintf(stderr,"Usage: scload [-f frame_buffer] filename\n");
  58.        exit(1);
  59.     }
  60.     fb = strcpy((char *)malloc(strlen(argv[2])+1), argv[2]);
  61.     my_fb = 1;
  62.    }
  63.    else fb = strcpy((char *)malloc(8), "/dev/fb");
  64.    if (argc)
  65.    {
  66.    for(i=1+my_fb*2;i<argc;i++)
  67.      new_sc_load(argv[i], fb);
  68.    }
  69.    else
  70.      new_sc_load("", fb);
  71. }
  72.  
  73.  
  74. new_sc_load(filename, fb)
  75. char *filename, *fb;
  76. {
  77.   char colormapname[256];
  78.   struct rasterfile rh;
  79.   colormap_t colormap;
  80.   FILE *fp,*fopen();
  81.   int    i, j,width,height,off_x,off_y;
  82.   struct pixrect    *line, *screen, *screen_temp;
  83.   int sleep_time=500;
  84.  
  85.     srand(time_rand());
  86.     if (filename[0])
  87.     {
  88.         fp = fopen(filename,"r");
  89.         if (!fp)
  90.         {
  91.           fprintf(stderr,"error open file %s for read\n", filename);
  92.           return;
  93.         }
  94.     }
  95.     else
  96.       fp = stdin;
  97.  
  98.     screen = pr_open(fb);
  99.     if (!screen)
  100.        exit(1);
  101.  
  102.     if (screen->pr_depth > 1)
  103.     {
  104.       sleep_time = 0;
  105.       if (pr_load_header(fp,&rh)) {
  106.         perror("scload: pr_load_header");
  107.         exit(-1);
  108.         };
  109.       if (pr_load_colormap(fp,&rh,&colormap)) {
  110.         perror("scload: pr_load_colormap");
  111.         exit(-1);
  112.         };
  113.       if (!(screen_temp=pr_load_image(fp,&rh,&colormap))) {
  114.          perror("scload: pr_load_image");
  115.          exit(-1);
  116.          };
  117.       if (colormap.length)
  118.         pr_putcolormap(screen,0,rh.ras_maplength/3,colormap.map[0],
  119.                      colormap.map[1],colormap.map[2]);
  120.   
  121.     }
  122.     else
  123.     {
  124.         screen_temp = pr_load(fp,NULL);
  125.         if (!screen_temp)
  126.         {
  127.             fprintf(stderr,"Error reading rasterfile header.\n");
  128.             exit(0);
  129.         }
  130.     }
  131.     width = screen_temp->pr_size.x;
  132.     height = screen_temp->pr_size.y;
  133.     if (screen->pr_size.x > screen_temp->pr_size.x)
  134.        off_x = (screen->pr_size.x - screen_temp->pr_size.x)/2;
  135.     if (screen->pr_size.y > screen_temp->pr_size.y)
  136.        off_y = (screen->pr_size.y - screen_temp->pr_size.y)/2;
  137.  
  138.     switch(rand()%8) {  
  139.     case 0:
  140.         for (j=height-16; j > 0; j-=16)
  141.         {
  142.            pr_rop(screen,off_x,j+off_y,width,height-j,PIX_SRC,screen_temp,0,0);
  143.            usleep(sleep_time);
  144.         }
  145.         pr_rop(screen,off_x,off_y,width,height,PIX_SRC,screen_temp,0,0);
  146.         
  147.         break;
  148.     case 1:
  149.  
  150.         for (j=0; j < height; j+=32)
  151.            for (i=0; i < width; i+=32)
  152.               pr_rop(screen,i+off_x,j+off_y,16,16,PIX_SRC,screen_temp,i,j);
  153.         for (j=16; j < height; j+=32)
  154.            for (i=16; i < width; i+=32)
  155.               pr_rop(screen,i+off_x,j+off_y,16,16,PIX_SRC,screen_temp,i,j);
  156.         for (j=16; j < height; j+=32)
  157.            for (i=0; i < width; i+=32)
  158.               pr_rop(screen,i+off_x,j+off_y,16,16,PIX_SRC,screen_temp,i,j);
  159.         for (j=0; j < height; j+=32)
  160.            for (i=16; i < width; i+=32)
  161.               pr_rop(screen,i+off_x,j+off_y,16,16,PIX_SRC,screen_temp,i,j);
  162.         break;
  163.  
  164.     case 2:
  165.         for (j=height-16; j > 0; j-=16)
  166.         {
  167.        
  168.            pr_rop(screen,off_x,off_y,width,height-j,PIX_SRC,screen_temp,0,j);
  169.            usleep(sleep_time);
  170.         }
  171.         pr_rop(screen,off_x,off_y,width,height,PIX_SRC,screen_temp,0,0);
  172.         break;
  173.  
  174.     case 3:
  175.         for (j=height-16; j > 0; j-=16)
  176.         {
  177.        
  178.            pr_rop(screen,off_x,j+off_y,width/2,height-j,PIX_SRC,screen_temp,0,0);
  179.            pr_rop(screen,off_x+width/2,off_y,width/2,height-j,PIX_SRC,screen_temp,width/2,j);
  180.            usleep(sleep_time);
  181.         }
  182.         pr_rop(screen,off_x,off_y,width,height,PIX_SRC,screen_temp,0,0);
  183.         break;
  184.     case 4:
  185.         for (j=height-16; j > 0; j-=16)
  186.         {
  187.        
  188.            pr_rop(screen,off_x+width/2,j+off_y,width/2,height-j,PIX_SRC,screen_temp,width/2,0);
  189.            pr_rop(screen,off_x,off_y,width/2,height-j,PIX_SRC,screen_temp,0,j);
  190.            usleep(sleep_time);
  191.         }
  192.         pr_rop(screen,off_x,off_y,width,height,PIX_SRC,screen_temp,0,0);
  193.         break;
  194.  
  195.     case 5:
  196.         for (j=height-16; j > 0; j-=16)
  197.         {
  198.        
  199.            pr_rop(screen,off_x,off_y,width/4,height-j,PIX_SRC,screen_temp,0,j);
  200.            pr_rop(screen,off_x+width/4,j+off_y,width/4+2,height-j,PIX_SRC,screen_temp,width/4,0);
  201.            pr_rop(screen,off_x+width/4*3,j+off_y,width/4,height-j,PIX_SRC,screen_temp,width/4*3,0);
  202.            pr_rop(screen,off_x+width/2,off_y,width/4,height-j,PIX_SRC,screen_temp,width/2,j);
  203.            usleep(sleep_time);
  204.         }
  205.         pr_rop(screen,off_x,off_y,width,height,PIX_SRC,screen_temp,0,0);
  206.         break;
  207.     case 6:
  208.         for (j=height-16; j > 0; j-=16)
  209.         {
  210.        
  211.            pr_rop(screen,off_x,off_y,width/4,height-j,PIX_SRC,screen_temp,0,j);
  212.            pr_rop(screen,off_x+width/4,j+off_y,width/4,height-j,PIX_SRC,screen_temp,width/4,0);
  213.            pr_rop(screen,off_x+width/2,j+off_y,width/4,height-j,PIX_SRC,screen_temp,width/2,0);
  214.            pr_rop(screen,off_x+width/4*3,off_y,width/4,height-j,PIX_SRC,screen_temp,width/4*3,j);
  215.            usleep(sleep_time);
  216.         }
  217.         pr_rop(screen,off_x,off_y,width,height,PIX_SRC,screen_temp,0,0);
  218.         break;
  219.  
  220.     case 7:
  221.         for (j=16; j < width/2; j+=16)
  222.         {
  223.        
  224.            pr_rop(screen,off_x+width/2-j,off_y,j,height,PIX_SRC,screen_temp,0,0);
  225.            pr_rop(screen,off_x+width/2,off_y,j,height,PIX_SRC,screen_temp,width-j,0);
  226.            usleep(sleep_time);
  227.         }
  228.         pr_rop(screen,off_x,off_y,width,height,PIX_SRC,screen_temp,0,0);
  229.         break;
  230.     }
  231.  
  232.     pr_destroy(screen_temp);
  233.     pr_close(screen);
  234.         fclose(fp);
  235. }
  236.  
  237.