--- ray/src/px/ra_t8.c 1989/10/20 20:36:06 1.3 +++ ray/src/px/ra_t8.c 1991/04/18 14:35:45 1.9 @@ -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,8 @@ char *argv[]; quiterr(errmsg); } /* put header */ - printargs(argc, argv, stdout); + printargs(i, argv, stdout); + fputformat(COLRFMT, stdout); putchar('\n'); fputresolu(YMAJOR|YDECR, xmax, ymax, stdout); /* convert file */ @@ -227,7 +232,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) @@ -278,10 +283,10 @@ register struct hdStruct *h; p->fp = stdin; else if ((p->fp = fopen(fname, "r")) == NULL) return(NULL); - /* discard header */ - getheader(p->fp, NULL); - if (fgetresolu(&xmax, &ymax, p->fp) != (YMAJOR|YDECR)) - quiterr("bad picture size"); + /* get header info. */ + if (checkheader(p->fp, COLRFMT, NULL) < 0 || + fgetresolu(&xmax, &ymax, p->fp) != (YMAJOR|YDECR)) + quiterr("bad picture format"); p->nexty = 0; p->bytes_line = 0; /* variable length lines */ p->pos.y = (long *)ecalloc(ymax, sizeof(long)); @@ -300,7 +305,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 +325,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++) @@ -364,7 +369,7 @@ register rgbpixel *l3; 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); } @@ -374,15 +379,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 */ - normcolrs(inline, xmax); + normcolrs(inl, xmax, 0); for (i = 0; i < xmax; i++) { - l3[i].r = inline[i][RED]; - l3[i].g = inline[i][GRN]; - l3[i].b = inline[i][BLU]; + l3[i].r = inl[i][RED]; + l3[i].g = inl[i][GRN]; + l3[i].b = inl[i][BLU]; } } @@ -391,7 +396,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)); } @@ -401,7 +406,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; } @@ -418,7 +423,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; } @@ -461,7 +466,7 @@ colormap map; register int i, val; for (i = 0; i < 256; i++) { - val = pow(i/256.0, 1.0/gamma) * 256.0; + val = pow((i+0.5)/256.0, 1.0/gamma) * 256.0; map[0][i] = map[1][i] = map[2][i] = val; } }