| 1 |
< |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
| 1 |
> |
/* Copyright (c) 1999 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
| 91 |
|
int xmax, ymax; /* picture dimensions */ |
| 92 |
|
int width, height; /* window size */ |
| 93 |
|
char *fname = NULL; /* input file name */ |
| 94 |
< |
FILE *fin = stdin; /* input file */ |
| 94 |
> |
FILE *fin = NULL; /* input file */ |
| 95 |
|
long *scanpos = NULL; /* scan line positions in file */ |
| 96 |
|
int cury = 0; /* current scan location */ |
| 97 |
|
|
| 143 |
|
int pid; |
| 144 |
|
|
| 145 |
|
progname = argv[0]; |
| 146 |
+ |
fin = stdin; |
| 147 |
|
|
| 148 |
|
for (i = 1; i < argc; i++) |
| 149 |
|
if (argv[i][0] == '-') |
| 251 |
|
} |
| 252 |
|
|
| 253 |
|
|
| 254 |
+ |
int |
| 255 |
|
headline(s) /* get relevant info from header */ |
| 256 |
|
char *s; |
| 257 |
|
{ |
| 263 |
|
wrongformat = strcmp(fmt, COLRFMT); |
| 264 |
|
else if (isview(s) && sscanview(&ourview, s) > 0) |
| 265 |
|
gotview++; |
| 266 |
+ |
return(0); |
| 267 |
|
} |
| 268 |
|
|
| 269 |
|
|
| 419 |
|
return(-1); |
| 420 |
|
if (v1->depth == 32 && v2->depth == 24) |
| 421 |
|
return(1); |
| 422 |
< |
return(0); |
| 422 |
> |
/* go for maximum depth otherwise */ |
| 423 |
> |
return(v2->depth - v1->depth); |
| 424 |
|
} |
| 425 |
|
/* don't be too greedy */ |
| 426 |
|
if (maxcolors <= 1<<v1->depth && maxcolors <= 1<<v2->depth) |
| 427 |
|
return(v1->depth - v2->depth); |
| 428 |
|
return(v2->depth - v1->depth); |
| 429 |
|
} |
| 430 |
< |
/* prefer Pseudo when < 24-bit */ |
| 430 |
> |
/* prefer Pseudo when < 15-bit */ |
| 431 |
|
if ((v1->class == TrueColor || v1->class == DirectColor) && |
| 432 |
< |
v1->depth < 24) |
| 432 |
> |
v1->depth < 15) |
| 433 |
|
bad1 = 1; |
| 434 |
|
if ((v2->class == TrueColor || v2->class == DirectColor) && |
| 435 |
< |
v2->depth < 24) |
| 435 |
> |
v2->depth < 15) |
| 436 |
|
bad2 = -1; |
| 437 |
|
if (bad1 | bad2) |
| 438 |
|
return(bad1+bad2); |
| 543 |
|
goto fail; |
| 544 |
|
getmono(); |
| 545 |
|
} else if (ourvis.class == TrueColor | ourvis.class == DirectColor) { |
| 546 |
< |
ourdata = (unsigned char *)malloc(sizeof(int4)*xmax*ymax); |
| 546 |
> |
int datsiz = ourvis.depth>16 ? sizeof(int4) : sizeof(int2); |
| 547 |
> |
ourdata = (unsigned char *)malloc(datsiz*xmax*ymax); |
| 548 |
|
if (ourdata == NULL) |
| 549 |
|
goto fail; |
| 550 |
< |
ourras = make_raster(thedisplay, &ourvis, sizeof(int4)*8, |
| 551 |
< |
ourdata, xmax, ymax, 32); |
| 550 |
> |
ourras = make_raster(thedisplay, &ourvis, datsiz*8, |
| 551 |
> |
ourdata, xmax, ymax, datsiz*8); |
| 552 |
|
if (ourras == NULL) |
| 553 |
|
goto fail; |
| 554 |
|
getfull(); |
| 1160 |
|
{ |
| 1161 |
|
int y; |
| 1162 |
|
register unsigned int4 *dp; |
| 1163 |
+ |
register unsigned int2 *dph; |
| 1164 |
|
register int x; |
| 1165 |
|
/* initialize tone mapping */ |
| 1166 |
|
make_tonemap(); |
| 1167 |
|
/* read and convert file */ |
| 1168 |
|
dp = (unsigned int4 *)ourdata; |
| 1169 |
+ |
dph = (unsigned int2 *)ourdata; |
| 1170 |
|
for (y = 0; y < ymax; y++) { |
| 1171 |
|
getscan(y); |
| 1172 |
|
add2icon(y, scanline); |
| 1173 |
|
tmap_colrs(scanline, xmax); |
| 1174 |
< |
if (ourras->image->blue_mask & 1) |
| 1174 |
> |
switch (ourras->image->blue_mask) { |
| 1175 |
> |
case 0xff: /* 24-bit RGB */ |
| 1176 |
|
for (x = 0; x < xmax; x++) |
| 1177 |
|
*dp++ = (unsigned int4)scanline[x][RED] << 16 | |
| 1178 |
|
(unsigned int4)scanline[x][GRN] << 8 | |
| 1179 |
|
(unsigned int4)scanline[x][BLU] ; |
| 1180 |
< |
else |
| 1180 |
> |
break; |
| 1181 |
> |
case 0xff0000: /* 24-bit BGR */ |
| 1182 |
|
for (x = 0; x < xmax; x++) |
| 1183 |
|
*dp++ = (unsigned int4)scanline[x][RED] | |
| 1184 |
|
(unsigned int4)scanline[x][GRN] << 8 | |
| 1185 |
|
(unsigned int4)scanline[x][BLU] << 16 ; |
| 1186 |
+ |
break; |
| 1187 |
+ |
#if 0 |
| 1188 |
+ |
case 0x1f: /* 15-bit RGB */ |
| 1189 |
+ |
for (x = 0; x < xmax; x++) |
| 1190 |
+ |
*dph++ = (scanline[x][RED] << 7 & 0x7c00) | |
| 1191 |
+ |
(scanline[x][GRN] << 2 & 0x3e0) | |
| 1192 |
+ |
(unsigned)scanline[x][BLU] >> 3 ; |
| 1193 |
+ |
break; |
| 1194 |
+ |
case 0x7c00: /* 15-bit BGR */ |
| 1195 |
+ |
for (x = 0; x < xmax; x++) |
| 1196 |
+ |
*dph++ = (unsigned)scanline[x][RED] >> 3 | |
| 1197 |
+ |
(scanline[x][GRN] << 2 & 0x3e0) | |
| 1198 |
+ |
(scanline[x][BLU] << 7 & 0x7c00) ; |
| 1199 |
+ |
break; |
| 1200 |
+ |
#endif |
| 1201 |
+ |
default: /* unknown */ |
| 1202 |
+ |
if (ourvis.depth > 16) |
| 1203 |
+ |
for (x = 0; x < xmax; x++) { |
| 1204 |
+ |
*dp = ourras->image->red_mask & |
| 1205 |
+ |
ourras->image->red_mask*scanline[x][RED]/255; |
| 1206 |
+ |
*dp |= ourras->image->green_mask & |
| 1207 |
+ |
ourras->image->green_mask*scanline[x][GRN]/255; |
| 1208 |
+ |
*dp++ |= ourras->image->blue_mask & |
| 1209 |
+ |
ourras->image->blue_mask*scanline[x][BLU]/255; |
| 1210 |
+ |
} |
| 1211 |
+ |
else |
| 1212 |
+ |
for (x = 0; x < xmax; x++) { |
| 1213 |
+ |
*dph = ourras->image->red_mask & |
| 1214 |
+ |
ourras->image->red_mask*scanline[x][RED]/255; |
| 1215 |
+ |
*dph |= ourras->image->green_mask & |
| 1216 |
+ |
ourras->image->green_mask*scanline[x][GRN]/255; |
| 1217 |
+ |
*dph++ |= ourras->image->blue_mask & |
| 1218 |
+ |
ourras->image->blue_mask*scanline[x][BLU]/255; |
| 1219 |
+ |
} |
| 1220 |
+ |
break; |
| 1221 |
+ |
} |
| 1222 |
|
} |
| 1223 |
|
} |
| 1224 |
|
|