--- ray/src/px/ra_pr.c 1989/09/01 12:07:48 1.2 +++ ray/src/px/ra_pr.c 1990/03/12 15:14:40 1.8 @@ -47,7 +47,7 @@ char *progname; char errmsg[128]; -COLR *inline; +COLR *inl; int xmax, ymax; @@ -102,7 +102,7 @@ char *argv[]; quiterr(errmsg); } /* get header */ - if (fread(&head, sizeof(head), 1, stdin) != 1) + if (fread((char *)&head, sizeof(head), 1, stdin) != 1) quiterr("missing header"); if (head.ras_magic != RAS_MAGIC) quiterr("bad raster format"); @@ -113,9 +113,9 @@ char *argv[]; head.ras_depth != 8) quiterr("incompatible format"); /* put header */ - printargs(argc, argv, stdout); + printargs(i, argv, stdout); putchar('\n'); - printf("-Y %d +X %d\n", ymax, xmax); + fputresolu(YMAJOR|YDECR, xmax, ymax, stdout); /* convert file */ pr2ra(&head); } else { @@ -187,7 +187,7 @@ register struct rasterfile *h; return(NULL); /* discard header */ getheader(p->fp, NULL); - if (fscanf(p->fp, "-Y %d +X %d\n", &ymax, &xmax) != 2) + if (fgetresolu(&xmax, &ymax, p->fp) != (YMAJOR|YDECR)) quiterr("bad picture size"); p->nexty = 0; p->bytes_line = 0; /* variable length lines */ @@ -203,7 +203,7 @@ register struct rasterfile *h; h->ras_maptype = RMT_EQUAL_RGB; h->ras_maplength = 256*3; /* allocate scanline */ - inline = (COLR *)emalloc(xmax*sizeof(COLR)); + inl = (COLR *)emalloc(xmax*sizeof(COLR)); return(p); } @@ -223,7 +223,7 @@ register struct rasterfile *h; else if ((p->fp = fopen(fname, "w")) == NULL) return(NULL); /* write header */ - fwrite(h, sizeof(*h), 1, p->fp); + fwrite((char *)h, sizeof(*h), 1, p->fp); p->nexty = -1; /* needs color map */ p->bytes_line = h->ras_width; p->pos.b = 0; @@ -243,7 +243,7 @@ struct rasterfile *h; scanline = (COLR *)emalloc(xmax*sizeof(COLR)); /* get color table */ for (i = 0; i < 3; i ++) - if (fread(cmap[i], h->ras_maplength/3, 1, stdin) != 1) + if (fread((char *)cmap[i], h->ras_maplength/3, 1, stdin) != 1) quiterr("error reading color table"); /* convert table */ for (i = 0; i < h->ras_maplength/3; i++) @@ -271,15 +271,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); } @@ -289,32 +287,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]; } } @@ -333,7 +314,7 @@ register pixel *l; quiterr("seek error in picwriteline"); } /* write scanline */ - if (fwrite(l, sizeof(pixel), xmax, outpic->fp) != xmax) + if (fwrite((char *)l, sizeof(pixel), xmax, outpic->fp) != xmax) quiterr("write error in picwriteline"); if (xmax&1) /* on 16-bit boundary */ putc(l[xmax-1], outpic->fp);