Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
show3.c
Go to the documentation of this file.
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 LATTICE
13 #include <proto/exec.h>
14 #include <proto/intuition.h>
15 #include <proto/graphics.h>
16 #include <iffpragmas.h>
17 #endif
18 #include <iff.h>
19 
20 struct Library *IntuitionBase = NULL, *IFFBase = NULL, *OpenLibrary();
21 struct GfxBase *GfxBase = NULL;
22 
23 struct NewScreen ns =
24 {
25  0,0,0,0,0,0,0, NULL, CUSTOMSCREEN | SCREENQUIET, NULL, (STRPTR)"Show3", NULL,
26  NULL
27 };
28 
29 struct Screen *screen[3] = {NULL, NULL, NULL}, *OpenScreen();
30 APTR ifffile = NULL;
31 char *fname[3] = {NULL, NULL, NULL};
32 int fsiz = 0;
33 void CenterScreen(register struct Screen *, int *, int *);
34 
35 void
36 Fail(char *text, int status)
37 {
38  int i;
39 
40  if(ifffile) CloseIFF(ifffile);
41  if(screen[0]) CloseScreen(screen[0]);
42  if(screen[1]) CloseScreen(screen[1]);
43  if(screen[2]) CloseScreen(screen[2]);
44  if (fsiz) {
45  for (i=0; i<3; i++) {
46  if (fname[i]) FreeMem(fname[i], fsiz);
47  }
48  }
49  if (*text) {
50  printf("%s\n",text);
51  }
52  if(IFFBase) {
53  if (i = IffError()) {
54  printf("IffError = %ld\n", i);
55  }
56  CloseLibrary(IFFBase); /* MUST ALWAYS BE CLOSED !! */
57  }
58  if(IntuitionBase) CloseLibrary(IntuitionBase);
59  if(GfxBase) CloseLibrary((struct Library *)GfxBase);
60  exit(status);
61 }
62 
63 main(int argc, char *argv[])
64 {
65  long count,i;
66  int dx, dy;
67  WORD colortable[128];
68  struct BitMapHeader *bmhd;
69 
70  if(!strcmp(argv[1],"?") || ((argc !=4) && (argc != 2))) {
71  printf("Usage: %s redfile greenfile bluefile\n"
72  " %s filename (.[rgb] will be appended)\n",
73  argv[0], argv[0]);
74  exit(1);
75  }
76  if (argc == 4) {
77  for (i=0; i<3; i++) {
78  fname[i] = argv[i+1];
79  }
80  }else{
81  fsiz = strlen(argv[1]) + 3;
82  for (i=0; i<3; i++) {
83  fname[i] = AllocMem(fsiz, 0L);
84  if (!fname[i]) {
85  Fail("Can't allocate memory", 1);
86  }
87  strcpy(fname[i], argv[1]);
88  strcat(fname[i], ((i == 0) ? ".r" : ((i == 1) ? ".g" : ".b")));
89  }
90  }
91  GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0L);
92  if (!GfxBase) {
93  Fail("Can't open graphics.library", 1);
94  }
95  IntuitionBase = OpenLibrary("intuition.library",0L);
96  if (!IntuitionBase) {
97  Fail("Can't open intuition.library", 1);
98  }
99  if(!(IFFBase = OpenLibrary(IFFNAME,IFFVERSION))) {
100  Fail("Copy the iff.library to your LIBS: directory!", 1);
101  }
102 
103  for (i=0; i<3; i++) {
104  if(!(ifffile=OpenIFF(fname[i]))){
105  Fail("Error opening file", 1);
106  }
107  if(!(bmhd=GetBMHD(ifffile))) {
108  Fail("BitMapHeader not found", 1);
109  }
110  ns.Width = bmhd->w;
111  ns.Height = bmhd->h;
112  ns.Depth = bmhd->nPlanes;
113  ns.ViewModes = GetViewModes(ifffile);
114 
115  if(!(screen[i] = OpenScreen(&ns))) {
116  Fail("Can't open screen!", 1);
117  }
118  CenterScreen(screen[i], &dx, &dy);
119 
120  count = GetColorTab(ifffile,colortable);
121  if(count>32L) count = 32L; /* Some HAM pictures have 64 colors ?! */
122  LoadRGB4(&(screen[i]->ViewPort),colortable,count);
123 
124  if(!DecodePic(ifffile,&screen[i]->BitMap)) {
125  Fail("Can't decode picture", 1);
126  }
127  CloseIFF(ifffile);
128  ifffile = NULL;
129  }
130  SetTaskPri(FindTask(0L), 20L); /* Run at high priority to reduce */
131  for(;;) { /* flicker! */
132  if(!((*((UBYTE*)0xbfe001))&64)) break; /* I know it's a hack */
133  ScreenToFront(screen[0]);
134  if(!((*((UBYTE*)0xbfe001))&64)) break; /* I know it's a hack */
135  ScreenToFront(screen[1]);
136  if(!((*((UBYTE*)0xbfe001))&64)) break; /* I know it's a hack */
137  ScreenToFront(screen[2]);
138  }
139  Fail("", 0); /* Close the whole stuff */
140 }
struct NewScreen ns
Definition: show3.c:23
void main(int argc, char **argv)
Definition: aliastorle.c:121
int fsiz
Definition: show3.c:32
APTR ifffile
Definition: show3.c:30
int screen
Definition: show3.c:29
struct Library * IntuitionBase
Definition: show3.c:20
struct Library * IFFBase
Definition: show3.c:20
char * fname
Definition: read98721.c:71