Thanks Neko. You really are the one who (by example) sets the
helpful
tone for this entire forum.
It took me a bit of research, but I did the conversion manually (at least as far as my needs go).
Here is a smal
pasted-together
excerpt from my (ANSI C !!) code that gives the general idea:
It uses the
iopen
function that is provided with all SGI systems (see
man rgb
) and is linked in using -limage.
This I/O library seems to date back to when the RGB format was first created at SGI, and even the support techs have forgotten about it.
Code:
Select all
#include <gl/image.h>
#define PIXMAP_WD 100
#define PIXMAP_HT 100
#define BUFSIZE 4*PIXMAP_WD*PIXMAP_HT
Pixmap *rgbToPixmap( Widget w, char *fname ) {
int cc, x, y, z, offset, bitmap_pad, bytes_per_line;
unsigned int icon_w, icon_h, depth;
IMAGE *sgi_image;
short *rbuf, *gbuf, *bbuf;
char *zbuf;
XImage *ximg;
Pixmap icon_pixmap;
GC gc;
XGCValues gcvalues;
Display *dpy;
Window root_win;
dpy = XtDisplay(w);
root_win = RootWindowOfScreen( XtScreen( w ) );
XtVaGetValues( w, XmNdepth, &depth, NULL );
icon_pixmap = XCreatePixmap( dpy, root_win, PIXMAP_WD, PIXMAP_HT, depth );
gc = XtGetGC( w, GCForeground | GCBackground, &gcvalues );
sgi_image = iopen(fname,"r");
printf("geticon: converting SGI RGB format file %s\n",fname);
printf("Image x and y size in pixels: %d,%d\n",sgi_image->xsize,sgi_image->ysize);
printf("Image zsize in channels: %d\n",sgi_image->zsize);
printf("Image pixel min and max: %d %d\n",sgi_image->min,sgi_image->max);
/* this assumes zsize is 3 (RGB) but it could be 1 (B&W) or 4 (RGBA) */
zbuf = (char *)malloc(BUFSIZE*sizeof(short));
bzero( zbuf, BUFSIZE*sizeof(short) );
rbuf = (short *)malloc(sgi_image->xsize*sizeof(short));
gbuf = (short *)malloc(sgi_image->xsize*sizeof(short));
bbuf = (short *)malloc(sgi_image->xsize*sizeof(short));
z = 0;
for (y=sgi_image->ysize-1;y>=0;y--) {
getrow(sgi_image,rbuf,y,0);
getrow(sgi_image,gbuf,y,1);
getrow(sgi_image,bbuf,y,2);
for (x=0;x<sgi_image->xsize;x++) {
zbuf[z++] = (char)rbuf[x]; /* red (0-255) */
zbuf[z++] = (char)gbuf[x]; /* green (0-255) */
zbuf[z++] = (char)bbuf[x]; /* blue (0-255) */
zbuf[z++] = 255; /* alpha (0-255) */
}
}
/* create an XImage from the SGI RGB data */
offset = 0;
bitmap_pad = 32;
bytes_per_line = 0;
/* NOTE: this may not work if the default visual is not 24bit !! */
icon_w = sgi_image->xsize;
icon_h = sgi_image->ysize;
ximg = XCreateImage( dpy, DefaultVisual( dpy, DefaultScreen(dpy) ),
DefaultDepth( dpy, DefaultScreen(dpy) ), ZPixmap,
offset, zbuf, icon_w, icon_h, bitmap_pad, bytes_per_line );
ximg->byte_order = LSBFirst;
/* write the XImage to a Pixmap for displaying on a widget */
XPutImage( dpy, icon_pixmap, gc, ximg, 0, 0,
(unsigned int)x_off, (unsigned int)y_off, icon_w, icon_h );
/* to save it to an XPM file you need the Xpm library and would first */
/* set up XpmAtrributes and then call XpmWriteFileFromPixmap(... ) */
return( &icon_pixmap );
}
As a side note, my iconbar app is really coming along. I have worked out a method for getting the application pixmaps that even the X Windows gurus said couldn't be done! I hope to have an alpha test version out in less than a week.