home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / grafik / raytracing / rayshade-4.0.6.3 / urt / amiga_extras / getami / show3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-22  |  4.2 KB  |  166 lines

  1. /*
  2.     Show3.c: display three IFF files in rapid succession continuously.
  3.     Based on showiff.c by Christian A. Weber.
  4.     Modified by Kriton Kyrimis.
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <exec/types.h>
  10. #include <graphics/gfxbase.h>
  11. #include <intuition/intuition.h>
  12. #ifdef __SASC
  13. #include <proto/exec.h>
  14. #include <proto/intuition.h>
  15. #include <proto/graphics.h>
  16. #endif
  17. #ifdef __GNUC__
  18. #include <inline/exec.h>
  19. #include <inline/intuition.h>
  20. #include <inline/graphics.h>
  21. #endif
  22. #include <iff.h>
  23.  
  24. struct IntuitionBase *IntuitionBase = NULL;
  25. struct Library *IFFBase = NULL;
  26. struct GfxBase *GfxBase = NULL;
  27.  
  28. struct NewScreen ns =
  29. {
  30.   0,0,0,0,0,0,0, NULL, AUTOSCROLL | CUSTOMSCREEN | SCREENQUIET, NULL,
  31.   (STRPTR)"Show3", NULL, NULL
  32. };
  33.  
  34. static struct TagItem ScreenTags[] = {
  35. #define DISPIDTAG 0
  36.   {SA_DisplayID, NULL},
  37.   {SA_Overscan, OSCAN_VIDEO},
  38.   {TAG_DONE, NULL}
  39. };
  40.  
  41. struct Screen *screen[3] = {NULL, NULL, NULL};
  42. IFFL_HANDLE ifffile = NULL;
  43. char *fname[3] = {NULL, NULL, NULL};
  44. int fsiz = 0;
  45.  
  46. extern int IsPAL(void);
  47.  
  48. void
  49. Fail(char *text, int status)
  50. {
  51.     int i;
  52.  
  53.     if(ifffile) IFFL_CloseIFF(ifffile);
  54.     if(screen[0]) CloseScreen(screen[0]);
  55.     if(screen[1]) CloseScreen(screen[1]);
  56.     if(screen[2]) CloseScreen(screen[2]);
  57.     if (fsiz) {
  58.       for (i=0; i<3; i++) {
  59.         if (fname[i]) FreeMem(fname[i], fsiz);
  60.       }
  61.     }
  62.     if (*text) {
  63.       printf("%s\n",text);
  64.     }
  65.     if(IFFBase) {
  66.       if (i = IFFL_IFFError()) {
  67.         printf("IffError = %ld\n", i);
  68.       }
  69.           CloseLibrary(IFFBase);    /* MUST ALWAYS BE CLOSED !! */
  70.         }
  71.     if(IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
  72.     if(GfxBase) CloseLibrary((struct Library *)GfxBase);
  73.     exit(status);
  74. }
  75.  
  76. int
  77. main(int argc, char *argv[])
  78. {
  79.   long count,i;
  80.   WORD colortable[128];
  81.   struct IFFL_BMHD *bmhd;
  82.   long oldpri;
  83.  
  84.   if(!strcmp(argv[1],"?") || ((argc !=4) && (argc != 2))) {
  85.     printf("Usage: %s redfile greenfile bluefile\n"
  86.        "       %s filename (.[rgb] will be appended)\n",
  87.        argv[0], argv[0]);
  88.     exit(1);
  89.   }
  90.   if (argc == 4) {
  91.     for (i=0; i<3; i++) {
  92.       fname[i] = argv[i+1];
  93.     }
  94.   }else{
  95.     fsiz = strlen(argv[1]) + 3;
  96.     for (i=0; i<3; i++) {
  97.       fname[i] = AllocMem(fsiz, 0L);
  98.       if (!fname[i]) {
  99.         Fail("Can't allocate memory", 1);
  100.       }
  101.       strcpy(fname[i], argv[1]);
  102.       strcat(fname[i], ((i == 0) ? ".r" : ((i == 1) ? ".g" : ".b")));
  103.     }
  104.   }
  105.   GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0L);
  106.   if (!GfxBase) {
  107.     Fail("Can't open graphics.library", 1);
  108.   }
  109.   IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0L);
  110.   if (!IntuitionBase) {
  111.     Fail("Can't open intuition.library", 1);
  112.   }
  113.   if(!(IFFBase = OpenLibrary(IFFNAME,IFFVERSION))) {
  114.     Fail("Copy the iff.library to your LIBS: directory!", 1);
  115.   }
  116.  
  117.   for (i=0; i<3; i++) {
  118.     if(!(ifffile = IFFL_OpenIFF(fname[i], IFFL_MODE_READ))){
  119.       Fail("Error opening file", 1);
  120.     }
  121.     if(!(bmhd = IFFL_GetBMHD(ifffile))) {
  122.       Fail("BitMapHeader not found", 1);
  123.     }
  124.     ns.Width      = bmhd->w;
  125.     ns.Height     = bmhd->h;
  126.     ns.Depth      = bmhd->nPlanes;
  127.     ns.ViewModes  = IFFL_GetViewModes(ifffile);
  128.  
  129.     ScreenTags[DISPIDTAG].ti_Data = ns.ViewModes;
  130.     if (IsPAL()) {
  131.       ScreenTags[DISPIDTAG].ti_Data |= PAL_MONITOR_ID;
  132.     }else{
  133.       ScreenTags[DISPIDTAG].ti_Data |= NTSC_MONITOR_ID;
  134.     }
  135.  
  136.     if(!(screen[i] = OpenScreenTagList(&ns, ScreenTags))) {
  137.       Fail("Can't open screen!", 1);
  138.     }
  139.  
  140.     count = IFFL_GetColorTab(ifffile,colortable);
  141.     if(count > 32L) count = 32L; /* Some HAM pictures have 64 colors ?! */
  142.     LoadRGB4(&(screen[i]->ViewPort), colortable, count);
  143.  
  144.     if(!IFFL_DecodePic(ifffile, &screen[i]->BitMap)) {
  145.       Fail("Can't decode picture", 1);
  146.     }
  147.     IFFL_CloseIFF(ifffile);
  148.     ifffile = NULL;
  149.   }
  150.   oldpri = SetTaskPri(FindTask(0L), 19L); /* Run at high priority to reduce */
  151.   for(;;) {                  /* flicker! */
  152.     volatile UBYTE *click = (UBYTE *)0xbfe001;
  153.     if (!(*click & 64)) break;    /* I know it's a hack */
  154.     ScreenToFront(screen[0]);
  155.     if (!(*click & 64)) break;    /* I know it's a hack */
  156.     ScreenToFront(screen[1]);
  157.     if (!(*click & 64)) break;    /* I know it's a hack */
  158.     ScreenToFront(screen[2]);
  159.   }
  160.   SetTaskPri(FindTask(0L), oldpri);
  161.   Fail("", 0); /* Close the whole stuff */
  162. #ifdef __SASC
  163.   return 0;
  164. #endif
  165. }
  166.