--- ray/src/px/ra_t8.c 1989/09/12 13:04:38 1.2 +++ ray/src/px/ra_t8.c 1990/03/12 15:14:46 1.7 @@ -19,6 +19,10 @@ static char SCCSid[] = "$SunId$ LBL"; #include "targa.h" +#ifndef BSD +#define bcopy(s,d,n) (void)memcpy(d,s,n) +extern char *memcpy(); +#endif /* descriptor for a picture file or frame buffer */ typedef struct { char *name; /* file name */ @@ -55,7 +59,7 @@ char *progname; char errmsg[128]; -COLR *inline; +COLR *inl; pixel *tarData; @@ -120,7 +124,7 @@ char *argv[]; quiterr(errmsg); } /* put header */ - printargs(argc, argv, stdout); + printargs(i, argv, stdout); putchar('\n'); fputresolu(YMAJOR|YDECR, xmax, ymax, stdout); /* convert file */ @@ -227,7 +231,7 @@ register FILE *fp; if (ip != NULL) if (nidbytes) - fread(ip, nidbytes, 1, fp); + fread((char *)ip, nidbytes, 1, fp); else *ip = '\0'; else if (nidbytes) @@ -300,7 +304,7 @@ register struct hdStruct *h; h->dataBits = 8; h->imType = 0; /* allocate scanline */ - inline = (COLR *)emalloc(xmax*sizeof(COLR)); + inl = (COLR *)emalloc(xmax*sizeof(COLR)); /* allocate targa data */ tarData = taralloc(h); @@ -320,8 +324,8 @@ struct hdStruct *hp; register int i, j; /* get color table */ - if ((hp->CMapBits==24 ? fread(map.c3, sizeof(map.c3), 1, stdin) : - fread(map.c4, sizeof(map.c4), 1, stdin)) != 1) + if ((hp->CMapBits==24 ? fread((char *)map.c3,sizeof(map.c3),1,stdin) : + fread((char *)map.c4,sizeof(map.c4),1,stdin)) != 1) quiterr("error reading color table"); /* convert table */ for (i = hp->mapOrig; i < hp->mapOrig+hp->mapLength; i++) @@ -358,15 +362,13 @@ picreadline3(y, l3) /* read in 3-byte scanline */ int y; register rgbpixel *l3; { - register BYTE *l4; - register int shift, c; - int i; + register int i; - if (inpic->nexty != y) { /* find scanline */ + if (inpic->nexty != y) { /* find scanline */ if (inpic->bytes_line == 0) { if (inpic->pos.y[y] == 0) { while (inpic->nexty < y) { - if (freadcolrs(inline, xmax, inpic->fp) < 0) + if (freadcolrs(inl, xmax, inpic->fp) < 0) quiterr("read error in picreadline3"); inpic->pos.y[++inpic->nexty] = ftell(inpic->fp); } @@ -376,32 +378,15 @@ register rgbpixel *l3; quiterr("seek error in picreadline3"); } else if (inpic->bytes_line == 0 && inpic->pos.y[inpic->nexty] == 0) inpic->pos.y[inpic->nexty] = ftell(inpic->fp); - if (freadcolrs(inline, xmax, inpic->fp) < 0) /* read scanline */ + if (freadcolrs(inl, xmax, inpic->fp) < 0) /* read scanline */ quiterr("read error in picreadline3"); inpic->nexty = y+1; /* convert scanline */ - for (l4=inline[0], i=xmax; i--; l4+=4, l3++) { - shift = l4[EXP] - COLXS; - if (shift >= 8) { - l3->r = l3->g = l3->b = 255; - } else if (shift <= -8) { - l3->r = l3->g = l3->b = 0; - } else if (shift > 0) { - c = l4[RED] << shift; - l3->r = c > 255 ? 255 : c; - c = l4[GRN] << shift; - l3->g = c > 255 ? 255 : c; - c = l4[BLU] << shift; - l3->b = c > 255 ? 255 : c; - } else if (shift < 0) { - l3->r = l4[RED] >> -shift; - l3->g = l4[GRN] >> -shift; - l3->b = l4[BLU] >> -shift; - } else { - l3->r = l4[RED]; - l3->g = l4[GRN]; - l3->b = l4[BLU]; - } + normcolrs(inl, xmax, 0); + for (i = 0; i < xmax; i++) { + l3[i].r = inl[i][RED]; + l3[i].g = inl[i][GRN]; + l3[i].b = inl[i][BLU]; } } @@ -410,7 +395,7 @@ picwriteline(y, l) /* save output scanline */ int y; pixel *l; { - bcopy(l, &tarData[(ymax-1-y)*xmax], xmax*sizeof(pixel)); + bcopy((char *)l, (char *)&tarData[(ymax-1-y)*xmax], xmax*sizeof(pixel)); } @@ -420,7 +405,7 @@ pixel *d; FILE *fp; { if (h->dataType == IM_CMAP) { /* uncompressed */ - if (fwrite(d, h->x*sizeof(pixel), h->y, fp) != h->y) + if (fwrite((char *)d,h->x*sizeof(pixel),h->y,fp) != h->y) quiterr("error writing targa file"); return; } @@ -437,7 +422,7 @@ FILE *fp; register pixel *dp; if (h->dataType == IM_CMAP) { /* uncompressed */ - if (fread(data, h->x*sizeof(pixel), h->y, fp) != h->y) + if (fread((char *)data,h->x*sizeof(pixel),h->y,fp) != h->y) goto readerr; return; }