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 */ |
59 |
|
|
60 |
|
char errmsg[128]; |
61 |
|
|
62 |
< |
COLR *inline; |
62 |
> |
COLR *inl; |
63 |
|
|
64 |
|
pixel *tarData; |
65 |
|
|
124 |
|
quiterr(errmsg); |
125 |
|
} |
126 |
|
/* put header */ |
127 |
< |
printargs(argc, argv, stdout); |
127 |
> |
printargs(i, argv, stdout); |
128 |
> |
fputformat(COLRFMT, stdout); |
129 |
|
putchar('\n'); |
130 |
|
fputresolu(YMAJOR|YDECR, xmax, ymax, stdout); |
131 |
|
/* convert file */ |
232 |
|
|
233 |
|
if (ip != NULL) |
234 |
|
if (nidbytes) |
235 |
< |
fread(ip, nidbytes, 1, fp); |
235 |
> |
fread((char *)ip, nidbytes, 1, fp); |
236 |
|
else |
237 |
|
*ip = '\0'; |
238 |
|
else if (nidbytes) |
283 |
|
p->fp = stdin; |
284 |
|
else if ((p->fp = fopen(fname, "r")) == NULL) |
285 |
|
return(NULL); |
286 |
< |
/* discard header */ |
287 |
< |
getheader(p->fp, NULL); |
288 |
< |
if (fgetresolu(&xmax, &ymax, p->fp) != (YMAJOR|YDECR)) |
289 |
< |
quiterr("bad picture size"); |
286 |
> |
/* get header info. */ |
287 |
> |
if (checkheader(p->fp, COLRFMT, NULL) < 0 || |
288 |
> |
fgetresolu(&xmax, &ymax, p->fp) != (YMAJOR|YDECR)) |
289 |
> |
quiterr("bad picture format"); |
290 |
|
p->nexty = 0; |
291 |
|
p->bytes_line = 0; /* variable length lines */ |
292 |
|
p->pos.y = (long *)ecalloc(ymax, sizeof(long)); |
305 |
|
h->dataBits = 8; |
306 |
|
h->imType = 0; |
307 |
|
/* allocate scanline */ |
308 |
< |
inline = (COLR *)emalloc(xmax*sizeof(COLR)); |
308 |
> |
inl = (COLR *)emalloc(xmax*sizeof(COLR)); |
309 |
|
/* allocate targa data */ |
310 |
|
tarData = taralloc(h); |
311 |
|
|
325 |
|
register int i, j; |
326 |
|
|
327 |
|
/* get color table */ |
328 |
< |
if ((hp->CMapBits==24 ? fread(map.c3, sizeof(map.c3), 1, stdin) : |
329 |
< |
fread(map.c4, sizeof(map.c4), 1, stdin)) != 1) |
328 |
> |
if ((hp->CMapBits==24 ? fread((char *)map.c3,sizeof(map.c3),1,stdin) : |
329 |
> |
fread((char *)map.c4,sizeof(map.c4),1,stdin)) != 1) |
330 |
|
quiterr("error reading color table"); |
331 |
|
/* convert table */ |
332 |
|
for (i = hp->mapOrig; i < hp->mapOrig+hp->mapLength; i++) |
369 |
|
if (inpic->bytes_line == 0) { |
370 |
|
if (inpic->pos.y[y] == 0) { |
371 |
|
while (inpic->nexty < y) { |
372 |
< |
if (freadcolrs(inline, xmax, inpic->fp) < 0) |
372 |
> |
if (freadcolrs(inl, xmax, inpic->fp) < 0) |
373 |
|
quiterr("read error in picreadline3"); |
374 |
|
inpic->pos.y[++inpic->nexty] = ftell(inpic->fp); |
375 |
|
} |
379 |
|
quiterr("seek error in picreadline3"); |
380 |
|
} else if (inpic->bytes_line == 0 && inpic->pos.y[inpic->nexty] == 0) |
381 |
|
inpic->pos.y[inpic->nexty] = ftell(inpic->fp); |
382 |
< |
if (freadcolrs(inline, xmax, inpic->fp) < 0) /* read scanline */ |
382 |
> |
if (freadcolrs(inl, xmax, inpic->fp) < 0) /* read scanline */ |
383 |
|
quiterr("read error in picreadline3"); |
384 |
|
inpic->nexty = y+1; |
385 |
|
/* convert scanline */ |
386 |
< |
normcolrs(inline, xmax); |
386 |
> |
normcolrs(inl, xmax, 0); |
387 |
|
for (i = 0; i < xmax; i++) { |
388 |
< |
l3[i].r = inline[i][RED]; |
389 |
< |
l3[i].g = inline[i][GRN]; |
390 |
< |
l3[i].b = inline[i][BLU]; |
388 |
> |
l3[i].r = inl[i][RED]; |
389 |
> |
l3[i].g = inl[i][GRN]; |
390 |
> |
l3[i].b = inl[i][BLU]; |
391 |
|
} |
392 |
|
} |
393 |
|
|
396 |
|
int y; |
397 |
|
pixel *l; |
398 |
|
{ |
399 |
< |
bcopy(l, &tarData[(ymax-1-y)*xmax], xmax*sizeof(pixel)); |
399 |
> |
bcopy((char *)l, (char *)&tarData[(ymax-1-y)*xmax], xmax*sizeof(pixel)); |
400 |
|
} |
401 |
|
|
402 |
|
|
406 |
|
FILE *fp; |
407 |
|
{ |
408 |
|
if (h->dataType == IM_CMAP) { /* uncompressed */ |
409 |
< |
if (fwrite(d, h->x*sizeof(pixel), h->y, fp) != h->y) |
409 |
> |
if (fwrite((char *)d,h->x*sizeof(pixel),h->y,fp) != h->y) |
410 |
|
quiterr("error writing targa file"); |
411 |
|
return; |
412 |
|
} |
423 |
|
register pixel *dp; |
424 |
|
|
425 |
|
if (h->dataType == IM_CMAP) { /* uncompressed */ |
426 |
< |
if (fread(data, h->x*sizeof(pixel), h->y, fp) != h->y) |
426 |
> |
if (fread((char *)data,h->x*sizeof(pixel),h->y,fp) != h->y) |
427 |
|
goto readerr; |
428 |
|
return; |
429 |
|
} |
466 |
|
register int i, val; |
467 |
|
|
468 |
|
for (i = 0; i < 256; i++) { |
469 |
< |
val = pow(i/256.0, 1.0/gamma) * 256.0; |
469 |
> |
val = pow((i+0.5)/256.0, 1.0/gamma) * 256.0; |
470 |
|
map[0][i] = map[1][i] = map[2][i] = val; |
471 |
|
} |
472 |
|
} |