home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- * *
- * Copyright (c) 1988, David B. Wecker *
- * All Rights Reserved *
- * *
- * This file is part of DBW_uRAY *
- * *
- * DBW_uRAY is distributed in the hope that it will be useful, but *
- * WITHOUT ANY WARRANTY. No author or distributor accepts *
- * responsibility to anyone for the consequences of using it or for *
- * whether it serves any particular purpose or works at all, unless *
- * he says so in writing. Refer to the DBW_uRAY General Public *
- * License for full details. *
- * *
- * Everyone is granted permission to copy, modify and redistribute *
- * DBW_uRAY, but only under the conditions described in the *
- * DBW_uRAY General Public License. A copy of this license is *
- * supposed to have been given to you along with DBW_uRAY so you *
- * can know your rights and responsibilities. It should be in a file *
- * named COPYING. Among other things, the copyright notice and this *
- * notice must be preserved on all copies. *
- ************************************************************************
- * *
- * Authors: *
- * DBW - David B. Wecker *
- * *
- * Versions: *
- * V1.0 881023 DBW - First released version *
- * V1.1 881110 DBW - Fixed scan coherence code *
- * V1.2 881125 DBW - Removed ALL scan coherence code (useless) *
- * added "fat" extent boxes *
- * *
- ************************************************************************/
-
- #define VERSION "uRAY v1.0 881029 (C) 1988 D. Wecker - all rights reserved\n"
-
- /************************************************************************/
- /************* program to display IFF/ILBM files on an AMIGA ************/
- /************************************************************************/
-
- #include <stdio.h>
- #include <intuition/intuitionbase.h>
- #include <functions.h>
-
- #define BPP 4 /* Bits per pixel */
- #define DEPTH 6 /* HAM screen depth */
-
- #define MAXGRAY (1 << BPP)
- #define ABS(x) ((x) < 0 ? -(x) : (x))
- #define MIN(a,b) ((a) < (b) ? (a) : (b))
- #define MAX(a,b) ((a) > (b) ? (a) : (b))
-
- /* chunk sizes */
- long FORMsize,BODYsize,CAMGsize,CMAPsize,BMHDsize;
-
- FILE *fp;
- short bytcnt,val;
- unsigned char chr,buf[128],*planes[DEPTH];
- char cod,str[10],colors[256][3];
- unsigned long class;
- unsigned short code;
- unsigned char docompress,depth;
- short ham,lace,hires;
- short width,height,top,left,maxbyte;
- long modes;
-
- /*********************** 68000 I/O routines ******************************/
-
- void wfil(fil,cnt,val) /* write a number to a file (68000 order) */
- FILE *fil;
- short cnt;
- char val[];
- {
- #ifdef MCH_AMIGA
- fwrite(val,cnt,1,fil);
- #else
- while (cnt--) fwrite(&val[cnt],1,1,fil);
- #endif
- }
-
- short rfil(fil,cnt,val) /* read a number from a file (68000 order) */
- FILE *fil;
- short cnt;
- char val[];
- {
-
- #ifdef MCH_AMIGA
- if (fread(val,cnt,1,fil) != 1) return(-1);
- #else
- while (cnt--) if (fread(&val[cnt],1,1,fil) != 1) return(-1);
- #endif
-
- return(0);
- }
-
- /************************* structure defs *********************************/
-
- struct GfxBase *GfxBase;
- struct IntuitionBase *IntuitionBase;
- struct RastPort *rp;
- struct ViewPort *vp;
- struct Screen *screen;
- struct NewScreen ns = {
- 0L,0L,352L,464L,6L,
- 0,1,HAM|LACE,
- CUSTOMSCREEN,NULL,
- (UBYTE *)"uRAY Display",
- NULL,NULL };
-
-
- /* leave program and return all resources */
- error(lev,msg)
- short lev;
- char *msg;
- {
- switch (lev) {
-
- case 5:
- CloseScreen(screen);
- RemakeDisplay();
-
- case 4:
- CloseLibrary(IntuitionBase);
-
- case 3:
- CloseLibrary(GfxBase);
-
- case 2:
-
- case 1:
- if (fp != NULL) fclose(fp);
-
- case 0:
- if (msg) {
- fprintf(stderr,"display: %s\n",msg);
- exit(2);
- }
- }
- exit(0);
- }
-
- main(argc,argv)
- int argc;
- char **argv;
- {
- char f1[40],f2[40],fname[80];
- short i,j,k,modulo;
-
- printf(VERSION);
- printf("\n\t(Type <return> to end display)\n\n");
-
-
- if (argc < 2) strcpy(fname,"uray");
- else strcpy(fname,argv[1]);
- strcat(fname,".ilbm");
- fp = fopen(fname, "r");
- if (fp == NULL) error(1,"Error opening input file");
-
- /* here is where we read the ILBM file in */
- if (fread(str,1,4,fp) != 4 || strncmp(str,"FORM",4) != 0) error(2,"no FORM");
- if (rfil(fp,4,&FORMsize)) error(2,"no FORM length");
- if (fread(str,1,4,fp) != 4 || strncmp(str,"ILBM",4) != 0) error(2,"no ILBM");
-
- if (fread(str,1,4,fp) != 4 || strncmp(str,"BMHD",4) != 0) error(2,"no BMHD");
- if (rfil(fp,4,&BMHDsize) || BMHDsize != 20L) error(2,"bad BMHD length");
- if (rfil(fp,2,&width)) error(2,"bad BMHD");
- if (rfil(fp,2,&height)) error(2,"bad BMHD");
- if (rfil(fp,2,&top)) error(2,"bad BMHD");
- if (rfil(fp,2,&left)) error(2,"bad BMHD");
- if (rfil(fp,1,&depth)) error(2,"bad BMHD");
- if (rfil(fp,1,buf)) error(2,"bad BMHD");
- if (rfil(fp,1,&docompress)) error(2,"bad BMHD");
- if (rfil(fp,9,buf)) error(2,"bad BMHD");
- maxbyte = width >> 3;
- if (docompress != 0 && docompress != 1)
- error(2,"Unknown compression technique");
- if (depth < 1 || depth > 6) error(2,"Bad depth!!");
-
- if (fread(str,1,4,fp) != 4 || strncmp(str,"CAMG",4) != 0) error(2,"no CAMG");
- if (rfil(fp,4,&CAMGsize) || CAMGsize != 4L) error(2,"bad CAMG length");
- if (rfil(fp,4,&modes)) error(2,"can't read in CAMG");
- if (modes & HIRES) hires = 1;
- else hires = 0;
- if (modes & HAM) ham = 1;
- else ham = 0;
- if (modes & LACE) lace = 1;
- else lace = 0;
- ns.ViewModes = modes;
- ns.Depth = (long)depth;
- ns.TopEdge = (long)top;
- if (height > 464) ns.Height = (long)height;
- if (width > 352) ns.Width = (long)width;
- if (width < 352) modulo = (352 >> 3) - maxbyte;
- else modulo = 0;
-
- /* set up to display the image */
- GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0L);
- if (GfxBase == NULL) error(2,"No graphics library");
- IntuitionBase =
- (struct IntuitionBase *)OpenLibrary("intuition.library",0L);
- if (IntuitionBase == NULL) error(3,"No intuition library");
- screen = (struct Screen *)OpenScreen(&ns);
- if (screen == NULL) error(4,"Can't open screen");
-
- vp = &screen->ViewPort;
- rp = &screen->RastPort;
-
- if (lace && height > 400) vp->DyOffset += (400 - height) >> 1;
- if (lace == 0 && height > 200) vp->DyOffset += (200 - height) >> 1;
- if (hires && width > 640) vp->DxOffset += (640 - width) >> 1;
- if (hires == 0 && width > 320) vp->DxOffset += (320 - width) >> 1;
-
- RemakeDisplay();
-
- if (fread(str,1,4,fp) != 4 || strncmp(str,"CMAP",4) != 0) error(5,"no CMAP");
- if (rfil(fp,4,&CMAPsize)) error(5,"bad CMAP length");
- CMAPsize /= 3;
- for (i = 0; i < CMAPsize; i++) {
- if (fread(str,1,3,fp) != 3) error(5,"can't read in color table");
- colors[i][0] = (str[0] >> 4) & 0xF;
- colors[i][1] = (str[1] >> 4) & 0xF;
- colors[i][2] = (str[2] >> 4) & 0xF;
- if (i < 16 || ham == 0)
- SetRGB4(vp, (long)i,
- (long)colors[i][0],
- (long)colors[i][1],
- (long)colors[i][2]);
- }
-
- if (fread(str,1,4,fp) != 4 || strncmp(str,"BODY",4) != 0) error(5,"no BODY");
- if (rfil(fp,4,&BODYsize)) error(5,"bad BODY length");
-
-
- for (i = 0; i < depth; i++) {
- planes[i] = (unsigned char *)rp->BitMap->Planes[i];
- }
-
- for (i = 0; i < height; i++) {
- for (j = 0; j < depth; j++) {
-
- if (docompress) {
- bytcnt = 0;
-
- while (bytcnt < maxbyte) {
- if (fread(&cod,1,1,fp) != 1) goto DONE;
- val = (short)cod;
-
- if (val >= 0) {
- val++;
- if (fread(planes[j],1,val,fp) != val) goto DONE;
- }
- else if (val > -128) {
- val = (-val) + 1;
- if (fread(&chr,1,1,fp) != 1) goto DONE;
- for (k = 0; k < val; k++) planes[j][k] = chr;
- }
- else val = 0;
-
- bytcnt += val;
- planes[j] += val;
- if (bytcnt > maxbyte) error(5,"Bad run/dump count");
- }
- }
- else {
- if (fread(planes[j],1,maxbyte,fp) != maxbyte) goto DONE;
- planes[j] += maxbyte;
- }
- planes[j] += modulo; /* take care of undersized image */
- }
- }
- DONE:
- fclose(fp);
- RemakeDisplay();
-
-
- /* wait here until we get a close window message */
- getchar();
- error(5,NULL);
- }
-