home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
580b.lha
/
Wasp_v1.23
/
src.LZH
/
src
/
readras.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-11-15
|
3KB
|
174 lines
/* wasp - copyright 1991 by Steven Reiz
* see wasp.c for further info,
* readras.c, 24/7/91
*/
#include "wasp.h"
/* #include "readras.sh" */
static struct {
long magic;
long width;
long height;
long depth;
long length;
long type;
long maptype;
long maplength; /* nr of bytes, always directly behind the header */
} header;
#define MAGIC 0x59a66a95
#define RASOLD 0
#define RASSTANDARD 1
#define RASBYTEENCODED 2
#define RASEXPERIMENTAL 0xffff
#define RMTNONE 0
#define RMTRAW 1
#define RMTRGB 2
#define BUFSZ 32768
static char *buf;
static long xsz1;
#ifdef __STDC__
read_ras(void)
#else
read_ras()
#endif
{
short y;
long t, t1;
cread(&header, sizeof(header));
if (header.magic!=MAGIC) {
lseek(infd, 0L, 0);
return 0;
}
xsz=header.width;
xsz1=(xsz+15)& -16L;
ysz=header.height;
printf("RAS input; %ld x %ld, depth: %ld", xsz, ysz, header.depth);
if (header.type==RASBYTEENCODED)
printf(", compressed");
if (header.maplength==0)
header.maptype=RMTNONE;
if (header.maptype!=RMTNONE)
printf(", with colormap");
putchar('\n'); fflush(stdout);
if (!outfilename)
exit(0);
if (header.depth!=1)
error0(E0_FATAL, E1_RAS, E2_FORMAT, E3_ONLYDEPTH1);
rgb=Malloc(ysz*sizeof(u_short *));
for (y=0; y<ysz; ++y)
rgb[y]=Malloc(xsz1*sizeof(u_short));
buf=Malloc(BUFSZ);
init_counter(0, (int)ysz, 10, NULL);
if (header.type==RASBYTEENCODED)
read_compressed();
else
read_normal();
erase_counter(NULL);
return 1;
}
#ifdef __STDC__
PRIVATE read_normal(void)
#else
PRIVATE read_normal()
#endif
{
short *bufp;
int bufn;
int x, y;
u_short *p;
int sh, mask;
bufn=read(infd, buf, BUFSZ)/2;
bufp=(short *)buf;
for (y=0; y<ysz; ++y) {
counter();
x=xsz1/16-1;
p=rgb[y];
do {
if (--bufn<0) {
bufp=(short *)buf;
bufn=read(infd, buf, BUFSZ)/2;
if (bufn<=0)
error0(E0_FATAL, E1_RAS, E2_FORMAT, E3_UNEXPEND);
}
sh= *bufp++;
mask=0x8000;
do {
*p++ =(sh&mask ? 0 : 0xfff);
mask>>=1;
} while (mask);
} while (--x>=0);
}
}
#ifdef __STDC__
PRIVATE read_compressed(void)
#else
PRIVATE read_compressed()
#endif
{
u_char *bufp;
int bufn;
int x, y;
u_short *p;
int sh, mask, count;
bufn=read(infd, buf, BUFSZ);
bufp=(u_char *)buf;
y=0;
counter();
x=xsz-1;
p=rgb[y];
do {
if (--bufn<0) {
bufp=(u_char *)buf;
bufn=read(infd, buf, BUFSZ);
if (bufn<=0)
error0(E0_FATAL, E1_RAS, E2_FORMAT, E3_UNEXPEND);
}
sh= *bufp++;
if (sh==0x80) {
if (--bufn<0) {
bufp=(u_char *)buf;
bufn=read(infd, buf, BUFSZ);
if (bufn<=0)
error0(E0_FATAL, E1_RAS, E2_FORMAT, E3_UNEXPEND);
}
if (count= *bufp++) {
if (--bufn<0) {
bufp=(u_char *)buf;
bufn=read(infd, buf, BUFSZ);
if (bufn<=0)
error0(E0_FATAL, E1_RAS, E2_FORMAT, E3_UNEXPEND);
}
sh= *bufp++;
}
} else
count=0;
do {
mask=0x80;
do {
*p++ =(sh&mask ? 0 : 0xfff);
if (--x<0) {
++y;
if (y>=ysz)
return;
counter();
x=xsz-1;
p=rgb[y];
mask=0; count=0;
}
mask>>=1;
} while (mask);
} while (--count>=0);
} while (1);
}