Don Hatch (hatch++at++hell.engr.sgi.com)
Fri, 17 Apr 1998 14:39:07 -0700
Here's a from5551 program we had lying around...
Don
/*
* Compile with:
cc from5551.c -o from5551 -limage
*/
#include "gl/image.h"
#include "malloc.h"
unsigned short rbuf[8192];
unsigned short gbuf[8192];
unsigned short bbuf[8192];
unsigned short packed[8192];
/*
** Convert a 5551 image into rgb format
*/
main(argc,argv)
int argc;
char **argv;
{
IMAGE *image;
FILE *input;
int x, y, xsize, ysize;
int z, zsize;
ushort* img;
if( argc != 5 ) {
fprintf(stderr,
"usage: %s inimage.5551 outimage.rgb xsize ysize\n", argv[0]);
exit(1);
}
if((input=fopen(argv[1],"r")) == NULL ) {
fprintf(stderr,"%s: can't open input file %s\n", argv[0], argv[1]);
exit(1);
}
if ((image = iopen(argv[2], "w", 1, 3, atoi(argv[3]), atoi(argv[4]), 3)) == NULL) {
fprintf(stderr,"%s: can't open output file %s\n", argv[0], argv[2]);
exit(2);
}
xsize = atoi(argv[3]);
ysize = atoi(argv[4]);
zsize = 3;
img = (ushort*)malloc(2*xsize*ysize);
if (fread(img, 2, xsize*ysize, input) != xsize*ysize)
{
fprintf(stderr,"%s: couldn't read %d texels from file %s\n",
argv[0], xsize*ysize, argv[1]);
exit(1);
}
fclose(input);
for(y=0; y<ysize; y++)
{
for(x=0;x<xsize;x++)
{
/* [r:15..11][g:10..6][b:5..1][a:0] */
int r5 = (img[y*xsize + x]>>11)&31;
int g5 = (img[y*xsize + x]>>6)&31;
int b5 = (img[y*xsize + x]>>1)&31;
rbuf[x] = (r5<<3)|(r5>>2);
gbuf[x] = (g5<<3)|(g5>>2);
bbuf[x] = (b5<<3)|(b5>>2);
}
putrow(image,rbuf,y,0);
putrow(image,gbuf,y,1);
putrow(image,bbuf,y,2);
}
iclose(image);
exit(0);
}
--
Don Hatch hatch++at++sgi.com (415) 933-5150 Silicon Graphics, Inc.
=======================================================================
List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer/
Submissions: info-performer++at++sgi.com
Admin. requests: info-performer-request++at++sgi.com
This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:57:15 PDT