home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GRIPS 2: Government Rast…rocessing Software & Data
/
GRIPS_2.cdr
/
dos
/
imcomp
/
display.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-12-29
|
9KB
|
424 lines
/* =======================================================================*
* imcomp.c (from imgiotar.c and others) by Dai 5/11/87*
* =======================================================================*/
/* Modified by M. Krogh, NCSA, June 3, 1988 */
/* This source will make either the display driver for the Number Nine */
/* Revolution 512 Graphics board or the Targa M8 Graphics board. Both */
/* boards are designed to work in an IBM PC or compatible. */
/* If 'TARGAM8' is defined, this source will compile for the M8 board. */
/* If 'NINE8' is defined, this source will compile for the #9 board. */
#define TARGAM8 1
/* #define NINE8 1 */
#include "def.h"
#include <fcntl.h>
#define DISKIO 1
#include "diskio.h"
#include "tardev.h"
#include "targah.h"
#ifdef TARGAM8
int sw= 0;
#else
int sw= 1; /* for number 9 need to flip image */
#endif
#ifdef TARGAM8
struct M8Struct *m8;
/* krogh - next line added. */
extern struct TARStruct *targa;
#endif
/*-------------------------------------------------------------------------*/
COLSIZE rbuff[1024];
COLSIZE bline[1024],gbuff[256];
main(argc,argv)
int argc; char *argv[];
{
char fnam[20];
if (--argc)
{
strcpy(fnam,*(++argv));
}
else
{
printf("syntax: imcomp filename.ext\n");
exit(1);
}
#ifdef TARGAM8
GraphInit(-1); /* INITIALIZE TARGA BOARD */
#endif
slutone();
zgetimg(fnam);
exit(0);
}
/**********************
* GETIMAGE *
**********************/
/*=======================================================================*/
zgetimg(fname)
char *fname;
/*=======================================================================*/
{
register int fd;
int i, xstart, ystart, xsize, ysize, y, nbytes;
unsigned char *r, *g, *b;
unsigned char *q, *rz;
int x;
int sx,sy,j,k;
int lutarr = 0;
unsigned int temp;
char tst[20];
if ((fd = open(fname,O_RDONLY|O_BINARY)) == ERROR)
{
fprintf(stderr,"can't open file %s\n",fname);
return;
}
if (read(fd,tst,16) == ERROR)
{
close(fd);
fprintf(stderr,"read error\n");
return;
}
for(sx= 0; sx<8; sx++)
{
if (tst[sx]==' ')
tst[sx] = '0';
}
sx = tst[0] - '0';
sx = sx + (tst[1] - '0') * 10;
sx = sx + (tst[2] - '0') * 100;
sx = sx + (tst[3] - '0') * 1000;
sy = tst[4] - '0';
sy = sy + (tst[5] - '0') * 10;
sy = sy + (tst[6] - '0') * 100;
sy = sy + (tst[7] - '0') * 1000;
lseek(fd,(long)(1024+16),0);
xsize = sx;
ysize = sy;
xstart = 0;
ystart = 0;
sy = sy / 4;
nbytes = 1<<TNUMB;
q = (unsigned char *)bline;
if (tst[11] == 'I' && tst[10] == 'F' && tst[9] == '8')
{
if (sw)
{
for(y= ystart+ysize-1; y>=ystart; --y)
{
if (read(fd,q,nbytes*xsize) == ERROR)
{
close(fd);
fprintf(stderr,"read error\n");
return;
}
pline(xstart,y,bline,xsize,0);
}
}
else
{
for(y= ystart; y <= ystart+ysize-1; ++y)
{
if (read(fd,q,nbytes*xsize) == ERROR)
{
close(fd);
fprintf(stderr,"read error\n");
return;
}
pline(xstart,y,bline,xsize,0);
}
}
}
else if(tst[11] == 'I' && tst[10] == 'F' && tst[9] == '2')
{
if (sw)
y = ystart + ysize - 1;
else
y = ystart;
for(; sy>0; sy--)
{
if (read(fd,q,sx) == ERROR)
{
close(fd);
fprintf(stderr,"read error\n");
return;
}
for(i= 3; i>=0; i--)
{
k = 0;
for(j= 0; j<sx; j= j+4)
{
rz = (char *) &temp;
*rz++ = bline[j+2];
*rz = bline[j+3];
temp = temp >> (i * 4);
if (temp & 010) rbuff[k++] = bline[j+1];
else rbuff[k++] = bline[j];
if (temp & 04) rbuff[k++] = bline[j+1];
else rbuff[k++] = bline[j];
if (temp & 02) rbuff[k++] = bline[j+1];
else rbuff[k++] = bline[j];
if (temp & 01) rbuff[k++] = bline[j+1];
else rbuff[k++] = bline[j];
} /* for j */
pline(xstart,y,rbuff,xsize,0);
if (sw)
y--;
else
y++;
} /* for i */
} /* for ; */
}
else
{
close(fd);
fprintf(stderr,"wrong image file\n");
return;
/* return(cerror(-1,"wrong image file")); */
}
lseek(fd,(long)(16),0);
if (read(fd,bline,1024) == ERROR)
{
close(fd);
fprintf(stderr,"read error\n");
return;
}
r = (unsigned char *) rbuff;
g = (unsigned char *) gbuff;
b = (unsigned char *) fname;
for(i = 0; i < 1024; ++r,++g,++b)
{
*b = bline[i++];
*g = bline[i++];
*r = bline[i++];
i++;
}
r = r - 256;
g = g - 256;
b = b - 256;
zputmap(0,r,g,b,0);
close(fd);
return;
} /* zgetimg::end TARGAM8 */
/**************** pline *********************
* copy a horizontal run of pixels from memory
* onto the screen.
*********************************************/
pline(x, y, bl, xs, xm)
int x, y, xs, xm;
COLSIZE *bl;
{
register COLSIZE *addr;
addr = POINT(x,y);
memcpy(addr,bl,xs<<TNUMB);
}
#ifdef TARGAM8
zgetmap(io,r,g,b, num)
char *r, *g, *b;
int num, io;
{
int tempMap;
SetM8Index(0); /* Select the starting index */
SetM8Function(11); /* access the input lookup table (*/
tempMap = m8->inMap;
FASTVWait(); /* wait for vertical blanking */
SetM8OutMap(num&7); /* select the desired map */
SetM8Function(8);
getmap(targa->iobase+M8READ,256,r);
SetM8Index(0); /* Select the starting index */
SetM8Function(9);
getmap(targa->iobase+M8READ,256,g);
SetM8Index(0); /* Select the starting index */
SetM8Function(10);
getmap(targa->iobase+M8READ,256,b);
SetM8InMap(tempMap);
}
zputmap(io,r,g,b, num)
char *r, *g, *b;
int num, io;
{
int tempMap;
if(io) /* if input map load... */
{
SetM8Index(0); /* Select the starting index */
if ( (tempMap = m8->inMap) != num )
{
FASTVWait(); /* wait for vertical blanking */
SetM8InMap(num); /* select the desired map */
SetM8Function(8);
}
else
{
SetM8Function(8);
FASTVWait();
}
putmap(targa->iobase+M8WRITE,256,r);
SetM8InMap(tempMap);
return;
}
else /* output a map */
{
tempMap = m8->inMap;
FASTVwait();
SetM8Index(0); /* Select the starting index */
SetM8Function(11); /* access the input lookup table (*/
SetM8OutMap(num & 7); /* select the desired map */
SetM8Function(8);
pputmap(targa->iobase+M8WRITE,256,r);
SetM8Function(9);
pputmap(targa->iobase+M8WRITE,256,g);
SetM8Function(10);
pputmap(targa->iobase+M8WRITE,256,b);
SetM8InMap(tempMap);
return;
}
}
/*
* FASTVWait: Wait for next Border Region at the
* Bottom of a Screen
*
*/
extern int GetLine();
FASTVwait()
{
while (GetLine(RASTERREG) <240);
}
pputmap(io, count, array)
int io; /* array in IO space to Write to */
int count; /* Number of bytes to read */
char *array; /* pointer to byte array */
{
int i,j;
for(j=0; j<8; j++)
{
FASTVwait();
for (i=0; i<32; i++)
OUTPORTB(io,*(array++));
}
return;
}
#endif
#ifdef NINE8
zputmap(io,r,g,b, num)
char *r, *g, *b;
int num, io;
{
/* char *memcpy(); */
while(!(*NNSTATS & NNVBIT));
memcpy(NNRED,r,256);
while(!(*NNSTATS & NNVBIT));
memcpy(NNGRN,g,256);
while(!(*NNSTATS & NNVBIT));
memcpy(NNBLU,b,256);
}
#endif
slutone()
{
#ifdef TARGAM8
int i;
unsigned char r[256], g[256], b[256], bw[256];
for (i = 0; i < 64; i++)
bw[i] = i;
for (i = 0; i < 64; i++) {
r[i] = g[i] = b[i] = i*4; /* black and white */
}
for (i = 64; i < 96; i++) {
r[i] = (i-64)*8; /* RED */
g[i] = b[i] = 0;
}
for (i = 96; i <128; i++) {
g[i] = (i-96)*8; /* green */
r[i] = b[i] = 0;
}
for (i = 128; i <160; i++) {
b[i] = (i-128)*8; /* BLUE */
g[i] = r[i] = 0;
}
for (i = 160; i <192; i++) {
r[i] = b[i] = (i-160)*8; /* magenta */
g[i] = 0;
}
for (i = 192; i < 224; i++) {
b[i] = g[i] = (i-192)*8; /* CYAN */
r[i] = 0;
}
for (i = 224; i < 256; i++) {
g[i] = r[i] = (i-224)*8; /* YELLOW */
b[i] = 0;
}
/* write it out */
/* PutM8BWAll(0,0); setup input map */
zputmap(1,bw,bw,bw,1);
zputmap(0,bw,bw,bw,1);
zputmap(0,r,g,b,0); /* first arg is output/input */
return;
#endif
#ifdef NINE8
int i;
unsigned char r[256], g[256], b[256];
for (i = 0; i < 64; i++) {
r[i] = g[i] = b[i] = i*4; /* black and white */
}
for (i = 64; i < 96; i++) {
r[i] = (i-64)*8; /* RED */
g[i] = b[i] = 0;
}
for (i = 96; i <128; i++) {
g[i] = (i-96)*8; /* green */
r[i] = b[i] = 0;
}
for (i = 128; i <160; i++) {
b[i] = (i-128)*8; /* BLUE */
g[i] = r[i] = 0;
}
for (i = 160; i <192; i++) {
r[i] = b[i] = (i-160)*8; /* magenta */
g[i] = 0;
}
for (i = 192; i < 224; i++) {
b[i] = g[i] = (i-192)*8; /* CYAN */
r[i] = 0;
}
for (i = 224; i < 256; i++) {
g[i] = r[i] = (i-224)*8; /* YELLOW */
b[i] = 0;
}
/* write it out */
zputmap(0,r,g,b,0);
#endif
}