Re: 5551 Clipmap Textures

New Message Reply Date view Thread view Subject view Author view

Don Hatch (hatch++at++hell.engr.sgi.com)
Fri, 17 Apr 1998 14:39:07 -0700


On Apr 17, 11:46am, Lee, Karin S wrote:
> Subject: 5551 Clipmap Textures
> > Hi.
> >
> > This is probably a very simple question.
> >
> > We have quite a number of clipmaps in 5551 format. Supposedly,
> > that means there's 2 bytes per texel: 5 R, 5 G, 5 B, 1 A.
> > We need these textures in another format, preferably SGI RGB
> > or TIFF.
> >
> > Does anyone know of a tool that is capable of converting 5551
> > images? We located to5551 and viewtile (a viewer) on the SGI,
> > but nothing else. I'm a novice when it comes to texture
> > formats and the C programming language, and I do not want
> > to do something that's already been done, so writing my own tool
> > is my very last resort.
> >
> > Any help would be appreciated.
> >
> > -Karin

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

New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:57:15 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.