19 |
|
|
20 |
|
#include "targa.h" |
21 |
|
|
22 |
+ |
#ifndef BSD |
23 |
+ |
#define bcopy(s,d,n) (void)memcpy(d,s,n) |
24 |
+ |
extern char *memcpy(); |
25 |
+ |
#endif |
26 |
|
/* descriptor for a picture file or frame buffer */ |
27 |
|
typedef struct { |
28 |
|
char *name; /* file name */ |
126 |
|
/* put header */ |
127 |
|
printargs(argc, argv, stdout); |
128 |
|
putchar('\n'); |
129 |
< |
printf("-Y %d +X %d\n", ymax, xmax); |
129 |
> |
fputresolu(YMAJOR|YDECR, xmax, ymax, stdout); |
130 |
|
/* convert file */ |
131 |
|
tg2ra(&head); |
132 |
|
} else { |
231 |
|
|
232 |
|
if (ip != NULL) |
233 |
|
if (nidbytes) |
234 |
< |
fread(ip, nidbytes, 1, fp); |
234 |
> |
fread((char *)ip, nidbytes, 1, fp); |
235 |
|
else |
236 |
|
*ip = '\0'; |
237 |
|
else if (nidbytes) |
284 |
|
return(NULL); |
285 |
|
/* discard header */ |
286 |
|
getheader(p->fp, NULL); |
287 |
< |
if (fscanf(p->fp, "-Y %d +X %d\n", &ymax, &xmax) != 2) |
287 |
> |
if (fgetresolu(&xmax, &ymax, p->fp) != (YMAJOR|YDECR)) |
288 |
|
quiterr("bad picture size"); |
289 |
|
p->nexty = 0; |
290 |
|
p->bytes_line = 0; /* variable length lines */ |
324 |
|
register int i, j; |
325 |
|
|
326 |
|
/* get color table */ |
327 |
< |
if ((hp->CMapBits==24 ? fread(map.c3, sizeof(map.c3), 1, stdin) : |
328 |
< |
fread(map.c4, sizeof(map.c4), 1, stdin)) != 1) |
327 |
> |
if ((hp->CMapBits==24 ? fread((char *)map.c3,sizeof(map.c3),1,stdin) : |
328 |
> |
fread((char *)map.c4,sizeof(map.c4),1,stdin)) != 1) |
329 |
|
quiterr("error reading color table"); |
330 |
|
/* convert table */ |
331 |
|
for (i = hp->mapOrig; i < hp->mapOrig+hp->mapLength; i++) |
362 |
|
int y; |
363 |
|
register rgbpixel *l3; |
364 |
|
{ |
365 |
< |
register BYTE *l4; |
362 |
< |
register int shift, c; |
363 |
< |
int i; |
365 |
> |
register int i; |
366 |
|
|
367 |
< |
if (inpic->nexty != y) { /* find scanline */ |
367 |
> |
if (inpic->nexty != y) { /* find scanline */ |
368 |
|
if (inpic->bytes_line == 0) { |
369 |
|
if (inpic->pos.y[y] == 0) { |
370 |
|
while (inpic->nexty < y) { |
382 |
|
quiterr("read error in picreadline3"); |
383 |
|
inpic->nexty = y+1; |
384 |
|
/* convert scanline */ |
385 |
< |
for (l4=inline[0], i=xmax; i--; l4+=4, l3++) { |
386 |
< |
shift = l4[EXP] - COLXS; |
387 |
< |
if (shift >= 8) { |
388 |
< |
l3->r = l3->g = l3->b = 255; |
389 |
< |
} else if (shift <= -8) { |
388 |
< |
l3->r = l3->g = l3->b = 0; |
389 |
< |
} else if (shift > 0) { |
390 |
< |
c = l4[RED] << shift; |
391 |
< |
l3->r = c > 255 ? 255 : c; |
392 |
< |
c = l4[GRN] << shift; |
393 |
< |
l3->g = c > 255 ? 255 : c; |
394 |
< |
c = l4[BLU] << shift; |
395 |
< |
l3->b = c > 255 ? 255 : c; |
396 |
< |
} else if (shift < 0) { |
397 |
< |
l3->r = l4[RED] >> -shift; |
398 |
< |
l3->g = l4[GRN] >> -shift; |
399 |
< |
l3->b = l4[BLU] >> -shift; |
400 |
< |
} else { |
401 |
< |
l3->r = l4[RED]; |
402 |
< |
l3->g = l4[GRN]; |
403 |
< |
l3->b = l4[BLU]; |
404 |
< |
} |
385 |
> |
normcolrs(inline, xmax); |
386 |
> |
for (i = 0; i < xmax; i++) { |
387 |
> |
l3[i].r = inline[i][RED]; |
388 |
> |
l3[i].g = inline[i][GRN]; |
389 |
> |
l3[i].b = inline[i][BLU]; |
390 |
|
} |
391 |
|
} |
392 |
|
|
395 |
|
int y; |
396 |
|
pixel *l; |
397 |
|
{ |
398 |
< |
bcopy(l, &tarData[(ymax-1-y)*xmax], xmax*sizeof(pixel)); |
398 |
> |
bcopy((char *)l, (char *)&tarData[(ymax-1-y)*xmax], xmax*sizeof(pixel)); |
399 |
|
} |
400 |
|
|
401 |
|
|
405 |
|
FILE *fp; |
406 |
|
{ |
407 |
|
if (h->dataType == IM_CMAP) { /* uncompressed */ |
408 |
< |
if (fwrite(d, h->x*sizeof(pixel), h->y, fp) != h->y) |
408 |
> |
if (fwrite((char *)d,h->x*sizeof(pixel),h->y,fp) != h->y) |
409 |
|
quiterr("error writing targa file"); |
410 |
|
return; |
411 |
|
} |
422 |
|
register pixel *dp; |
423 |
|
|
424 |
|
if (h->dataType == IM_CMAP) { /* uncompressed */ |
425 |
< |
if (fread(data, h->x*sizeof(pixel), h->y, fp) != h->y) |
425 |
> |
if (fread((char *)data,h->x*sizeof(pixel),h->y,fp) != h->y) |
426 |
|
goto readerr; |
427 |
|
return; |
428 |
|
} |